@nu-art/ts-common 0.201.37 → 0.201.39

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/db/types.d.ts CHANGED
@@ -26,7 +26,7 @@ export type DBProto<P extends Proto_DB_Object<any, any, any, any>, ModifiableSub
26
26
  generatedPropsValidator: ValidatorTypeResolver<GeneratedSubType>;
27
27
  modifiablePropsValidator: ValidatorTypeResolver<ModifiableSubType>;
28
28
  uniqueKeys: P['uniqueKeys'][];
29
- generatedProps: P['generatedKeys'][];
29
+ generatedProps: (P['generatedKeys'] | keyof DB_Object)[];
30
30
  versions: P['versions']['versions'];
31
31
  indices: DBIndex<P['type']>[];
32
32
  uniqueParam: UniqueId | {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/ts-common",
3
- "version": "0.201.37",
3
+ "version": "0.201.39",
4
4
  "description": "js and ts infra",
5
5
  "keywords": [
6
6
  "TacB0sS",
package/utils/types.d.ts CHANGED
@@ -148,3 +148,56 @@ export type MergeTypes<T extends unknown[]> = T extends [a: infer A, ...rest: in
148
148
  export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
149
149
  export type NonEmptyArray<T> = [T, ...T[]];
150
150
  export type AssetValueType<T, K extends keyof T, Ex> = T[K] extends Ex ? K : never;
151
+ /**
152
+ * Constructs a union of string paths representing the properties and nested properties of an object type.
153
+ *
154
+ * @typeParam ObjectType - The object type to analyze.
155
+ *
156
+ * @example
157
+ * // Simple Example: Analyzing a flat object
158
+ * type Person = { name: string; age: number };
159
+ * type PersonPaths = DotNotation<Person>; // 'name' | 'age'
160
+ *
161
+ * @example
162
+ * // Nested Example: Analyzing an object with nested properties
163
+ * type User = { name: string; address: { city: string; zip: string } };
164
+ * type UserPaths = DotNotation<User>; // 'name' | 'address' | 'address.city' | 'address.zip'
165
+ *
166
+ * @example
167
+ * // Complex Example: Analyzing an object with multiple levels of nesting
168
+ * type Profile = { name: string; contacts: { email: { primary: string; secondary: string } } };
169
+ * type ProfilePaths = DotNotation<Profile>; // 'name' | 'contacts' | 'contacts.email' | 'contacts.email.primary' | 'contacts.email.secondary'
170
+ */
171
+ export type DotNotation<T> = T extends object ? {
172
+ [K in keyof T]: K extends string ? `${K & string}` | `${K & string}.${DotNotation<T[K]>}` : never;
173
+ }[keyof T] : '';
174
+ /**
175
+ * Replaces the type of nested property within an object, based on a specified path.
176
+ *
177
+ * @typeParam ObjectType - The original object type.
178
+ * @typeParam PropertyPath - The path to the property to replace, expressed as a dot-notation string.
179
+ * @typeParam NewValueType - The new type to replace the old type with.
180
+ *
181
+ * @example
182
+ * // Simple Example: Replace the 'age' property with a string
183
+ * type Person = { name: string; age: number };
184
+ * type NewPerson = ManipulateInnerPropValue<Person, 'age', string>;
185
+ * // Result: { name: string; age: string }
186
+ *
187
+ * @example
188
+ * // Nested Example: Replace the 'address.city' property with a number
189
+ * type User = { name: string; address: { city: string; zip: string } };
190
+ * type NewUser = ManipulateInnerPropValue<User, 'address.city', number>;
191
+ * // Result: { name: string; address: { city: number; zip: string } }
192
+ *
193
+ * @example
194
+ * // Complex Example: Replace the 'contacts.email.primary' property with a boolean
195
+ * type Profile = { name: string; contacts: { email: { primary: string; secondary: string } } };
196
+ * type NewProfile = ManipulateInnerPropValue<Profile, 'contacts.email.primary', boolean>;
197
+ * // Result: { name: string; contacts: { email: { primary: boolean; secondary: string } } }
198
+ */
199
+ export type ManipulateInnerPropValue<ObjectType, PropertyPath extends DotNotation<ObjectType>, NewValueType> = PropertyPath extends `${infer Key}.${infer Rest}` ? Key extends keyof ObjectType ? {
200
+ [Prop in keyof ObjectType]: Prop extends Key ? Rest extends DotNotation<ObjectType[Key]> ? ManipulateInnerPropValue<ObjectType[Key], Rest, NewValueType> : never : ObjectType[Prop];
201
+ } : never : {
202
+ [Prop in keyof ObjectType]: Prop extends PropertyPath ? NewValueType : ObjectType[Prop];
203
+ };