react-native-onyx 2.0.141 → 3.0.2

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.
@@ -1,129 +0,0 @@
1
- import type { ForwardedRef } from 'react';
2
- import type { IsEqual } from 'type-fest';
3
- import type { CollectionKeyBase, ExtractOnyxCollectionValue, KeyValueMapping, OnyxCollection, OnyxEntry, OnyxKey, OnyxValue, Selector } from '../types';
4
- /**
5
- * Represents the base mapping options between an Onyx key and the component's prop.
6
- */
7
- type BaseMapping<TComponentProps, TOnyxProps> = {
8
- canEvict?: boolean | ((props: Omit<TComponentProps, keyof TOnyxProps>) => boolean);
9
- initWithStoredValues?: boolean;
10
- allowStaleData?: boolean;
11
- };
12
- /**
13
- * Represents the string / function `key` mapping option between an Onyx key and the component's prop.
14
- *
15
- * If `key` is `string`, the type of the Onyx value that is associated with `key` must match with the type of the component's prop,
16
- * otherwise an error will be thrown.
17
- *
18
- * If `key` is `function`, the return type of `key` function must be a valid Onyx key and the type of the Onyx value associated
19
- * with `key` must match with the type of the component's prop, otherwise an error will be thrown.
20
- *
21
- * @example
22
- * ```ts
23
- * // Onyx prop with `string` key
24
- * onyxProp: {
25
- * key: ONYXKEYS.ACCOUNT,
26
- * },
27
- *
28
- * // Onyx prop with `function` key
29
- * onyxProp: {
30
- * key: ({reportId}) => ONYXKEYS.ACCOUNT,
31
- * },
32
- * ```
33
- */
34
- type BaseMappingKey<TComponentProps, TOnyxProps, TOnyxProp extends keyof TOnyxProps, TOnyxKey extends OnyxKey, TOnyxValue> = IsEqual<TOnyxValue, TOnyxProps[TOnyxProp]> extends true ? {
35
- key: TOnyxKey | ((props: Omit<TComponentProps, keyof TOnyxProps> & Partial<TOnyxProps>) => TOnyxKey);
36
- } : never;
37
- /**
38
- * Represents the string `key` and `selector` mapping options between an Onyx key and the component's prop.
39
- *
40
- * The function signature and return type of `selector` must match with the type of the component's prop,
41
- * otherwise an error will be thrown.
42
- *
43
- * @example
44
- * ```ts
45
- * // Onyx prop with `string` key and selector
46
- * onyxProp: {
47
- * key: ONYXKEYS.ACCOUNT,
48
- * selector: (value: Account | null): string => value?.id ?? '',
49
- * },
50
- * ```
51
- */
52
- type BaseMappingStringKeyAndSelector<TComponentProps, TOnyxProps, TReturnType, TOnyxKey extends OnyxKey> = {
53
- key: TOnyxKey;
54
- selector: Selector<TOnyxKey, TOnyxProps, TReturnType>;
55
- };
56
- /**
57
- * Represents the function `key` and `selector` mapping options between an Onyx key and the component's prop.
58
- *
59
- * The function signature and return type of `selector` must match with the type of the component's prop,
60
- * otherwise an error will be thrown.
61
- *
62
- * @example
63
- * ```ts
64
- * // Onyx prop with `function` key and selector
65
- * onyxProp: {
66
- * key: ({reportId}) => ONYXKEYS.ACCOUNT,
67
- * selector: (value: Account | null) => value?.id ?? '',
68
- * },
69
- * ```
70
- */
71
- type BaseMappingFunctionKeyAndSelector<TComponentProps, TOnyxProps, TReturnType, TOnyxKey extends OnyxKey> = {
72
- key: (props: Omit<TComponentProps, keyof TOnyxProps> & Partial<TOnyxProps>) => TOnyxKey;
73
- selector: Selector<TOnyxKey, TOnyxProps, TReturnType>;
74
- };
75
- /**
76
- * Represents the mapping options between an Onyx key and the component's prop with all its possibilities.
77
- */
78
- type Mapping<TComponentProps, TOnyxProps, TOnyxProp extends keyof TOnyxProps, TOnyxKey extends OnyxKey> = BaseMapping<TComponentProps, TOnyxProps> & (BaseMappingKey<TComponentProps, TOnyxProps, TOnyxProp, TOnyxKey, OnyxEntry<KeyValueMapping[TOnyxKey]>> | BaseMappingStringKeyAndSelector<TComponentProps, TOnyxProps, TOnyxProps[TOnyxProp], TOnyxKey> | BaseMappingFunctionKeyAndSelector<TComponentProps, TOnyxProps, TOnyxProps[TOnyxProp], TOnyxKey>);
79
- /**
80
- * Represents a superset of `Mapping` type with internal properties included.
81
- */
82
- type WithOnyxMapping<TComponentProps, TOnyxProps> = Mapping<TComponentProps, TOnyxProps, keyof TOnyxProps, OnyxKey> & {
83
- subscriptionID: number;
84
- previousKey?: OnyxKey;
85
- };
86
- /**
87
- * Represents the mapping options between an Onyx collection key without suffix and the component's prop with all its possibilities.
88
- */
89
- type CollectionMapping<TComponentProps, TOnyxProps, TOnyxProp extends keyof TOnyxProps, TOnyxKey extends CollectionKeyBase> = BaseMapping<TComponentProps, TOnyxProps> & (BaseMappingKey<TComponentProps, TOnyxProps, TOnyxProp, TOnyxKey, OnyxCollection<KeyValueMapping[TOnyxKey]>> | BaseMappingStringKeyAndSelector<TComponentProps, TOnyxProps, ExtractOnyxCollectionValue<TOnyxProps[TOnyxProp]>, TOnyxKey> | BaseMappingFunctionKeyAndSelector<TComponentProps, TOnyxProps, ExtractOnyxCollectionValue<TOnyxProps[TOnyxProp]>, TOnyxKey>);
90
- /**
91
- * Represents an union type of all the possible Onyx key mappings.
92
- * Each `OnyxPropMapping` will be associated with its respective Onyx key, ensuring different type-safety for each object.
93
- */
94
- type OnyxPropMapping<TComponentProps, TOnyxProps, TOnyxProp extends keyof TOnyxProps> = {
95
- [TOnyxKey in OnyxKey]: Mapping<TComponentProps, TOnyxProps, TOnyxProp, TOnyxKey>;
96
- }[OnyxKey];
97
- /**
98
- * Represents an union type of all the possible Onyx collection keys without suffix mappings.
99
- * Each `OnyxPropCollectionMapping` will be associated with its respective Onyx key, ensuring different type-safety for each object.
100
- */
101
- type OnyxPropCollectionMapping<TComponentProps, TOnyxProps, TOnyxProp extends keyof TOnyxProps> = {
102
- [TOnyxKey in CollectionKeyBase]: CollectionMapping<TComponentProps, TOnyxProps, TOnyxProp, TOnyxKey>;
103
- }[CollectionKeyBase];
104
- /**
105
- * Represents an Onyx mapping object that connects Onyx keys to component's props.
106
- */
107
- type MapOnyxToState<TComponentProps, TOnyxProps> = {
108
- [TOnyxProp in keyof TOnyxProps]: OnyxPropMapping<TComponentProps, TOnyxProps, TOnyxProp> | OnyxPropCollectionMapping<TComponentProps, TOnyxProps, TOnyxProp>;
109
- };
110
- /**
111
- * Represents the `withOnyx` internal component props.
112
- */
113
- type WithOnyxProps<TComponentProps, TOnyxProps> = Omit<TComponentProps, keyof TOnyxProps> & {
114
- forwardedRef?: ForwardedRef<unknown>;
115
- };
116
- /**
117
- * Represents the `withOnyx` internal component state.
118
- */
119
- type WithOnyxState<TOnyxProps> = TOnyxProps & {
120
- loading: boolean;
121
- };
122
- /**
123
- * Represents the `withOnyx` internal component instance.
124
- */
125
- type WithOnyxInstance = React.Component<unknown, WithOnyxState<KeyValueMapping>> & {
126
- setStateProxy: (modifier: Record<string, OnyxCollection<KeyValueMapping[OnyxKey]>> | ((state: Record<string, OnyxCollection<KeyValueMapping[OnyxKey]>>) => OnyxValue<OnyxKey>)) => void;
127
- setWithOnyxState: (statePropertyName: OnyxKey, value: OnyxValue<OnyxKey>) => void;
128
- };
129
- export type { WithOnyxMapping, MapOnyxToState, WithOnyxProps, WithOnyxInstance, WithOnyxState };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });