@etsoo/shared 1.1.62 → 1.1.63

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 CHANGED
@@ -105,6 +105,7 @@ Data type definitions and type safe functions. ListItemType and ListItemType1 ar
105
105
  |Keys|Get specific type keys|
106
106
  |MConstructor|Mixins constructor|
107
107
  |ObjType|Generic object type|
108
+ |Optional|Make properties optional|
108
109
  |RequireAtLeastOne|Require at least one property of the keys|
109
110
  |Simple|Basic or basic array type|
110
111
  |SimpleEnum|Simple type enum|
@@ -120,15 +120,15 @@ export declare namespace DataTypes {
120
120
  type IdType = number | string;
121
121
  /**
122
122
  * Add or edit conditional type for same data model
123
- * Dynamic add id and changedFields for editing case
123
+ * ChangedFields for editing case
124
124
  */
125
- type AddOrEditType<T extends object, E extends boolean, // Editing or not
126
- I extends IdType = number, // Id type, default is number
127
- D extends string = 'id'> = E extends true ? Partial<T> & {
128
- [key in D]: I;
129
- } & {
125
+ type AddOrEditType<T extends object, // Entity modal
126
+ E extends boolean, // Editing or not
127
+ D extends keyof T = T extends {
128
+ id: number | string;
129
+ } ? 'id' : any> = E extends false ? Optional<T, D> : Partial<T> & Readonly<Pick<T, D>> & {
130
130
  changedFields?: string[];
131
- } : T;
131
+ };
132
132
  /**
133
133
  * Key collection, like { key1: {}, key2: {} }
134
134
  */
@@ -151,6 +151,10 @@ export declare namespace DataTypes {
151
151
  * Mixins constructor
152
152
  */
153
153
  type MConstructor<T = {}> = new (...args: any[]) => T;
154
+ /**
155
+ * Make properties optional
156
+ */
157
+ type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
154
158
  /**
155
159
  * String key, unknown value Record
156
160
  */
@@ -68,12 +68,16 @@ export declare namespace DomUtils {
68
68
  * @param culture Detected culture
69
69
  */
70
70
  const getCulture: <T extends DataTypes.StringRecord>(items: Readonly<{
71
- name: string;
71
+ name: string; /**
72
+ * Current detected country
73
+ */
72
74
  label: string;
73
75
  resources: T;
74
76
  compatibleName?: string[] | undefined;
75
77
  }>[], culture: string) => Readonly<{
76
- name: string;
78
+ name: string; /**
79
+ * Current detected country
80
+ */
77
81
  label: string;
78
82
  resources: T;
79
83
  compatibleName?: string[] | undefined;
@@ -120,15 +120,15 @@ export declare namespace DataTypes {
120
120
  type IdType = number | string;
121
121
  /**
122
122
  * Add or edit conditional type for same data model
123
- * Dynamic add id and changedFields for editing case
123
+ * ChangedFields for editing case
124
124
  */
125
- type AddOrEditType<T extends object, E extends boolean, // Editing or not
126
- I extends IdType = number, // Id type, default is number
127
- D extends string = 'id'> = E extends true ? Partial<T> & {
128
- [key in D]: I;
129
- } & {
125
+ type AddOrEditType<T extends object, // Entity modal
126
+ E extends boolean, // Editing or not
127
+ D extends keyof T = T extends {
128
+ id: number | string;
129
+ } ? 'id' : any> = E extends false ? Optional<T, D> : Partial<T> & Readonly<Pick<T, D>> & {
130
130
  changedFields?: string[];
131
- } : T;
131
+ };
132
132
  /**
133
133
  * Key collection, like { key1: {}, key2: {} }
134
134
  */
@@ -151,6 +151,10 @@ export declare namespace DataTypes {
151
151
  * Mixins constructor
152
152
  */
153
153
  type MConstructor<T = {}> = new (...args: any[]) => T;
154
+ /**
155
+ * Make properties optional
156
+ */
157
+ type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
154
158
  /**
155
159
  * String key, unknown value Record
156
160
  */
@@ -68,12 +68,16 @@ export declare namespace DomUtils {
68
68
  * @param culture Detected culture
69
69
  */
70
70
  const getCulture: <T extends DataTypes.StringRecord>(items: Readonly<{
71
- name: string;
71
+ name: string; /**
72
+ * Current detected country
73
+ */
72
74
  label: string;
73
75
  resources: T;
74
76
  compatibleName?: string[] | undefined;
75
77
  }>[], culture: string) => Readonly<{
76
- name: string;
78
+ name: string; /**
79
+ * Current detected country
80
+ */
77
81
  label: string;
78
82
  resources: T;
79
83
  compatibleName?: string[] | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.62",
3
+ "version": "1.1.63",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
package/src/DataTypes.ts CHANGED
@@ -155,18 +155,15 @@ export namespace DataTypes {
155
155
 
156
156
  /**
157
157
  * Add or edit conditional type for same data model
158
- * Dynamic add id and changedFields for editing case
158
+ * ChangedFields for editing case
159
159
  */
160
160
  export type AddOrEditType<
161
- T extends object,
161
+ T extends object, // Entity modal
162
162
  E extends boolean, // Editing or not
163
- I extends IdType = number, // Id type, default is number
164
- D extends string = 'id' // Id field name
165
- > = E extends true
166
- ? Partial<T> & { [key in D]: I } & {
167
- changedFields?: string[];
168
- }
169
- : T;
163
+ D extends keyof T = T extends { id: number | string } ? 'id' : any // Default is 'id' field
164
+ > = E extends false
165
+ ? Optional<T, D>
166
+ : Partial<T> & Readonly<Pick<T, D>> & { changedFields?: string[] };
170
167
 
171
168
  /**
172
169
  * Key collection, like { key1: {}, key2: {} }
@@ -195,6 +192,12 @@ export namespace DataTypes {
195
192
  */
196
193
  export type MConstructor<T = {}> = new (...args: any[]) => T;
197
194
 
195
+ /**
196
+ * Make properties optional
197
+ */
198
+ export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> &
199
+ Omit<T, K>;
200
+
198
201
  /**
199
202
  * String key, unknown value Record
200
203
  */