Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract uuid function into @firebase/util #6363

Merged
merged 64 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
db50631
WIP
maneesht May 13, 2022
46cd378
Simulate add/remove event registration in repoGetValue
jmwski May 13, 2022
c334171
Fixed duplicate onValue calls
maneesht May 17, 2022
f7298df
Updated test file
maneesht May 18, 2022
00a5907
Updated integration test to include get
maneesht May 19, 2022
3ea9604
Reduced timeout for tests
maneesht May 20, 2022
9520427
Removed unnecessary imports
maneesht May 20, 2022
e7dd651
Added back imports
maneesht May 20, 2022
f7ed576
Removed snapshot param
maneesht May 20, 2022
98c6e34
Addressed comments
maneesht May 23, 2022
43f1f8a
Fixed test
maneesht May 23, 2022
9394170
Removed only
maneesht May 23, 2022
2f82052
Removed unnecessary import
maneesht May 23, 2022
c976987
Updated test
maneesht May 23, 2022
fc4cf5c
Added extra test
maneesht May 24, 2022
7c31ece
Merge branch 'master' into fix-get-cache
maneesht May 25, 2022
3959cf3
Fixed formatting
maneesht May 25, 2022
536e103
Create rotten-tables-brush.md
maneesht May 25, 2022
3812a33
Added documentation
maneesht May 25, 2022
a8d8ea6
Passed formatting
maneesht May 25, 2022
7de3c12
Merge remote-tracking branch 'origin/master' into fix-get-cache
maneesht May 26, 2022
766f46d
Addressed comments
maneesht May 26, 2022
04356e4
WIP
maneesht May 31, 2022
a467055
Used unique id instead of foo
maneesht May 31, 2022
6145b2b
Used exactCount instead of Count for accumulator
maneesht Jun 1, 2022
788aaa0
Removed only
maneesht Jun 1, 2022
51d57a2
Reformatted
maneesht Jun 1, 2022
41a7303
Removed get wip
maneesht Jun 2, 2022
a58bb33
Got minimal repro
maneesht Jun 2, 2022
5d41ce0
Got minimal repro
maneesht Jun 2, 2022
bdfd40b
Fixed race condition issue
maneesht Jun 2, 2022
4ca2289
Updated tests
maneesht Jun 2, 2022
b52f468
Updated yarn lock file
maneesht Jun 3, 2022
27f9ea1
Updated module type
maneesht Jun 3, 2022
065dab0
Added comment
maneesht Jun 3, 2022
d5fef45
Merge remote-tracking branch 'origin/master' into fix-get-cache
maneesht Jun 3, 2022
74fe5e8
Removed unnecessary code
maneesht Jun 3, 2022
5858b86
Merge remote-tracking branch 'origin/master' into fix-get-cache
maneesht Jun 6, 2022
be41979
Removed unnecessary comment
maneesht Jun 6, 2022
f320a93
Removed unused imports
maneesht Jun 6, 2022
c4f8ff7
Updated test to remove redundant assertion
maneesht Jun 6, 2022
1dc798c
Moved query check
maneesht Jun 8, 2022
42e38f6
Updated tests to include example queries
maneesht Jun 8, 2022
b4c7f28
Fixed formatting
maneesht Jun 8, 2022
5559921
Added suggestions
maneesht Jun 8, 2022
52fcf72
Fixed formatting
maneesht Jun 8, 2022
c553405
Replaced let with const
maneesht Jun 8, 2022
a7e5865
Fixed tests
maneesht Jun 9, 2022
98845d1
Fixed test
maneesht Jun 9, 2022
69feeb7
Fixed formatting
maneesht Jun 9, 2022
60f9da0
Fixed tests
maneesht Jun 15, 2022
6f39fef
Removed comments
maneesht Jun 15, 2022
57a8db5
Removed version of uuid
maneesht Jun 15, 2022
31a747e
Added a new line
maneesht Jun 15, 2022
bd23960
Addressed comments
maneesht Jun 16, 2022
6656e5a
Extracted out uuid
maneesht Jun 16, 2022
11f31f9
Merge remote-tracking branch 'origin/master' into mtewani/extract-uuidv4
maneesht Jun 16, 2022
e1318b6
Reformatted files
maneesht Jun 16, 2022
d79919c
Reformatted again
maneesht Jun 16, 2022
5fd68d8
Create tame-rice-peel.md
maneesht Jun 16, 2022
5ee6096
Addressed comments
maneesht Jun 16, 2022
324ce39
Removed global import
maneesht Jun 16, 2022
65234d5
Fixed lint error
maneesht Jun 16, 2022
199478c
Ran formatter
maneesht Jun 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/tame-rice-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@firebase/app-check": patch
"@firebase/database": patch
"@firebase/util": patch
---

Extract uuid function into @firebase/util
3 changes: 3 additions & 0 deletions common/api-review/util.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@ export interface Subscribe<T> {
// @public (undocumented)
export type Unsubscribe = () => void;

// @public
maneesht marked this conversation as resolved.
Show resolved Hide resolved
export const uuidv4: () => string;

// Warning: (ae-missing-release-tag) "validateArgCount" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
Expand Down
3 changes: 1 addition & 2 deletions packages/app-check/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
* limitations under the License.
*/

import { uuidv4 } from './util';
import { FirebaseApp } from '@firebase/app';
import { isIndexedDBAvailable } from '@firebase/util';
import { isIndexedDBAvailable, uuidv4 } from '@firebase/util';
import {
readDebugTokenFromIndexedDB,
readTokenFromIndexedDB,
Expand Down
11 changes: 0 additions & 11 deletions packages/app-check/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ export function ensureActivated(app: FirebaseApp): void {
}
}

/**
* Copied from https://stackoverflow.com/a/2117523
*/
export function uuidv4(): string {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
const r = (Math.random() * 16) | 0,
v = c === 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}

export function getDurationString(durationInMillis: number): string {
const totalSeconds = Math.round(durationInMillis / 1000);
const days = Math.floor(totalSeconds / (3600 * 24));
Expand Down
14 changes: 2 additions & 12 deletions packages/database/test/helpers/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

import { uuidv4 } from '@firebase/util';

import { Database, ref } from '../../src';
import { ConnectionTarget } from '../../src/api/test_access';

Expand Down Expand Up @@ -78,18 +80,6 @@ export function waitFor(waitTimeInMS: number) {
return new Promise(resolve => setTimeout(resolve, waitTimeInMS));
}

/**
* Copied from https://stackoverflow.com/a/2117523
* TODO: extract this into @firebase/util
*/
export function uuidv4(): string {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
const r = (Math.random() * 16) | 0,
v = c === 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}

// Creates a unique reference using uuid
export function getUniqueRef(db: Database) {
const path = uuidv4();
Expand Down
1 change: 1 addition & 0 deletions packages/util/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export * from './src/sha1';
export * from './src/subscribe';
export * from './src/validation';
export * from './src/utf8';
export * from './src/uuid';
export * from './src/exponential_backoff';
export * from './src/formatters';
export * from './src/compat';
1 change: 1 addition & 0 deletions packages/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export * from './src/sha1';
export * from './src/subscribe';
export * from './src/validation';
export * from './src/utf8';
export * from './src/uuid';
maneesht marked this conversation as resolved.
Show resolved Hide resolved
export * from './src/exponential_backoff';
export * from './src/formatters';
export * from './src/compat';
29 changes: 29 additions & 0 deletions packages/util/src/uuid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @license
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Copied from https://stackoverflow.com/a/2117523
* Generates a new uuid.
maneesht marked this conversation as resolved.
Show resolved Hide resolved
* @public
*/
export const uuidv4 = function (): string {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
const r = (Math.random() * 16) | 0,
v = c === 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
};