-
Notifications
You must be signed in to change notification settings - Fork 9
feat(query-parser, shell-bson-parser, constants): add shell helpers for legacy UUID MONGOSH-2486 #594
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
base: main
Are you sure you want to change the base?
feat(query-parser, shell-bson-parser, constants): add shell helpers for legacy UUID MONGOSH-2486 #594
Changes from all commits
8a41879
e442dcd
d69f6e8
f2fc449
e4c1e05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,6 +122,46 @@ const BSON_TYPES = [ | |
| description: 'BSON Regex type', | ||
| snippet: "RegExp('${1:source}', '${2:opts}')", | ||
| }, | ||
| { | ||
| name: 'LegacyJavaUUID', | ||
| value: 'LegacyJavaUUID', | ||
| label: 'LegacyJavaUUID', | ||
| score: 1, | ||
| meta: 'bson-legacy-uuid', | ||
| version: '0.0.0', | ||
| description: 'BSON Binary subtype 3 (Java legacy UUID)', | ||
| snippet: "LegacyJavaUUID('${1:uuid}')", | ||
| }, | ||
| { | ||
| name: 'LegacyCSharpUUID', | ||
| value: 'LegacyCSharpUUID', | ||
| label: 'LegacyCSharpUUID', | ||
| score: 1, | ||
| meta: 'bson-legacy-uuid', | ||
| version: '0.0.0', | ||
| description: 'BSON Binary subtype 3 (CSharp legacy UUID)', | ||
| snippet: "LegacyCSharpUUID('${1:uuid}')", | ||
| }, | ||
| { | ||
| name: 'LegacyPythonUUID', | ||
| value: 'LegacyPythonUUID', | ||
| label: 'LegacyPythonUUID', | ||
| score: 1, | ||
| meta: 'bson-legacy-uuid', | ||
| version: '0.0.0', | ||
| description: 'BSON Binary subtype 3 (Python legacy UUID)', | ||
| snippet: "LegacyPythonUUID('${1:uuid}')", | ||
| }, | ||
| { | ||
| name: 'UUID', | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| value: 'UUID', | ||
| label: 'UUID', | ||
| score: 1, | ||
| meta: 'bson', | ||
| version: '0.0.0', | ||
| description: 'BSON Binary subtype 4', | ||
| snippet: "UUID('${1:uuid}')", | ||
| }, | ||
| ] as const; | ||
|
|
||
| export { BSON_TYPES }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,78 @@ const SCOPE_ANY: { [x: string]: Function } = lookupMap({ | |
| Binary: function (buffer: any, subType: any) { | ||
| return new bson.Binary(buffer, subType); | ||
| }, | ||
|
|
||
| // Legacy UUID functions from | ||
| // https://github.com/mongodb/mongo-csharp-driver/blob/ac2b2a61c6b7a193cf0266dfb8c65f86c2bf7572/uuidhelpers.js | ||
| LegacyJavaUUID: function (u: any) { | ||
| if (u === undefined) { | ||
| // Generate a new UUID and format it. | ||
| u = new bson.UUID().toHexString(); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Chatting with @nbbeeken I think we were thinking of throwing an error here instead. This is when someone writes |
||
| } | ||
|
|
||
| let hex: string = String.prototype.replace.call(u, /[{}-]/g, () => ''); | ||
| let msb = String.prototype.substring.call(hex, 0, 16); | ||
| let lsb = String.prototype.substring.call(hex, 16, 32); | ||
| msb = | ||
| String.prototype.substring.call(msb, 14, 16) + | ||
| String.prototype.substring.call(msb, 12, 14) + | ||
| String.prototype.substring.call(msb, 10, 12) + | ||
| String.prototype.substring.call(msb, 8, 10) + | ||
| String.prototype.substring.call(msb, 6, 8) + | ||
| String.prototype.substring.call(msb, 4, 6) + | ||
| String.prototype.substring.call(msb, 2, 4) + | ||
| String.prototype.substring.call(msb, 0, 2); | ||
| lsb = | ||
| String.prototype.substring.call(lsb, 14, 16) + | ||
| String.prototype.substring.call(lsb, 12, 14) + | ||
| String.prototype.substring.call(lsb, 10, 12) + | ||
| String.prototype.substring.call(lsb, 8, 10) + | ||
| String.prototype.substring.call(lsb, 6, 8) + | ||
| String.prototype.substring.call(lsb, 4, 6) + | ||
| String.prototype.substring.call(lsb, 2, 4) + | ||
| String.prototype.substring.call(lsb, 0, 2); | ||
| hex = msb + lsb; | ||
|
|
||
| const hexBuffer = Buffer.from(hex, 'hex'); | ||
| return new bson.Binary(hexBuffer, 3); | ||
| }, | ||
| LegacyCSharpUUID: function (u: any) { | ||
| if (u === undefined) { | ||
| // Generate a new UUID and format it. | ||
| u = new bson.UUID().toHexString(); | ||
| } | ||
|
|
||
| let hex: string = String.prototype.replace.call(u, /[{}-]/g, () => ''); | ||
| const a = | ||
| String.prototype.substring.call(hex, 6, 8) + | ||
| String.prototype.substring.call(hex, 4, 6) + | ||
| String.prototype.substring.call(hex, 2, 4) + | ||
| String.prototype.substring.call(hex, 0, 2); | ||
| const b = | ||
| String.prototype.substring.call(hex, 10, 12) + | ||
| String.prototype.substring.call(hex, 8, 10); | ||
| const c = | ||
| String.prototype.substring.call(hex, 14, 16) + | ||
| String.prototype.substring.call(hex, 12, 14); | ||
| const d = String.prototype.substring.call(hex, 16, 32); | ||
| hex = a + b + c + d; | ||
|
|
||
| const hexBuffer = Buffer.from(hex, 'hex'); | ||
| return new bson.Binary(hexBuffer, 3); | ||
| }, | ||
| LegacyPythonUUID: function (u: any) { | ||
| if (u === undefined) { | ||
| return new bson.Binary(new bson.UUID().toBinary().buffer, 3); | ||
| } | ||
|
|
||
| return new bson.Binary( | ||
| Buffer.from( | ||
| String.prototype.replace.call(u, /[{}-]/g, () => ''), | ||
| 'hex', | ||
| ), | ||
| 3, | ||
| ); | ||
| }, | ||
| BinData: function (t: any, d: any) { | ||
| return new bson.Binary(Buffer.from(d, 'base64'), t); | ||
| }, | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
metahere will make it into Compass' autocompleter: