@etsoo/shared 1.2.55 → 1.2.57

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.
@@ -217,6 +217,26 @@ test("Tests for AddAndEditType", () => {
217
217
  expect(data2.name).toBe(data3.name);
218
218
  });
219
219
 
220
+ test("Tests for AddOrEditType", () => {
221
+ type Entity = {
222
+ id: number;
223
+ name: string;
224
+ age?: number;
225
+ };
226
+ type AddEntity = DataTypes.AddOrEditType<Entity, false>;
227
+ type EditEntity = DataTypes.AddOrEditType<Entity, true>;
228
+
229
+ const data1: AddEntity = { id: 1, name: "hello" };
230
+ const data2: AddEntity = { id: undefined, name: "hello" };
231
+ const data3: AddEntity = { name: "hello" };
232
+
233
+ const data4: EditEntity = { id: 1, name: "hello", changedFields: ["name"] };
234
+
235
+ expect(data1.name).toBe(data2.name);
236
+ expect(data2.name).toBe(data3.name);
237
+ expect(data3.name).toBe(data4.name);
238
+ });
239
+
220
240
  test("Tests for BasicTemplate", () => {
221
241
  const template: DataTypes.BasicTemplate = {
222
242
  id: "number",
@@ -253,7 +253,7 @@ test("Tests for getCulture", () => {
253
253
  });
254
254
 
255
255
  test("Tests for getLocationKey", () => {
256
- expect(DomUtils.getLocationKey("test")).toBe("http://localhost/:test");
256
+ expect(DomUtils.getLocationKey("test")).toBe("http://localhost:3000/:test");
257
257
  });
258
258
 
259
259
  test("Tests for headersToObject", () => {
@@ -292,7 +292,7 @@ test("Tests for mergeURLSearchParams", () => {
292
292
 
293
293
  test("Tests for setFocus", () => {
294
294
  // Arrange
295
- const focus = jest.fn();
295
+ const focus = vi.fn();
296
296
 
297
297
  const root = document.body;
298
298
  const container = document.createElement("div");
@@ -419,7 +419,7 @@ test("Tests for getUserAgentData 8", () => {
419
419
 
420
420
  test("Tests for setupLogging", async () => {
421
421
  // Arrange
422
- const action = jest.fn((data: ErrorData) => {
422
+ const action = vi.fn((data: ErrorData) => {
423
423
  expect(data.message).toBe("Test");
424
424
  });
425
425
  DomUtils.setupLogging(action, true, globalThis.self);
@@ -29,13 +29,13 @@ test("Tests for history", () => {
29
29
  });
30
30
 
31
31
  test("Tests for events", () => {
32
- const navigatorFn = jest.fn();
33
- const navigatorStopFn = jest.fn((event: EHistoryNavigateEvent) => {
32
+ const navigatorFn = vi.fn();
33
+ const navigatorStopFn = vi.fn((event: EHistoryNavigateEvent) => {
34
34
  event.stopImmediatePropagation();
35
35
  });
36
- const clearFn = jest.fn();
37
- const pushFn = jest.fn();
38
- const replaceFn = jest.fn();
36
+ const clearFn = vi.fn();
37
+ const pushFn = vi.fn();
38
+ const replaceFn = vi.fn();
39
39
 
40
40
  const history = new LHistory(3);
41
41
 
@@ -25,7 +25,7 @@ test("Tests for applyMixins", () => {
25
25
 
26
26
  test("Tests for delayedExecutor", () => {
27
27
  // Arrange
28
- const f = jest.fn();
28
+ const f = vi.fn();
29
29
 
30
30
  const e = ExtendUtils.delayedExecutor(f, 50);
31
31
 
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES2020",
4
- "module": "ESNext",
5
- "moduleResolution": "Node10",
4
+ "module": "ES2022",
5
+ "moduleResolution": "bundler",
6
6
  "allowJs": false,
7
7
  "skipLibCheck": true,
8
8
  "esModuleInterop": true,
@@ -12,6 +12,7 @@
12
12
  "resolveJsonModule": true,
13
13
  "isolatedModules": true,
14
14
  "noEmit": true,
15
- "declaration": true
15
+ "declaration": true,
16
+ "types": ["vitest/globals"]
16
17
  }
17
18
  }
@@ -147,7 +147,7 @@ export declare namespace DataTypes {
147
147
  }, D extends string = "id"> = (Omit<T, D> & {
148
148
  [key in D]?: undefined | never;
149
149
  }) | (Partial<T> & Readonly<Pick<T, D>> & {
150
- changedFields?: string[];
150
+ changedFields?: (keyof T & string)[];
151
151
  });
152
152
  /**
153
153
  * Add or edit conditional type
@@ -158,7 +158,7 @@ export declare namespace DataTypes {
158
158
  }, // Entity modal
159
159
  E extends boolean, // Editing or not
160
160
  D extends string = "id"> = E extends false ? Optional<T, D> : Partial<T> & Readonly<Pick<T, D>> & {
161
- changedFields?: string[];
161
+ changedFields?: (keyof T & string)[];
162
162
  };
163
163
  /**
164
164
  * Key collection, like { key1: {}, key2: {} }
@@ -158,7 +158,7 @@ export declare namespace Utils {
158
158
  * @param ignoreFields Ignore fields
159
159
  * @returns
160
160
  */
161
- function getDataChanges(input: object, initData: object, ignoreFields?: string[]): string[];
161
+ function getDataChanges<T extends object>(input: T, initData: object, ignoreFields?: string[]): (keyof T & string)[];
162
162
  /**
163
163
  * Get nested value from object
164
164
  * @param data Data
@@ -147,7 +147,7 @@ export declare namespace DataTypes {
147
147
  }, D extends string = "id"> = (Omit<T, D> & {
148
148
  [key in D]?: undefined | never;
149
149
  }) | (Partial<T> & Readonly<Pick<T, D>> & {
150
- changedFields?: string[];
150
+ changedFields?: (keyof T & string)[];
151
151
  });
152
152
  /**
153
153
  * Add or edit conditional type
@@ -158,7 +158,7 @@ export declare namespace DataTypes {
158
158
  }, // Entity modal
159
159
  E extends boolean, // Editing or not
160
160
  D extends string = "id"> = E extends false ? Optional<T, D> : Partial<T> & Readonly<Pick<T, D>> & {
161
- changedFields?: string[];
161
+ changedFields?: (keyof T & string)[];
162
162
  };
163
163
  /**
164
164
  * Key collection, like { key1: {}, key2: {} }
@@ -158,7 +158,7 @@ export declare namespace Utils {
158
158
  * @param ignoreFields Ignore fields
159
159
  * @returns
160
160
  */
161
- function getDataChanges(input: object, initData: object, ignoreFields?: string[]): string[];
161
+ function getDataChanges<T extends object>(input: T, initData: object, ignoreFields?: string[]): (keyof T & string)[];
162
162
  /**
163
163
  * Get nested value from object
164
164
  * @param data Data
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.2.55",
3
+ "version": "1.2.57",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -14,23 +14,7 @@
14
14
  "sideEffects": false,
15
15
  "scripts": {
16
16
  "build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json",
17
- "test": "jest",
18
- "test:debug": "node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand"
19
- },
20
- "jest": {
21
- "automock": false,
22
- "testMatch": [
23
- "<rootDir>/__tests__/**/*.ts"
24
- ],
25
- "testEnvironment": "jsdom",
26
- "moduleFileExtensions": [
27
- "js",
28
- "ts",
29
- "d.ts"
30
- ],
31
- "transform": {
32
- ".+\\.ts$": "ts-jest"
33
- }
17
+ "test": "vitest"
34
18
  },
35
19
  "repository": {
36
20
  "type": "git",
@@ -52,12 +36,11 @@
52
36
  },
53
37
  "homepage": "https://github.com/ETSOO/Shared#readme",
54
38
  "devDependencies": {
55
- "@types/jest": "^29.5.14",
56
39
  "@types/lodash.isequal": "^4.5.8",
57
- "jest": "^29.7.0",
58
- "jest-environment-jsdom": "^29.7.0",
59
- "ts-jest": "^29.2.5",
60
- "typescript": "^5.7.2"
40
+ "@vitejs/plugin-react": "^4.3.4",
41
+ "jsdom": "^26.0.0",
42
+ "typescript": "^5.7.3",
43
+ "vitest": "^2.1.8"
61
44
  },
62
45
  "dependencies": {
63
46
  "lodash.isequal": "^4.5.0"
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> & Readonly<Pick<T, D>> & { changedFields?: string[] });
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> & Readonly<Pick<T, D>> & { changedFields?: string[] };
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
@@ -403,13 +403,13 @@ export namespace Utils {
403
403
  * @param ignoreFields Ignore fields
404
404
  * @returns
405
405
  */
406
- export function getDataChanges(
407
- input: object,
406
+ export function getDataChanges<T extends object>(
407
+ input: T,
408
408
  initData: object,
409
409
  ignoreFields: string[] = ["id"]
410
- ): string[] {
410
+ ): (keyof T & string)[] {
411
411
  // Changed fields
412
- const changes: string[] = [];
412
+ const changes: (keyof T & string)[] = [];
413
413
 
414
414
  Object.entries(input).forEach(([key, value]) => {
415
415
  // Ignore fields, no process
@@ -431,7 +431,7 @@ export namespace Utils {
431
431
  Reflect.deleteProperty(input, key);
432
432
  return;
433
433
  }
434
- changes.push(key);
434
+ changes.push(key as any);
435
435
  return;
436
436
  }
437
437
 
@@ -451,7 +451,7 @@ export namespace Utils {
451
451
  }
452
452
 
453
453
  // Hold the key
454
- changes.push(key);
454
+ changes.push(key as any);
455
455
  });
456
456
 
457
457
  return changes;
package/tsconfig.cjs.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "declaration": true,
11
11
  "strict": true,
12
12
  "esModuleInterop": true,
13
- "skipLibCheck": true,
13
+ "skipLibCheck": false,
14
14
  "forceConsistentCasingInFileNames": true,
15
15
  "lib": ["dom", "dom.iterable", "ESNext"]
16
16
  },
package/tsconfig.json CHANGED
@@ -2,15 +2,15 @@
2
2
  "compilerOptions": {
3
3
  /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
4
  "target": "ES2020",
5
- "module": "ESNext",
6
- "moduleResolution": "Node10",
5
+ "module": "ES2020",
6
+ "moduleResolution": "bundler",
7
7
  "isolatedModules": true,
8
8
  "outDir": "./lib/mjs",
9
9
  "noEmit": false,
10
10
  "declaration": true,
11
11
  "strict": true,
12
12
  "esModuleInterop": true,
13
- "skipLibCheck": true,
13
+ "skipLibCheck": false,
14
14
  "forceConsistentCasingInFileNames": true,
15
15
  "lib": ["dom", "dom.iterable", "esnext"]
16
16
  },
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from "vitest/config";
2
+ import react from "@vitejs/plugin-react";
3
+
4
+ export default defineConfig({
5
+ plugins: [react()],
6
+ test: {
7
+ globals: true,
8
+ environment: "jsdom",
9
+ include: ["__tests__/**/*.ts(x)?"]
10
+ }
11
+ });