oak-domain 5.1.24 → 5.1.26

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.
@@ -167,8 +167,11 @@ function polishSelection(schema, entity, selection, context, option) {
167
167
  }
168
168
  const toBeAssignNode2 = {}; // 用来记录在表达式中涉及到的结点
169
169
  const projectionNodeDict = {};
170
- const checkProjectionNode = (entity2, projectionNode) => {
171
- const necessaryAttrs = ['id', '$$createAt$$', '$$updateAt$$']; // 有的页面依赖于其它页面取数据,有时两个页面的filter的差异会导致有一个加createAt,有一个不加,此时可能产生前台取数据不完整的异常。先统一加上
170
+ const checkProjectionNode = (entity2, projectionNode, root) => {
171
+ const necessaryAttrs = [types_1.PrimaryKeyAttribute, Entity_1.CreateAtAttribute, Entity_1.UpdateAtAttribute]; // 有的页面依赖于其它页面取数据,有时两个页面的filter的差异会导致有一个加createAt,有一个不加,此时可能产生前台取数据不完整的异常。先统一加上
172
+ if (root && option?.includedDeleted) {
173
+ necessaryAttrs.push(Entity_1.DeleteAtAttribute);
174
+ }
172
175
  for (const attr in projectionNode) {
173
176
  if (attr === '#id') {
174
177
  (0, assert_1.default)(!projectionNodeDict[projectionNode[attr]], `projection中结点的id有重复, ${projectionNode[attr]}`);
@@ -264,7 +267,7 @@ function polishSelection(schema, entity, selection, context, option) {
264
267
  }
265
268
  }
266
269
  };
267
- checkProjectionNode(entity, data);
270
+ checkProjectionNode(entity, data, true);
268
271
  if (!sorter && relevantIds.length === 0) {
269
272
  // 如果没有sorter,就给予一个按createAt逆序的sorter
270
273
  Object.assign(selection, {
@@ -1702,7 +1705,7 @@ class CascadeStore extends RowStore_1.RowStore {
1702
1705
  const entityBranch = lastOperation.d[entity];
1703
1706
  if (entityBranch) {
1704
1707
  rows.forEach((row) => {
1705
- if (row && row.id) { // 如果没有row.id就不加入结果集了
1708
+ if (row && row.id && !row[Entity_1.DeleteAtAttribute]) { // 如果没有row.id就不加入结果集了
1706
1709
  const { id } = row;
1707
1710
  if (!entityBranch[id]) {
1708
1711
  Object.assign(entityBranch, {
@@ -1727,7 +1730,7 @@ class CascadeStore extends RowStore_1.RowStore {
1727
1730
  }
1728
1731
  const entityBranch = {};
1729
1732
  rows.forEach((row) => {
1730
- if (row) {
1733
+ if (row && row.id && !row[Entity_1.DeleteAtAttribute]) {
1731
1734
  const { id } = row;
1732
1735
  Object.assign(entityBranch, {
1733
1736
  [id]: (0, lodash_1.cloneDeep)(row),
@@ -350,30 +350,33 @@ function createAttrUpdateCheckers(schema, attrUpdateMatrix) {
350
350
  }
351
351
  const filters = condition.map(ele => {
352
352
  if (typeof ele?.filter === 'function') {
353
- return ele.filter(action || 'select');
353
+ return (ele.filter)({ action: action || 'select', data: data, filter }, context);
354
354
  }
355
355
  return ele?.filter;
356
- }).filter(ele => !!ele);
357
- const f = filters.length > 0 && (0, filter_1.combineFilters)(entity, schema, filters);
358
- if (f) {
359
- const result = (0, filter_1.checkFilterContains)(entity, context, f, filter, true);
360
- if (result instanceof Promise) {
361
- return result.then((v) => {
362
- if (!v) {
363
- if (attrs.length > 1) {
364
- return cascadelyCheckUpdateFilters(entity, schema, action || 'select', data, filter, matrix, attrs, context);
365
- }
366
- throw new types_1.OakAttrCantUpdateException(entity, attrs);
356
+ });
357
+ const checkFiltersInner = (filters2) => {
358
+ const filters3 = filters2.filter(ele => !!ele);
359
+ const f = filters3.length > 0 && (0, filter_1.combineFilters)(entity, schema, filters3);
360
+ const checkResultInner = (result2) => {
361
+ if (!result2) {
362
+ if (attrs.length > 1) {
363
+ return cascadelyCheckUpdateFilters(entity, schema, action || 'select', data, filter, matrix, attrs, context);
367
364
  }
368
- });
369
- }
370
- if (!result) {
371
- if (attrs.length > 1) {
372
- return cascadelyCheckUpdateFilters(entity, schema, action || 'select', data, filter, matrix, attrs, context);
365
+ throw new types_1.OakAttrCantUpdateException(entity, attrs);
373
366
  }
374
- throw new types_1.OakAttrCantUpdateException(entity, attrs, '更新的行当前属性不满足约束,请仔细检查数据');
367
+ };
368
+ if (f) {
369
+ const result = (0, filter_1.checkFilterContains)(entity, context, f, filter, true);
370
+ if (result instanceof Promise) {
371
+ return result.then((r) => checkResultInner(r));
372
+ }
373
+ return checkResultInner(result);
375
374
  }
375
+ };
376
+ if (filters.find(ele => ele instanceof Promise)) {
377
+ return Promise.all(filters).then((ff) => checkFiltersInner(ff));
376
378
  }
379
+ return checkFiltersInner(filters);
377
380
  }
378
381
  };
379
382
  checkers.push(updateChecker);
@@ -46,6 +46,7 @@ export type ServerConfiguration = {
46
46
  methods?: string[];
47
47
  };
48
48
  ui?: {
49
+ path?: string;
49
50
  disable?: boolean;
50
51
  username?: string;
51
52
  password?: string;
@@ -53,8 +54,8 @@ export type ServerConfiguration = {
53
54
  internalExceptionMask?: string;
54
55
  koaBody?: IKoaBodyOptions;
55
56
  socket?: (ctx: Koa.ParameterizedContext<any, KoaRouter.IRouterParamContext<any, {}>, any>) => {
56
- url?: string;
57
- };
57
+ url: string;
58
+ } | undefined;
58
59
  };
59
60
  /**
60
61
  * 前后台访问配置
@@ -189,7 +189,7 @@ class SimpleConnector {
189
189
  };
190
190
  }
191
191
  async serializeResult(result, opRecords, headers, body, message) {
192
- if (result instanceof stream_1.Stream || result instanceof Buffer || result instanceof ReadableStream) {
192
+ if (result instanceof stream_1.Stream || result instanceof Buffer) {
193
193
  return {
194
194
  body: result,
195
195
  headers: {
@@ -23,4 +23,8 @@ export declare const isVehicleNumber: ValidatorFunction;
23
23
  export declare const isEmail: ValidatorFunction;
24
24
  export declare function checkAttributesNotNull<ED extends EntityDict, T extends keyof EntityDict>(entity: T, data: Partial<ED[T]['CreateOperationData']>, attributes: Array<keyof ED[T]['CreateOperationData']>, allowEmpty?: true): void;
25
25
  export declare function checkAttributesScope<ED extends EntityDict, T extends keyof EntityDict>(entity: T, data: Partial<ED[T]['CreateOperationData']>, attributes: Array<keyof ED[T]['CreateOperationData']>): void;
26
+ export declare const isIPV4: ValidatorFunction;
27
+ export declare const isIPV6: ValidatorFunction;
28
+ export declare const isIP: ValidatorFunction;
29
+ export declare const isDomain: ValidatorFunction;
26
30
  export {};
@@ -3,7 +3,7 @@
3
3
  */
4
4
  'use strict';
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.checkAttributesScope = exports.checkAttributesNotNull = exports.isEmail = exports.isVehicleNumber = exports.isMoney = exports.isNumber = exports.isTel = exports.isPhone = exports.isDigital = exports.isSizedCaptcha = exports.isNickname = exports.isUrl = exports.isSoldierNumber = exports.isBirthNumber = exports.isTwCardNumber = exports.isAmCardNumber = exports.isHkCardNumber = exports.isPassportNumber = exports.isIdCardNumber = exports.isCaptcha = exports.isPassword = exports.isMobile = void 0;
6
+ exports.isDomain = exports.isIP = exports.isIPV6 = exports.isIPV4 = exports.checkAttributesScope = exports.checkAttributesNotNull = exports.isEmail = exports.isVehicleNumber = exports.isMoney = exports.isNumber = exports.isTel = exports.isPhone = exports.isDigital = exports.isSizedCaptcha = exports.isNickname = exports.isUrl = exports.isSoldierNumber = exports.isBirthNumber = exports.isTwCardNumber = exports.isAmCardNumber = exports.isHkCardNumber = exports.isPassportNumber = exports.isIdCardNumber = exports.isCaptcha = exports.isPassword = exports.isMobile = void 0;
7
7
  const types_1 = require("../types");
8
8
  const isMobile = (text) => {
9
9
  return ((text) && (typeof text === "string") && ((/^1[3|4|5|6|7|8|9]\d{9}$/.test(text))));
@@ -131,3 +131,25 @@ function checkAttributesScope(entity, data, attributes) {
131
131
  }
132
132
  }
133
133
  exports.checkAttributesScope = checkAttributesScope;
134
+ const isIPV4 = (ip) => {
135
+ // IPv4正则
136
+ const ipv4Regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
137
+ return ipv4Regex.test(ip);
138
+ };
139
+ exports.isIPV4 = isIPV4;
140
+ const isIPV6 = (ip) => {
141
+ // IPv6正则(简化版,匹配常见格式)
142
+ const ipv6Regex = /^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$|^::([0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4}$|^[0-9a-fA-F]{1,4}::([0-9a-fA-F]{1,4}:){0,5}[0-9a-fA-F]{1,4}$|^([0-9a-fA-F]{1,4}:){1}:([0-9a-fA-F]{1,4}:){0,4}[0-9a-fA-F]{1,4}$|^([0-9a-fA-F]{1,4}:){2}:([0-9a-fA-F]{1,4}:){0,3}[0-9a-fA-F]{1,4}$|^([0-9a-fA-F]{1,4}:){3}:([0-9a-fA-F]{1,4}:){0,2}[0-9a-fA-F]{1,4}$|^([0-9a-fA-F]{1,4}:){4}:([0-9a-fA-F]{1,4}:){0,1}[0-9a-fA-F]{1,4}$|^([0-9a-fA-F]{1,4}:){5}:[0-9a-fA-F]{1,4}$|^([0-9a-fA-F]{1,4}:){1,6}:$/;
143
+ return ipv6Regex.test(ip);
144
+ };
145
+ exports.isIPV6 = isIPV6;
146
+ const isIP = (ip) => {
147
+ return (0, exports.isIPV4)(ip) || (0, exports.isIPV6)(ip);
148
+ };
149
+ exports.isIP = isIP;
150
+ const isDomain = (domain) => {
151
+ //基础域名验证正则
152
+ const domainRegex = /^(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\.[A-Za-z0-9-]{1,63}(?<!-))*\.[A-Za-z]{2,}$/;
153
+ return domainRegex.test(domain);
154
+ };
155
+ exports.isDomain = isDomain;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-domain",
3
- "version": "5.1.24",
3
+ "version": "5.1.26",
4
4
  "author": {
5
5
  "name": "XuChang"
6
6
  },