@etsoo/shared 1.1.65 → 1.1.67

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.
@@ -180,3 +180,18 @@ test('Tests for jsonReplacer', () => {
180
180
  );
181
181
  expect(json2).toBe('{"c":{"c2":false}}');
182
182
  });
183
+
184
+ test('Tests for AddAndEditType', () => {
185
+ type Entity = DataTypes.AddAndEditType<{
186
+ id: number;
187
+ name: string;
188
+ age?: number;
189
+ }>;
190
+
191
+ const data1: Entity = { id: 1, name: 'hello', changedFields: ['name'] };
192
+ const data2: Entity = { id: undefined, name: 'hello' };
193
+ const data3: Entity = { name: 'hello' };
194
+
195
+ expect(data1.name).toBe(data2.name);
196
+ expect(data2.name).toBe(data3.name);
197
+ });
@@ -14,6 +14,7 @@ test('Tests for addBlankItem', () => {
14
14
  test('Tests for correctTypes', () => {
15
15
  const input = {
16
16
  id: '1',
17
+ ignore: '2',
17
18
  price: '6.0',
18
19
  amount: '',
19
20
  date: '2022/01/28',
@@ -125,7 +125,7 @@ export declare namespace DataTypes {
125
125
  type AddAndEditType<T extends {
126
126
  [key in D]: IdType;
127
127
  }, D extends string = 'id'> = (Omit<T, D> & {
128
- [key in D]: undefined | never;
128
+ [key in D]?: undefined | never;
129
129
  }) | (Partial<T> & Readonly<Pick<T, D>> & {
130
130
  changedFields?: string[];
131
131
  });
@@ -66,7 +66,7 @@ export declare namespace Utils {
66
66
  * @param fields Fields to correct
67
67
  */
68
68
  function correctTypes<T extends object, F extends {
69
- [P in keyof T]: DataTypes.BasicNames;
69
+ [P in keyof T]?: DataTypes.BasicNames;
70
70
  }>(input: T, fields: F): void;
71
71
  /**
72
72
  * Two values equal
package/lib/cjs/Utils.js CHANGED
@@ -88,8 +88,11 @@ var Utils;
88
88
  */
89
89
  function correctTypes(input, fields) {
90
90
  for (const field in fields) {
91
+ const type = fields[field];
92
+ if (type == null)
93
+ continue;
91
94
  const value = Reflect.get(input, field);
92
- const newValue = DataTypes_1.DataTypes.convertByType(value, fields[field]);
95
+ const newValue = DataTypes_1.DataTypes.convertByType(value, type);
93
96
  if (newValue !== value) {
94
97
  Reflect.set(input, field, newValue);
95
98
  }
@@ -125,7 +125,7 @@ export declare namespace DataTypes {
125
125
  type AddAndEditType<T extends {
126
126
  [key in D]: IdType;
127
127
  }, D extends string = 'id'> = (Omit<T, D> & {
128
- [key in D]: undefined | never;
128
+ [key in D]?: undefined | never;
129
129
  }) | (Partial<T> & Readonly<Pick<T, D>> & {
130
130
  changedFields?: string[];
131
131
  });
@@ -66,7 +66,7 @@ export declare namespace Utils {
66
66
  * @param fields Fields to correct
67
67
  */
68
68
  function correctTypes<T extends object, F extends {
69
- [P in keyof T]: DataTypes.BasicNames;
69
+ [P in keyof T]?: DataTypes.BasicNames;
70
70
  }>(input: T, fields: F): void;
71
71
  /**
72
72
  * Two values equal
package/lib/mjs/Utils.js CHANGED
@@ -85,8 +85,11 @@ export var Utils;
85
85
  */
86
86
  function correctTypes(input, fields) {
87
87
  for (const field in fields) {
88
+ const type = fields[field];
89
+ if (type == null)
90
+ continue;
88
91
  const value = Reflect.get(input, field);
89
- const newValue = DataTypes.convertByType(value, fields[field]);
92
+ const newValue = DataTypes.convertByType(value, type);
90
93
  if (newValue !== value) {
91
94
  Reflect.set(input, field, newValue);
92
95
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.65",
3
+ "version": "1.1.67",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -54,14 +54,14 @@
54
54
  },
55
55
  "homepage": "https://github.com/ETSOO/Shared#readme",
56
56
  "devDependencies": {
57
- "@types/jest": "^29.1.2",
58
- "@typescript-eslint/eslint-plugin": "^5.40.0",
59
- "@typescript-eslint/parser": "^5.40.0",
60
- "eslint": "^8.25.0",
57
+ "@types/jest": "^29.2.0",
58
+ "@typescript-eslint/eslint-plugin": "^5.41.0",
59
+ "@typescript-eslint/parser": "^5.41.0",
60
+ "eslint": "^8.26.0",
61
61
  "eslint-config-airbnb-base": "^15.0.0",
62
62
  "eslint-plugin-import": "^2.26.0",
63
- "jest": "^29.2.0",
64
- "jest-environment-jsdom": "^29.2.0",
63
+ "jest": "^29.2.2",
64
+ "jest-environment-jsdom": "^29.2.2",
65
65
  "ts-jest": "^29.0.3",
66
66
  "typescript": "^4.8.4"
67
67
  }
package/src/DataTypes.ts CHANGED
@@ -161,7 +161,7 @@ export namespace DataTypes {
161
161
  T extends { [key in D]: IdType },
162
162
  D extends string = 'id'
163
163
  > =
164
- | (Omit<T, D> & { [key in D]: undefined | never })
164
+ | (Omit<T, D> & { [key in D]?: undefined | never })
165
165
  | (Partial<T> & Readonly<Pick<T, D>> & { changedFields?: string[] });
166
166
 
167
167
  /**
package/src/Utils.ts CHANGED
@@ -156,11 +156,13 @@ export namespace Utils {
156
156
  */
157
157
  export function correctTypes<
158
158
  T extends object,
159
- F extends { [P in keyof T]: DataTypes.BasicNames }
159
+ F extends { [P in keyof T]?: DataTypes.BasicNames }
160
160
  >(input: T, fields: F) {
161
161
  for (const field in fields) {
162
+ const type = fields[field];
163
+ if (type == null) continue;
162
164
  const value = Reflect.get(input, field);
163
- const newValue = DataTypes.convertByType(value, fields[field]);
165
+ const newValue = DataTypes.convertByType(value, type);
164
166
  if (newValue !== value) {
165
167
  Reflect.set(input, field, newValue);
166
168
  }