oak-domain 5.0.5 → 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,
@@ -63,7 +63,7 @@ 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
  }
@@ -78,7 +78,7 @@ function translateCheckerInAsyncContext(checker, schema) {
78
78
  dontCollect: true,
79
79
  blockTrigger: true,
80
80
  }); */
81
- const e = new Exception_1.OakRowInconsistencyException(undefined, errMsg);
81
+ const e = new Exception_1.OakRowInconsistencyException(errMsg);
82
82
  // e.addData(entity, rows2);
83
83
  throw e;
84
84
  }
@@ -156,7 +156,7 @@ function translateCheckerInSyncContext(checker, schema) {
156
156
  if ((0, filter_1.checkFilterContains)(entity, context, filter2, operationFilter2, true)) {
157
157
  return;
158
158
  }
159
- const e = new Exception_1.OakRowInconsistencyException(undefined, errMsg || 'row checker condition illegal');
159
+ const e = new Exception_1.OakRowInconsistencyException(errMsg || 'row checker condition illegal');
160
160
  throw e;
161
161
  };
162
162
  return {
@@ -258,7 +258,7 @@ function createRemoveCheckers(schema) {
258
258
  if (result instanceof Promise) {
259
259
  promises.push(result.then(([row]) => {
260
260
  if (row) {
261
- const err = new Exception_1.OakRowInconsistencyException(undefined, `您无法删除存在有效数据「${e}」关联的行`);
261
+ const err = new Exception_1.OakRowInconsistencyException(`您无法删除存在有效数据「${e}」关联的行`);
262
262
  err.addData(e, [row]);
263
263
  throw err;
264
264
  }
@@ -267,7 +267,7 @@ function createRemoveCheckers(schema) {
267
267
  else {
268
268
  const [row] = result;
269
269
  if (row) {
270
- const err = new Exception_1.OakRowInconsistencyException(undefined, `您无法删除存在有效数据「${e}」关联的行`);
270
+ const err = new Exception_1.OakRowInconsistencyException(`您无法删除存在有效数据「${e}」关联的行`);
271
271
  err.addData(e, [row]);
272
272
  throw err;
273
273
  }
@@ -293,7 +293,7 @@ function createRemoveCheckers(schema) {
293
293
  if (result instanceof Promise) {
294
294
  promises.push(result.then(([row]) => {
295
295
  if (row) {
296
- const e = new Exception_1.OakRowInconsistencyException(undefined, `您无法删除存在有效数据「${otm}」关联的行`);
296
+ const e = new Exception_1.OakRowInconsistencyException(`您无法删除存在有效数据「${otm}」关联的行`);
297
297
  e.addData(otm, [row]);
298
298
  throw e;
299
299
  }
@@ -310,7 +310,7 @@ function createRemoveCheckers(schema) {
310
310
  }
311
311
  }
312
312
  };
313
- const e = new Exception_1.OakRowInconsistencyException(undefined, `您无法删除存在有效数据「${otm}」关联的行`);
313
+ const e = new Exception_1.OakRowInconsistencyException(`您无法删除存在有效数据「${otm}」关联的行`);
314
314
  e.addData(otm, [row]);
315
315
  throw e;
316
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;
@@ -67,7 +67,6 @@ export declare class OakServerProxyException<ED extends EntityDict> extends OakE
67
67
  *
68
68
  */
69
69
  export declare class OakRowInconsistencyException<ED extends EntityDict> extends OakUserException<ED> {
70
- constructor(data?: OpRecord<ED>, message?: string);
71
70
  toString(): string;
72
71
  }
73
72
  /**
@@ -1,8 +1,6 @@
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
5
  opRecords;
8
6
  constructor(message) {
@@ -135,10 +133,6 @@ 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
137
  const data = super.getSerialData();
144
138
  return JSON.stringify(data);
@@ -354,7 +348,7 @@ function makeException(data) {
354
348
  break;
355
349
  }
356
350
  case 'OakRowInconsistencyException': {
357
- e = new OakRowInconsistencyException(data.data, data.message);
351
+ e = new OakRowInconsistencyException(data.message);
358
352
  break;
359
353
  }
360
354
  case 'OakInputIllegalException': {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-domain",
3
- "version": "5.0.5",
3
+ "version": "5.0.6",
4
4
  "author": {
5
5
  "name": "XuChang"
6
6
  },