@steedos/service-objectql 2.6.1-beta.6 → 2.6.2-beta.2

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/package.service.js +73 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/service-objectql",
3
- "version": "2.6.1-beta.6",
3
+ "version": "2.6.2-beta.2",
4
4
  "main": "package.service.js",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -13,8 +13,8 @@
13
13
  "description": "steedos package",
14
14
  "repository": {},
15
15
  "license": "MIT",
16
- "gitHead": "d77961251196c5352622d977e554660796ed6208",
16
+ "gitHead": "ddef9fbc34afc7b57c59a31e9ed4f56818dc4c31",
17
17
  "dependencies": {
18
- "@steedos/objectql": "2.6.1-beta.6"
18
+ "@steedos/objectql": "2.6.2-beta.2"
19
19
  }
20
20
  }
@@ -1,8 +1,8 @@
1
1
  /*
2
2
  * @Author: sunhaolin@hotoa.com
3
3
  * @Date: 2023-03-23 15:12:14
4
- * @LastEditors: baozhoutao@steedos.com
5
- * @LastEditTime: 2023-05-18 14:33:09
4
+ * @LastEditors: 孙浩林 sunhaolin@steedos.com
5
+ * @LastEditTime: 2023-11-14 10:43:21
6
6
  * @Description:
7
7
  */
8
8
  "use strict";
@@ -10,6 +10,7 @@
10
10
  const objectql = require('@steedos/objectql');
11
11
  const { getObject } = objectql;
12
12
 
13
+ const { ObjectId } = require('mongodb');
13
14
 
14
15
  /**
15
16
  * @typedef {import('moleculer').Context} Context Moleculer's Context
@@ -35,6 +36,19 @@ module.exports = {
35
36
  * Actions
36
37
  */
37
38
  actions: {
39
+ aggregate: {
40
+ params: {
41
+ objectName: { type: "string" },
42
+ query: { type: "object" },
43
+ externalPipeline: { type: "array", items: "object" }
44
+ },
45
+ async handler(ctx) {
46
+ const userSession = ctx.meta.user;
47
+ const { objectName, query, externalPipeline } = ctx.params;
48
+ const obj = getObject(objectName)
49
+ return await obj.aggregate(query, externalPipeline, userSession)
50
+ }
51
+ },
38
52
  find: {
39
53
  params: {
40
54
  objectName: { type: "string" },
@@ -319,7 +333,7 @@ module.exports = {
319
333
  params: {
320
334
  objectName: { type: "string" },
321
335
  },
322
- async handler() {
336
+ async handler(ctx) {
323
337
  const { objectName } = ctx.params;
324
338
  const obj = getObject(objectName)
325
339
  return obj.isEnableAudit();
@@ -329,7 +343,7 @@ module.exports = {
329
343
  params: {
330
344
  objectName: { type: "string" },
331
345
  },
332
- async handler() {
346
+ async handler(ctx) {
333
347
  const { objectName } = ctx.params;
334
348
  const obj = getObject(objectName)
335
349
  return await obj._makeNewID();
@@ -339,7 +353,7 @@ module.exports = {
339
353
  params: {
340
354
  objectName: { type: "string" },
341
355
  },
342
- async handler() {
356
+ async handler(ctx) {
343
357
  const { objectName } = ctx.params;
344
358
  const obj = getObject(objectName)
345
359
  return obj.getRecordAbsoluteUrl();
@@ -349,7 +363,7 @@ module.exports = {
349
363
  params: {
350
364
  objectName: { type: "string" },
351
365
  },
352
- async handler() {
366
+ async handler(ctx) {
353
367
  const { objectName } = ctx.params;
354
368
  const obj = getObject(objectName)
355
369
  return obj.getGridAbsoluteUrl();
@@ -358,7 +372,7 @@ module.exports = {
358
372
  getRecordPermissionsById: {
359
373
  params: {
360
374
  objectName: { type: "string" },
361
- recordId: { type: "string" },
375
+ recordId: { type: "any" },
362
376
  },
363
377
  async handler(ctx) {
364
378
  const userSession = ctx.meta.user;
@@ -493,6 +507,38 @@ module.exports = {
493
507
  const { objectName, doc } = ctx.params;
494
508
  return await this.encryptFieldValue(objectName, doc);
495
509
  }
510
+ },
511
+ makeNewID: {
512
+ async handler(ctx) {
513
+ return new ObjectId().toHexString();
514
+ }
515
+ },
516
+ createIndex: {
517
+ params: {
518
+ objectName: { type: "string" },
519
+ fieldName: { type: "string" },
520
+ },
521
+ async handler(ctx) {
522
+ const { objectName, fieldName } = ctx.params;
523
+ const obj = getObject(objectName)
524
+ return await obj.createIndex(fieldName);
525
+ }
526
+ },
527
+ dropIndex: {
528
+ params: {
529
+ objectName: { type: "string" },
530
+ fieldName: { type: "string" },
531
+ },
532
+ async handler(ctx) {
533
+ const { objectName, fieldName } = ctx.params;
534
+ const obj = getObject(objectName)
535
+ return await obj.dropIndex(fieldName);
536
+ }
537
+ },
538
+ getPrimarySpaceId: {
539
+ async handler(ctx) {
540
+ return await this.getPrimarySpaceId()
541
+ }
496
542
  }
497
543
 
498
544
  },
@@ -551,6 +597,26 @@ module.exports = {
551
597
  console.error(`[字段级加密] 对象${objectName}中字段加密失败:`, error);
552
598
  }
553
599
  return doc;
600
+ },
601
+ getPrimarySpaceId: async function () {
602
+ const steedosConfig = objectql.getSteedosConfig();
603
+ let spaceId;
604
+ if (steedosConfig && steedosConfig.tenant && steedosConfig.tenant._id) {
605
+ spaceId = steedosConfig.tenant._id
606
+ }
607
+ if (!spaceId) {
608
+ const datasource = objectql.getDataSource('default');
609
+ if (datasource) {
610
+ const adapter = datasource.adapter;
611
+ await adapter.connect()
612
+ const collection = adapter.collection('spaces');
613
+ const space = await collection.findOne()
614
+ if (space) {
615
+ spaceId = space._id;
616
+ }
617
+ }
618
+ }
619
+ return spaceId
554
620
  }
555
621
  },
556
622