@ldsg/rrm-query-resource-records 0.3.41 → 0.3.43

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ldsg/rrm-query-resource-records",
3
- "version": "0.3.41",
3
+ "version": "0.3.43",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -14,7 +14,7 @@
14
14
  "access": "public"
15
15
  },
16
16
  "dependencies": {
17
- "@ldsg/rrm-utils": "0.3.41"
17
+ "@ldsg/rrm-utils": "0.3.43"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/jest": "^29.5.2",
@@ -29,12 +29,12 @@
29
29
  "ts-jest": "^29.1.5",
30
30
  "ts-node": "^10.9.2",
31
31
  "typescript": "^5.8.3",
32
- "@ldsg/application": "0.3.41",
33
- "@ldsg/graphql": "0.3.41",
34
- "@ldsg/object": "0.3.41",
35
- "@ldsg/object-field": "0.3.41",
36
- "@ldsg/types": "0.3.41",
37
- "@ldsg/workflow": "0.3.41"
32
+ "@ldsg/application": "0.3.43",
33
+ "@ldsg/graphql": "0.3.43",
34
+ "@ldsg/object": "0.3.43",
35
+ "@ldsg/object-field": "0.3.43",
36
+ "@ldsg/types": "0.3.43",
37
+ "@ldsg/workflow": "0.3.43"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "tsc --project tsconfig.build.json",
@@ -1,24 +0,0 @@
1
- import { WorkflowNodeTypeResourceExtendedHandler } from "@ldsg/workflow-node-type";
2
- interface ResourceRecord {
3
- id: string;
4
- kind: string;
5
- parentId?: string;
6
- settings: Record<string, any>;
7
- }
8
- interface CreatedResourceRecord extends ResourceRecord {
9
- originalId: string;
10
- }
11
- type ResourceRecords = ResourceRecord[];
12
- interface InputVariables {
13
- ownerId: string;
14
- createResourceRecords?: ResourceRecords;
15
- updateResourceRecords?: ResourceRecords;
16
- }
17
- interface OutputVariables {
18
- createdResourceRecords?: CreatedResourceRecord[];
19
- updatedResourceRecords?: ResourceRecords;
20
- }
21
- export type MutateResourceRecords = WorkflowNodeTypeResourceExtendedHandler<InputVariables, OutputVariables>;
22
- export declare const mutateResourceRecords: MutateResourceRecords;
23
- export {};
24
- //# sourceMappingURL=mutate-resource-records.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mutate-resource-records.d.ts","sourceRoot":"","sources":["../src/mutate-resource-records.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uCAAuC,EAAE,MAAM,0BAA0B,CAAC;AAkCnF,UAAU,cAAc;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B;AAED,UAAU,qBAAsB,SAAQ,cAAc;IACpD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,KAAK,eAAe,GAAG,cAAc,EAAE,CAAC;AAExC,UAAU,cAAc;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,qBAAqB,CAAC,EAAE,eAAe,CAAC;IACxC,qBAAqB,CAAC,EAAE,eAAe,CAAC;CACzC;AAED,UAAU,eAAe;IACvB,sBAAsB,CAAC,EAAE,qBAAqB,EAAE,CAAC;IACjD,sBAAsB,CAAC,EAAE,eAAe,CAAC;CAC1C;AA4DD,MAAM,MAAM,qBAAqB,GAAG,uCAAuC,CACzE,cAAc,EACd,eAAe,CAChB,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,qBAklBnC,CAAC"}
@@ -1,496 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.mutateResourceRecords = void 0;
7
- const utils_1 = require("@ldsg/utils");
8
- const lodash_1 = __importDefault(require("lodash"));
9
- const mongoose_1 = __importDefault(require("mongoose"));
10
- const countRootResourceRecords = (params) => {
11
- const { resourceRecords } = params;
12
- const rootResourceRecords = lodash_1.default.filter(resourceRecords, (resourceRecord) => {
13
- return !resourceRecord.parentId;
14
- });
15
- const count = rootResourceRecords.length;
16
- const res = {
17
- count,
18
- rootResourceRecords,
19
- };
20
- return res;
21
- };
22
- /**
23
- * 拓扑排序
24
- * 以拓扑序(父节点优先于子节点)处理,主要是为了计算 path,这样可以确保父级 path 先计算出
25
- */
26
- function topologicalSort(records) {
27
- const sorted = [];
28
- const visited = new Set();
29
- const ids = new Set(records.map((r) => r.id));
30
- const byId = new Map(records.map((r) => [r.id, r]));
31
- function visit(id) {
32
- if (visited.has(id))
33
- return;
34
- visited.add(id);
35
- const record = byId.get(id);
36
- if ((record === null || record === void 0 ? void 0 : record.parentId) && ids.has(record.parentId)) {
37
- visit(record.parentId);
38
- }
39
- const r = byId.get(id);
40
- if (r)
41
- sorted.push(r);
42
- }
43
- for (const record of records) {
44
- visit(record.id);
45
- }
46
- return sorted;
47
- }
48
- const mutateResourceRecords = async (params) => {
49
- var _a, _b;
50
- const { variables, handlerResourceInstance } = params;
51
- const mutatedAt = new Date();
52
- const { ownerId, createResourceRecords = [], updateResourceRecords = [] } = variables;
53
- if (!ownerId) {
54
- throw new Error("owner id is required when updating resource records");
55
- }
56
- const getFilteredResourceRes = handlerResourceInstance.getFilteredResource({
57
- kind: "tables",
58
- });
59
- const tablesResource = getFilteredResourceRes.resource;
60
- const { ResourceRecord, ResourceRecordVersion, ResourceRecordChange } = tablesResource.mongooseModels;
61
- const createdResourceRecords = [];
62
- const updatedResourceRecords = [];
63
- const newResourceRecordDocuments = [];
64
- const updateOps = [];
65
- /**
66
- * 资源ID映射
67
- */
68
- let resourceIdMap = {};
69
- /**
70
- * 根资源ID
71
- * 一次变更资源记录操作仅操作同一资源树中的资源
72
- */
73
- let rootResourceId;
74
- /**
75
- * 是否拟创建根资源记录
76
- */
77
- let isCreateRootResourceRecord = false;
78
- /**
79
- * 旧资源ID对新资源ID映射
80
- * 仅新增加资源ID才会被记录
81
- */
82
- const oldIdToNewIdMap = {};
83
- const { count: createRootResourceRecordsCount, rootResourceRecords: createRootResourceRecords } = countRootResourceRecords({
84
- resourceRecords: createResourceRecords,
85
- });
86
- const { count: updateRootResourceRecordsCount, rootResourceRecords: updateRootResourceRecords } = countRootResourceRecords({
87
- resourceRecords: updateResourceRecords,
88
- });
89
- if (createRootResourceRecordsCount + updateRootResourceRecordsCount > 1) {
90
- console.info("mutateResourceRecords createRootResourceRecordsCount", createRootResourceRecordsCount);
91
- console.info("mutateResourceRecords updateRootResourceRecordsCount", updateRootResourceRecordsCount);
92
- console.info("mutateResourceRecords createRootResourceRecords", createRootResourceRecords);
93
- console.info("mutateResourceRecords updateRootResourceRecords", updateRootResourceRecords);
94
- throw new Error("创建与更新资源记录中只能有一个顶级资源记录");
95
- }
96
- /**
97
- * 1. 找出找创建根资源ID
98
- * 2. 找出全部已存在应用资源与版本(仅非新建应用时执行)
99
- * 3. 批量处理拟创建资源记录文档
100
- * 4. 批量处理拟更新资源记录(仅非新建应用时执行)
101
- * 5. 批量执行写入
102
- */
103
- /**
104
- * 1. 找出找创建根资源ID
105
- */
106
- {
107
- if (createRootResourceRecordsCount === 1) {
108
- /**
109
- * 拟创建资源中包含根资源时,说明是创建新应用,此时不应包含旧应用
110
- */
111
- isCreateRootResourceRecord = true;
112
- const createRootResourceRecord = createResourceRecords.find((r) => !r.parentId);
113
- if (!createRootResourceRecord) {
114
- throw new Error("invalid create root resource record");
115
- }
116
- const oldResourceId = createRootResourceRecord.id;
117
- if (!oldResourceId) {
118
- throw new Error("invalid create root resource id");
119
- }
120
- const rootNewId = new mongoose_1.default.Types.ObjectId().toString();
121
- oldIdToNewIdMap[oldResourceId] = rootNewId;
122
- rootResourceId = rootNewId;
123
- if (updateResourceRecords.length) {
124
- throw new Error("如果创建资源记录中有一个顶级资源记录(说明是新应用),那么就不能存在任何更新资源记录");
125
- }
126
- }
127
- else {
128
- /**
129
- * 拟创建资源中不包含根资源时,说明是变更旧应用资源,此时可以通过找出任一旧资源并根据 path 找出根资源
130
- */
131
- /**
132
- * 任一已存在资源ID
133
- */
134
- let anyExistingResourceId;
135
- if (updateResourceRecords.length > 0) {
136
- /**
137
- * 拟更新资源中不包含根资源但有多个资源时,通过任一拟更新资源找出根资源
138
- */
139
- const anyExistingResourceRecord = updateResourceRecords[0];
140
- anyExistingResourceId = anyExistingResourceRecord.id;
141
- }
142
- else if (createResourceRecords.length > 0) {
143
- /**
144
- * 拟创建资源中不包含根资源但有多个资源时,找出拟创建资源中最顶级资源,最顶级资源的父资源应是已存在的资源,通过此已存在的资源找出根资源
145
- */
146
- const createResourceIds = new Set(createResourceRecords.map((r) => r.id));
147
- let currentResourceRecord = createResourceRecords[0];
148
- let parentId = currentResourceRecord.parentId;
149
- while (parentId && createResourceIds.has(parentId)) {
150
- const findRes = createResourceRecords.find((r) => r.id === parentId);
151
- if (!findRes)
152
- break;
153
- currentResourceRecord = findRes;
154
- parentId = currentResourceRecord.parentId;
155
- }
156
- anyExistingResourceId = parentId;
157
- }
158
- if (!anyExistingResourceId || !mongoose_1.default.Types.ObjectId.isValid(anyExistingResourceId)) {
159
- throw new Error("invalid root resource id");
160
- }
161
- const findByIdRes = await ResourceRecord.findById(anyExistingResourceId);
162
- if (!findByIdRes) {
163
- throw new Error("invalid any existing resource id");
164
- }
165
- const { path } = findByIdRes !== null && findByIdRes !== void 0 ? findByIdRes : {};
166
- if (!path) {
167
- throw new Error("invalid path");
168
- }
169
- rootResourceId = path.split("/")[1];
170
- }
171
- if (!rootResourceId || !mongoose_1.default.Types.ObjectId.isValid(rootResourceId)) {
172
- throw new Error("invalid root resource id");
173
- }
174
- }
175
- /**
176
- * 已存在资源ID对资源记录文档映射
177
- */
178
- let existingResourceIdToResourceRecordDocumentMap;
179
- /**
180
- * 资源记录版本ID集合
181
- */
182
- let resourceRecordVersionIdSet = new Set();
183
- /**
184
- * 已存在资源ID对版本ID映射
185
- */
186
- let existingResourceIdToVersionId = new Map();
187
- /**
188
- * 已存在资源ID对资源路径映射
189
- */
190
- const existingResourceIdToPathMap = {};
191
- /**
192
- * 2. 找出全部已存在应用资源与版本(仅非新建应用时执行)
193
- */
194
- if (!isCreateRootResourceRecord) {
195
- /**
196
- * 应用树形资源记录文档
197
- */
198
- const applicationTreeResourceRecordDocuments = await ResourceRecord.find({
199
- path: { $regex: new RegExp(`^/${rootResourceId}`) },
200
- });
201
- existingResourceIdToResourceRecordDocumentMap = new Map(applicationTreeResourceRecordDocuments.map((r) => [r._id.toString(), r]));
202
- for (const [id, resourceRecordDocument] of existingResourceIdToResourceRecordDocumentMap) {
203
- existingResourceIdToPathMap[id] = resourceRecordDocument.path;
204
- }
205
- const applicationTreeResourceRecordDocumentActiveVersionIds = applicationTreeResourceRecordDocuments
206
- .map((r) => r.activeVersionId)
207
- .filter((id) => id != null);
208
- const resourceRecordVersionDocuments = await ResourceRecordVersion.find({
209
- _id: { $in: applicationTreeResourceRecordDocumentActiveVersionIds },
210
- });
211
- resourceRecordVersionIdSet = new Set(resourceRecordVersionDocuments.map((v) => v._id.toString()));
212
- for (const applicationTreeResourceRecordDocument of applicationTreeResourceRecordDocuments) {
213
- const { id, activeVersionId } = applicationTreeResourceRecordDocument;
214
- /**
215
- * 有的版本ID可能不存在,在此处不报错主要是为了提高容错性,如:
216
- * 当资源的 activeVersionId 被误删或相应的资源版本被清空时,应用需要可以正常运转。
217
- */
218
- if (activeVersionId && resourceRecordVersionIdSet.has(activeVersionId.toString())) {
219
- existingResourceIdToVersionId.set(id, activeVersionId.toString());
220
- }
221
- }
222
- /**
223
- * 校验拟更新资源父级ID与类型是否一致
224
- */
225
- for (const resourceRecord of updateResourceRecords) {
226
- const { id: resourceId } = resourceRecord;
227
- const resourceRecordDocument = existingResourceIdToResourceRecordDocumentMap.get(resourceId);
228
- if (!resourceRecordDocument) {
229
- throw new Error(`Resource record not found: ${resourceId}`);
230
- }
231
- if (resourceRecordDocument.ownerId !== ownerId) {
232
- throw new Error(`Resource record ${resourceId} does not belong to the current user`);
233
- }
234
- const resourceRecordDocumentParentIdStr = ((_a = resourceRecordDocument.parentId) === null || _a === void 0 ? void 0 : _a.toString()) || "";
235
- const resourceRecordParentId = resourceRecord.parentId || "";
236
- if (resourceRecordParentId !== resourceRecordDocumentParentIdStr) {
237
- throw new Error(`Resource record ${resourceId} parentId mismatch`);
238
- }
239
- if (resourceRecord.kind !== resourceRecordDocument.kind) {
240
- throw new Error(`Resource record ${resourceId} kind mismatch`);
241
- }
242
- }
243
- }
244
- /**
245
- * 已替换 ID 后的资源设置快照
246
- * 当无新建资源时,映射表为空,直接使用原始设置
247
- */
248
- let newResourceIdToSettings;
249
- /**
250
- * 3. 批量处理拟创建资源记录文档
251
- */
252
- if (createResourceRecords.length) {
253
- for (const resourceRecord of createResourceRecords) {
254
- const { id: oldResourceId } = resourceRecord;
255
- /**
256
- * 这里判断一下是否已经存在,主要是为了避免替换拟创建根资源ID
257
- */
258
- if (!oldIdToNewIdMap[oldResourceId]) {
259
- oldIdToNewIdMap[oldResourceId] = new mongoose_1.default.Types.ObjectId().toString();
260
- }
261
- }
262
- /**
263
- * 一次性替换所有资源记录 settings 中的旧 ID
264
- */
265
- const oldResourceIdToSettings = {};
266
- const allOldResourceRecords = [...createResourceRecords, ...updateResourceRecords];
267
- for (const r of allOldResourceRecords) {
268
- oldResourceIdToSettings[r.id] = r.settings;
269
- }
270
- const replaceResourceIdsRes = (0, utils_1.replaceResourceIds)({
271
- source: oldResourceIdToSettings,
272
- oldResourceIdToNewResourceIdMap: oldIdToNewIdMap,
273
- });
274
- newResourceIdToSettings = replaceResourceIdsRes.replacement;
275
- const topologicalSortedCreateResourceRecords = topologicalSort(createResourceRecords);
276
- const newResourceIdToPathMap = {};
277
- for (const resourceRecord of topologicalSortedCreateResourceRecords) {
278
- const { id: oldResourceId, parentId: oldParentId, kind } = resourceRecord;
279
- const newResourceId = oldIdToNewIdMap[oldResourceId];
280
- const newResourceIdObject = new mongoose_1.default.Types.ObjectId(newResourceId);
281
- let parentId = oldParentId ? oldIdToNewIdMap[oldParentId] || oldParentId : undefined;
282
- if (parentId && !mongoose_1.default.Types.ObjectId.isValid(parentId)) {
283
- throw new Error("invalid parent id");
284
- }
285
- const resourceSettings = newResourceIdToSettings[newResourceId];
286
- let path = "";
287
- /**
288
- * 为新资源ID写入资源路径
289
- */
290
- {
291
- if (parentId) {
292
- const parentPath = newResourceIdToPathMap[parentId] || existingResourceIdToPathMap[parentId];
293
- if (!parentPath) {
294
- throw new Error("invalid parent path");
295
- }
296
- path = `${parentPath}/${newResourceId}`;
297
- }
298
- else {
299
- path = `/${newResourceId}`;
300
- }
301
- newResourceIdToPathMap[newResourceId] = path;
302
- }
303
- const newVersionId = new mongoose_1.default.Types.ObjectId();
304
- newResourceRecordDocuments.push({
305
- createdAt: mutatedAt,
306
- updatedAt: mutatedAt,
307
- _id: newResourceIdObject,
308
- kind,
309
- parentId: parentId ? new mongoose_1.default.Types.ObjectId(parentId) : undefined,
310
- path,
311
- settings: resourceSettings,
312
- ownerId,
313
- activeVersionId: newVersionId,
314
- });
315
- resourceIdMap[newResourceId] = {
316
- versionId: newVersionId.toString(),
317
- isNewResource: true,
318
- isNewVersion: true,
319
- isNeedToCreateVersion: true,
320
- settings: resourceSettings,
321
- };
322
- createdResourceRecords.push({
323
- id: newResourceId,
324
- originalId: oldResourceId,
325
- kind,
326
- parentId,
327
- settings: resourceSettings,
328
- });
329
- }
330
- }
331
- /**
332
- * 4. 批量处理拟更新资源记录(仅非新建应用时执行)
333
- */
334
- if (!isCreateRootResourceRecord) {
335
- if (!existingResourceIdToResourceRecordDocumentMap) {
336
- throw new Error("invalid existing resource id to resource record document map");
337
- }
338
- for (const resourceRecord of updateResourceRecords) {
339
- const { id: resourceId, parentId, kind, settings: oldResourceSettings } = resourceRecord;
340
- const resourceRecordDocument = existingResourceIdToResourceRecordDocumentMap.get(resourceId);
341
- if (!resourceRecordDocument) {
342
- throw new Error("invalid resource record document");
343
- }
344
- const resourceSettings = (_b = newResourceIdToSettings === null || newResourceIdToSettings === void 0 ? void 0 : newResourceIdToSettings[resourceId]) !== null && _b !== void 0 ? _b : oldResourceSettings;
345
- const isSettingsUnchanged = lodash_1.default.isEqual(resourceRecordDocument.settings, resourceSettings);
346
- if (isSettingsUnchanged) {
347
- const existingVersionId = existingResourceIdToVersionId.get(resourceId);
348
- if (existingVersionId) {
349
- resourceIdMap[resourceId] = {
350
- versionId: existingVersionId,
351
- isNewResource: false,
352
- isNewVersion: false,
353
- isNeedToCreateVersion: false,
354
- settings: resourceSettings,
355
- };
356
- }
357
- else {
358
- const newVersionId = new mongoose_1.default.Types.ObjectId();
359
- resourceIdMap[resourceId] = {
360
- versionId: newVersionId.toString(),
361
- isNewResource: false,
362
- isNewVersion: false,
363
- isNeedToCreateVersion: true,
364
- settings: resourceSettings,
365
- };
366
- }
367
- }
368
- else {
369
- const newVersionId = new mongoose_1.default.Types.ObjectId();
370
- updateOps.push({
371
- updateOne: {
372
- filter: { _id: resourceRecordDocument._id },
373
- update: {
374
- $set: {
375
- settings: resourceSettings,
376
- activeVersionId: newVersionId,
377
- updatedAt: mutatedAt,
378
- },
379
- },
380
- },
381
- });
382
- resourceIdMap[resourceId] = {
383
- versionId: newVersionId.toString(),
384
- isNewResource: false,
385
- isNewVersion: true,
386
- isNeedToCreateVersion: true,
387
- settings: resourceSettings,
388
- };
389
- }
390
- updatedResourceRecords.push({
391
- id: resourceId,
392
- kind,
393
- parentId,
394
- settings: resourceSettings,
395
- });
396
- }
397
- /**
398
- * 本次改变的资源ID集合
399
- */
400
- const changedRecordIdSet = new Set([
401
- ...createResourceRecords.map((r) => oldIdToNewIdMap[r.id]),
402
- ...updateResourceRecords.map((r) => r.id),
403
- ]);
404
- for (const [resourceId, resourceRecordDocument,] of existingResourceIdToResourceRecordDocumentMap) {
405
- const { settings } = resourceRecordDocument;
406
- /**
407
- * 已在本次改变的资源ID集合中的资源ID就跳过
408
- */
409
- if (changedRecordIdSet.has(resourceId))
410
- continue;
411
- const existingVersionId = existingResourceIdToVersionId.get(resourceId);
412
- if (existingVersionId) {
413
- resourceIdMap[resourceId] = {
414
- versionId: existingVersionId,
415
- isNewResource: false,
416
- isNewVersion: false,
417
- isNeedToCreateVersion: false,
418
- settings,
419
- };
420
- }
421
- else {
422
- /**
423
- * 理论上已存在在资源ID应该存在相应的版本,但为了容错以提升应用健壮性,当已存在资源的版本丢失时,创建新版本
424
- */
425
- const newVersionId = new mongoose_1.default.Types.ObjectId();
426
- resourceIdMap[resourceId] = {
427
- versionId: newVersionId.toString(),
428
- isNewResource: false,
429
- isNewVersion: false,
430
- isNeedToCreateVersion: true,
431
- settings,
432
- };
433
- }
434
- }
435
- }
436
- /**
437
- * 5. 批量执行写入
438
- */
439
- {
440
- /**
441
- * 批量创建资源记录
442
- */
443
- if (newResourceRecordDocuments.length > 0) {
444
- await ResourceRecord.insertMany(newResourceRecordDocuments);
445
- }
446
- /**
447
- * 批量更新资源记录
448
- */
449
- if (updateOps.length > 0) {
450
- await ResourceRecord.bulkWrite(updateOps);
451
- }
452
- /**
453
- * 批量创建版本
454
- */
455
- {
456
- const newVersionDocuments = [];
457
- for (const [resourceId, { versionId, isNeedToCreateVersion, settings }] of Object.entries(resourceIdMap)) {
458
- /**
459
- * 当无需要创建版本时,跳过执行,一般是因为版本已存在。
460
- */
461
- if (!isNeedToCreateVersion)
462
- continue;
463
- newVersionDocuments.push({
464
- createdAt: mutatedAt,
465
- _id: versionId,
466
- resourceId,
467
- settings,
468
- });
469
- }
470
- if (newVersionDocuments.length > 0) {
471
- await ResourceRecordVersion.insertMany(newVersionDocuments);
472
- }
473
- }
474
- /**
475
- * 创建资源记录变更
476
- */
477
- if (Object.keys(resourceIdMap).length > 0) {
478
- const reducedResourceIdMap = lodash_1.default.mapValues(resourceIdMap, (value) => lodash_1.default.pick(value, ["versionId", "isNewResource", "isNewVersion"]));
479
- await ResourceRecordChange.create({
480
- createdAt: mutatedAt,
481
- rootResourceId,
482
- resourceIdMap: reducedResourceIdMap,
483
- remark: "",
484
- });
485
- }
486
- }
487
- const resVariables = {
488
- createdResourceRecords,
489
- updatedResourceRecords,
490
- };
491
- const res = {
492
- variables: resVariables,
493
- };
494
- return res;
495
- };
496
- exports.mutateResourceRecords = mutateResourceRecords;
@@ -1,3 +0,0 @@
1
- import { QueryResourceRecords } from "./types";
2
- export declare const queryResourceRecords: QueryResourceRecords;
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/query-resource-records/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAA4B,MAAM,SAAS,CAAC;AAEzE,eAAO,MAAM,oBAAoB,EAAE,oBA6BlC,CAAC"}
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.queryResourceRecords = void 0;
4
- const types_1 = require("./types");
5
- const queryResourceRecords = async (params) => {
6
- const { variables, handlerResourceInstance } = params;
7
- const { rootResourceId, purpose = types_1.Purpose.RUNTIME } = variables;
8
- const getFilteredResourceRes = handlerResourceInstance.getFilteredResource({
9
- kind: "tables",
10
- });
11
- const tablesResource = getFilteredResourceRes.resource;
12
- const { ResourceRecord, ResourceRecordVersion, ResourceRecordChange } = tablesResource.mongooseModels;
13
- const resourceRecords = [];
14
- const resVariables = {
15
- resourceRecords,
16
- };
17
- const res = {
18
- variables: resVariables,
19
- };
20
- return res;
21
- };
22
- exports.queryResourceRecords = queryResourceRecords;
@@ -1,35 +0,0 @@
1
- import { ResourceRecords } from "@ldsg/types";
2
- import { WorkflowNodeTypeResourceExtendedHandler } from "@ldsg/workflow-node-type";
3
- /**
4
- * 用途
5
- */
6
- export declare enum Purpose {
7
- /**
8
- * 编辑态
9
- */
10
- EDIT = "edit",
11
- /**
12
- * 运行态
13
- */
14
- RUNTIME = "runtime"
15
- }
16
- export interface InputVariables {
17
- /**
18
- * 根资源 ID
19
- * 必选
20
- * 用于限定资源记录查询范围
21
- */
22
- rootResourceId: string;
23
- /**
24
- * 用途
25
- * 必选
26
- * 默认值:runtime
27
- * 用于表明资源记录查询用途
28
- */
29
- purpose?: Purpose;
30
- }
31
- export interface OutputVariables {
32
- resourceRecords?: ResourceRecords;
33
- }
34
- export type QueryResourceRecords = WorkflowNodeTypeResourceExtendedHandler<InputVariables, OutputVariables>;
35
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/query-resource-records/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,uCAAuC,EAAE,MAAM,0BAA0B,CAAC;AAEnF;;GAEG;AACH,oBAAY,OAAO;IACjB;;OAEG;IACH,IAAI,SAAS;IAEb;;OAEG;IACH,OAAO,YAAY;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAED,MAAM,MAAM,oBAAoB,GAAG,uCAAuC,CACxE,cAAc,EACd,eAAe,CAChB,CAAC"}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Purpose = void 0;
4
- /**
5
- * 用途
6
- */
7
- var Purpose;
8
- (function (Purpose) {
9
- /**
10
- * 编辑态
11
- */
12
- Purpose["EDIT"] = "edit";
13
- /**
14
- * 运行态
15
- */
16
- Purpose["RUNTIME"] = "runtime";
17
- })(Purpose || (exports.Purpose = Purpose = {}));