proto.io 0.0.205 → 0.0.207
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 +2 -2
- package/dist/adapters/file/database.mjs.map +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 +9 -20
- package/dist/adapters/storage/progres.js +28 -109
- package/dist/adapters/storage/progres.js.map +1 -1
- package/dist/adapters/storage/progres.mjs +28 -109
- package/dist/adapters/storage/progres.mjs.map +1 -1
- package/dist/client.d.ts +3 -3
- package/dist/client.js +2 -1
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +3 -2
- package/dist/client.mjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +45 -109
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46 -110
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{base-Cf7WkDhO.d.ts → base-DHkvlTFy.d.ts} +2 -2
- package/dist/internals/base-DHkvlTFy.d.ts.map +1 -0
- package/dist/internals/{chunk-ONaLyXL0.d.ts → chunk-C7kDLOLD.d.ts} +3 -3
- package/dist/internals/chunk-C7kDLOLD.d.ts.map +1 -0
- package/dist/internals/{index-DByHjIHI.js → index-BRzKDwPs.js} +64 -22
- package/dist/internals/index-BRzKDwPs.js.map +1 -0
- package/dist/internals/{index-DI-jPA6f.d.ts → index-CKcESGqE.d.ts} +3 -3
- package/dist/internals/index-CKcESGqE.d.ts.map +1 -0
- package/dist/internals/{index-C4vwSN74.js → index-CkAvNaAe.js} +240 -1
- package/dist/internals/index-CkAvNaAe.js.map +1 -0
- package/dist/internals/{index-DtCgllhg.mjs → index-DAkcqabS.mjs} +64 -22
- package/dist/internals/index-DAkcqabS.mjs.map +1 -0
- package/dist/internals/{index-Blw7vAq5.mjs → index-DlY33lfO.mjs} +240 -1
- package/dist/internals/index-DlY33lfO.mjs.map +1 -0
- package/dist/internals/{index-JdEs5VLY.d.ts → index-PLz89AWF.d.ts} +23 -31
- package/dist/internals/index-PLz89AWF.d.ts.map +1 -0
- package/dist/internals/{random-Dk3OhDNU.js → random-B0V0EnjP.js} +2 -2
- package/dist/internals/random-B0V0EnjP.js.map +1 -0
- package/dist/internals/{random-6nHcBOxn.mjs → random-ZgzzM5v_.mjs} +2 -2
- package/dist/internals/random-ZgzzM5v_.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/internals/base-Cf7WkDhO.d.ts.map +0 -1
- package/dist/internals/chunk-ONaLyXL0.d.ts.map +0 -1
- package/dist/internals/index-Blw7vAq5.mjs.map +0 -1
- package/dist/internals/index-C4vwSN74.js.map +0 -1
- package/dist/internals/index-DByHjIHI.js.map +0 -1
- package/dist/internals/index-DI-jPA6f.d.ts.map +0 -1
- package/dist/internals/index-DtCgllhg.mjs.map +0 -1
- package/dist/internals/index-JdEs5VLY.d.ts.map +0 -1
- package/dist/internals/random-6nHcBOxn.mjs.map +0 -1
- package/dist/internals/random-Dk3OhDNU.js.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import { Server } from '@o2ter/server-js';
|
|
3
|
-
import { Q as QueryValidator, r as resolveColumn, a as resolveDataType, g as generateId } from './internals/random-
|
|
3
|
+
import { Q as QueryValidator, r as resolveColumn, a as resolveDataType, g as generateId } from './internals/random-ZgzzM5v_.mjs';
|
|
4
4
|
import { P as PVK } from './internals/private-CNw40LZ7.mjs';
|
|
5
5
|
import { asyncStream, prototypes, isBinaryData, base64ToBuffer } from '@o2ter/utils-js';
|
|
6
|
-
import { T as TQuery, d as deserialize, P as PROTO_NOTY_MSG, M as MASTER_USER_HEADER_NAME, a as MASTER_PASS_HEADER_NAME, A as AUTH_COOKIE_KEY, b as TUser, c as ProtoType, s as serialize, U as UPLOAD_TOKEN_HEADER_NAME } from './internals/index-
|
|
7
|
-
export { e as ProtoClient, f as classExtends, k as isFile, l as isJob, g as isObject, i as isQuery, j as isRole, h as isUser } from './internals/index-
|
|
6
|
+
import { T as TQuery, d as deserialize, P as PROTO_NOTY_MSG, M as MASTER_USER_HEADER_NAME, a as MASTER_PASS_HEADER_NAME, A as AUTH_COOKIE_KEY, b as TUser, c as ProtoType, s as serialize, U as UPLOAD_TOKEN_HEADER_NAME } from './internals/index-DAkcqabS.mjs';
|
|
7
|
+
export { e as ProtoClient, f as classExtends, k as isFile, l as isJob, g as isObject, i as isQuery, j as isRole, h as isUser } from './internals/index-DAkcqabS.mjs';
|
|
8
8
|
import { i as isPointer, a as isRelation, T as TObject, b as isShape, d as defaultObjectKeyTypes, c as isPrimitive } from './internals/index-al1N-qi7.mjs';
|
|
9
9
|
import jwt from 'jsonwebtoken';
|
|
10
10
|
import { Blob } from 'node:buffer';
|
|
@@ -13,7 +13,7 @@ import { scrypt } from 'node:crypto';
|
|
|
13
13
|
import { promisify } from 'util';
|
|
14
14
|
import { randomBytes, randomUUID } from '@o2ter/crypto-js';
|
|
15
15
|
export { Decimal } from 'decimal.js';
|
|
16
|
-
import { Q as QuerySelector } from './internals/index-
|
|
16
|
+
import { Q as QuerySelector } from './internals/index-DlY33lfO.mjs';
|
|
17
17
|
import queryType from 'query-types';
|
|
18
18
|
import busboy from 'busboy';
|
|
19
19
|
import 'axios';
|
|
@@ -85,6 +85,7 @@ const dispatcher = (proto, options) => {
|
|
|
85
85
|
master: options.master ?? false,
|
|
86
86
|
disableSecurity: options.disableSecurity,
|
|
87
87
|
});
|
|
88
|
+
const createFile = options.createFile;
|
|
88
89
|
return {
|
|
89
90
|
async explain(query) {
|
|
90
91
|
QueryValidator.recursiveCheck(query);
|
|
@@ -131,35 +132,9 @@ const dispatcher = (proto, options) => {
|
|
|
131
132
|
throw Error('No permission');
|
|
132
133
|
return proto.storage.random(decoded, opts);
|
|
133
134
|
},
|
|
134
|
-
async insert(options,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
_validator.validateCountMatches(options.className, options.countMatches ?? []);
|
|
138
|
-
const _includes = _validator.decodeIncludes(options.className, options.includes ?? ['*']);
|
|
139
|
-
const _matches = _validator.decodeMatches(options.className, options.matches ?? {}, _includes);
|
|
140
|
-
if (!_validator.validateCLPs(options.className, 'create'))
|
|
141
|
-
throw Error('No permission');
|
|
142
|
-
const _attrs = normalize(_validator.validateFields(options.className, attrs, 'create', QueryValidator.patterns.path));
|
|
143
|
-
while (true) {
|
|
144
|
-
try {
|
|
145
|
-
return await proto.storage.atomic((storage) => storage.insert({
|
|
146
|
-
className: options.className,
|
|
147
|
-
includes: _includes,
|
|
148
|
-
matches: _matches,
|
|
149
|
-
countMatches: options.countMatches ?? [],
|
|
150
|
-
objectIdSize: proto[PVK].options.objectIdSize
|
|
151
|
-
}, _attrs), { lockTable: options.className, retry: true });
|
|
152
|
-
}
|
|
153
|
-
catch (e) {
|
|
154
|
-
if (proto.storage.isDuplicateIdError(e))
|
|
155
|
-
continue;
|
|
156
|
-
throw e;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
async insertMany(options, values) {
|
|
161
|
-
if (options.className === 'File')
|
|
162
|
-
throw Error('File is not support insertMany');
|
|
135
|
+
async insert(options, values) {
|
|
136
|
+
if (!createFile && options.className === 'File')
|
|
137
|
+
throw Error('File is not support insert');
|
|
163
138
|
QueryValidator.recursiveCheck(values);
|
|
164
139
|
const _validator = await validator();
|
|
165
140
|
_validator.validateCountMatches(options.className, options.countMatches ?? []);
|
|
@@ -170,7 +145,7 @@ const dispatcher = (proto, options) => {
|
|
|
170
145
|
const _attrs = normalize(_.map(values, attr => _validator.validateFields(options.className, attr, 'create', QueryValidator.patterns.path)));
|
|
171
146
|
while (true) {
|
|
172
147
|
try {
|
|
173
|
-
return await proto.storage.atomic((storage) => storage.
|
|
148
|
+
return await proto.storage.atomic((storage) => storage.insert({
|
|
174
149
|
className: options.className,
|
|
175
150
|
includes: _includes,
|
|
176
151
|
matches: _matches,
|
|
@@ -185,44 +160,16 @@ const dispatcher = (proto, options) => {
|
|
|
185
160
|
}
|
|
186
161
|
}
|
|
187
162
|
},
|
|
188
|
-
async
|
|
189
|
-
QueryValidator.recursiveCheck(query, update);
|
|
190
|
-
const _validator = await validator();
|
|
191
|
-
if (!_validator.validateCLPs(query.className, 'update'))
|
|
192
|
-
throw Error('No permission');
|
|
193
|
-
return proto.storage.atomic((storage) => storage.updateOne(_validator.decodeQuery(normalize(query), 'update'), normalize(_validator.validateFields(query.className, update, 'update', QueryValidator.patterns.path))));
|
|
194
|
-
},
|
|
195
|
-
async updateMany(query, update) {
|
|
163
|
+
async update(query, update) {
|
|
196
164
|
QueryValidator.recursiveCheck(query, update);
|
|
197
165
|
const _validator = await validator();
|
|
198
166
|
if (!_validator.validateCLPs(query.className, 'update'))
|
|
199
167
|
throw Error('No permission');
|
|
200
|
-
return proto.storage.atomic((storage) => storage.
|
|
201
|
-
},
|
|
202
|
-
async upsertOne(query, update, setOnInsert) {
|
|
203
|
-
if (query.className === 'File')
|
|
204
|
-
throw Error('File is not support upsertOne');
|
|
205
|
-
QueryValidator.recursiveCheck(query, update, setOnInsert);
|
|
206
|
-
const _validator = await validator();
|
|
207
|
-
if (!_validator.validateCLPs(query.className, 'create', 'update'))
|
|
208
|
-
throw Error('No permission');
|
|
209
|
-
const _query = _validator.decodeQuery(normalize(query), 'update');
|
|
210
|
-
const _update = normalize(_validator.validateFields(query.className, update, 'update', QueryValidator.patterns.path));
|
|
211
|
-
const _setOnInsert = normalize(_validator.validateFields(query.className, setOnInsert, 'create', QueryValidator.patterns.path));
|
|
212
|
-
while (true) {
|
|
213
|
-
try {
|
|
214
|
-
return await proto.storage.atomic((storage) => storage.upsertOne(_query, _update, _setOnInsert), { lockTable: query.className, retry: true });
|
|
215
|
-
}
|
|
216
|
-
catch (e) {
|
|
217
|
-
if (proto.storage.isDuplicateIdError(e))
|
|
218
|
-
continue;
|
|
219
|
-
throw e;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
168
|
+
return proto.storage.atomic((storage) => storage.update(_validator.decodeQuery(normalize(query), 'update'), normalize(_validator.validateFields(query.className, update, 'update', QueryValidator.patterns.path))));
|
|
222
169
|
},
|
|
223
|
-
async
|
|
170
|
+
async upsert(query, update, setOnInsert) {
|
|
224
171
|
if (query.className === 'File')
|
|
225
|
-
throw Error('File is not support
|
|
172
|
+
throw Error('File is not support upsert');
|
|
226
173
|
QueryValidator.recursiveCheck(query, update, setOnInsert);
|
|
227
174
|
const _validator = await validator();
|
|
228
175
|
if (!_validator.validateCLPs(query.className, 'create', 'update'))
|
|
@@ -232,7 +179,7 @@ const dispatcher = (proto, options) => {
|
|
|
232
179
|
const _setOnInsert = normalize(_validator.validateFields(query.className, setOnInsert, 'create', QueryValidator.patterns.path));
|
|
233
180
|
while (true) {
|
|
234
181
|
try {
|
|
235
|
-
return await proto.storage.atomic((storage) => storage.
|
|
182
|
+
return await proto.storage.atomic((storage) => storage.upsert(_query, _update, _setOnInsert), { lockTable: query.className, retry: true });
|
|
236
183
|
}
|
|
237
184
|
catch (e) {
|
|
238
185
|
if (proto.storage.isDuplicateIdError(e))
|
|
@@ -241,19 +188,12 @@ const dispatcher = (proto, options) => {
|
|
|
241
188
|
}
|
|
242
189
|
}
|
|
243
190
|
},
|
|
244
|
-
async
|
|
191
|
+
async delete(query) {
|
|
245
192
|
QueryValidator.recursiveCheck(query);
|
|
246
193
|
const _validator = await validator();
|
|
247
194
|
if (!_validator.validateCLPs(query.className, 'delete'))
|
|
248
195
|
throw Error('No permission');
|
|
249
|
-
return proto.storage.atomic((storage) => storage.
|
|
250
|
-
},
|
|
251
|
-
async deleteMany(query) {
|
|
252
|
-
QueryValidator.recursiveCheck(query);
|
|
253
|
-
const _validator = await validator();
|
|
254
|
-
if (!_validator.validateCLPs(query.className, 'delete'))
|
|
255
|
-
throw Error('No permission');
|
|
256
|
-
return proto.storage.atomic((storage) => storage.deleteMany(_validator.decodeQuery(normalize(query), 'update')));
|
|
196
|
+
return proto.storage.atomic((storage) => storage.delete(_validator.decodeQuery(normalize(query), 'update')));
|
|
257
197
|
},
|
|
258
198
|
};
|
|
259
199
|
};
|
|
@@ -308,6 +248,7 @@ class _ProtoQuery extends TQuery {
|
|
|
308
248
|
return dispatcher(_serviceOf(options) ?? this._proto, {
|
|
309
249
|
...options ?? {},
|
|
310
250
|
disableSecurity: !!this._opts.insecure,
|
|
251
|
+
createFile: !!this._opts.createFile,
|
|
311
252
|
});
|
|
312
253
|
}
|
|
313
254
|
explain(options) {
|
|
@@ -343,45 +284,22 @@ class _ProtoQuery extends TQuery {
|
|
|
343
284
|
yield self._objectMethods(object);
|
|
344
285
|
});
|
|
345
286
|
}
|
|
346
|
-
async insert(attrs, options) {
|
|
347
|
-
const result = this._objectMethods(await this._dispatcher(options).insert({
|
|
348
|
-
className: this.className,
|
|
349
|
-
includes: this[PVK].options.includes,
|
|
350
|
-
matches: this[PVK].options.matches,
|
|
351
|
-
countMatches: this[PVK].options.countMatches,
|
|
352
|
-
}, attrs));
|
|
353
|
-
if (!result)
|
|
354
|
-
throw Error('Unable to insert document');
|
|
355
|
-
return result;
|
|
356
|
-
}
|
|
357
287
|
async insertMany(values, options) {
|
|
358
|
-
return this._dispatcher(options).
|
|
288
|
+
return this._objectMethods(await this._dispatcher(options).insert({
|
|
359
289
|
className: this.className,
|
|
360
290
|
includes: this[PVK].options.includes,
|
|
361
291
|
matches: this[PVK].options.matches,
|
|
362
292
|
countMatches: this[PVK].options.countMatches,
|
|
363
|
-
}, values);
|
|
364
|
-
}
|
|
365
|
-
async updateOne(update, options) {
|
|
366
|
-
return this._objectMethods(await this._dispatcher(options).updateOne(this._queryOptions, update));
|
|
293
|
+
}, values));
|
|
367
294
|
}
|
|
368
295
|
async updateMany(update, options) {
|
|
369
|
-
return this._dispatcher(options).
|
|
370
|
-
}
|
|
371
|
-
async upsertOne(update, setOnInsert, options) {
|
|
372
|
-
const result = this._objectMethods(await this._dispatcher(options).upsertOne(this._queryOptions, update, setOnInsert));
|
|
373
|
-
if (!result)
|
|
374
|
-
throw Error('Unable to upsert document');
|
|
375
|
-
return result;
|
|
296
|
+
return this._objectMethods(await this._dispatcher(options).update(this._queryOptions, update));
|
|
376
297
|
}
|
|
377
298
|
async upsertMany(update, setOnInsert, options) {
|
|
378
|
-
return this._dispatcher(options).
|
|
379
|
-
}
|
|
380
|
-
async deleteOne(options) {
|
|
381
|
-
return this._objectMethods(await this._dispatcher(options).deleteOne(this._queryOptions));
|
|
299
|
+
return this._objectMethods(await this._dispatcher(options).upsert(this._queryOptions, update, setOnInsert));
|
|
382
300
|
}
|
|
383
301
|
async deleteMany(options) {
|
|
384
|
-
return this._dispatcher(options).
|
|
302
|
+
return this._objectMethods(await this._dispatcher(options).delete(this._queryOptions));
|
|
385
303
|
}
|
|
386
304
|
}
|
|
387
305
|
class ProtoQuery extends _ProtoQuery {
|
|
@@ -958,9 +876,8 @@ class ProtoInternal {
|
|
|
958
876
|
object.set('size', file.size);
|
|
959
877
|
if (nonce)
|
|
960
878
|
object.set('nonce', nonce);
|
|
961
|
-
const
|
|
962
|
-
|
|
963
|
-
.insert(_.fromPairs([...object._set_entries()]), options);
|
|
879
|
+
const query = new ProtoQuery('File', proto, { createFile: true });
|
|
880
|
+
const created = await query.includes(...object.keys()).insert(_.fromPairs([...object._set_entries()]), options);
|
|
964
881
|
if (created) {
|
|
965
882
|
object[PVK].attributes = created.attributes;
|
|
966
883
|
object[PVK].mutated = {};
|
|
@@ -1640,8 +1557,11 @@ class ProtoService extends ProtoType {
|
|
|
1640
1557
|
notify(data) {
|
|
1641
1558
|
return this[PVK].notify(this, data);
|
|
1642
1559
|
}
|
|
1643
|
-
listen(callback) {
|
|
1560
|
+
listen(callback, selector) {
|
|
1561
|
+
const _selector = !_.isNil(selector) ? QuerySelector.decode(selector) : undefined;
|
|
1644
1562
|
return this[PVK].listen(this, data => {
|
|
1563
|
+
if (_selector && !_selector.eval(data))
|
|
1564
|
+
return;
|
|
1645
1565
|
callback(data);
|
|
1646
1566
|
});
|
|
1647
1567
|
}
|
|
@@ -1673,7 +1593,7 @@ class ProtoService extends ProtoType {
|
|
|
1673
1593
|
await this.fileStorage.destroy(this, token);
|
|
1674
1594
|
}
|
|
1675
1595
|
}
|
|
1676
|
-
await this.storage.
|
|
1596
|
+
await this.storage.delete({
|
|
1677
1597
|
className,
|
|
1678
1598
|
filter: QuerySelector.decode({ _expired_at: { $lt: time } }),
|
|
1679
1599
|
includes: ['_id', '_expired_at'],
|
|
@@ -2513,10 +2433,13 @@ const ProtoRoute = async (options) => {
|
|
|
2513
2433
|
const registerProtoSocket = (proto, server, endpoint) => {
|
|
2514
2434
|
const io = endpoint ? server.socket().of(endpoint) : server.socket();
|
|
2515
2435
|
io.on('connection', async (socket) => {
|
|
2436
|
+
let listeners = {};
|
|
2516
2437
|
const connect = async (token) => {
|
|
2517
2438
|
const payload = await proto.connectWithSessionToken(token);
|
|
2518
2439
|
const { remove } = payload.listen(data => {
|
|
2519
|
-
|
|
2440
|
+
const ids = _.keys(_.pickBy(listeners, v => v instanceof QuerySelector ? v.eval(data) : v));
|
|
2441
|
+
if (!_.isEmpty(ids))
|
|
2442
|
+
socket.emit('data', { ids, data });
|
|
2520
2443
|
});
|
|
2521
2444
|
return remove;
|
|
2522
2445
|
};
|
|
@@ -2529,6 +2452,19 @@ const registerProtoSocket = (proto, server, endpoint) => {
|
|
|
2529
2452
|
socket.on('disconnect', () => {
|
|
2530
2453
|
remove.then(rm => rm());
|
|
2531
2454
|
});
|
|
2455
|
+
socket.on('register', (payload) => {
|
|
2456
|
+
listeners = _.mapValues(payload, v => {
|
|
2457
|
+
if (_.isBoolean(v))
|
|
2458
|
+
return true;
|
|
2459
|
+
try {
|
|
2460
|
+
return QuerySelector.decode(v);
|
|
2461
|
+
}
|
|
2462
|
+
catch (error) {
|
|
2463
|
+
console.error(error);
|
|
2464
|
+
return false;
|
|
2465
|
+
}
|
|
2466
|
+
});
|
|
2467
|
+
});
|
|
2532
2468
|
});
|
|
2533
2469
|
return io;
|
|
2534
2470
|
};
|