Skip to content

Commit e6f15fd

Browse files
author
oneRain
authored
[bug] Fix weapp uuid error. (parse-community#1356)
* fix: weapp uuid error. * chore: wrapped uuid.
1 parent 66878f2 commit e6f15fd

10 files changed

+31
-9
lines changed

src/AnonymousUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import ParseUser from './ParseUser';
1313
import type { RequestOptions } from './RESTController';
14-
const uuidv4 = require('uuid/v4');
14+
const uuidv4 = require('./uuid');
1515

1616
let registered = false;
1717

src/InstallationController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
import Storage from './Storage';
13-
const uuidv4 = require('uuid/v4');
13+
const uuidv4 = require('./uuid');
1414

1515
let iidCache = null;
1616

src/ParseObject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import unsavedChildren from './unsavedChildren';
4343
import type { AttributeMap, OpsMap } from './ObjectStateMutations';
4444
import type { RequestOptions, FullOptions } from './RESTController';
4545

46-
const uuidv4 = require('uuid/v4');
46+
const uuidv4 = require('./uuid');
4747

4848
export type Pointer = {
4949
__type: string,

src/RESTController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @flow
1010
*/
1111
/* global XMLHttpRequest, XDomainRequest */
12-
const uuidv4 = require('uuid/v4');
12+
const uuidv4 = require('./uuid');
1313

1414
import CoreManager from './CoreManager';
1515
import ParseError from './ParseError';

src/__tests__/InstallationController-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jest.dontMock('../CoreManager');
1111
jest.dontMock('../InstallationController');
1212
jest.dontMock('../Storage');
1313
jest.dontMock('../StorageController.default');
14-
jest.mock('uuid/v4', () => {
14+
jest.mock('../uuid', () => {
1515
let value = 0;
1616
return () => value++ + '';
1717
});

src/__tests__/ParseObject-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jest.dontMock('../unsavedChildren');
3333
jest.dontMock('../ParseACL');
3434
jest.dontMock('../LocalDatastore');
3535

36-
jest.mock('uuid/v4', () => {
36+
jest.mock('../uuid', () => {
3737
let value = 0;
3838
return () => value++;
3939
});

src/__tests__/ParseQuery-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jest.dontMock('../LocalDatastore');
2121
jest.dontMock('../OfflineQuery');
2222
jest.dontMock('../LiveQuerySubscription');
2323

24-
jest.mock('uuid/v4', () => {
24+
jest.mock('../uuid', () => {
2525
let value = 0;
2626
return () => value++;
2727
});

src/__tests__/ParseUser-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jest.dontMock('../UniqueInstanceStateController');
3131
jest.dontMock('crypto-js/aes');
3232
jest.dontMock('crypto-js/enc-utf8');
3333

34-
jest.mock('uuid/v4', () => {
34+
jest.mock('../uuid', () => {
3535
let value = 0;
3636
return () => value++;
3737
});

src/__tests__/RESTController-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
jest.autoMockOff();
1111
jest.useFakeTimers();
12-
jest.mock('uuid/v4', () => {
12+
jest.mock('../uuid', () => {
1313
let value = 1000;
1414
return () => (value++).toString();
1515
});

src/uuid.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
let uuid = null;
2+
3+
if (process.env.PARSE_BUILD === 'weapp') {
4+
uuid = function () {
5+
const s = [];
6+
const hexDigits = '0123456789abcdef';
7+
8+
for (let i = 0; i < 36; i++) {
9+
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
10+
}
11+
12+
s[14] = '4'; // bits 12-15 of the time_hi_and_version field to 0010
13+
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
14+
s[8] = s[13] = s[18] = s[23] = '-';
15+
16+
return s.join('');
17+
};
18+
} else {
19+
uuid = require('uuid/v4');
20+
}
21+
22+
module.exports = uuid;

0 commit comments

Comments
 (0)