proto.io 0.0.153 → 0.0.155
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/database.d.ts +2 -2
- package/dist/adapters/file/filesystem.d.ts +2 -2
- package/dist/adapters/file/google-cloud-storage.d.ts +2 -2
- package/dist/adapters/storage/progres.d.ts +11 -7
- package/dist/adapters/storage/progres.js +55 -14
- package/dist/adapters/storage/progres.js.map +1 -1
- package/dist/adapters/storage/progres.mjs +55 -14
- package/dist/adapters/storage/progres.mjs.map +1 -1
- package/dist/client.d.ts +3 -3
- package/dist/client.js +1 -1
- package/dist/client.mjs +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +64 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -32
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{index-c-CaNuVY.mjs → index-B01TqoO1.mjs} +19 -4
- package/dist/internals/index-B01TqoO1.mjs.map +1 -0
- package/dist/internals/{index-m4WmZoWj.d.ts → index-BLVOKfv3.d.ts} +17 -6
- package/dist/internals/index-BLVOKfv3.d.ts.map +1 -0
- package/dist/internals/{index-D1YGwuNK.js → index-Bs06MNCK.js} +19 -4
- package/dist/internals/index-Bs06MNCK.js.map +1 -0
- package/dist/internals/{index-DeD3CiUK.d.ts → index-DSU589g6.d.ts} +2 -2
- package/dist/internals/index-DSU589g6.d.ts.map +1 -0
- package/dist/internals/{index-DQm5Xz3Q.d.ts → index-DmcvF1dx.d.ts} +3 -2
- package/dist/internals/index-DmcvF1dx.d.ts.map +1 -0
- package/dist/internals/{random-KZTFMK9-.mjs → random-DXre8Q46.mjs} +11 -1
- package/dist/internals/random-DXre8Q46.mjs.map +1 -0
- package/dist/internals/{random-DBDmz54D.js → random-DfnhGdY1.js} +11 -1
- package/dist/internals/random-DfnhGdY1.js.map +1 -0
- package/package.json +1 -1
- package/dist/internals/index-D1YGwuNK.js.map +0 -1
- package/dist/internals/index-DQm5Xz3Q.d.ts.map +0 -1
- package/dist/internals/index-DeD3CiUK.d.ts.map +0 -1
- package/dist/internals/index-c-CaNuVY.mjs.map +0 -1
- package/dist/internals/index-m4WmZoWj.d.ts.map +0 -1
- package/dist/internals/random-DBDmz54D.js.map +0 -1
- package/dist/internals/random-KZTFMK9-.mjs.map +0 -1
|
@@ -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/index-
|
|
1
|
+
import { T as TSchema, P as ProtoService } from '../../internals/index-BLVOKfv3.js';
|
|
2
|
+
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-DSU589g6.js';
|
|
3
3
|
import '@o2ter/utils-js';
|
|
4
4
|
import 'jsonwebtoken';
|
|
5
5
|
import '@o2ter/server-js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as ProtoService } from '../../internals/index-
|
|
2
|
-
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-
|
|
1
|
+
import { P as ProtoService } from '../../internals/index-BLVOKfv3.js';
|
|
2
|
+
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-DSU589g6.js';
|
|
3
3
|
import '@o2ter/utils-js';
|
|
4
4
|
import 'jsonwebtoken';
|
|
5
5
|
import '@o2ter/server-js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _google_cloud_storage from '@google-cloud/storage';
|
|
2
2
|
import { Storage } from '@google-cloud/storage';
|
|
3
|
-
import { P as ProtoService } from '../../internals/index-
|
|
4
|
-
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-
|
|
3
|
+
import { P as ProtoService } from '../../internals/index-BLVOKfv3.js';
|
|
4
|
+
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-DSU589g6.js';
|
|
5
5
|
import '@o2ter/utils-js';
|
|
6
6
|
import 'jsonwebtoken';
|
|
7
7
|
import '@o2ter/server-js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Pool, PoolClient, PoolConfig } from 'pg';
|
|
2
|
-
import { _ as _TValue, n as EventData, T as TSchema, o as DecodedQuery, F as FindOptions, Q as QuerySelector, p as DecodedSortOption, I as InsertOptions, q as TValue, r as FindOneOptions, t as TUpdateOp, u as FieldSelectorExpression, v as QueryExpression, w as TStorage, x as TransactionOptions, h as TObject, y as TQueryRandomOptions, z as TPubSub } from '../../internals/index-
|
|
2
|
+
import { _ as _TValue, n as EventData, T as TSchema, o as DecodedQuery, F as FindOptions, R as RelationOptions, Q as QuerySelector, p as DecodedSortOption, I as InsertOptions, q as TValue, r as FindOneOptions, t as TUpdateOp, u as FieldSelectorExpression, v as QueryExpression, w as TStorage, x as TransactionOptions, h as TObject, y as TQueryRandomOptions, z as TPubSub } from '../../internals/index-BLVOKfv3.js';
|
|
3
3
|
import * as _o2ter_utils_js from '@o2ter/utils-js';
|
|
4
4
|
import { asyncStream } from '@o2ter/utils-js';
|
|
5
5
|
import 'jsonwebtoken';
|
|
@@ -85,7 +85,7 @@ declare class QueryCompiler {
|
|
|
85
85
|
private _encodeIncludes;
|
|
86
86
|
private _baseSelectQuery;
|
|
87
87
|
private _refetch;
|
|
88
|
-
_selectQuery(query: DecodedQuery<FindOptions>, options?: _SelectOptions | ((x: {
|
|
88
|
+
_selectQuery(query: DecodedQuery<FindOptions & RelationOptions>, options?: _SelectOptions | ((x: {
|
|
89
89
|
fetchName: string;
|
|
90
90
|
}) => _SelectOptions)): SQL;
|
|
91
91
|
private _modifyQuery;
|
|
@@ -134,6 +134,10 @@ interface SqlDialect {
|
|
|
134
134
|
className: string;
|
|
135
135
|
name: string;
|
|
136
136
|
}): Record<string, SQL>;
|
|
137
|
+
encodeRelation(compiler: QueryCompiler, context: CompileContext, parent: {
|
|
138
|
+
className: string;
|
|
139
|
+
name: string;
|
|
140
|
+
}, relatedBy: NonNullable<RelationOptions['relatedBy']>): SQL;
|
|
137
141
|
encodeSortKey(compiler: QueryCompiler, parent: {
|
|
138
142
|
className?: string;
|
|
139
143
|
name: string;
|
|
@@ -188,13 +192,13 @@ declare abstract class SqlStorage implements TStorage {
|
|
|
188
192
|
protected abstract _query(text: string, values: any[]): ReturnType<typeof asyncStream<any>>;
|
|
189
193
|
abstract _refs(schema: Record<string, TSchema>, className: string, keys: string[], item: SQL): SQL;
|
|
190
194
|
query(sql: SQL): _o2ter_utils_js.AsyncStream<any>;
|
|
191
|
-
abstract _explain(compiler: QueryCompiler, query: DecodedQuery<FindOptions>): PromiseLike<any>;
|
|
195
|
+
abstract _explain(compiler: QueryCompiler, query: DecodedQuery<FindOptions & RelationOptions>): PromiseLike<any>;
|
|
192
196
|
private _decodeShapedObject;
|
|
193
197
|
protected _decodeObject(className: string, attrs: Record<string, any>): TObject;
|
|
194
|
-
explain(query: DecodedQuery<FindOptions>): Promise<any>;
|
|
195
|
-
count(query: DecodedQuery<FindOptions>): Promise<number>;
|
|
196
|
-
find(query: DecodedQuery<FindOptions>): AsyncGenerator<TObject, void, unknown>;
|
|
197
|
-
random(query: DecodedQuery<FindOptions>, opts?: TQueryRandomOptions): AsyncGenerator<TObject, void, unknown>;
|
|
198
|
+
explain(query: DecodedQuery<FindOptions & RelationOptions>): Promise<any>;
|
|
199
|
+
count(query: DecodedQuery<FindOptions & RelationOptions>): Promise<number>;
|
|
200
|
+
find(query: DecodedQuery<FindOptions & RelationOptions>): AsyncGenerator<TObject, void, unknown>;
|
|
201
|
+
random(query: DecodedQuery<FindOptions & RelationOptions>, opts?: TQueryRandomOptions): AsyncGenerator<TObject, void, unknown>;
|
|
198
202
|
refs(object: TObject, classNames: string[], roles?: string[]): AsyncGenerator<TObject, void, unknown>;
|
|
199
203
|
nonrefs(query: DecodedQuery<FindOptions>): AsyncGenerator<TObject, void, unknown>;
|
|
200
204
|
insert(options: InsertOptions, attrs: Record<string, TValue>): Promise<TObject | undefined>;
|
|
@@ -11,7 +11,7 @@ var Decimal = require('decimal.js');
|
|
|
11
11
|
var utils = require('pg/lib/utils');
|
|
12
12
|
var index$1 = require('../../internals/index-CSNRyhjB.js');
|
|
13
13
|
require('@o2ter/crypto-js');
|
|
14
|
-
var random$1 = require('../../internals/random-
|
|
14
|
+
var random$1 = require('../../internals/random-DfnhGdY1.js');
|
|
15
15
|
var _private = require('../../internals/private-CSB1Ep4g.js');
|
|
16
16
|
|
|
17
17
|
//
|
|
@@ -286,35 +286,38 @@ class QueryCompiler {
|
|
|
286
286
|
}
|
|
287
287
|
_baseSelectQuery(query, options) {
|
|
288
288
|
const context = this._makeContext(query);
|
|
289
|
-
const
|
|
290
|
-
const stages = _.fromPairs(_.flatMap(_.values(
|
|
289
|
+
const _stages = _.mapValues(context.populates, (populate) => this.dialect.encodePopulate(this, context, populate));
|
|
290
|
+
const stages = _.fromPairs(_.flatMap(_.values(_stages), (p) => _.toPairs(p)));
|
|
291
291
|
const fetchName = `_fetch_$${query.className.toLowerCase()}`;
|
|
292
|
-
const
|
|
293
|
-
const
|
|
294
|
-
const
|
|
295
|
-
const
|
|
292
|
+
const parent = { className: query.className, name: fetchName };
|
|
293
|
+
const baseFilter = this._encodeFilter(context, parent, query.filter);
|
|
294
|
+
const populates = this._selectPopulateMap(context, query.className, fetchName);
|
|
295
|
+
const joins = _.compact(_.map(populates, ({ join }) => join));
|
|
296
|
+
const includes = {
|
|
296
297
|
literal: [
|
|
297
298
|
...this._selectIncludes(fetchName, context.includes),
|
|
298
|
-
..._.flatMap(
|
|
299
|
+
..._.flatMap(populates, ({ columns }) => columns),
|
|
299
300
|
],
|
|
300
301
|
separator: ',\n',
|
|
301
302
|
};
|
|
302
303
|
const _options = _.isFunction(options) ? options({ fetchName }) : options;
|
|
304
|
+
const filter = _.compact([
|
|
305
|
+
baseFilter,
|
|
306
|
+
_options?.extraFilter,
|
|
307
|
+
query.relatedBy && this.dialect.encodeRelation(this, context, parent, query.relatedBy),
|
|
308
|
+
]);
|
|
303
309
|
return {
|
|
304
310
|
stages,
|
|
305
311
|
fetchName,
|
|
306
312
|
context: context,
|
|
307
313
|
query: sql `
|
|
308
314
|
SELECT ${_options?.select ? _options?.select : sql `*`} FROM (
|
|
309
|
-
SELECT ${
|
|
315
|
+
SELECT ${includes}
|
|
310
316
|
FROM ${{ identifier: query.className }} AS ${{ identifier: fetchName }}
|
|
311
|
-
${!_.isEmpty(
|
|
317
|
+
${!_.isEmpty(joins) ? { literal: joins, separator: '\n' } : sql ``}
|
|
312
318
|
${this.selectLock ? this.isUpdate ? sql `FOR UPDATE NOWAIT` : sql `FOR SHARE NOWAIT` : sql ``}
|
|
313
319
|
) AS ${{ identifier: fetchName }}
|
|
314
|
-
${
|
|
315
|
-
literal: _.map(_.compact([_filter, _options?.extraFilter]), x => sql `(${x})`),
|
|
316
|
-
separator: ' AND '
|
|
317
|
-
}}` : sql ``}
|
|
320
|
+
${!_.isEmpty(filter) ? sql `WHERE ${{ literal: _.map(filter, x => sql `(${x})`), separator: ' AND ' }}` : sql ``}
|
|
318
321
|
${_options?.sort ? _options?.sort : sql ``}
|
|
319
322
|
${!_.isEmpty(query.sort) ? sql `ORDER BY ${this._encodeSort(query.sort, { className: query.className, name: fetchName })}` : sql ``}
|
|
320
323
|
${query.limit ? sql `LIMIT ${{ literal: `${query.limit}` }}` : sql ``}
|
|
@@ -2293,6 +2296,43 @@ const encodePopulate = (compiler, context, parent, remix) => {
|
|
|
2293
2296
|
});
|
|
2294
2297
|
};
|
|
2295
2298
|
|
|
2299
|
+
//
|
|
2300
|
+
// relation.ts
|
|
2301
|
+
//
|
|
2302
|
+
// The MIT License
|
|
2303
|
+
// Copyright (c) 2021 - 2024 O2ter Limited. All rights reserved.
|
|
2304
|
+
//
|
|
2305
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
2306
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
2307
|
+
// in the Software without restriction, including without limitation the rights
|
|
2308
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
2309
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
2310
|
+
// furnished to do so, subject to the following conditions:
|
|
2311
|
+
//
|
|
2312
|
+
// The above copyright notice and this permission notice shall be included in
|
|
2313
|
+
// all copies or substantial portions of the Software.
|
|
2314
|
+
//
|
|
2315
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
2316
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
2317
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
2318
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
2319
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
2320
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
2321
|
+
// THE SOFTWARE.
|
|
2322
|
+
//
|
|
2323
|
+
const encodeRelation = (compiler, context, parent, relatedBy) => {
|
|
2324
|
+
const name = `_relation_$${relatedBy.className.toLowerCase()}`;
|
|
2325
|
+
const _local = (field) => sql `${{ identifier: parent.name }}.${{ identifier: field }}`;
|
|
2326
|
+
const _foreign = (field) => sql `${{ identifier: name }}.${{ identifier: field }}`;
|
|
2327
|
+
return sql `
|
|
2328
|
+
EXISTS (
|
|
2329
|
+
SELECT 1
|
|
2330
|
+
FROM ${{ identifier: relatedBy.className }} AS ${{ identifier: name }}
|
|
2331
|
+
WHERE ${_foreign('_id')} = ${{ value: relatedBy.objectId }} AND ${sql `(${{ quote: parent.className + '$' }} || ${_local('_id')})`} = ANY(${_foreign(relatedBy.key)})
|
|
2332
|
+
)
|
|
2333
|
+
`;
|
|
2334
|
+
};
|
|
2335
|
+
|
|
2296
2336
|
//
|
|
2297
2337
|
// index.ts
|
|
2298
2338
|
//
|
|
@@ -2329,6 +2369,7 @@ const PostgresDialect = {
|
|
|
2329
2369
|
encodeFieldExpression,
|
|
2330
2370
|
encodeQueryExpression,
|
|
2331
2371
|
encodePopulate,
|
|
2372
|
+
encodeRelation,
|
|
2332
2373
|
encodeSortKey,
|
|
2333
2374
|
random,
|
|
2334
2375
|
};
|