@etsoo/shared 1.1.62 → 1.1.64

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
@@ -79,7 +79,8 @@ Data type definitions and type safe functions. ListItemType and ListItemType1 ar
79
79
  |Name|Description|
80
80
  |---:|---|
81
81
  |DataType|Data type enum|
82
- |AddOrEditType|Add or edit conditional type for same data model|
82
+ |AddAndEditType|Add and edit data type|
83
+ |AddOrEditType|Add or edit conditional type|
83
84
  |Basic|Basic types, includes number, bigint, Date, boolean, string|
84
85
  |BasicArray|Basic type name array|
85
86
  |BasicConditional|Conditional type based on BasicNames|
@@ -105,6 +106,7 @@ Data type definitions and type safe functions. ListItemType and ListItemType1 ar
105
106
  |Keys|Get specific type keys|
106
107
  |MConstructor|Mixins constructor|
107
108
  |ObjType|Generic object type|
109
+ |Optional|Make properties optional|
108
110
  |RequireAtLeastOne|Require at least one property of the keys|
109
111
  |Simple|Basic or basic array type|
110
112
  |SimpleEnum|Simple type enum|
@@ -119,16 +119,27 @@ export declare namespace DataTypes {
119
119
  */
120
120
  type IdType = number | string;
121
121
  /**
122
- * Add or edit conditional type for same data model
123
- * Dynamic add id and changedFields for editing case
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
- } & {
122
+ * Add and edit data type
123
+ * ChangedFields for editing case
124
+ */
125
+ type AddAndEditType<T extends object, D extends keyof T = T extends {
126
+ id: IdType;
127
+ } ? 'id' : any> = (Omit<T, D> & {
128
+ [key in D]: undefined | never;
129
+ }) | (Partial<T> & Readonly<Pick<T, D>> & {
130
130
  changedFields?: string[];
131
- } : T;
131
+ });
132
+ /**
133
+ * Add or edit conditional type
134
+ * ChangedFields for editing case
135
+ */
136
+ type AddOrEditType<T extends object, // Entity modal
137
+ E extends boolean, // Editing or not
138
+ D extends keyof T = T extends {
139
+ id: IdType;
140
+ } ? 'id' : any> = E extends false ? Optional<T, D> : Partial<T> & Readonly<Pick<T, D>> & {
141
+ changedFields?: string[];
142
+ };
132
143
  /**
133
144
  * Key collection, like { key1: {}, key2: {} }
134
145
  */
@@ -151,6 +162,10 @@ export declare namespace DataTypes {
151
162
  * Mixins constructor
152
163
  */
153
164
  type MConstructor<T = {}> = new (...args: any[]) => T;
165
+ /**
166
+ * Make properties optional
167
+ */
168
+ type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
154
169
  /**
155
170
  * String key, unknown value Record
156
171
  */
@@ -119,16 +119,27 @@ export declare namespace DataTypes {
119
119
  */
120
120
  type IdType = number | string;
121
121
  /**
122
- * Add or edit conditional type for same data model
123
- * Dynamic add id and changedFields for editing case
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
- } & {
122
+ * Add and edit data type
123
+ * ChangedFields for editing case
124
+ */
125
+ type AddAndEditType<T extends object, D extends keyof T = T extends {
126
+ id: IdType;
127
+ } ? 'id' : any> = (Omit<T, D> & {
128
+ [key in D]: undefined | never;
129
+ }) | (Partial<T> & Readonly<Pick<T, D>> & {
130
130
  changedFields?: string[];
131
- } : T;
131
+ });
132
+ /**
133
+ * Add or edit conditional type
134
+ * ChangedFields for editing case
135
+ */
136
+ type AddOrEditType<T extends object, // Entity modal
137
+ E extends boolean, // Editing or not
138
+ D extends keyof T = T extends {
139
+ id: IdType;
140
+ } ? 'id' : any> = E extends false ? Optional<T, D> : Partial<T> & Readonly<Pick<T, D>> & {
141
+ changedFields?: string[];
142
+ };
132
143
  /**
133
144
  * Key collection, like { key1: {}, key2: {} }
134
145
  */
@@ -151,6 +162,10 @@ export declare namespace DataTypes {
151
162
  * Mixins constructor
152
163
  */
153
164
  type MConstructor<T = {}> = new (...args: any[]) => T;
165
+ /**
166
+ * Make properties optional
167
+ */
168
+ type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
154
169
  /**
155
170
  * String key, unknown value Record
156
171
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.62",
3
+ "version": "1.1.64",
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
@@ -154,19 +154,27 @@ export namespace DataTypes {
154
154
  export type IdType = number | string;
155
155
 
156
156
  /**
157
- * Add or edit conditional type for same data model
158
- * Dynamic add id and changedFields for editing case
157
+ * Add and edit data type
158
+ * ChangedFields for editing case
159
159
  */
160
- export type AddOrEditType<
160
+ export type AddAndEditType<
161
161
  T extends object,
162
+ D extends keyof T = T extends { id: IdType } ? 'id' : any
163
+ > =
164
+ | (Omit<T, D> & { [key in D]: undefined | never })
165
+ | (Partial<T> & Readonly<Pick<T, D>> & { changedFields?: string[] });
166
+
167
+ /**
168
+ * Add or edit conditional type
169
+ * ChangedFields for editing case
170
+ */
171
+ export type AddOrEditType<
172
+ T extends object, // Entity modal
162
173
  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;
174
+ D extends keyof T = T extends { id: IdType } ? 'id' : any // Default is 'id' field
175
+ > = E extends false
176
+ ? Optional<T, D>
177
+ : Partial<T> & Readonly<Pick<T, D>> & { changedFields?: string[] };
170
178
 
171
179
  /**
172
180
  * Key collection, like { key1: {}, key2: {} }
@@ -195,6 +203,12 @@ export namespace DataTypes {
195
203
  */
196
204
  export type MConstructor<T = {}> = new (...args: any[]) => T;
197
205
 
206
+ /**
207
+ * Make properties optional
208
+ */
209
+ export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> &
210
+ Omit<T, K>;
211
+
198
212
  /**
199
213
  * String key, unknown value Record
200
214
  */