Skip to content

Commit 6db1fb4

Browse files
authored
fix(analytics): update superstruct dependency / forward-port to new API (#8153)
1 parent 11c7fa8 commit 6db1fb4

File tree

6 files changed

+181
-251
lines changed

6 files changed

+181
-251
lines changed

packages/analytics/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
isString,
2727
isUndefined,
2828
} from '@react-native-firebase/app/lib/common';
29-
import { validateStruct, validateCompound } from '@react-native-firebase/app/lib/common/struct';
3029

3130
import {
3231
createModuleNamespace,
@@ -36,6 +35,7 @@ import {
3635
import { setReactNativeModule } from '@react-native-firebase/app/lib/internal/nativeModule';
3736
import { isBoolean } from '@react-native-firebase/app/lib/common';
3837

38+
import { validateStruct, validateCompound } from './struct';
3939
import fallBackModule from './web/RNFBAnalyticsModule';
4040
import version from './version';
4141
import * as structs from './structs';

packages/app/lib/common/struct.js renamed to packages/analytics/lib/struct.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,20 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { superstruct } from 'superstruct/lib/index';
18-
import { isUndefined } from './validate';
19-
20-
export default superstruct({
21-
types: {
22-
shortDate: value => typeof value === 'string' && !!value.match(/^\d{4}-\d{2}-\d{2}$/),
23-
},
24-
});
17+
import { isUndefined } from '@react-native-firebase/app/lib/common/validate';
18+
import { create } from 'superstruct';
2519

2620
export const validateStruct = (value = {}, struct, prefix = '') => {
2721
try {
28-
return struct(value);
22+
return create(value, struct);
2923
} catch (e) {
30-
const { path, reason } = e;
24+
const { path, message } = e;
25+
3126
const key = path[0];
3227

33-
if (reason === undefined) {
28+
if (message === undefined) {
3429
throw new Error(`${prefix} unknown property '${key}'.`);
3530
}
36-
3731
e.message = `${prefix} ${e.message}`;
3832

3933
throw e;

0 commit comments

Comments
 (0)