proto.io 0.0.206 → 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 +3 -3
- package/dist/adapters/file/database.js.map +1 -1
- package/dist/adapters/file/database.mjs +3 -3
- 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 -17
- package/dist/adapters/storage/progres.js +24 -101
- package/dist/adapters/storage/progres.js.map +1 -1
- package/dist/adapters/storage/progres.mjs +24 -101
- package/dist/adapters/storage/progres.mjs.map +1 -1
- package/dist/client.d.ts +3 -3
- package/dist/client.js +2 -2
- package/dist/client.mjs +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +24 -107
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -108
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{base-Be7PFKEC.d.ts → base-DHkvlTFy.d.ts} +2 -2
- package/dist/internals/base-DHkvlTFy.d.ts.map +1 -0
- package/dist/internals/{chunk-CEQtSsWb.d.ts → chunk-C7kDLOLD.d.ts} +3 -3
- package/dist/internals/chunk-C7kDLOLD.d.ts.map +1 -0
- package/dist/internals/{index-CsmAYB_t.js → index-B8TESzd9.js} +1 -2
- package/dist/internals/{index-CsmAYB_t.js.map → index-B8TESzd9.js.map} +1 -1
- package/dist/internals/{index-BFZlY3IO.js → index-BRzKDwPs.js} +44 -2
- package/dist/internals/index-BRzKDwPs.js.map +1 -0
- package/dist/internals/{index-CURcwPBG.d.ts → index-CKcESGqE.d.ts} +2 -2
- package/dist/internals/index-CKcESGqE.d.ts.map +1 -0
- package/dist/internals/{index-CyPxh5dl.js → index-CkAvNaAe.js} +2 -2
- package/dist/internals/{index-CyPxh5dl.js.map → index-CkAvNaAe.js.map} +1 -1
- package/dist/internals/{index-CSnRU_KQ.mjs → index-DAkcqabS.mjs} +44 -2
- package/dist/internals/index-DAkcqabS.mjs.map +1 -0
- package/dist/internals/{index-iRVgw566.mjs → index-DlY33lfO.mjs} +2 -2
- package/dist/internals/{index-iRVgw566.mjs.map → index-DlY33lfO.mjs.map} +1 -1
- package/dist/internals/{index-DnbbpIaO.d.ts → index-PLz89AWF.d.ts} +14 -19
- package/dist/internals/index-PLz89AWF.d.ts.map +1 -0
- package/dist/internals/{index-DpN9tcbY.mjs → index-al1N-qi7.mjs} +2 -2
- package/dist/internals/{index-DpN9tcbY.mjs.map → index-al1N-qi7.mjs.map} +1 -1
- package/dist/internals/{random-D7S1XD7F.js → random-B0V0EnjP.js} +3 -3
- package/dist/internals/random-B0V0EnjP.js.map +1 -0
- package/dist/internals/{random-BnGB_bVS.mjs → random-ZgzzM5v_.mjs} +3 -3
- package/dist/internals/random-ZgzzM5v_.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/internals/base-Be7PFKEC.d.ts.map +0 -1
- package/dist/internals/chunk-CEQtSsWb.d.ts.map +0 -1
- package/dist/internals/index-BFZlY3IO.js.map +0 -1
- package/dist/internals/index-CSnRU_KQ.mjs.map +0 -1
- package/dist/internals/index-CURcwPBG.d.ts.map +0 -1
- package/dist/internals/index-DnbbpIaO.d.ts.map +0 -1
- package/dist/internals/random-BnGB_bVS.mjs.map +0 -1
- package/dist/internals/random-D7S1XD7F.js.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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-
|
|
8
|
-
import { i as isPointer, a as isRelation, T as TObject, b as isShape, d as defaultObjectKeyTypes, c as isPrimitive } 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
|
+
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';
|
|
11
11
|
import { Readable } from 'node:stream';
|
|
@@ -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
|
|
163
|
+
async update(query, update) {
|
|
189
164
|
QueryValidator.recursiveCheck(query, update);
|
|
190
165
|
const _validator = await validator();
|
|
191
166
|
if (!_validator.validateCLPs(query.className, 'update'))
|
|
192
167
|
throw Error('No permission');
|
|
193
|
-
return proto.storage.atomic((storage) => storage.
|
|
194
|
-
},
|
|
195
|
-
async updateMany(query, update) {
|
|
196
|
-
QueryValidator.recursiveCheck(query, update);
|
|
197
|
-
const _validator = await validator();
|
|
198
|
-
if (!_validator.validateCLPs(query.className, 'update'))
|
|
199
|
-
throw Error('No permission');
|
|
200
|
-
return proto.storage.atomic((storage) => storage.updateMany(_validator.decodeQuery(normalize(query), 'update'), normalize(_validator.validateFields(query.className, update, 'update', QueryValidator.patterns.path))));
|
|
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
|
|
245
|
-
QueryValidator.recursiveCheck(query);
|
|
246
|
-
const _validator = await validator();
|
|
247
|
-
if (!_validator.validateCLPs(query.className, 'delete'))
|
|
248
|
-
throw Error('No permission');
|
|
249
|
-
return proto.storage.atomic((storage) => storage.deleteOne(_validator.decodeQuery(normalize(query), 'update')));
|
|
250
|
-
},
|
|
251
|
-
async deleteMany(query) {
|
|
191
|
+
async delete(query) {
|
|
252
192
|
QueryValidator.recursiveCheck(query);
|
|
253
193
|
const _validator = await validator();
|
|
254
194
|
if (!_validator.validateCLPs(query.className, 'delete'))
|
|
255
195
|
throw Error('No permission');
|
|
256
|
-
return proto.storage.atomic((storage) => storage.
|
|
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._objectMethods(await 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
293
|
}, values));
|
|
364
294
|
}
|
|
365
|
-
async updateOne(update, options) {
|
|
366
|
-
return this._objectMethods(await this._dispatcher(options).updateOne(this._queryOptions, update));
|
|
367
|
-
}
|
|
368
295
|
async updateMany(update, options) {
|
|
369
|
-
return this._objectMethods(await 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._objectMethods(await 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._objectMethods(await 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 = {};
|
|
@@ -1676,7 +1593,7 @@ class ProtoService extends ProtoType {
|
|
|
1676
1593
|
await this.fileStorage.destroy(this, token);
|
|
1677
1594
|
}
|
|
1678
1595
|
}
|
|
1679
|
-
await this.storage.
|
|
1596
|
+
await this.storage.delete({
|
|
1680
1597
|
className,
|
|
1681
1598
|
filter: QuerySelector.decode({ _expired_at: { $lt: time } }),
|
|
1682
1599
|
includes: ['_id', '_expired_at'],
|