Skip to content

Commit

Permalink
fix(analytics): update superstruct dependency / forward-port to new A…
Browse files Browse the repository at this point in the history
…PI (#8153)
  • Loading branch information
exzos28 authored Nov 20, 2024
1 parent 11c7fa8 commit 6db1fb4
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 251 deletions.
2 changes: 1 addition & 1 deletion packages/analytics/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
isString,
isUndefined,
} from '@react-native-firebase/app/lib/common';
import { validateStruct, validateCompound } from '@react-native-firebase/app/lib/common/struct';

import {
createModuleNamespace,
Expand All @@ -36,6 +35,7 @@ import {
import { setReactNativeModule } from '@react-native-firebase/app/lib/internal/nativeModule';
import { isBoolean } from '@react-native-firebase/app/lib/common';

import { validateStruct, validateCompound } from './struct';
import fallBackModule from './web/RNFBAnalyticsModule';
import version from './version';
import * as structs from './structs';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,20 @@
* limitations under the License.
*/

import { superstruct } from 'superstruct/lib/index';
import { isUndefined } from './validate';

export default superstruct({
types: {
shortDate: value => typeof value === 'string' && !!value.match(/^\d{4}-\d{2}-\d{2}$/),
},
});
import { isUndefined } from '@react-native-firebase/app/lib/common/validate';
import { create } from 'superstruct';

export const validateStruct = (value = {}, struct, prefix = '') => {
try {
return struct(value);
return create(value, struct);
} catch (e) {
const { path, reason } = e;
const { path, message } = e;

const key = path[0];

if (reason === undefined) {
if (message === undefined) {
throw new Error(`${prefix} unknown property '${key}'.`);
}

e.message = `${prefix} ${e.message}`;

throw e;
Expand Down
Loading

0 comments on commit 6db1fb4

Please sign in to comment.