oak-domain 5.0.4 → 5.0.6

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.
@@ -572,51 +572,54 @@ function analyzeImportDeclaration(node, referencedSchemas, additionalImports, fi
572
572
  * @param filename
573
573
  * @returns
574
574
  */
575
- function searchImportedPath(path, fileSpecifierPath, filename) {
576
- const cwd = process.cwd();
577
- const fileSpecifierPaths = fileSpecifierPath.split('/');
578
- const moduleName = fileSpecifierPaths[0] || fileSpecifierPaths[1];
579
- (0, assert_1.default)(moduleName);
580
- // 找到path路径对应的最近package.json
581
- const paths = path.split('/');
582
- for (let iter = paths.length; iter >= 0; iter--) {
583
- const paths2 = paths.slice(0, iter);
584
- const pkgJsonPath = path_1.default.join(cwd, ...paths2, 'package.json');
585
- if ((0, fs_1.existsSync)(pkgJsonPath)) {
586
- const pkgJson = require(pkgJsonPath);
587
- if (pkgJson.dependencies?.hasOwnProperty(moduleName)) {
588
- const dependentPath = pkgJson.dependencies[moduleName];
589
- if (dependentPath.trimStart().startsWith('file:')) {
590
- const dependentFilePath = dependentPath.trimStart().slice(5);
591
- return path_1.default.join(pkgJsonPath, '..', dependentFilePath, ...(fileSpecifierPaths[0] ? fileSpecifierPaths.slice(1) : (fileSpecifierPaths.slice(2))));
592
- }
593
- else {
594
- return path_1.default.join(pkgJsonPath, '..', 'node_modules', fileSpecifierPath);
575
+ function getImportedFilePath(path, fileSpecifierPath, filename) {
576
+ let importedFilepath = '';
577
+ const getExistedFileName = () => {
578
+ if ((0, fs_1.existsSync)(`${importedFilepath}.ts`)) {
579
+ return `${importedFilepath}.ts`;
580
+ }
581
+ else if ((0, fs_1.existsSync)(`${importedFilepath}.d.ts`)) {
582
+ return `${importedFilepath}.d.ts`;
583
+ }
584
+ return '';
585
+ };
586
+ if (fileSpecifierPath.startsWith('.')) {
587
+ importedFilepath = path_1.default.join(process.cwd(), path, fileSpecifierPath);
588
+ const importedFilename = getExistedFileName();
589
+ (0, assert_1.default)(importedFilename, `「${filename}」中import路径${fileSpecifierPath}找不到对应的声明`);
590
+ return importedFilename;
591
+ }
592
+ else {
593
+ const cwd = process.cwd();
594
+ const fileSpecifierPaths = fileSpecifierPath.split('/');
595
+ const moduleName = fileSpecifierPaths[0] || fileSpecifierPaths[1];
596
+ (0, assert_1.default)(moduleName);
597
+ // 从path向外找package.json -> node_modules直至找到fileSpecifier
598
+ const paths = path.split('/');
599
+ for (let iter = paths.length; iter >= 0; iter--) {
600
+ const paths2 = paths.slice(0, iter);
601
+ const pkgJsonPath = path_1.default.join(cwd, ...paths2, 'package.json');
602
+ if ((0, fs_1.existsSync)(pkgJsonPath)) {
603
+ const pkgJson = require(pkgJsonPath);
604
+ if (pkgJson.dependencies?.hasOwnProperty(moduleName)) {
605
+ const dependentPath = pkgJson.dependencies[moduleName];
606
+ if (dependentPath.trimStart().startsWith('file:')) {
607
+ const dependentFilePath = dependentPath.trimStart().slice(5);
608
+ importedFilepath = path_1.default.join(pkgJsonPath, '..', dependentFilePath, ...(fileSpecifierPaths[0] ? fileSpecifierPaths.slice(1) : (fileSpecifierPaths.slice(2))));
609
+ }
610
+ else {
611
+ importedFilepath = path_1.default.join(pkgJsonPath, '..', 'node_modules', fileSpecifierPath);
612
+ }
613
+ const importedFilename = getExistedFileName();
614
+ if (importedFilename) {
615
+ return importedFilename;
616
+ }
595
617
  }
596
618
  }
597
619
  }
598
620
  }
599
621
  (0, assert_1.default)(false, `「${filename}」中import路径${fileSpecifierPath}找不到对应的声明`);
600
622
  }
601
- /**
602
- * 获得import的某个文件的绝对路径
603
- * @param path
604
- * @param fileSpecifierPath
605
- * @returns
606
- */
607
- function getImportedFilePath(path, fileSpecifierPath, filename) {
608
- let importedFilename = fileSpecifierPath.startsWith('.') ? path_1.default.join(process.cwd(), path, fileSpecifierPath) : searchImportedPath(path, fileSpecifierPath, filename);
609
- if ((0, fs_1.existsSync)(`${importedFilename}.ts`)) {
610
- return `${importedFilename}.ts`;
611
- }
612
- else if ((0, fs_1.existsSync)(`${importedFilename}.d.ts`)) {
613
- return `${importedFilename}.d.ts`;
614
- }
615
- else {
616
- // 目前不可能引用js文件
617
- (0, assert_1.default)(false, `「${filename}」import路径${fileSpecifierPath}找不到对应的文件`);
618
- }
619
- }
620
623
  function analyzeSchemaDefinition(node, moduleName, filename, path, program, referencedSchemas, schemaAttrs, enumAttributes, importAttrFrom, relativePath) {
621
624
  let hasEntityAttr = false;
622
625
  let hasEntityIdAttr = false;
@@ -92,7 +92,7 @@ class AsyncContext {
92
92
  (0, assert_1.default)(!action_1.readOnlyActions.includes(action));
93
93
  this.opRecords.push({
94
94
  id,
95
- a: 'u',
95
+ a: action,
96
96
  e: entity,
97
97
  d: data,
98
98
  f: filter,
@@ -16,10 +16,10 @@ function checkUniqueBetweenRows(rows, uniqAttrs) {
16
16
  let s = '';
17
17
  for (const a of uniqAttrs) {
18
18
  if (row[a] === null || row[a] === undefined) {
19
- s + row.id;
19
+ s += row.id;
20
20
  }
21
21
  else {
22
- s + `-${row[a]}`;
22
+ s += `-${row[a]}`;
23
23
  }
24
24
  }
25
25
  if (dict[s]) {
@@ -188,7 +188,17 @@ function createActionTransformerCheckers(actionDefDict) {
188
188
  type: 'row',
189
189
  entity,
190
190
  filter: conditionalFilter,
191
- errMsg: '',
191
+ errMsg: '数据状态已经改变',
192
+ inconsistentRows: {
193
+ entity,
194
+ selection: (filter) => ({
195
+ data: {
196
+ id: 1,
197
+ [attr]: 1,
198
+ },
199
+ filter,
200
+ }),
201
+ },
192
202
  });
193
203
  // 这里用data类型的checker改数据了不太好,先这样
194
204
  checkers.push({
@@ -331,7 +341,6 @@ function createAttrUpdateCheckers(schema, attrUpdateMatrix) {
331
341
  }
332
342
  if (f) {
333
343
  const rr = (0, filter_1.contains)(entity, context.getSchema(), data, f);
334
- console.log(rr);
335
344
  const result = (0, filter_1.checkFilterContains)(entity, context, f, filter, true);
336
345
  if (result instanceof Promise) {
337
346
  return result.then((v) => {
@@ -63,12 +63,13 @@ function translateCheckerInAsyncContext(checker, schema) {
63
63
  dontCollect: true,
64
64
  blockTrigger: true,
65
65
  });
66
- const e = new Exception_1.OakRowInconsistencyException(undefined, errMsg);
66
+ const e = new Exception_1.OakRowInconsistencyException(errMsg);
67
67
  e.addData(entity2, rows2);
68
68
  throw e;
69
69
  }
70
70
  else {
71
- const rows2 = await context.select(entity, {
71
+ // 可能会暴露隐私信息,暂时不能这样做。by Xc
72
+ /* const rows2 = await context.select(entity, {
72
73
  data: getFullProjection(entity, context.getSchema()),
73
74
  filter: Object.assign({}, operationFilter, {
74
75
  $not: filter2,
@@ -76,9 +77,9 @@ function translateCheckerInAsyncContext(checker, schema) {
76
77
  }, {
77
78
  dontCollect: true,
78
79
  blockTrigger: true,
79
- });
80
- const e = new Exception_1.OakRowInconsistencyException(undefined, errMsg);
81
- e.addData(entity, rows2);
80
+ }); */
81
+ const e = new Exception_1.OakRowInconsistencyException(errMsg);
82
+ // e.addData(entity, rows2);
82
83
  throw e;
83
84
  }
84
85
  };
@@ -155,7 +156,7 @@ function translateCheckerInSyncContext(checker, schema) {
155
156
  if ((0, filter_1.checkFilterContains)(entity, context, filter2, operationFilter2, true)) {
156
157
  return;
157
158
  }
158
- const e = new Exception_1.OakRowInconsistencyException(undefined, errMsg || 'row checker condition illegal');
159
+ const e = new Exception_1.OakRowInconsistencyException(errMsg || 'row checker condition illegal');
159
160
  throw e;
160
161
  };
161
162
  return {
@@ -257,7 +258,7 @@ function createRemoveCheckers(schema) {
257
258
  if (result instanceof Promise) {
258
259
  promises.push(result.then(([row]) => {
259
260
  if (row) {
260
- const err = new Exception_1.OakRowInconsistencyException(undefined, `您无法删除存在有效数据「${e}」关联的行`);
261
+ const err = new Exception_1.OakRowInconsistencyException(`您无法删除存在有效数据「${e}」关联的行`);
261
262
  err.addData(e, [row]);
262
263
  throw err;
263
264
  }
@@ -266,7 +267,7 @@ function createRemoveCheckers(schema) {
266
267
  else {
267
268
  const [row] = result;
268
269
  if (row) {
269
- const err = new Exception_1.OakRowInconsistencyException(undefined, `您无法删除存在有效数据「${e}」关联的行`);
270
+ const err = new Exception_1.OakRowInconsistencyException(`您无法删除存在有效数据「${e}」关联的行`);
270
271
  err.addData(e, [row]);
271
272
  throw err;
272
273
  }
@@ -292,7 +293,7 @@ function createRemoveCheckers(schema) {
292
293
  if (result instanceof Promise) {
293
294
  promises.push(result.then(([row]) => {
294
295
  if (row) {
295
- const e = new Exception_1.OakRowInconsistencyException(undefined, `您无法删除存在有效数据「${otm}」关联的行`);
296
+ const e = new Exception_1.OakRowInconsistencyException(`您无法删除存在有效数据「${otm}」关联的行`);
296
297
  e.addData(otm, [row]);
297
298
  throw e;
298
299
  }
@@ -309,7 +310,7 @@ function createRemoveCheckers(schema) {
309
310
  }
310
311
  }
311
312
  };
312
- const e = new Exception_1.OakRowInconsistencyException(undefined, `您无法删除存在有效数据「${otm}」关联的行`);
313
+ const e = new Exception_1.OakRowInconsistencyException(`您无法删除存在有效数据「${otm}」关联的行`);
313
314
  e.addData(otm, [row]);
314
315
  throw e;
315
316
  }
@@ -12,7 +12,16 @@ function translateCreateDataToFilter(schema, entity, data, allowUnrecoganized) {
12
12
  const rel = (0, relation_1.judgeRelation)(schema, entity, attr, allowUnrecoganized);
13
13
  if (rel === 1) {
14
14
  // 只需要记住id和各种外键属性,不这样处理有些古怪的属性比如coordinate,其作为createdata和作为filter并不同构
15
- if (!['geometry', 'geography', 'st_geometry', 'st_point'].includes(schema[entity].attributes[attr]?.type)) {
15
+ if (![
16
+ 'geometry',
17
+ 'geography',
18
+ 'st_geometry',
19
+ 'st_point',
20
+ 'function',
21
+ 'sequence',
22
+ 'array',
23
+ 'object'
24
+ ].includes(schema[entity].attributes[attr]?.type)) {
16
25
  data2[attr] = data[attr];
17
26
  }
18
27
  }
@@ -1602,9 +1611,7 @@ function checkDeduceFilters(dfc, context) {
1602
1611
  * @returns
1603
1612
  */
1604
1613
  function checkFilterContains(entity, context, contained, filter, dataCompare, warningOnDataCompare) {
1605
- if (!filter) {
1606
- throw new types_1.OakRowInconsistencyException();
1607
- }
1614
+ (0, assert_1.default)(filter);
1608
1615
  const schema = context.getSchema();
1609
1616
  const result = contains(entity, schema, filter, contained);
1610
1617
  if (typeof result === 'boolean') {
@@ -1620,9 +1627,7 @@ function checkFilterContains(entity, context, contained, filter, dataCompare, wa
1620
1627
  }
1621
1628
  exports.checkFilterContains = checkFilterContains;
1622
1629
  function checkFilterRepel(entity, context, filter1, filter2, dataCompare, warningOnDataCompare) {
1623
- if (!filter2) {
1624
- throw new types_1.OakRowInconsistencyException();
1625
- }
1630
+ (0, assert_1.default)(filter2);
1626
1631
  const schema = context.getSchema();
1627
1632
  const result = repel(entity, schema, filter2, filter1);
1628
1633
  if (typeof result === 'boolean') {
@@ -153,7 +153,7 @@ export type CreateOpResult<ED extends EntityDict, T extends keyof ED> = {
153
153
  };
154
154
  export type UpdateOpResult<ED extends EntityDict, T extends keyof ED> = {
155
155
  id: string;
156
- a: 'u';
156
+ a: string;
157
157
  e: T;
158
158
  d: UpdateOperationData;
159
159
  f?: Filter;
@@ -1,9 +1,14 @@
1
- import { EntityDict, OpRecord, SelectOpResult } from "./Entity";
1
+ import { EntityDict, OpRecord } from "./Entity";
2
2
  export declare class OakException<ED extends EntityDict> extends Error {
3
- opRecord: SelectOpResult<ED>;
3
+ opRecords: OpRecord<ED>[];
4
4
  constructor(message?: string);
5
5
  addData<T extends keyof ED>(entity: T, rows: Partial<ED[T]['OpSchema']>[]): void;
6
- setOpRecords(opRecord: SelectOpResult<ED>): void;
6
+ setOpRecords(opRecords: OpRecord<ED>[]): void;
7
+ getSerialData(): {
8
+ name: string;
9
+ message: string;
10
+ opRecords: OpRecord<ED>[];
11
+ };
7
12
  toString(): string;
8
13
  }
9
14
  export declare class OakMakeSureByMySelfException<ED extends EntityDict> extends OakException<ED> {
@@ -62,7 +67,6 @@ export declare class OakServerProxyException<ED extends EntityDict> extends OakE
62
67
  *
63
68
  */
64
69
  export declare class OakRowInconsistencyException<ED extends EntityDict> extends OakUserException<ED> {
65
- constructor(data?: OpRecord<ED>, message?: string);
66
70
  toString(): string;
67
71
  }
68
72
  /**
@@ -158,6 +162,6 @@ export declare class OakExternalException<ED extends EntityDict> extends OakUser
158
162
  export declare function makeException<ED extends EntityDict>(data: {
159
163
  name: string;
160
164
  message?: string;
161
- opRecords: SelectOpResult<ED>;
165
+ opRecords: OpRecord<ED>[];
162
166
  [A: string]: any;
163
167
  }): OakException<ED> | undefined;
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeException = exports.OakExternalException = exports.OakPreConditionUnsetException = exports.OakDeadlock = exports.OakCongruentRowExists = exports.OakRowLockedException = exports.OakUnloggedInException = exports.OakUserInvisibleException = exports.OakUserUnpermittedException = exports.OakAttrCantUpdateException = exports.OakAttrNotNullException = exports.OakInputIllegalException = exports.OakRowInconsistencyException = exports.OakServerProxyException = exports.OakNetworkException = exports.OakUserException = exports.OakRowUnexistedException = exports.OakOperExistedException = exports.OakNoRelationDefException = exports.OakImportDataParseException = exports.OakUniqueViolationException = exports.OakDataException = exports.OakMakeSureByMySelfException = exports.OakException = void 0;
4
- const tslib_1 = require("tslib");
5
- const assert_1 = tslib_1.__importDefault(require("assert"));
6
4
  class OakException extends Error {
7
- opRecord;
5
+ opRecords;
8
6
  constructor(message) {
9
7
  super(message);
10
8
  this.name = new.target.name;
@@ -17,36 +15,32 @@ class OakException extends Error {
17
15
  else {
18
16
  this.__proto__ = new.target.prototype;
19
17
  }
20
- this.opRecord = {
21
- a: 's',
22
- d: {},
23
- };
18
+ this.opRecords = [];
24
19
  }
25
20
  addData(entity, rows) {
26
- const { d } = this.opRecord;
27
- const addSingleRow = (rowRoot, row) => {
28
- const { id } = row;
29
- if (rowRoot[id]) {
30
- Object.assign(rowRoot[id], row);
31
- }
32
- else {
33
- rowRoot[id] = row;
21
+ const record = {
22
+ a: 's',
23
+ d: {
24
+ [entity]: {},
34
25
  }
35
26
  };
36
- if (!d[entity]) {
37
- d[entity] = {};
27
+ for (const row of rows) {
28
+ record.d[entity][row.id] = row;
38
29
  }
39
- rows.forEach(row => addSingleRow(d[entity], row));
30
+ this.opRecords.push(record);
40
31
  }
41
- setOpRecords(opRecord) {
42
- this.opRecord = opRecord;
32
+ setOpRecords(opRecords) {
33
+ this.opRecords = opRecords;
43
34
  }
44
- toString() {
45
- return JSON.stringify({
35
+ getSerialData() {
36
+ return {
46
37
  name: this.constructor.name,
47
38
  message: this.message,
48
- opRecord: this.opRecord,
49
- });
39
+ opRecords: this.opRecords,
40
+ };
41
+ }
42
+ toString() {
43
+ return JSON.stringify(this.getSerialData());
50
44
  }
51
45
  }
52
46
  exports.OakException = OakException;
@@ -85,9 +79,9 @@ class OakNoRelationDefException extends OakDataException {
85
79
  this.actions = actions;
86
80
  }
87
81
  toString() {
82
+ const data = super.getSerialData();
88
83
  return JSON.stringify({
89
- name: this.constructor.name,
90
- message: this.message,
84
+ ...data,
91
85
  entity: this.entity,
92
86
  action: this.actions,
93
87
  });
@@ -105,7 +99,11 @@ class OakRowUnexistedException extends OakDataException {
105
99
  this.rows = rows;
106
100
  }
107
101
  toString() {
108
- return JSON.stringify({ rows: this.rows });
102
+ const data = super.getSerialData();
103
+ return JSON.stringify({
104
+ ...data,
105
+ rows: this.rows
106
+ });
109
107
  }
110
108
  getRows() {
111
109
  return this.rows;
@@ -135,15 +133,9 @@ exports.OakServerProxyException = OakServerProxyException;
135
133
  *
136
134
  */
137
135
  class OakRowInconsistencyException extends OakUserException {
138
- constructor(data, message) {
139
- super(message);
140
- (0, assert_1.default)(!data, '现在使用addData接口来传数据');
141
- }
142
136
  toString() {
143
- return JSON.stringify({
144
- name: this.constructor.name,
145
- message: this.message,
146
- });
137
+ const data = super.getSerialData();
138
+ return JSON.stringify(data);
147
139
  }
148
140
  }
149
141
  exports.OakRowInconsistencyException = OakRowInconsistencyException;
@@ -169,10 +161,10 @@ class OakInputIllegalException extends OakUserException {
169
161
  this.attributes = this.attributes.map(ele => `${prefix}.${ele}`);
170
162
  }
171
163
  toString() {
164
+ const data = super.getSerialData();
172
165
  return JSON.stringify({
166
+ ...data,
173
167
  entity: this.entity,
174
- name: this.constructor.name,
175
- message: this.message,
176
168
  attributes: this.attributes,
177
169
  });
178
170
  }
@@ -209,10 +201,10 @@ class OakUserUnpermittedException extends OakUserException {
209
201
  this.operation = operation;
210
202
  }
211
203
  toString() {
204
+ const data = super.getSerialData();
212
205
  return JSON.stringify({
206
+ ...data,
213
207
  entity: this.entity,
214
- name: this.constructor.name,
215
- message: this.message,
216
208
  operation: this.operation,
217
209
  });
218
210
  }
@@ -231,10 +223,10 @@ class OakUserInvisibleException extends OakUserException {
231
223
  this.operation = operation;
232
224
  }
233
225
  toString() {
226
+ const data = super.getSerialData();
234
227
  return JSON.stringify({
228
+ ...data,
235
229
  entity: this.entity,
236
- name: this.constructor.name,
237
- message: this.message,
238
230
  operation: this.operation,
239
231
  });
240
232
  }
@@ -279,9 +271,9 @@ class OakCongruentRowExists extends OakUserException {
279
271
  return this.entity;
280
272
  }
281
273
  toString() {
274
+ const data = super.getSerialData();
282
275
  return JSON.stringify({
283
- name: this.constructor.name,
284
- message: this.message,
276
+ ...data,
285
277
  data: this.data,
286
278
  entity: this.entity,
287
279
  });
@@ -310,9 +302,9 @@ class OakPreConditionUnsetException extends OakUserException {
310
302
  this.code = code;
311
303
  }
312
304
  toString() {
305
+ const data = super.getSerialData();
313
306
  return JSON.stringify({
314
- name: this.constructor.name,
315
- message: this.message,
307
+ ...data,
316
308
  code: this.code,
317
309
  entity: this.entity,
318
310
  });
@@ -333,9 +325,10 @@ class OakExternalException extends OakUserException {
333
325
  this.data = data;
334
326
  }
335
327
  toString() {
328
+ const data = super.getSerialData();
336
329
  return JSON.stringify({
330
+ ...data,
337
331
  code: this.code,
338
- message: this.message,
339
332
  source: this.source,
340
333
  data: this.data,
341
334
  });
@@ -355,7 +348,7 @@ function makeException(data) {
355
348
  break;
356
349
  }
357
350
  case 'OakRowInconsistencyException': {
358
- e = new OakRowInconsistencyException(data.data, data.message);
351
+ e = new OakRowInconsistencyException(data.message);
359
352
  break;
360
353
  }
361
354
  case 'OakInputIllegalException': {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-domain",
3
- "version": "5.0.4",
3
+ "version": "5.0.6",
4
4
  "author": {
5
5
  "name": "XuChang"
6
6
  },