@etsoo/shared 1.1.63 → 1.1.65

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|
@@ -119,14 +119,25 @@ export declare namespace DataTypes {
119
119
  */
120
120
  type IdType = number | string;
121
121
  /**
122
- * Add or edit conditional type for same data model
122
+ * Add and edit data type
123
123
  * ChangedFields for editing case
124
124
  */
125
- type AddOrEditType<T extends object, // Entity modal
125
+ type AddAndEditType<T extends {
126
+ [key in D]: IdType;
127
+ }, D extends string = 'id'> = (Omit<T, D> & {
128
+ [key in D]: undefined | never;
129
+ }) | (Partial<T> & Readonly<Pick<T, D>> & {
130
+ changedFields?: string[];
131
+ });
132
+ /**
133
+ * Add or edit conditional type
134
+ * ChangedFields for editing case
135
+ */
136
+ type AddOrEditType<T extends {
137
+ [key in D]: IdType;
138
+ }, // Entity modal
126
139
  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>> & {
140
+ D extends string = 'id'> = E extends false ? Optional<T, D> : Partial<T> & Readonly<Pick<T, D>> & {
130
141
  changedFields?: string[];
131
142
  };
132
143
  /**
@@ -68,18 +68,18 @@ 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; /**
72
- * Current detected country
73
- */
71
+ name: string;
74
72
  label: string;
75
- resources: T;
73
+ resources: T; /**
74
+ * Current detected culture
75
+ */
76
76
  compatibleName?: string[] | undefined;
77
77
  }>[], culture: string) => Readonly<{
78
- name: string; /**
79
- * Current detected country
80
- */
78
+ name: string;
81
79
  label: string;
82
- resources: T;
80
+ resources: T; /**
81
+ * Current detected culture
82
+ */
83
83
  compatibleName?: string[] | undefined;
84
84
  }> | undefined;
85
85
  /**
@@ -119,14 +119,25 @@ export declare namespace DataTypes {
119
119
  */
120
120
  type IdType = number | string;
121
121
  /**
122
- * Add or edit conditional type for same data model
122
+ * Add and edit data type
123
123
  * ChangedFields for editing case
124
124
  */
125
- type AddOrEditType<T extends object, // Entity modal
125
+ type AddAndEditType<T extends {
126
+ [key in D]: IdType;
127
+ }, D extends string = 'id'> = (Omit<T, D> & {
128
+ [key in D]: undefined | never;
129
+ }) | (Partial<T> & Readonly<Pick<T, D>> & {
130
+ changedFields?: string[];
131
+ });
132
+ /**
133
+ * Add or edit conditional type
134
+ * ChangedFields for editing case
135
+ */
136
+ type AddOrEditType<T extends {
137
+ [key in D]: IdType;
138
+ }, // Entity modal
126
139
  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>> & {
140
+ D extends string = 'id'> = E extends false ? Optional<T, D> : Partial<T> & Readonly<Pick<T, D>> & {
130
141
  changedFields?: string[];
131
142
  };
132
143
  /**
@@ -68,18 +68,18 @@ 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; /**
72
- * Current detected country
73
- */
71
+ name: string;
74
72
  label: string;
75
- resources: T;
73
+ resources: T; /**
74
+ * Current detected culture
75
+ */
76
76
  compatibleName?: string[] | undefined;
77
77
  }>[], culture: string) => Readonly<{
78
- name: string; /**
79
- * Current detected country
80
- */
78
+ name: string;
81
79
  label: string;
82
- resources: T;
80
+ resources: T; /**
81
+ * Current detected culture
82
+ */
83
83
  compatibleName?: string[] | undefined;
84
84
  }> | undefined;
85
85
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.63",
3
+ "version": "1.1.65",
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,13 +154,24 @@ export namespace DataTypes {
154
154
  export type IdType = number | string;
155
155
 
156
156
  /**
157
- * Add or edit conditional type for same data model
157
+ * Add and edit data type
158
+ * ChangedFields for editing case
159
+ */
160
+ export type AddAndEditType<
161
+ T extends { [key in D]: IdType },
162
+ D extends string = 'id'
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
158
169
  * ChangedFields for editing case
159
170
  */
160
171
  export type AddOrEditType<
161
- T extends object, // Entity modal
172
+ T extends { [key in D]: IdType }, // Entity modal
162
173
  E extends boolean, // Editing or not
163
- D extends keyof T = T extends { id: number | string } ? 'id' : any // Default is 'id' field
174
+ D extends string = 'id' // Default is 'id' field
164
175
  > = E extends false
165
176
  ? Optional<T, D>
166
177
  : Partial<T> & Readonly<Pick<T, D>> & { changedFields?: string[] };