Skip to content

Commit

Permalink
[bug] Fix weapp uuid error. (#1356)
Browse files Browse the repository at this point in the history
* fix: weapp uuid error.

* chore: wrapped uuid.
  • Loading branch information
oneRain committed May 8, 2021
1 parent 66878f2 commit e6f15fd
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/AnonymousUtils.js
Expand Up @@ -11,7 +11,7 @@

import ParseUser from './ParseUser';
import type { RequestOptions } from './RESTController';
const uuidv4 = require('uuid/v4');
const uuidv4 = require('./uuid');

let registered = false;

Expand Down
2 changes: 1 addition & 1 deletion src/InstallationController.js
Expand Up @@ -10,7 +10,7 @@
*/

import Storage from './Storage';
const uuidv4 = require('uuid/v4');
const uuidv4 = require('./uuid');

let iidCache = null;

Expand Down
2 changes: 1 addition & 1 deletion src/ParseObject.js
Expand Up @@ -43,7 +43,7 @@ import unsavedChildren from './unsavedChildren';
import type { AttributeMap, OpsMap } from './ObjectStateMutations';
import type { RequestOptions, FullOptions } from './RESTController';

const uuidv4 = require('uuid/v4');
const uuidv4 = require('./uuid');

export type Pointer = {
__type: string,
Expand Down
2 changes: 1 addition & 1 deletion src/RESTController.js
Expand Up @@ -9,7 +9,7 @@
* @flow
*/
/* global XMLHttpRequest, XDomainRequest */
const uuidv4 = require('uuid/v4');
const uuidv4 = require('./uuid');

import CoreManager from './CoreManager';
import ParseError from './ParseError';
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/InstallationController-test.js
Expand Up @@ -11,7 +11,7 @@ jest.dontMock('../CoreManager');
jest.dontMock('../InstallationController');
jest.dontMock('../Storage');
jest.dontMock('../StorageController.default');
jest.mock('uuid/v4', () => {
jest.mock('../uuid', () => {
let value = 0;
return () => value++ + '';
});
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/ParseObject-test.js
Expand Up @@ -33,7 +33,7 @@ jest.dontMock('../unsavedChildren');
jest.dontMock('../ParseACL');
jest.dontMock('../LocalDatastore');

jest.mock('uuid/v4', () => {
jest.mock('../uuid', () => {
let value = 0;
return () => value++;
});
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/ParseQuery-test.js
Expand Up @@ -21,7 +21,7 @@ jest.dontMock('../LocalDatastore');
jest.dontMock('../OfflineQuery');
jest.dontMock('../LiveQuerySubscription');

jest.mock('uuid/v4', () => {
jest.mock('../uuid', () => {
let value = 0;
return () => value++;
});
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/ParseUser-test.js
Expand Up @@ -31,7 +31,7 @@ jest.dontMock('../UniqueInstanceStateController');
jest.dontMock('crypto-js/aes');
jest.dontMock('crypto-js/enc-utf8');

jest.mock('uuid/v4', () => {
jest.mock('../uuid', () => {
let value = 0;
return () => value++;
});
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/RESTController-test.js
Expand Up @@ -9,7 +9,7 @@

jest.autoMockOff();
jest.useFakeTimers();
jest.mock('uuid/v4', () => {
jest.mock('../uuid', () => {
let value = 1000;
return () => (value++).toString();
});
Expand Down
22 changes: 22 additions & 0 deletions src/uuid.js
@@ -0,0 +1,22 @@
let uuid = null;

if (process.env.PARSE_BUILD === 'weapp') {
uuid = function () {
const s = [];
const hexDigits = '0123456789abcdef';

for (let i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}

s[14] = '4'; // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
s[8] = s[13] = s[18] = s[23] = '-';

return s.join('');
};
} else {
uuid = require('uuid/v4');
}

module.exports = uuid;

0 comments on commit e6f15fd

Please sign in to comment.