11import type { Merge } from 'type-fest' ;
2- import type { BuiltIns } from 'type-fest/source/internal' ;
32import type OnyxUtils from './OnyxUtils' ;
43import type { OnyxMethod } from './OnyxUtils' ;
54import type { FastMergeReplaceNullPatch } from './utils' ;
@@ -157,6 +156,10 @@ type OnyxValue<TKey extends OnyxKey> = string extends TKey ? unknown : TKey exte
157156/** Utility type to extract `TOnyxValue` from `OnyxCollection<TOnyxValue>` */
158157type ExtractOnyxCollectionValue < TOnyxCollection > = TOnyxCollection extends NonNullable < OnyxCollection < infer U > > ? U : never ;
159158
159+ type Primitive = null | undefined | string | number | boolean | symbol | bigint ;
160+
161+ type BuiltIns = Primitive | void | Date | RegExp ;
162+
160163type NonTransformableTypes =
161164 | BuiltIns
162165 // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -205,13 +208,7 @@ type NullishObjectDeep<ObjectType extends object> = {
205208 * Also, the `TMap` type is inferred automatically in `mergeCollection()` method and represents
206209 * the object of collection keys/values specified in the second parameter of the method.
207210 */
208- type Collection < TKey extends CollectionKeyBase , TValue , TMap = never > = {
209- [ MapK in keyof TMap ] : MapK extends `${TKey } ${string } `
210- ? MapK extends `${TKey } `
211- ? never // forbids empty id
212- : TValue
213- : never ;
214- } ;
211+ type Collection < TKey extends CollectionKeyBase , TValue > = Record < `${TKey } ${string } `, TValue > & { [ P in TKey ] ?: never } ;
215212
216213/** Represents the base options used in `Onyx.connect()` method. */
217214// NOTE: Any changes to this type like adding or removing options must be accounted in OnyxConnectionManager's `generateConnectionID()` method!
@@ -322,48 +319,58 @@ type OnyxMergeInput<TKey extends OnyxKey> = OnyxInput<TKey>;
322319/**
323320 * This represents the value that can be passed to `Onyx.merge` and to `Onyx.update` with the method "MERGE"
324321 */
325- type OnyxMergeCollectionInput < TKey extends OnyxKey , TMap = object > = Collection < TKey , NonNullable < OnyxInput < TKey > > , TMap > ;
322+ type OnyxMergeCollectionInput < TKey extends OnyxKey > = Collection < TKey , NonNullable < OnyxInput < TKey > > > ;
326323
327- type OnyxMethodMap = typeof OnyxUtils . METHOD ;
324+ /**
325+ * This represents the value that can be passed to `Onyx.setCollection` and to `Onyx.update` with the method "SET_COLLECTION"
326+ */
327+ type OnyxSetCollectionInput < TKey extends OnyxKey > = Collection < TKey , OnyxInput < TKey > > ;
328328
329- // Maps onyx methods to their corresponding value types
330- type OnyxMethodValueMap = {
331- [ OnyxUtils . METHOD . SET ] : {
332- key : OnyxKey ;
333- value : OnyxSetInput < OnyxKey > ;
334- } ;
335- [ OnyxUtils . METHOD . MULTI_SET ] : {
336- key : OnyxKey ;
337- value : OnyxMultiSetInput ;
338- } ;
339- [ OnyxUtils . METHOD . MERGE ] : {
340- key : OnyxKey ;
341- value : OnyxMergeInput < OnyxKey > ;
342- } ;
343- [ OnyxUtils . METHOD . CLEAR ] : {
344- key : OnyxKey ;
345- value ?: undefined ;
346- } ;
347- [ OnyxUtils . METHOD . MERGE_COLLECTION ] : {
348- key : CollectionKeyBase ;
349- value : OnyxMergeCollectionInput < CollectionKeyBase > ;
350- } ;
351- [ OnyxUtils . METHOD . SET_COLLECTION ] : {
352- key : CollectionKeyBase ;
353- value : OnyxMergeCollectionInput < CollectionKeyBase > ;
354- } ;
355- } ;
329+ type OnyxMethodMap = typeof OnyxUtils . METHOD ;
356330
357331/**
358332 * OnyxUpdate type includes all onyx methods used in OnyxMethodValueMap.
359333 * If a new method is added to OnyxUtils.METHOD constant, it must be added to OnyxMethodValueMap type.
360334 * Otherwise it will show static type errors.
361335 */
362- type OnyxUpdate = {
363- [ Method in OnyxMethod ] : {
364- onyxMethod : Method ;
365- } & OnyxMethodValueMap [ Method ] ;
366- } [ OnyxMethod ] ;
336+ type OnyxUpdate =
337+ // ⚠️ DO NOT CHANGE THIS TYPE, UNLESS YOU KNOW WHAT YOU ARE DOING. ⚠️
338+ | {
339+ [ TKey in OnyxKey ] :
340+ | {
341+ onyxMethod : typeof OnyxUtils . METHOD . SET ;
342+ key : TKey ;
343+ value : OnyxSetInput < TKey > ;
344+ }
345+ | {
346+ onyxMethod : typeof OnyxUtils . METHOD . MULTI_SET ;
347+ key : TKey ;
348+ value : OnyxMultiSetInput ;
349+ }
350+ | {
351+ onyxMethod : typeof OnyxUtils . METHOD . MERGE ;
352+ key : TKey ;
353+ value : OnyxMergeInput < TKey > ;
354+ }
355+ | {
356+ onyxMethod : typeof OnyxUtils . METHOD . CLEAR ;
357+ key : TKey ;
358+ value ?: undefined ;
359+ } ;
360+ } [ OnyxKey ]
361+ | {
362+ [ TKey in CollectionKeyBase ] :
363+ | {
364+ onyxMethod : typeof OnyxUtils . METHOD . MERGE_COLLECTION ;
365+ key : TKey ;
366+ value : OnyxMergeCollectionInput < TKey > ;
367+ }
368+ | {
369+ onyxMethod : typeof OnyxUtils . METHOD . SET_COLLECTION ;
370+ key : TKey ;
371+ value : OnyxSetCollectionInput < TKey > ;
372+ } ;
373+ } [ CollectionKeyBase ] ;
367374
368375/**
369376 * Represents the options used in `Onyx.set()` method.
@@ -379,14 +386,14 @@ type SetParams<TKey extends OnyxKey> = {
379386 options ?: SetOptions ;
380387} ;
381388
382- type SetCollectionParams < TKey extends CollectionKeyBase , TMap > = {
389+ type SetCollectionParams < TKey extends CollectionKeyBase > = {
383390 collectionKey : TKey ;
384- collection : OnyxMergeCollectionInput < TKey , TMap > ;
391+ collection : OnyxSetCollectionInput < TKey > ;
385392} ;
386393
387- type MergeCollectionWithPatchesParams < TKey extends CollectionKeyBase , TMap > = {
394+ type MergeCollectionWithPatchesParams < TKey extends CollectionKeyBase > = {
388395 collectionKey : TKey ;
389- collection : OnyxMergeCollectionInput < TKey , TMap > ;
396+ collection : OnyxMergeCollectionInput < TKey > ;
390397 mergeReplaceNullPatches ?: MultiMergeReplaceNullPatches ;
391398 isProcessingCollectionUpdate ?: boolean ;
392399} ;
@@ -499,6 +506,7 @@ export type {
499506 OnyxMultiSetInput ,
500507 OnyxMergeInput ,
501508 OnyxMergeCollectionInput ,
509+ OnyxSetCollectionInput ,
502510 OnyxMethod ,
503511 OnyxMethodMap ,
504512 OnyxUpdate ,
0 commit comments