@etsoo/shared 1.1.61 → 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,13 +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, Editing extends boolean, D extends string = 'id'> = Editing extends true ? Partial<T> & {
126
- [key in D]: number | string;
127
- } & {
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>> & {
128
130
  changedFields?: string[];
129
- } : T;
131
+ };
130
132
  /**
131
133
  * Key collection, like { key1: {}, key2: {} }
132
134
  */
@@ -149,6 +151,10 @@ export declare namespace DataTypes {
149
151
  * Mixins constructor
150
152
  */
151
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>;
152
158
  /**
153
159
  * String key, unknown value Record
154
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,13 +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, Editing extends boolean, D extends string = 'id'> = Editing extends true ? Partial<T> & {
126
- [key in D]: number | string;
127
- } & {
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>> & {
128
130
  changedFields?: string[];
129
- } : T;
131
+ };
130
132
  /**
131
133
  * Key collection, like { key1: {}, key2: {} }
132
134
  */
@@ -149,6 +151,10 @@ export declare namespace DataTypes {
149
151
  * Mixins constructor
150
152
  */
151
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>;
152
158
  /**
153
159
  * String key, unknown value Record
154
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.61",
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,17 +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,
162
- Editing extends boolean,
163
- D extends string = 'id'
164
- > = Editing extends true
165
- ? Partial<T> & { [key in D]: number | string } & {
166
- changedFields?: string[];
167
- }
168
- : T;
161
+ T extends object, // Entity modal
162
+ E extends boolean, // Editing or not
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[] };
169
167
 
170
168
  /**
171
169
  * Key collection, like { key1: {}, key2: {} }
@@ -194,6 +192,12 @@ export namespace DataTypes {
194
192
  */
195
193
  export type MConstructor<T = {}> = new (...args: any[]) => T;
196
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
+
197
201
  /**
198
202
  * String key, unknown value Record
199
203
  */