@etsoo/shared 1.2.65 → 1.2.66
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/__tests__/Utils.ts +4 -3
- package/lib/cjs/Utils.d.ts +2 -2
- package/lib/cjs/Utils.js +5 -5
- package/lib/mjs/Utils.d.ts +2 -2
- package/lib/mjs/Utils.js +5 -5
- package/package.json +1 -1
- package/src/Utils.ts +13 -9
package/__tests__/Utils.ts
CHANGED
|
@@ -104,7 +104,7 @@ test("Tests for correctTypes", () => {
|
|
|
104
104
|
|
|
105
105
|
test("Tests for getDataChanges", () => {
|
|
106
106
|
const input = {
|
|
107
|
-
id:
|
|
107
|
+
id: 2,
|
|
108
108
|
name: "Name",
|
|
109
109
|
gender: "F",
|
|
110
110
|
brand: "",
|
|
@@ -146,10 +146,11 @@ test("Tests for getDataChanges", () => {
|
|
|
146
146
|
enabled: true,
|
|
147
147
|
value: undefined,
|
|
148
148
|
date: new Date("2023/03/18"),
|
|
149
|
-
ids: [1, 2]
|
|
149
|
+
ids: [1, 2],
|
|
150
|
+
changedFields: ["gender", "brand", "date"]
|
|
150
151
|
};
|
|
151
152
|
const fields1 = Utils.getDataChanges(input1, initData, ["brand", "date"]);
|
|
152
|
-
expect(fields1).toStrictEqual(["gender", "amount"]);
|
|
153
|
+
expect(fields1).toStrictEqual(["id", "gender", "amount", "changedFields"]);
|
|
153
154
|
});
|
|
154
155
|
|
|
155
156
|
test("Tests for object array getDataChanges", () => {
|
package/lib/cjs/Utils.d.ts
CHANGED
|
@@ -156,10 +156,10 @@ export declare namespace Utils {
|
|
|
156
156
|
* Get data changed fields (ignored changedFields) with input data updated
|
|
157
157
|
* @param input Input data
|
|
158
158
|
* @param initData Initial data
|
|
159
|
-
* @param ignoreFields Ignore fields
|
|
159
|
+
* @param ignoreFields Ignore fields, default is ['changedFields', 'id']
|
|
160
160
|
* @returns
|
|
161
161
|
*/
|
|
162
|
-
export function getDataChanges<T extends object, const I extends (keyof T & string)[]>(input: T, initData: object, ignoreFields?: I): Exclude<keyof T & string, (typeof
|
|
162
|
+
export function getDataChanges<T extends object, const I extends (keyof T & string)[] | undefined = undefined>(input: T, initData: object, ignoreFields?: I): Exclude<keyof T & string, I extends undefined ? (typeof IgnoredProperties)[number] : Exclude<I, undefined>[number]>[];
|
|
163
163
|
/**
|
|
164
164
|
* Get nested value from object
|
|
165
165
|
* @param data Data
|
package/lib/cjs/Utils.js
CHANGED
|
@@ -257,17 +257,17 @@ var Utils;
|
|
|
257
257
|
* Get data changed fields (ignored changedFields) with input data updated
|
|
258
258
|
* @param input Input data
|
|
259
259
|
* @param initData Initial data
|
|
260
|
-
* @param ignoreFields Ignore fields
|
|
260
|
+
* @param ignoreFields Ignore fields, default is ['changedFields', 'id']
|
|
261
261
|
* @returns
|
|
262
262
|
*/
|
|
263
|
-
function getDataChanges(input, initData, ignoreFields
|
|
263
|
+
function getDataChanges(input, initData, ignoreFields) {
|
|
264
|
+
// Default ignore fields
|
|
265
|
+
const fields = ignoreFields ?? IgnoredProperties;
|
|
264
266
|
// Changed fields
|
|
265
267
|
const changes = [];
|
|
266
|
-
// Ignored fields
|
|
267
|
-
const allFields = [...ignoreFields, ...IgnoredProperties];
|
|
268
268
|
Object.entries(input).forEach(([key, value]) => {
|
|
269
269
|
// Ignore fields, no process
|
|
270
|
-
if (
|
|
270
|
+
if (fields.includes(key))
|
|
271
271
|
return;
|
|
272
272
|
// Compare with init value
|
|
273
273
|
const initValue = Reflect.get(initData, key);
|
package/lib/mjs/Utils.d.ts
CHANGED
|
@@ -156,10 +156,10 @@ export declare namespace Utils {
|
|
|
156
156
|
* Get data changed fields (ignored changedFields) with input data updated
|
|
157
157
|
* @param input Input data
|
|
158
158
|
* @param initData Initial data
|
|
159
|
-
* @param ignoreFields Ignore fields
|
|
159
|
+
* @param ignoreFields Ignore fields, default is ['changedFields', 'id']
|
|
160
160
|
* @returns
|
|
161
161
|
*/
|
|
162
|
-
export function getDataChanges<T extends object, const I extends (keyof T & string)[]>(input: T, initData: object, ignoreFields?: I): Exclude<keyof T & string, (typeof
|
|
162
|
+
export function getDataChanges<T extends object, const I extends (keyof T & string)[] | undefined = undefined>(input: T, initData: object, ignoreFields?: I): Exclude<keyof T & string, I extends undefined ? (typeof IgnoredProperties)[number] : Exclude<I, undefined>[number]>[];
|
|
163
163
|
/**
|
|
164
164
|
* Get nested value from object
|
|
165
165
|
* @param data Data
|
package/lib/mjs/Utils.js
CHANGED
|
@@ -251,17 +251,17 @@ export var Utils;
|
|
|
251
251
|
* Get data changed fields (ignored changedFields) with input data updated
|
|
252
252
|
* @param input Input data
|
|
253
253
|
* @param initData Initial data
|
|
254
|
-
* @param ignoreFields Ignore fields
|
|
254
|
+
* @param ignoreFields Ignore fields, default is ['changedFields', 'id']
|
|
255
255
|
* @returns
|
|
256
256
|
*/
|
|
257
|
-
function getDataChanges(input, initData, ignoreFields
|
|
257
|
+
function getDataChanges(input, initData, ignoreFields) {
|
|
258
|
+
// Default ignore fields
|
|
259
|
+
const fields = ignoreFields ?? IgnoredProperties;
|
|
258
260
|
// Changed fields
|
|
259
261
|
const changes = [];
|
|
260
|
-
// Ignored fields
|
|
261
|
-
const allFields = [...ignoreFields, ...IgnoredProperties];
|
|
262
262
|
Object.entries(input).forEach(([key, value]) => {
|
|
263
263
|
// Ignore fields, no process
|
|
264
|
-
if (
|
|
264
|
+
if (fields.includes(key))
|
|
265
265
|
return;
|
|
266
266
|
// Compare with init value
|
|
267
267
|
const initValue = Reflect.get(initData, key);
|
package/package.json
CHANGED
package/src/Utils.ts
CHANGED
|
@@ -402,32 +402,36 @@ export namespace Utils {
|
|
|
402
402
|
* Get data changed fields (ignored changedFields) with input data updated
|
|
403
403
|
* @param input Input data
|
|
404
404
|
* @param initData Initial data
|
|
405
|
-
* @param ignoreFields Ignore fields
|
|
405
|
+
* @param ignoreFields Ignore fields, default is ['changedFields', 'id']
|
|
406
406
|
* @returns
|
|
407
407
|
*/
|
|
408
408
|
export function getDataChanges<
|
|
409
409
|
T extends object,
|
|
410
|
-
const I extends (keyof T & string)[]
|
|
410
|
+
const I extends (keyof T & string)[] | undefined = undefined
|
|
411
411
|
>(
|
|
412
412
|
input: T,
|
|
413
413
|
initData: object,
|
|
414
|
-
ignoreFields
|
|
414
|
+
ignoreFields?: I
|
|
415
415
|
): Exclude<
|
|
416
416
|
keyof T & string,
|
|
417
|
-
|
|
417
|
+
I extends undefined
|
|
418
|
+
? (typeof IgnoredProperties)[number]
|
|
419
|
+
: Exclude<I, undefined>[number]
|
|
418
420
|
>[] {
|
|
421
|
+
// Default ignore fields
|
|
422
|
+
const fields = ignoreFields ?? IgnoredProperties;
|
|
423
|
+
|
|
419
424
|
// Changed fields
|
|
420
425
|
const changes: Exclude<
|
|
421
426
|
keyof T & string,
|
|
422
|
-
|
|
427
|
+
I extends undefined
|
|
428
|
+
? (typeof IgnoredProperties)[number]
|
|
429
|
+
: Exclude<I, undefined>[number]
|
|
423
430
|
>[] = [];
|
|
424
431
|
|
|
425
|
-
// Ignored fields
|
|
426
|
-
const allFields: string[] = [...ignoreFields, ...IgnoredProperties];
|
|
427
|
-
|
|
428
432
|
Object.entries(input).forEach(([key, value]) => {
|
|
429
433
|
// Ignore fields, no process
|
|
430
|
-
if (
|
|
434
|
+
if (fields.includes(key as any)) return;
|
|
431
435
|
|
|
432
436
|
// Compare with init value
|
|
433
437
|
const initValue = Reflect.get(initData, key);
|