@etsoo/shared 1.2.56 → 1.2.58
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/README.md +256 -240
- package/__tests__/DataTypes.ts +20 -0
- package/__tests__/Utils.ts +2 -1
- package/__tests__/tsconfig.json +1 -1
- package/lib/cjs/DataTypes.d.ts +2 -2
- package/lib/cjs/Utils.d.ts +39 -37
- package/lib/cjs/Utils.js +3 -2
- package/lib/mjs/DataTypes.d.ts +2 -2
- package/lib/mjs/Utils.d.ts +39 -37
- package/lib/mjs/Utils.js +3 -2
- package/package.json +1 -2
- package/src/DataTypes.ts +4 -2
- package/src/Utils.ts +6 -4
- package/tsconfig.cjs.json +1 -1
- package/tsconfig.json +1 -1
package/src/DataTypes.ts
CHANGED
|
@@ -191,7 +191,8 @@ export namespace DataTypes {
|
|
|
191
191
|
D extends string = "id"
|
|
192
192
|
> =
|
|
193
193
|
| (Omit<T, D> & { [key in D]?: undefined | never })
|
|
194
|
-
| (Partial<T> &
|
|
194
|
+
| (Partial<T> &
|
|
195
|
+
Readonly<Pick<T, D>> & { changedFields?: (keyof T & string)[] });
|
|
195
196
|
|
|
196
197
|
/**
|
|
197
198
|
* Add or edit conditional type
|
|
@@ -203,7 +204,8 @@ export namespace DataTypes {
|
|
|
203
204
|
D extends string = "id" // Default is 'id' field
|
|
204
205
|
> = E extends false
|
|
205
206
|
? Optional<T, D>
|
|
206
|
-
: Partial<T> &
|
|
207
|
+
: Partial<T> &
|
|
208
|
+
Readonly<Pick<T, D>> & { changedFields?: (keyof T & string)[] };
|
|
207
209
|
|
|
208
210
|
/**
|
|
209
211
|
* Key collection, like { key1: {}, key2: {} }
|
package/src/Utils.ts
CHANGED
|
@@ -261,6 +261,8 @@ String.prototype.removeNonLetters = function (this: string) {
|
|
|
261
261
|
* Utilities
|
|
262
262
|
*/
|
|
263
263
|
export namespace Utils {
|
|
264
|
+
const IgnoredProperty = "changedFields" as const;
|
|
265
|
+
|
|
264
266
|
/**
|
|
265
267
|
* Add blank item to collection
|
|
266
268
|
* @param options Options
|
|
@@ -397,7 +399,7 @@ export namespace Utils {
|
|
|
397
399
|
}
|
|
398
400
|
|
|
399
401
|
/**
|
|
400
|
-
* Get data changed fields with input data updated
|
|
402
|
+
* Get data changed fields (ignored changedFields) with input data updated
|
|
401
403
|
* @param input Input data
|
|
402
404
|
* @param initData Initial data
|
|
403
405
|
* @param ignoreFields Ignore fields
|
|
@@ -407,13 +409,13 @@ export namespace Utils {
|
|
|
407
409
|
input: T,
|
|
408
410
|
initData: object,
|
|
409
411
|
ignoreFields: string[] = ["id"]
|
|
410
|
-
):
|
|
412
|
+
): Exclude<keyof T & string, typeof IgnoredProperty>[] {
|
|
411
413
|
// Changed fields
|
|
412
|
-
const changes:
|
|
414
|
+
const changes: Exclude<keyof T & string, typeof IgnoredProperty>[] = [];
|
|
413
415
|
|
|
414
416
|
Object.entries(input).forEach(([key, value]) => {
|
|
415
417
|
// Ignore fields, no process
|
|
416
|
-
if (ignoreFields.includes(key)) return;
|
|
418
|
+
if (key === IgnoredProperty || ignoreFields.includes(key)) return;
|
|
417
419
|
|
|
418
420
|
// Compare with init value
|
|
419
421
|
const initValue = Reflect.get(initData, key);
|
package/tsconfig.cjs.json
CHANGED