@mongoosejs/studio 0.5.8 → 0.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/backend/integrations/streamLLM.js +2 -2
- package/eslint.config.js +3 -1
- package/frontend/index.js +2 -1
- package/frontend/public/app.js +529 -469
- package/frontend/src/_util/document-search-autocomplete.js +11 -0
- package/frontend/src/index.js +1 -5
- package/frontend/src/models/document-search/document-search.js +16 -0
- package/frontend/src/models/models.js +46 -10
- package/frontend/src/routes.js +2 -1
- package/package.json +1 -1
package/frontend/public/app.js
CHANGED
|
@@ -614,6 +614,16 @@ function applySuggestion(searchText, cursorPos, suggestion) {
|
|
|
614
614
|
return null;
|
|
615
615
|
}
|
|
616
616
|
|
|
617
|
+
function insertClosingBrace(searchText, selectionStart, selectionEnd) {
|
|
618
|
+
const start = typeof selectionStart === 'number' ? selectionStart : searchText.length;
|
|
619
|
+
const end = typeof selectionEnd === 'number' ? selectionEnd : start;
|
|
620
|
+
const selectedText = searchText.slice(start, end);
|
|
621
|
+
return {
|
|
622
|
+
text: searchText.slice(0, start) + `{${selectedText}}` + searchText.slice(end),
|
|
623
|
+
newCursorPos: start + 1 + selectedText.length
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
|
|
617
627
|
/**
|
|
618
628
|
* When the cursor is inside a Date(…) or new Date(…) argument, returns the
|
|
619
629
|
* slice indices of that argument so a picker can replace it with a quoted ISO string.
|
|
@@ -695,6 +705,7 @@ module.exports = {
|
|
|
695
705
|
getAutocompleteContext,
|
|
696
706
|
getAutocompleteSuggestions,
|
|
697
707
|
applySuggestion,
|
|
708
|
+
insertClosingBrace,
|
|
698
709
|
getDatePickerInsertionRange,
|
|
699
710
|
dateArgumentSliceToDatetimeLocal,
|
|
700
711
|
formatDateArgumentValue,
|
|
@@ -7736,10 +7747,6 @@ module.exports = function getCurrentDateTimeContext() {
|
|
|
7736
7747
|
"use strict";
|
|
7737
7748
|
|
|
7738
7749
|
|
|
7739
|
-
if (typeof process === 'undefined') {
|
|
7740
|
-
__webpack_require__.g.process = { env: {} }; // To make `util` package work
|
|
7741
|
-
}
|
|
7742
|
-
|
|
7743
7750
|
const { version } = __webpack_require__(/*! ../../package.json */ "./package.json");
|
|
7744
7751
|
console.log(`Mongoose Studio Version ${version}`);
|
|
7745
7752
|
|
|
@@ -7928,7 +7935,7 @@ app.component('app-component', {
|
|
|
7928
7935
|
<div v-else-if="!hasAPIKey || user">
|
|
7929
7936
|
<navbar :user="user" :roles="roles" />
|
|
7930
7937
|
<div class="view">
|
|
7931
|
-
<router-view :key="$route.fullPath" :user="user" :roles="roles" :hasAPIKey="hasAPIKey" />
|
|
7938
|
+
<router-view :key="$route.meta.preserveStateKey || $route.fullPath" :user="user" :roles="roles" :hasAPIKey="hasAPIKey" />
|
|
7932
7939
|
</div>
|
|
7933
7940
|
</div>
|
|
7934
7941
|
</div>
|
|
@@ -9023,6 +9030,7 @@ const {
|
|
|
9023
9030
|
buildAutocompleteTrie,
|
|
9024
9031
|
getAutocompleteSuggestions,
|
|
9025
9032
|
applySuggestion,
|
|
9033
|
+
insertClosingBrace,
|
|
9026
9034
|
getDatePickerInsertionRange,
|
|
9027
9035
|
dateArgumentSliceToDatetimeLocal,
|
|
9028
9036
|
insertDateInDateArgument
|
|
@@ -9157,6 +9165,21 @@ module.exports = app => app.component('document-search', {
|
|
|
9157
9165
|
});
|
|
9158
9166
|
},
|
|
9159
9167
|
handleKeyDown(ev) {
|
|
9168
|
+
if (ev.key === '{') {
|
|
9169
|
+
ev.preventDefault();
|
|
9170
|
+
const input = this.$refs.searchInput;
|
|
9171
|
+
const selectionStart = input ? input.selectionStart : this.searchText.length;
|
|
9172
|
+
const selectionEnd = input ? input.selectionEnd : selectionStart;
|
|
9173
|
+
const result = insertClosingBrace(this.searchText, selectionStart, selectionEnd);
|
|
9174
|
+
this.searchText = result.text;
|
|
9175
|
+
this.$nextTick(() => {
|
|
9176
|
+
if (input) {
|
|
9177
|
+
input.setSelectionRange(result.newCursorPos, result.newCursorPos);
|
|
9178
|
+
}
|
|
9179
|
+
this.updateAutocomplete();
|
|
9180
|
+
});
|
|
9181
|
+
return;
|
|
9182
|
+
}
|
|
9160
9183
|
if (this.autocompleteSuggestions.length === 0) {
|
|
9161
9184
|
return;
|
|
9162
9185
|
}
|
|
@@ -9513,6 +9536,7 @@ module.exports = app => app.component('models', {
|
|
|
9513
9536
|
currentModel: null,
|
|
9514
9537
|
modelDocumentCounts: {},
|
|
9515
9538
|
documents: [],
|
|
9539
|
+
allSchemaPaths: null,
|
|
9516
9540
|
schemaPaths: [],
|
|
9517
9541
|
filteredPaths: [],
|
|
9518
9542
|
selectedPaths: [],
|
|
@@ -9630,8 +9654,9 @@ module.exports = app => app.component('models', {
|
|
|
9630
9654
|
this.query = Object.assign({}, this.$route.query);
|
|
9631
9655
|
// Keep UI mode in sync with the URL on remounts.
|
|
9632
9656
|
this.isProjectionMenuSelected = this.$route?.query?.[PROJECTION_MODE_QUERY_KEY] === '1';
|
|
9633
|
-
const { models, readyState } = await api.Model.listModels();
|
|
9657
|
+
const { models, modelSchemaPaths, readyState } = await api.Model.listModels();
|
|
9634
9658
|
this.models = models;
|
|
9659
|
+
this.allSchemaPaths = modelSchemaPaths;
|
|
9635
9660
|
await this.loadModelCounts();
|
|
9636
9661
|
if (this.currentModel == null && this.models.length > 0) {
|
|
9637
9662
|
this.currentModel = this.models[0];
|
|
@@ -9642,6 +9667,29 @@ module.exports = app => app.component('models', {
|
|
|
9642
9667
|
if (readyState === 0) {
|
|
9643
9668
|
this.error = 'No models found and Mongoose is not connected. Check our documentation for more information.';
|
|
9644
9669
|
}
|
|
9670
|
+
} else {
|
|
9671
|
+
this._refreshSidebar = setInterval(async() => {
|
|
9672
|
+
try {
|
|
9673
|
+
const { models, modelSchemaPaths, readyState } = await api.Model.listModels();
|
|
9674
|
+
this.models = models;
|
|
9675
|
+
this.allSchemaPaths = modelSchemaPaths;
|
|
9676
|
+
await this.loadModelCounts();
|
|
9677
|
+
if (this.currentModel) {
|
|
9678
|
+
const schemaPaths = this.allSchemaPaths?.[this.currentModel] ?? {};
|
|
9679
|
+
this.schemaPaths = Object.keys(schemaPaths).sort((k1, k2) => {
|
|
9680
|
+
if (k1 === '_id' && k2 !== '_id') {
|
|
9681
|
+
return -1;
|
|
9682
|
+
}
|
|
9683
|
+
if (k1 !== '_id' && k2 === '_id') {
|
|
9684
|
+
return 1;
|
|
9685
|
+
}
|
|
9686
|
+
return 0;
|
|
9687
|
+
}).map(key => schemaPaths[key]);
|
|
9688
|
+
}
|
|
9689
|
+
} catch (e) {
|
|
9690
|
+
console.error(e);
|
|
9691
|
+
}
|
|
9692
|
+
}, 20000);
|
|
9645
9693
|
}
|
|
9646
9694
|
|
|
9647
9695
|
await this.initSearchFromUrl();
|
|
@@ -9652,25 +9700,33 @@ module.exports = app => app.component('models', {
|
|
|
9652
9700
|
this.$nextTick(() => {
|
|
9653
9701
|
const focusIntent = takeModelsRemountFocusIntent();
|
|
9654
9702
|
if (focusIntent === 'documentSearch') {
|
|
9655
|
-
|
|
9656
|
-
if (ds && typeof ds.focusInput === 'function') {
|
|
9657
|
-
ds.focusInput();
|
|
9658
|
-
}
|
|
9703
|
+
this.$refs.documentSearch?.focusInput();
|
|
9659
9704
|
return;
|
|
9660
9705
|
}
|
|
9661
9706
|
if (focusIntent === 'projection' && this.isProjectionMenuSelected) {
|
|
9662
|
-
|
|
9663
|
-
if (projectionSearch && typeof projectionSearch.focusInput === 'function') {
|
|
9664
|
-
projectionSearch.focusInput();
|
|
9665
|
-
}
|
|
9707
|
+
this.$refs.projectionSearch?.focusInput();
|
|
9666
9708
|
}
|
|
9667
9709
|
});
|
|
9668
9710
|
},
|
|
9711
|
+
unmounted() {
|
|
9712
|
+
clearInterval(this._refreshSidebar);
|
|
9713
|
+
},
|
|
9669
9714
|
watch: {
|
|
9670
9715
|
model(newModel) {
|
|
9671
9716
|
if (newModel !== this.currentModel) {
|
|
9672
9717
|
this.currentModel = newModel;
|
|
9673
9718
|
if (this.currentModel != null) {
|
|
9719
|
+
this.$refs.documentSearch?.focusInput();
|
|
9720
|
+
const schemaPaths = this.allSchemaPaths?.[newModel] ?? {};
|
|
9721
|
+
this.schemaPaths = Object.keys(schemaPaths).sort((k1, k2) => {
|
|
9722
|
+
if (k1 === '_id' && k2 !== '_id') {
|
|
9723
|
+
return -1;
|
|
9724
|
+
}
|
|
9725
|
+
if (k1 !== '_id' && k2 === '_id') {
|
|
9726
|
+
return 1;
|
|
9727
|
+
}
|
|
9728
|
+
return 0;
|
|
9729
|
+
}).map(key => schemaPaths[key]);
|
|
9674
9730
|
this.initSearchFromUrl();
|
|
9675
9731
|
}
|
|
9676
9732
|
}
|
|
@@ -10114,6 +10170,8 @@ module.exports = app => app.component('models', {
|
|
|
10114
10170
|
this.query.sortKey = sortKey;
|
|
10115
10171
|
this.query.sortDirection = sortDirection;
|
|
10116
10172
|
delete this.query.sort;
|
|
10173
|
+
} else {
|
|
10174
|
+
this.sortBy = {};
|
|
10117
10175
|
}
|
|
10118
10176
|
if (this.currentModel != null) {
|
|
10119
10177
|
await this.getDocuments();
|
|
@@ -10129,6 +10187,8 @@ module.exports = app => app.component('models', {
|
|
|
10129
10187
|
this.selectedPaths = [...this.filteredPaths];
|
|
10130
10188
|
this.syncProjectionInputFromQueryOrPaths();
|
|
10131
10189
|
}
|
|
10190
|
+
} else {
|
|
10191
|
+
this.selectedPaths = [];
|
|
10132
10192
|
}
|
|
10133
10193
|
this.status = 'loaded';
|
|
10134
10194
|
|
|
@@ -10410,7 +10470,6 @@ module.exports = app => app.component('models', {
|
|
|
10410
10470
|
|
|
10411
10471
|
// Clear previous data
|
|
10412
10472
|
this.documents = [];
|
|
10413
|
-
this.schemaPaths = [];
|
|
10414
10473
|
this.numDocuments = null;
|
|
10415
10474
|
this.loadedAllDocs = false;
|
|
10416
10475
|
this.lastSelectedIndex = null;
|
|
@@ -11731,7 +11790,8 @@ module.exports = {
|
|
|
11731
11790
|
name: 'model',
|
|
11732
11791
|
component: 'models',
|
|
11733
11792
|
meta: {
|
|
11734
|
-
authorized: false
|
|
11793
|
+
authorized: false,
|
|
11794
|
+
preserveStateKey: 'model'
|
|
11735
11795
|
}
|
|
11736
11796
|
},
|
|
11737
11797
|
{
|
|
@@ -60598,7 +60658,7 @@ class Binary extends BSONValue {
|
|
|
60598
60658
|
!Array.isArray(buffer)) {
|
|
60599
60659
|
throw new BSONError('Binary can only be constructed from Uint8Array or number[]');
|
|
60600
60660
|
}
|
|
60601
|
-
this.sub_type = subType ?? Binary.BSON_BINARY_SUBTYPE_DEFAULT;
|
|
60661
|
+
this.sub_type = (subType ?? Binary.BSON_BINARY_SUBTYPE_DEFAULT) & 0xff;
|
|
60602
60662
|
if (buffer == null) {
|
|
60603
60663
|
this.buffer = ByteUtils.allocate(Binary.BUFFER_SIZE);
|
|
60604
60664
|
this.position = 0;
|
|
@@ -60704,7 +60764,7 @@ class Binary extends BSONValue {
|
|
|
60704
60764
|
if (this.sub_type === Binary.SUBTYPE_UUID) {
|
|
60705
60765
|
return new UUID(this.buffer.subarray(0, this.position));
|
|
60706
60766
|
}
|
|
60707
|
-
throw new BSONError(`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only
|
|
60767
|
+
throw new BSONError(`Binary sub_type "${this.sub_type}" (${typeof this.sub_type}) is not supported for converting to UUID. Only 0x${Binary.SUBTYPE_UUID.toString(16).padStart(2, '0')} is currently supported.`);
|
|
60708
60768
|
}
|
|
60709
60769
|
static createFromHexString(hex, subType) {
|
|
60710
60770
|
return new Binary(ByteUtils.fromHex(hex), subType);
|
|
@@ -62493,13 +62553,24 @@ class MinKey extends BSONValue {
|
|
|
62493
62553
|
}
|
|
62494
62554
|
}
|
|
62495
62555
|
|
|
62496
|
-
let PROCESS_UNIQUE = null;
|
|
62497
62556
|
const __idCache = new WeakMap();
|
|
62498
62557
|
class ObjectId extends BSONValue {
|
|
62499
62558
|
get _bsontype() {
|
|
62500
62559
|
return 'ObjectId';
|
|
62501
62560
|
}
|
|
62502
|
-
static index =
|
|
62561
|
+
static index = 0;
|
|
62562
|
+
static PROCESS_UNIQUE = null;
|
|
62563
|
+
static resetState = () => {
|
|
62564
|
+
this.index = Math.floor(Math.random() * 0x1000000);
|
|
62565
|
+
this.PROCESS_UNIQUE = ByteUtils.randomBytes(5);
|
|
62566
|
+
};
|
|
62567
|
+
static {
|
|
62568
|
+
this.resetState();
|
|
62569
|
+
const { startupSnapshot } = globalThis?.process?.getBuiltinModule('v8') ?? {};
|
|
62570
|
+
if (startupSnapshot?.isBuildingSnapshot()) {
|
|
62571
|
+
startupSnapshot?.addDeserializeCallback(this.resetState);
|
|
62572
|
+
}
|
|
62573
|
+
}
|
|
62503
62574
|
static cacheHexString;
|
|
62504
62575
|
buffer;
|
|
62505
62576
|
constructor(inputId) {
|
|
@@ -62576,7 +62647,7 @@ class ObjectId extends BSONValue {
|
|
|
62576
62647
|
return hexString;
|
|
62577
62648
|
}
|
|
62578
62649
|
static getInc() {
|
|
62579
|
-
return (ObjectId.index = (ObjectId.index + 1) %
|
|
62650
|
+
return (ObjectId.index = (ObjectId.index + 1) % 0x1000000);
|
|
62580
62651
|
}
|
|
62581
62652
|
static generate(time) {
|
|
62582
62653
|
if ('number' !== typeof time) {
|
|
@@ -62585,9 +62656,7 @@ class ObjectId extends BSONValue {
|
|
|
62585
62656
|
const inc = ObjectId.getInc();
|
|
62586
62657
|
const buffer = ByteUtils.allocateUnsafe(12);
|
|
62587
62658
|
NumberUtils.setInt32BE(buffer, 0, time);
|
|
62588
|
-
|
|
62589
|
-
PROCESS_UNIQUE = ByteUtils.randomBytes(5);
|
|
62590
|
-
}
|
|
62659
|
+
const PROCESS_UNIQUE = this.PROCESS_UNIQUE;
|
|
62591
62660
|
buffer[4] = PROCESS_UNIQUE[0];
|
|
62592
62661
|
buffer[5] = PROCESS_UNIQUE[1];
|
|
62593
62662
|
buffer[6] = PROCESS_UNIQUE[2];
|
|
@@ -62705,23 +62774,33 @@ class ObjectId extends BSONValue {
|
|
|
62705
62774
|
}
|
|
62706
62775
|
|
|
62707
62776
|
function internalCalculateObjectSize(object, serializeFunctions, ignoreUndefined) {
|
|
62708
|
-
|
|
62709
|
-
|
|
62710
|
-
|
|
62711
|
-
|
|
62777
|
+
const objectStack = [
|
|
62778
|
+
{ obj: object, ignoreUndefined: ignoreUndefined ?? false }
|
|
62779
|
+
];
|
|
62780
|
+
let total = 0;
|
|
62781
|
+
while (objectStack.length > 0) {
|
|
62782
|
+
const { obj, ignoreUndefined: frameIgnoreUndefined } = objectStack.pop();
|
|
62783
|
+
total += 5;
|
|
62784
|
+
const isObjArray = Array.isArray(obj);
|
|
62785
|
+
let target = obj;
|
|
62786
|
+
if (!isObjArray && typeof obj?.toBSON === 'function') {
|
|
62787
|
+
target = obj.toBSON();
|
|
62712
62788
|
}
|
|
62713
|
-
|
|
62714
|
-
|
|
62715
|
-
|
|
62716
|
-
|
|
62789
|
+
if (isObjArray) {
|
|
62790
|
+
const array = target;
|
|
62791
|
+
for (let i = 0; i < array.length; i++) {
|
|
62792
|
+
total += calculateElementSize(i.toString(), array[i], serializeFunctions, true, frameIgnoreUndefined, objectStack);
|
|
62793
|
+
}
|
|
62717
62794
|
}
|
|
62718
|
-
|
|
62719
|
-
|
|
62795
|
+
else {
|
|
62796
|
+
for (const key of Object.keys(target)) {
|
|
62797
|
+
total += calculateElementSize(key, target[key], serializeFunctions, false, frameIgnoreUndefined, objectStack);
|
|
62798
|
+
}
|
|
62720
62799
|
}
|
|
62721
62800
|
}
|
|
62722
|
-
return
|
|
62801
|
+
return total;
|
|
62723
62802
|
}
|
|
62724
|
-
function
|
|
62803
|
+
function calculateElementSize(name, value, serializeFunctions = false, isArray = false, ignoreUndefined = false, objectStack) {
|
|
62725
62804
|
if (typeof value?.toBSON === 'function') {
|
|
62726
62805
|
value = value.toBSON();
|
|
62727
62806
|
}
|
|
@@ -62733,21 +62812,21 @@ function calculateElement(name, value, serializeFunctions = false, isArray = fal
|
|
|
62733
62812
|
value >= JS_INT_MIN &&
|
|
62734
62813
|
value <= JS_INT_MAX) {
|
|
62735
62814
|
if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) {
|
|
62736
|
-
return
|
|
62815
|
+
return ByteUtils.utf8ByteLength(name) + 1 + (4 + 1);
|
|
62737
62816
|
}
|
|
62738
62817
|
else {
|
|
62739
|
-
return
|
|
62818
|
+
return ByteUtils.utf8ByteLength(name) + 1 + (8 + 1);
|
|
62740
62819
|
}
|
|
62741
62820
|
}
|
|
62742
62821
|
else {
|
|
62743
|
-
return
|
|
62822
|
+
return ByteUtils.utf8ByteLength(name) + 1 + (8 + 1);
|
|
62744
62823
|
}
|
|
62745
62824
|
case 'undefined':
|
|
62746
62825
|
if (isArray || !ignoreUndefined)
|
|
62747
|
-
return
|
|
62826
|
+
return ByteUtils.utf8ByteLength(name) + 1 + 1;
|
|
62748
62827
|
return 0;
|
|
62749
62828
|
case 'boolean':
|
|
62750
|
-
return
|
|
62829
|
+
return ByteUtils.utf8ByteLength(name) + 1 + (1 + 1);
|
|
62751
62830
|
case 'object':
|
|
62752
62831
|
if (value != null &&
|
|
62753
62832
|
typeof value._bsontype === 'string' &&
|
|
@@ -62755,39 +62834,41 @@ function calculateElement(name, value, serializeFunctions = false, isArray = fal
|
|
|
62755
62834
|
throw new BSONVersionError();
|
|
62756
62835
|
}
|
|
62757
62836
|
else if (value == null || value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
62758
|
-
return
|
|
62837
|
+
return ByteUtils.utf8ByteLength(name) + 1 + 1;
|
|
62759
62838
|
}
|
|
62760
62839
|
else if (value._bsontype === 'ObjectId') {
|
|
62761
|
-
return
|
|
62840
|
+
return ByteUtils.utf8ByteLength(name) + 1 + (12 + 1);
|
|
62762
62841
|
}
|
|
62763
62842
|
else if (value instanceof Date || isDate(value)) {
|
|
62764
|
-
return
|
|
62843
|
+
return ByteUtils.utf8ByteLength(name) + 1 + (8 + 1);
|
|
62765
62844
|
}
|
|
62766
62845
|
else if (ArrayBuffer.isView(value) ||
|
|
62767
62846
|
value instanceof ArrayBuffer ||
|
|
62768
62847
|
isAnyArrayBuffer(value)) {
|
|
62769
|
-
return
|
|
62848
|
+
return ByteUtils.utf8ByteLength(name) + 1 + (1 + 4 + 1) + value.byteLength;
|
|
62770
62849
|
}
|
|
62771
62850
|
else if (value._bsontype === 'Long' ||
|
|
62772
62851
|
value._bsontype === 'Double' ||
|
|
62773
62852
|
value._bsontype === 'Timestamp') {
|
|
62774
|
-
return
|
|
62853
|
+
return ByteUtils.utf8ByteLength(name) + 1 + (8 + 1);
|
|
62775
62854
|
}
|
|
62776
62855
|
else if (value._bsontype === 'Decimal128') {
|
|
62777
|
-
return
|
|
62856
|
+
return ByteUtils.utf8ByteLength(name) + 1 + (16 + 1);
|
|
62778
62857
|
}
|
|
62779
62858
|
else if (value._bsontype === 'Code') {
|
|
62780
62859
|
if (value.scope != null && Object.keys(value.scope).length > 0) {
|
|
62781
|
-
|
|
62860
|
+
objectStack.push({ obj: value.scope, ignoreUndefined });
|
|
62861
|
+
return (ByteUtils.utf8ByteLength(name) +
|
|
62862
|
+
1 +
|
|
62782
62863
|
1 +
|
|
62783
62864
|
4 +
|
|
62784
62865
|
4 +
|
|
62785
62866
|
ByteUtils.utf8ByteLength(value.code.toString()) +
|
|
62786
|
-
1
|
|
62787
|
-
internalCalculateObjectSize(value.scope, serializeFunctions, ignoreUndefined));
|
|
62867
|
+
1);
|
|
62788
62868
|
}
|
|
62789
62869
|
else {
|
|
62790
|
-
return (
|
|
62870
|
+
return (ByteUtils.utf8ByteLength(name) +
|
|
62871
|
+
1 +
|
|
62791
62872
|
1 +
|
|
62792
62873
|
4 +
|
|
62793
62874
|
ByteUtils.utf8ByteLength(value.code.toString()) +
|
|
@@ -62797,19 +62878,14 @@ function calculateElement(name, value, serializeFunctions = false, isArray = fal
|
|
|
62797
62878
|
else if (value._bsontype === 'Binary') {
|
|
62798
62879
|
const binary = value;
|
|
62799
62880
|
if (binary.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
|
|
62800
|
-
return (
|
|
62801
|
-
(binary.position + 1 + 4 + 1 + 4));
|
|
62881
|
+
return ByteUtils.utf8ByteLength(name) + 1 + (binary.position + 1 + 4 + 1 + 4);
|
|
62802
62882
|
}
|
|
62803
62883
|
else {
|
|
62804
|
-
return
|
|
62884
|
+
return ByteUtils.utf8ByteLength(name) + 1 + (binary.position + 1 + 4 + 1);
|
|
62805
62885
|
}
|
|
62806
62886
|
}
|
|
62807
62887
|
else if (value._bsontype === 'Symbol') {
|
|
62808
|
-
return ((name
|
|
62809
|
-
ByteUtils.utf8ByteLength(value.value) +
|
|
62810
|
-
4 +
|
|
62811
|
-
1 +
|
|
62812
|
-
1);
|
|
62888
|
+
return (ByteUtils.utf8ByteLength(name) + 1 + ByteUtils.utf8ByteLength(value.value) + 4 + 1 + 1);
|
|
62813
62889
|
}
|
|
62814
62890
|
else if (value._bsontype === 'DBRef') {
|
|
62815
62891
|
const ordered_values = Object.assign({
|
|
@@ -62819,12 +62895,12 @@ function calculateElement(name, value, serializeFunctions = false, isArray = fal
|
|
|
62819
62895
|
if (value.db != null) {
|
|
62820
62896
|
ordered_values['$db'] = value.db;
|
|
62821
62897
|
}
|
|
62822
|
-
|
|
62823
|
-
|
|
62824
|
-
internalCalculateObjectSize(ordered_values, serializeFunctions, ignoreUndefined));
|
|
62898
|
+
objectStack.push({ obj: ordered_values, ignoreUndefined: true });
|
|
62899
|
+
return ByteUtils.utf8ByteLength(name) + 1 + 1;
|
|
62825
62900
|
}
|
|
62826
62901
|
else if (value instanceof RegExp || isRegExp(value)) {
|
|
62827
|
-
return (
|
|
62902
|
+
return (ByteUtils.utf8ByteLength(name) +
|
|
62903
|
+
1 +
|
|
62828
62904
|
1 +
|
|
62829
62905
|
ByteUtils.utf8ByteLength(value.source) +
|
|
62830
62906
|
1 +
|
|
@@ -62834,7 +62910,8 @@ function calculateElement(name, value, serializeFunctions = false, isArray = fal
|
|
|
62834
62910
|
1);
|
|
62835
62911
|
}
|
|
62836
62912
|
else if (value._bsontype === 'BSONRegExp') {
|
|
62837
|
-
return (
|
|
62913
|
+
return (ByteUtils.utf8ByteLength(name) +
|
|
62914
|
+
1 +
|
|
62838
62915
|
1 +
|
|
62839
62916
|
ByteUtils.utf8ByteLength(value.pattern) +
|
|
62840
62917
|
1 +
|
|
@@ -62842,13 +62919,13 @@ function calculateElement(name, value, serializeFunctions = false, isArray = fal
|
|
|
62842
62919
|
1);
|
|
62843
62920
|
}
|
|
62844
62921
|
else {
|
|
62845
|
-
|
|
62846
|
-
|
|
62847
|
-
1);
|
|
62922
|
+
objectStack.push({ obj: value, ignoreUndefined });
|
|
62923
|
+
return ByteUtils.utf8ByteLength(name) + 1 + 1;
|
|
62848
62924
|
}
|
|
62849
62925
|
case 'function':
|
|
62850
62926
|
if (serializeFunctions) {
|
|
62851
|
-
return (
|
|
62927
|
+
return (ByteUtils.utf8ByteLength(name) +
|
|
62928
|
+
1 +
|
|
62852
62929
|
1 +
|
|
62853
62930
|
4 +
|
|
62854
62931
|
ByteUtils.utf8ByteLength(value.toString()) +
|
|
@@ -62856,7 +62933,7 @@ function calculateElement(name, value, serializeFunctions = false, isArray = fal
|
|
|
62856
62933
|
}
|
|
62857
62934
|
return 0;
|
|
62858
62935
|
case 'bigint':
|
|
62859
|
-
return
|
|
62936
|
+
return ByteUtils.utf8ByteLength(name) + 1 + (8 + 1);
|
|
62860
62937
|
case 'symbol':
|
|
62861
62938
|
return 0;
|
|
62862
62939
|
default:
|
|
@@ -63072,7 +63149,28 @@ function internalDeserialize(buffer, options, isArray) {
|
|
|
63072
63149
|
return deserializeObject(buffer, index, options, isArray);
|
|
63073
63150
|
}
|
|
63074
63151
|
const allowedDBRefKeys = /^\$ref$|^\$id$|^\$db$/;
|
|
63152
|
+
function assignValue(dest, name, value) {
|
|
63153
|
+
if (name === '__proto__') {
|
|
63154
|
+
Object.defineProperty(dest, name, {
|
|
63155
|
+
value,
|
|
63156
|
+
writable: true,
|
|
63157
|
+
enumerable: true,
|
|
63158
|
+
configurable: true
|
|
63159
|
+
});
|
|
63160
|
+
}
|
|
63161
|
+
else {
|
|
63162
|
+
dest[name] = value;
|
|
63163
|
+
}
|
|
63164
|
+
}
|
|
63165
|
+
function toPotentialDbRef(doc) {
|
|
63166
|
+
if (isDBRefLike(doc)) {
|
|
63167
|
+
const { $ref, $id, $db, ...fields } = doc;
|
|
63168
|
+
return new DBRef($ref, $id, $db, fields);
|
|
63169
|
+
}
|
|
63170
|
+
return doc;
|
|
63171
|
+
}
|
|
63075
63172
|
function deserializeObject(buffer, index, options, isArray = false) {
|
|
63173
|
+
options = { ...options };
|
|
63076
63174
|
const fieldsAsRaw = options['fieldsAsRaw'] == null ? null : options['fieldsAsRaw'];
|
|
63077
63175
|
const raw = options['raw'] == null ? false : options['raw'];
|
|
63078
63176
|
const bsonRegExp = typeof options['bsonRegExp'] === 'boolean' ? options['bsonRegExp'] : false;
|
|
@@ -63123,31 +63221,87 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
63123
63221
|
index += 4;
|
|
63124
63222
|
if (size < 5 || size > buffer.length)
|
|
63125
63223
|
throw new BSONError('corrupt bson message');
|
|
63126
|
-
const
|
|
63224
|
+
const rootObject = isArray ? [] : {};
|
|
63127
63225
|
let arrayIndex = 0;
|
|
63128
63226
|
let isPossibleDBRef = isArray ? false : null;
|
|
63227
|
+
let currentFrame = null;
|
|
63228
|
+
let currentDest = rootObject;
|
|
63229
|
+
let currentIsArray = isArray;
|
|
63129
63230
|
while (true) {
|
|
63130
63231
|
const elementType = buffer[index++];
|
|
63131
|
-
if (elementType === 0)
|
|
63132
|
-
|
|
63232
|
+
if (elementType === 0) {
|
|
63233
|
+
if (currentFrame) {
|
|
63234
|
+
if (index === currentFrame.lastIndex) {
|
|
63235
|
+
const completedFrame = currentFrame;
|
|
63236
|
+
currentFrame = completedFrame.prev;
|
|
63237
|
+
if (currentFrame === null) {
|
|
63238
|
+
currentDest = rootObject;
|
|
63239
|
+
currentIsArray = isArray;
|
|
63240
|
+
}
|
|
63241
|
+
else {
|
|
63242
|
+
currentDest = currentFrame.holdingDocument;
|
|
63243
|
+
currentIsArray = currentFrame.isArray;
|
|
63244
|
+
}
|
|
63245
|
+
let result = completedFrame.holdingDocument;
|
|
63246
|
+
switch (completedFrame.elementType) {
|
|
63247
|
+
case BSON_DATA_OBJECT:
|
|
63248
|
+
if (completedFrame.isPossibleDBRef) {
|
|
63249
|
+
result = toPotentialDbRef(result);
|
|
63250
|
+
}
|
|
63251
|
+
break;
|
|
63252
|
+
case BSON_DATA_ARRAY:
|
|
63253
|
+
break;
|
|
63254
|
+
case BSON_DATA_CODE_W_SCOPE:
|
|
63255
|
+
result = new Code(completedFrame.functionString, completedFrame.holdingDocument);
|
|
63256
|
+
break;
|
|
63257
|
+
default:
|
|
63258
|
+
throw new BSONError('Unexpected element type in frame stack');
|
|
63259
|
+
}
|
|
63260
|
+
assignValue(currentDest, completedFrame.propertyName, result);
|
|
63261
|
+
continue;
|
|
63262
|
+
}
|
|
63263
|
+
else {
|
|
63264
|
+
if (currentFrame.elementType === BSON_DATA_ARRAY) {
|
|
63265
|
+
throw new BSONError('corrupted array bson');
|
|
63266
|
+
}
|
|
63267
|
+
throw new BSONError('Bad BSON Document: object not properly terminated');
|
|
63268
|
+
}
|
|
63269
|
+
}
|
|
63270
|
+
else {
|
|
63271
|
+
break;
|
|
63272
|
+
}
|
|
63273
|
+
}
|
|
63133
63274
|
let i = index;
|
|
63134
63275
|
while (buffer[i] !== 0x00 && i < buffer.length) {
|
|
63135
63276
|
i++;
|
|
63136
63277
|
}
|
|
63137
63278
|
if (i >= buffer.byteLength)
|
|
63138
63279
|
throw new BSONError('Bad BSON Document: illegal CString');
|
|
63139
|
-
const name =
|
|
63140
|
-
|
|
63141
|
-
|
|
63280
|
+
const name = currentIsArray
|
|
63281
|
+
? currentFrame !== null
|
|
63282
|
+
? currentFrame.arrayIndex++
|
|
63283
|
+
: arrayIndex++
|
|
63284
|
+
: ByteUtils.toUTF8(buffer, index, i, false);
|
|
63285
|
+
let shouldValidateKey;
|
|
63286
|
+
if (currentFrame !== null) {
|
|
63287
|
+
shouldValidateKey = currentFrame.validationSetting;
|
|
63288
|
+
}
|
|
63289
|
+
else if (globalUTFValidation || utf8KeysSet?.has(name)) {
|
|
63142
63290
|
shouldValidateKey = validationSetting;
|
|
63143
63291
|
}
|
|
63144
63292
|
else {
|
|
63145
63293
|
shouldValidateKey = !validationSetting;
|
|
63146
63294
|
}
|
|
63147
|
-
if (
|
|
63295
|
+
if (currentFrame !== null) {
|
|
63296
|
+
if (currentFrame.isPossibleDBRef !== false && typeof name === 'string' && name[0] === '$') {
|
|
63297
|
+
currentFrame.isPossibleDBRef = allowedDBRefKeys.test(name);
|
|
63298
|
+
}
|
|
63299
|
+
}
|
|
63300
|
+
else if (isPossibleDBRef !== false && name[0] === '$') {
|
|
63148
63301
|
isPossibleDBRef = allowedDBRefKeys.test(name);
|
|
63149
63302
|
}
|
|
63150
63303
|
let value;
|
|
63304
|
+
let isDeferredValue = false;
|
|
63151
63305
|
index = i + 1;
|
|
63152
63306
|
if (elementType === BSON_DATA_STRING) {
|
|
63153
63307
|
const stringSize = NumberUtils.getInt32LE(buffer, index);
|
|
@@ -63193,39 +63347,58 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
63193
63347
|
value = buffer[index++] === 1;
|
|
63194
63348
|
}
|
|
63195
63349
|
else if (elementType === BSON_DATA_OBJECT) {
|
|
63196
|
-
const _index = index;
|
|
63197
63350
|
const objectSize = NumberUtils.getInt32LE(buffer, index);
|
|
63198
|
-
if (objectSize
|
|
63351
|
+
if (objectSize < 5 || objectSize > buffer.length - index)
|
|
63199
63352
|
throw new BSONError('bad embedded document length in bson');
|
|
63200
|
-
if (raw) {
|
|
63353
|
+
if (raw || (currentFrame?.raw ?? false)) {
|
|
63201
63354
|
value = buffer.subarray(index, index + objectSize);
|
|
63355
|
+
index = index + objectSize;
|
|
63202
63356
|
}
|
|
63203
63357
|
else {
|
|
63204
|
-
|
|
63205
|
-
|
|
63206
|
-
|
|
63207
|
-
|
|
63208
|
-
|
|
63358
|
+
isDeferredValue = true;
|
|
63359
|
+
const objectFrame = {
|
|
63360
|
+
holdingDocument: {},
|
|
63361
|
+
elementType: BSON_DATA_OBJECT,
|
|
63362
|
+
propertyName: name,
|
|
63363
|
+
functionString: null,
|
|
63364
|
+
lastIndex: index + objectSize,
|
|
63365
|
+
isArray: false,
|
|
63366
|
+
arrayIndex: 0,
|
|
63367
|
+
raw: false,
|
|
63368
|
+
isPossibleDBRef: null,
|
|
63369
|
+
validationSetting: shouldValidateKey,
|
|
63370
|
+
prev: currentFrame
|
|
63371
|
+
};
|
|
63372
|
+
currentFrame = objectFrame;
|
|
63373
|
+
currentDest = objectFrame.holdingDocument;
|
|
63374
|
+
currentIsArray = false;
|
|
63375
|
+
index = index + 4;
|
|
63209
63376
|
}
|
|
63210
|
-
index = index + objectSize;
|
|
63211
63377
|
}
|
|
63212
63378
|
else if (elementType === BSON_DATA_ARRAY) {
|
|
63213
|
-
const _index = index;
|
|
63214
63379
|
const objectSize = NumberUtils.getInt32LE(buffer, index);
|
|
63215
|
-
|
|
63380
|
+
if (objectSize < 5 || objectSize > buffer.length - index)
|
|
63381
|
+
throw new BSONError('bad embedded array length in bson');
|
|
63216
63382
|
const stopIndex = index + objectSize;
|
|
63217
|
-
|
|
63218
|
-
|
|
63219
|
-
|
|
63220
|
-
|
|
63221
|
-
|
|
63222
|
-
|
|
63223
|
-
|
|
63224
|
-
|
|
63225
|
-
|
|
63226
|
-
|
|
63227
|
-
|
|
63228
|
-
|
|
63383
|
+
const arrayRaw = !!(fieldsAsRaw && fieldsAsRaw[name]) || (currentFrame?.raw ?? false);
|
|
63384
|
+
isDeferredValue = true;
|
|
63385
|
+
const arrayFrame = {
|
|
63386
|
+
holdingDocument: [],
|
|
63387
|
+
elementType: BSON_DATA_ARRAY,
|
|
63388
|
+
propertyName: name,
|
|
63389
|
+
functionString: null,
|
|
63390
|
+
lastIndex: stopIndex,
|
|
63391
|
+
isArray: true,
|
|
63392
|
+
arrayIndex: 0,
|
|
63393
|
+
raw: arrayRaw,
|
|
63394
|
+
isPossibleDBRef: false,
|
|
63395
|
+
validationSetting: shouldValidateKey,
|
|
63396
|
+
prev: currentFrame
|
|
63397
|
+
};
|
|
63398
|
+
currentFrame = arrayFrame;
|
|
63399
|
+
currentDest = arrayFrame.holdingDocument;
|
|
63400
|
+
currentIsArray = true;
|
|
63401
|
+
index = index + 4;
|
|
63229
63402
|
}
|
|
63230
63403
|
else if (elementType === BSON_DATA_UNDEFINED) {
|
|
63231
63404
|
value = undefined;
|
|
@@ -63397,15 +63570,32 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
63397
63570
|
index = index + stringSize;
|
|
63398
63571
|
const _index = index;
|
|
63399
63572
|
const objectSize = NumberUtils.getInt32LE(buffer, index);
|
|
63400
|
-
|
|
63401
|
-
|
|
63573
|
+
if (objectSize < 5 || objectSize > buffer.length - index)
|
|
63574
|
+
throw new BSONError('bad scope document size in code_w_scope');
|
|
63402
63575
|
if (totalSize < 4 + 4 + objectSize + stringSize) {
|
|
63403
63576
|
throw new BSONError('code_w_scope total size is too short, truncating scope');
|
|
63404
63577
|
}
|
|
63405
63578
|
if (totalSize > 4 + 4 + objectSize + stringSize) {
|
|
63406
63579
|
throw new BSONError('code_w_scope total size is too long, clips outer document');
|
|
63407
63580
|
}
|
|
63408
|
-
|
|
63581
|
+
isDeferredValue = true;
|
|
63582
|
+
const scopeFrame = {
|
|
63583
|
+
holdingDocument: {},
|
|
63584
|
+
elementType: BSON_DATA_CODE_W_SCOPE,
|
|
63585
|
+
propertyName: name,
|
|
63586
|
+
functionString: functionString,
|
|
63587
|
+
lastIndex: _index + objectSize,
|
|
63588
|
+
isArray: false,
|
|
63589
|
+
arrayIndex: 0,
|
|
63590
|
+
raw: false,
|
|
63591
|
+
isPossibleDBRef: null,
|
|
63592
|
+
validationSetting: shouldValidateKey,
|
|
63593
|
+
prev: currentFrame
|
|
63594
|
+
};
|
|
63595
|
+
currentFrame = scopeFrame;
|
|
63596
|
+
currentDest = scopeFrame.holdingDocument;
|
|
63597
|
+
currentIsArray = false;
|
|
63598
|
+
index = index + 4;
|
|
63409
63599
|
}
|
|
63410
63600
|
else if (elementType === BSON_DATA_DBPOINTER) {
|
|
63411
63601
|
const stringSize = NumberUtils.getInt32LE(buffer, index);
|
|
@@ -63426,18 +63616,14 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
63426
63616
|
else {
|
|
63427
63617
|
throw new BSONError(`Detected unknown BSON type ${elementType.toString(16)} for fieldname "${name}"`);
|
|
63428
63618
|
}
|
|
63429
|
-
if (
|
|
63430
|
-
|
|
63431
|
-
value,
|
|
63432
|
-
writable: true,
|
|
63433
|
-
enumerable: true,
|
|
63434
|
-
configurable: true
|
|
63435
|
-
});
|
|
63436
|
-
}
|
|
63437
|
-
else {
|
|
63438
|
-
object[name] = value;
|
|
63619
|
+
if (!isDeferredValue) {
|
|
63620
|
+
assignValue(currentDest, name, value);
|
|
63439
63621
|
}
|
|
63440
63622
|
}
|
|
63623
|
+
if (currentFrame !== null) {
|
|
63624
|
+
throw new BSONError('corrupted bson, more objects expected based on the current document size');
|
|
63625
|
+
}
|
|
63626
|
+
const object = rootObject;
|
|
63441
63627
|
if (size !== index - startIndex) {
|
|
63442
63628
|
if (isArray)
|
|
63443
63629
|
throw new BSONError('corrupt array bson');
|
|
@@ -63445,14 +63631,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
63445
63631
|
}
|
|
63446
63632
|
if (!isPossibleDBRef)
|
|
63447
63633
|
return object;
|
|
63448
|
-
|
|
63449
|
-
const copy = Object.assign({}, object);
|
|
63450
|
-
delete copy.$ref;
|
|
63451
|
-
delete copy.$id;
|
|
63452
|
-
delete copy.$db;
|
|
63453
|
-
return new DBRef(object.$ref, object.$id, object.$db, copy);
|
|
63454
|
-
}
|
|
63455
|
-
return object;
|
|
63634
|
+
return toPotentialDbRef(object);
|
|
63456
63635
|
}
|
|
63457
63636
|
|
|
63458
63637
|
const regexp = /\x00/;
|
|
@@ -63561,7 +63740,7 @@ function serializeMinMax(buffer, key, value, index) {
|
|
|
63561
63740
|
if (value === null) {
|
|
63562
63741
|
buffer[index++] = BSON_DATA_NULL;
|
|
63563
63742
|
}
|
|
63564
|
-
else if (value
|
|
63743
|
+
else if (value[bsonType] === 'MinKey') {
|
|
63565
63744
|
buffer[index++] = BSON_DATA_MIN_KEY;
|
|
63566
63745
|
}
|
|
63567
63746
|
else {
|
|
@@ -63598,19 +63777,6 @@ function serializeBuffer(buffer, key, value, index) {
|
|
|
63598
63777
|
index = index + size;
|
|
63599
63778
|
return index;
|
|
63600
63779
|
}
|
|
63601
|
-
function serializeObject(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path) {
|
|
63602
|
-
if (path.has(value)) {
|
|
63603
|
-
throw new BSONError('Cannot convert circular structure to BSON');
|
|
63604
|
-
}
|
|
63605
|
-
path.add(value);
|
|
63606
|
-
buffer[index++] = Array.isArray(value) ? BSON_DATA_ARRAY : BSON_DATA_OBJECT;
|
|
63607
|
-
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
|
63608
|
-
index = index + numberOfWrittenBytes;
|
|
63609
|
-
buffer[index++] = 0;
|
|
63610
|
-
const endIndex = serializeInto(buffer, value, checkKeys, index, depth + 1, serializeFunctions, ignoreUndefined, path);
|
|
63611
|
-
path.delete(value);
|
|
63612
|
-
return endIndex;
|
|
63613
|
-
}
|
|
63614
63780
|
function serializeDecimal128(buffer, key, value, index) {
|
|
63615
63781
|
buffer[index++] = BSON_DATA_DECIMAL128;
|
|
63616
63782
|
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
|
@@ -63622,7 +63788,7 @@ function serializeDecimal128(buffer, key, value, index) {
|
|
|
63622
63788
|
}
|
|
63623
63789
|
function serializeLong(buffer, key, value, index) {
|
|
63624
63790
|
buffer[index++] =
|
|
63625
|
-
value
|
|
63791
|
+
value[bsonType] === 'Long' ? BSON_DATA_LONG : BSON_DATA_TIMESTAMP;
|
|
63626
63792
|
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
|
63627
63793
|
index = index + numberOfWrittenBytes;
|
|
63628
63794
|
buffer[index++] = 0;
|
|
@@ -63661,38 +63827,6 @@ function serializeFunction(buffer, key, value, index) {
|
|
|
63661
63827
|
buffer[index++] = 0;
|
|
63662
63828
|
return index;
|
|
63663
63829
|
}
|
|
63664
|
-
function serializeCode(buffer, key, value, index, checkKeys = false, depth = 0, serializeFunctions = false, ignoreUndefined = true, path) {
|
|
63665
|
-
if (value.scope && typeof value.scope === 'object') {
|
|
63666
|
-
buffer[index++] = BSON_DATA_CODE_W_SCOPE;
|
|
63667
|
-
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
|
63668
|
-
index = index + numberOfWrittenBytes;
|
|
63669
|
-
buffer[index++] = 0;
|
|
63670
|
-
let startIndex = index;
|
|
63671
|
-
const functionString = value.code;
|
|
63672
|
-
index = index + 4;
|
|
63673
|
-
const codeSize = ByteUtils.encodeUTF8Into(buffer, functionString, index + 4) + 1;
|
|
63674
|
-
NumberUtils.setInt32LE(buffer, index, codeSize);
|
|
63675
|
-
buffer[index + 4 + codeSize - 1] = 0;
|
|
63676
|
-
index = index + codeSize + 4;
|
|
63677
|
-
const endIndex = serializeInto(buffer, value.scope, checkKeys, index, depth + 1, serializeFunctions, ignoreUndefined, path);
|
|
63678
|
-
index = endIndex - 1;
|
|
63679
|
-
const totalSize = endIndex - startIndex;
|
|
63680
|
-
startIndex += NumberUtils.setInt32LE(buffer, startIndex, totalSize);
|
|
63681
|
-
buffer[index++] = 0;
|
|
63682
|
-
}
|
|
63683
|
-
else {
|
|
63684
|
-
buffer[index++] = BSON_DATA_CODE;
|
|
63685
|
-
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
|
63686
|
-
index = index + numberOfWrittenBytes;
|
|
63687
|
-
buffer[index++] = 0;
|
|
63688
|
-
const functionString = value.code.toString();
|
|
63689
|
-
const size = ByteUtils.encodeUTF8Into(buffer, functionString, index + 4) + 1;
|
|
63690
|
-
NumberUtils.setInt32LE(buffer, index, size);
|
|
63691
|
-
index = index + 4 + size - 1;
|
|
63692
|
-
buffer[index++] = 0;
|
|
63693
|
-
}
|
|
63694
|
-
return index;
|
|
63695
|
-
}
|
|
63696
63830
|
function serializeBinary(buffer, key, value, index) {
|
|
63697
63831
|
buffer[index++] = BSON_DATA_BINARY;
|
|
63698
63832
|
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
|
@@ -63732,26 +63866,59 @@ function serializeSymbol(buffer, key, value, index) {
|
|
|
63732
63866
|
buffer[index++] = 0;
|
|
63733
63867
|
return index;
|
|
63734
63868
|
}
|
|
63735
|
-
function
|
|
63736
|
-
|
|
63737
|
-
|
|
63738
|
-
|
|
63739
|
-
|
|
63740
|
-
|
|
63741
|
-
|
|
63742
|
-
|
|
63743
|
-
|
|
63744
|
-
|
|
63745
|
-
|
|
63746
|
-
|
|
63869
|
+
function makeFrame(sourceObject, objectSizeIndex, codeSizeIndex, prev, checkKeys, ignoreUndefined) {
|
|
63870
|
+
if (Array.isArray(sourceObject)) {
|
|
63871
|
+
return {
|
|
63872
|
+
sourceObject,
|
|
63873
|
+
isArray: true,
|
|
63874
|
+
objectSizeIndex,
|
|
63875
|
+
codeSizeIndex,
|
|
63876
|
+
iterTarget: sourceObject,
|
|
63877
|
+
keys: null,
|
|
63878
|
+
keyIndex: 0,
|
|
63879
|
+
mapIterator: null,
|
|
63880
|
+
prev,
|
|
63881
|
+
checkKeys,
|
|
63882
|
+
ignoreUndefined
|
|
63883
|
+
};
|
|
63747
63884
|
}
|
|
63748
|
-
|
|
63749
|
-
|
|
63750
|
-
|
|
63751
|
-
|
|
63752
|
-
|
|
63753
|
-
|
|
63754
|
-
|
|
63885
|
+
if (sourceObject instanceof Map || isMap(sourceObject)) {
|
|
63886
|
+
return {
|
|
63887
|
+
sourceObject,
|
|
63888
|
+
isArray: false,
|
|
63889
|
+
objectSizeIndex,
|
|
63890
|
+
codeSizeIndex,
|
|
63891
|
+
iterTarget: sourceObject,
|
|
63892
|
+
keys: null,
|
|
63893
|
+
keyIndex: 0,
|
|
63894
|
+
mapIterator: sourceObject.entries(),
|
|
63895
|
+
prev,
|
|
63896
|
+
checkKeys,
|
|
63897
|
+
ignoreUndefined
|
|
63898
|
+
};
|
|
63899
|
+
}
|
|
63900
|
+
let target = sourceObject;
|
|
63901
|
+
if (typeof target?.toBSON === 'function') {
|
|
63902
|
+
target = target.toBSON();
|
|
63903
|
+
if (target != null && typeof target !== 'object') {
|
|
63904
|
+
throw new BSONError('toBSON function did not return an object');
|
|
63905
|
+
}
|
|
63906
|
+
}
|
|
63907
|
+
return {
|
|
63908
|
+
sourceObject,
|
|
63909
|
+
isArray: false,
|
|
63910
|
+
objectSizeIndex,
|
|
63911
|
+
codeSizeIndex,
|
|
63912
|
+
iterTarget: target,
|
|
63913
|
+
keys: Object.keys(target),
|
|
63914
|
+
keyIndex: 0,
|
|
63915
|
+
mapIterator: null,
|
|
63916
|
+
prev,
|
|
63917
|
+
checkKeys,
|
|
63918
|
+
ignoreUndefined
|
|
63919
|
+
};
|
|
63920
|
+
}
|
|
63921
|
+
function serializeInto(buffer, object, checkKeys, startingIndex, serializeFunctions, ignoreUndefined, path) {
|
|
63755
63922
|
if (path == null) {
|
|
63756
63923
|
if (object == null) {
|
|
63757
63924
|
buffer[0] = 0x05;
|
|
@@ -63779,308 +63946,200 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
63779
63946
|
path = new Set();
|
|
63780
63947
|
}
|
|
63781
63948
|
path.add(object);
|
|
63949
|
+
let currentFrame = makeFrame(object, startingIndex, null, null, checkKeys, ignoreUndefined);
|
|
63782
63950
|
let index = startingIndex + 4;
|
|
63783
|
-
|
|
63784
|
-
|
|
63785
|
-
|
|
63786
|
-
|
|
63787
|
-
|
|
63788
|
-
|
|
63789
|
-
|
|
63790
|
-
|
|
63791
|
-
|
|
63792
|
-
|
|
63793
|
-
|
|
63794
|
-
else if (value === null) {
|
|
63795
|
-
index = serializeNull(buffer, key, value, index);
|
|
63796
|
-
}
|
|
63797
|
-
else if (type === 'string') {
|
|
63798
|
-
index = serializeString(buffer, key, value, index);
|
|
63799
|
-
}
|
|
63800
|
-
else if (type === 'number') {
|
|
63801
|
-
index = serializeNumber(buffer, key, value, index);
|
|
63802
|
-
}
|
|
63803
|
-
else if (type === 'bigint') {
|
|
63804
|
-
index = serializeBigInt(buffer, key, value, index);
|
|
63805
|
-
}
|
|
63806
|
-
else if (type === 'boolean') {
|
|
63807
|
-
index = serializeBoolean(buffer, key, value, index);
|
|
63808
|
-
}
|
|
63809
|
-
else if (type === 'object' && value._bsontype == null) {
|
|
63810
|
-
if (value instanceof Date || isDate(value)) {
|
|
63811
|
-
index = serializeDate(buffer, key, value, index);
|
|
63812
|
-
}
|
|
63813
|
-
else if (value instanceof Uint8Array || isUint8Array(value)) {
|
|
63814
|
-
index = serializeBuffer(buffer, key, value, index);
|
|
63815
|
-
}
|
|
63816
|
-
else if (value instanceof RegExp || isRegExp(value)) {
|
|
63817
|
-
index = serializeRegExp(buffer, key, value, index);
|
|
63818
|
-
}
|
|
63819
|
-
else {
|
|
63820
|
-
index = serializeObject(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
63951
|
+
while (currentFrame !== null) {
|
|
63952
|
+
const frame = currentFrame;
|
|
63953
|
+
let key;
|
|
63954
|
+
let value;
|
|
63955
|
+
if (frame.mapIterator !== null) {
|
|
63956
|
+
const next = frame.mapIterator.next();
|
|
63957
|
+
if (next.done) {
|
|
63958
|
+
buffer[index++] = 0x00;
|
|
63959
|
+
NumberUtils.setInt32LE(buffer, frame.objectSizeIndex, index - frame.objectSizeIndex);
|
|
63960
|
+
if (frame.codeSizeIndex !== null) {
|
|
63961
|
+
NumberUtils.setInt32LE(buffer, frame.codeSizeIndex, index - frame.codeSizeIndex);
|
|
63821
63962
|
}
|
|
63963
|
+
path.delete(frame.sourceObject);
|
|
63964
|
+
currentFrame = frame.prev;
|
|
63965
|
+
continue;
|
|
63822
63966
|
}
|
|
63823
|
-
|
|
63824
|
-
|
|
63825
|
-
|
|
63826
|
-
|
|
63827
|
-
|
|
63828
|
-
|
|
63829
|
-
|
|
63830
|
-
|
|
63831
|
-
|
|
63832
|
-
}
|
|
63833
|
-
else if (value._bsontype === 'Long' || value._bsontype === 'Timestamp') {
|
|
63834
|
-
index = serializeLong(buffer, key, value, index);
|
|
63835
|
-
}
|
|
63836
|
-
else if (value._bsontype === 'Double') {
|
|
63837
|
-
index = serializeDouble(buffer, key, value, index);
|
|
63838
|
-
}
|
|
63839
|
-
else if (value._bsontype === 'Code') {
|
|
63840
|
-
index = serializeCode(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
63841
|
-
}
|
|
63842
|
-
else if (value._bsontype === 'Binary') {
|
|
63843
|
-
index = serializeBinary(buffer, key, value, index);
|
|
63844
|
-
}
|
|
63845
|
-
else if (value._bsontype === 'BSONSymbol') {
|
|
63846
|
-
index = serializeSymbol(buffer, key, value, index);
|
|
63847
|
-
}
|
|
63848
|
-
else if (value._bsontype === 'DBRef') {
|
|
63849
|
-
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
63850
|
-
}
|
|
63851
|
-
else if (value._bsontype === 'BSONRegExp') {
|
|
63852
|
-
index = serializeBSONRegExp(buffer, key, value, index);
|
|
63853
|
-
}
|
|
63854
|
-
else if (value._bsontype === 'Int32') {
|
|
63855
|
-
index = serializeInt32(buffer, key, value, index);
|
|
63856
|
-
}
|
|
63857
|
-
else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
63858
|
-
index = serializeMinMax(buffer, key, value, index);
|
|
63859
|
-
}
|
|
63860
|
-
else if (typeof value._bsontype !== 'undefined') {
|
|
63861
|
-
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
63967
|
+
key = next.value[0];
|
|
63968
|
+
value = next.value[1];
|
|
63969
|
+
}
|
|
63970
|
+
else if (frame.keys !== null) {
|
|
63971
|
+
if (frame.keyIndex >= frame.keys.length) {
|
|
63972
|
+
buffer[index++] = 0x00;
|
|
63973
|
+
NumberUtils.setInt32LE(buffer, frame.objectSizeIndex, index - frame.objectSizeIndex);
|
|
63974
|
+
if (frame.codeSizeIndex !== null) {
|
|
63975
|
+
NumberUtils.setInt32LE(buffer, frame.codeSizeIndex, index - frame.codeSizeIndex);
|
|
63862
63976
|
}
|
|
63977
|
+
path.delete(frame.sourceObject);
|
|
63978
|
+
currentFrame = frame.prev;
|
|
63979
|
+
continue;
|
|
63863
63980
|
}
|
|
63864
|
-
|
|
63865
|
-
|
|
63866
|
-
}
|
|
63981
|
+
key = frame.keys[frame.keyIndex++];
|
|
63982
|
+
value = frame.iterTarget[key];
|
|
63867
63983
|
}
|
|
63868
|
-
|
|
63869
|
-
|
|
63870
|
-
|
|
63871
|
-
|
|
63872
|
-
|
|
63873
|
-
|
|
63874
|
-
|
|
63875
|
-
|
|
63984
|
+
else {
|
|
63985
|
+
const arr = frame.iterTarget;
|
|
63986
|
+
if (frame.keyIndex >= arr.length) {
|
|
63987
|
+
buffer[index++] = 0x00;
|
|
63988
|
+
NumberUtils.setInt32LE(buffer, frame.objectSizeIndex, index - frame.objectSizeIndex);
|
|
63989
|
+
if (frame.codeSizeIndex !== null) {
|
|
63990
|
+
NumberUtils.setInt32LE(buffer, frame.codeSizeIndex, index - frame.codeSizeIndex);
|
|
63991
|
+
}
|
|
63992
|
+
path.delete(frame.sourceObject);
|
|
63993
|
+
currentFrame = frame.prev;
|
|
63876
63994
|
continue;
|
|
63877
|
-
|
|
63878
|
-
|
|
63879
|
-
|
|
63880
|
-
|
|
63881
|
-
|
|
63882
|
-
|
|
63883
|
-
|
|
63884
|
-
|
|
63885
|
-
|
|
63995
|
+
}
|
|
63996
|
+
const i = frame.keyIndex++;
|
|
63997
|
+
key = String(i);
|
|
63998
|
+
value = arr[i];
|
|
63999
|
+
}
|
|
64000
|
+
if (typeof value?.toBSON === 'function') {
|
|
64001
|
+
value = value.toBSON();
|
|
64002
|
+
}
|
|
64003
|
+
if (!frame.isArray && typeof key === 'string' && !(key[0] === '$' && ignoreKeys.has(key))) {
|
|
64004
|
+
if (regexp.test(key)) {
|
|
64005
|
+
throw new BSONError('key ' + key + ' must not contain null bytes');
|
|
64006
|
+
}
|
|
64007
|
+
if (frame.checkKeys) {
|
|
64008
|
+
if ('$' === key[0]) {
|
|
64009
|
+
throw new BSONError('key ' + key + " must not start with '$'");
|
|
63886
64010
|
}
|
|
63887
|
-
if (
|
|
63888
|
-
|
|
63889
|
-
throw new BSONError('key ' + key + " must not start with '$'");
|
|
63890
|
-
}
|
|
63891
|
-
else if (key.includes('.')) {
|
|
63892
|
-
throw new BSONError('key ' + key + " must not contain '.'");
|
|
63893
|
-
}
|
|
64011
|
+
else if (key.includes('.')) {
|
|
64012
|
+
throw new BSONError('key ' + key + " must not contain '.'");
|
|
63894
64013
|
}
|
|
63895
64014
|
}
|
|
63896
|
-
|
|
63897
|
-
|
|
63898
|
-
|
|
63899
|
-
|
|
63900
|
-
else if (value === null) {
|
|
64015
|
+
}
|
|
64016
|
+
const type = typeof value;
|
|
64017
|
+
if (value === undefined) {
|
|
64018
|
+
if (frame.isArray || frame.ignoreUndefined === false) {
|
|
63901
64019
|
index = serializeNull(buffer, key, value, index);
|
|
63902
64020
|
}
|
|
63903
|
-
|
|
63904
|
-
|
|
63905
|
-
|
|
63906
|
-
|
|
63907
|
-
|
|
63908
|
-
|
|
63909
|
-
|
|
63910
|
-
|
|
64021
|
+
}
|
|
64022
|
+
else if (value === null) {
|
|
64023
|
+
index = serializeNull(buffer, key, value, index);
|
|
64024
|
+
}
|
|
64025
|
+
else if (type === 'string') {
|
|
64026
|
+
index = serializeString(buffer, key, value, index);
|
|
64027
|
+
}
|
|
64028
|
+
else if (type === 'number') {
|
|
64029
|
+
index = serializeNumber(buffer, key, value, index);
|
|
64030
|
+
}
|
|
64031
|
+
else if (type === 'bigint') {
|
|
64032
|
+
index = serializeBigInt(buffer, key, value, index);
|
|
64033
|
+
}
|
|
64034
|
+
else if (type === 'boolean') {
|
|
64035
|
+
index = serializeBoolean(buffer, key, value, index);
|
|
64036
|
+
}
|
|
64037
|
+
else if (type === 'object' && value._bsontype == null) {
|
|
64038
|
+
if (value instanceof Date || isDate(value)) {
|
|
64039
|
+
index = serializeDate(buffer, key, value, index);
|
|
63911
64040
|
}
|
|
63912
|
-
else if (
|
|
63913
|
-
index =
|
|
64041
|
+
else if (value instanceof Uint8Array || isUint8Array(value)) {
|
|
64042
|
+
index = serializeBuffer(buffer, key, value, index);
|
|
63914
64043
|
}
|
|
63915
|
-
else if (
|
|
63916
|
-
|
|
63917
|
-
index = serializeDate(buffer, key, value, index);
|
|
63918
|
-
}
|
|
63919
|
-
else if (value instanceof Uint8Array || isUint8Array(value)) {
|
|
63920
|
-
index = serializeBuffer(buffer, key, value, index);
|
|
63921
|
-
}
|
|
63922
|
-
else if (value instanceof RegExp || isRegExp(value)) {
|
|
63923
|
-
index = serializeRegExp(buffer, key, value, index);
|
|
63924
|
-
}
|
|
63925
|
-
else {
|
|
63926
|
-
index = serializeObject(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
63927
|
-
}
|
|
64044
|
+
else if (value instanceof RegExp || isRegExp(value)) {
|
|
64045
|
+
index = serializeRegExp(buffer, key, value, index);
|
|
63928
64046
|
}
|
|
63929
|
-
else
|
|
63930
|
-
if (value
|
|
63931
|
-
throw new
|
|
63932
|
-
}
|
|
63933
|
-
else if (value._bsontype === 'ObjectId') {
|
|
63934
|
-
index = serializeObjectId(buffer, key, value, index);
|
|
63935
|
-
}
|
|
63936
|
-
else if (value._bsontype === 'Decimal128') {
|
|
63937
|
-
index = serializeDecimal128(buffer, key, value, index);
|
|
63938
|
-
}
|
|
63939
|
-
else if (value._bsontype === 'Long' || value._bsontype === 'Timestamp') {
|
|
63940
|
-
index = serializeLong(buffer, key, value, index);
|
|
63941
|
-
}
|
|
63942
|
-
else if (value._bsontype === 'Double') {
|
|
63943
|
-
index = serializeDouble(buffer, key, value, index);
|
|
63944
|
-
}
|
|
63945
|
-
else if (value._bsontype === 'Code') {
|
|
63946
|
-
index = serializeCode(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
63947
|
-
}
|
|
63948
|
-
else if (value._bsontype === 'Binary') {
|
|
63949
|
-
index = serializeBinary(buffer, key, value, index);
|
|
63950
|
-
}
|
|
63951
|
-
else if (value._bsontype === 'BSONSymbol') {
|
|
63952
|
-
index = serializeSymbol(buffer, key, value, index);
|
|
63953
|
-
}
|
|
63954
|
-
else if (value._bsontype === 'DBRef') {
|
|
63955
|
-
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
63956
|
-
}
|
|
63957
|
-
else if (value._bsontype === 'BSONRegExp') {
|
|
63958
|
-
index = serializeBSONRegExp(buffer, key, value, index);
|
|
63959
|
-
}
|
|
63960
|
-
else if (value._bsontype === 'Int32') {
|
|
63961
|
-
index = serializeInt32(buffer, key, value, index);
|
|
63962
|
-
}
|
|
63963
|
-
else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
63964
|
-
index = serializeMinMax(buffer, key, value, index);
|
|
63965
|
-
}
|
|
63966
|
-
else if (typeof value._bsontype !== 'undefined') {
|
|
63967
|
-
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
64047
|
+
else {
|
|
64048
|
+
if (path.has(value)) {
|
|
64049
|
+
throw new BSONError('Cannot convert circular structure to BSON');
|
|
63968
64050
|
}
|
|
63969
|
-
|
|
63970
|
-
|
|
63971
|
-
index
|
|
63972
|
-
|
|
63973
|
-
|
|
63974
|
-
|
|
63975
|
-
|
|
63976
|
-
|
|
63977
|
-
object = object.toBSON();
|
|
63978
|
-
if (object != null && typeof object !== 'object') {
|
|
63979
|
-
throw new BSONError('toBSON function did not return an object');
|
|
64051
|
+
const nestedIsArray = Array.isArray(value);
|
|
64052
|
+
buffer[index++] = nestedIsArray ? BSON_DATA_ARRAY : BSON_DATA_OBJECT;
|
|
64053
|
+
index += ByteUtils.encodeUTF8Into(buffer, key, index);
|
|
64054
|
+
buffer[index++] = 0x00;
|
|
64055
|
+
const nestedStartIndex = index;
|
|
64056
|
+
path.add(value);
|
|
64057
|
+
currentFrame = makeFrame(value, nestedStartIndex, null, frame, frame.checkKeys, frame.ignoreUndefined);
|
|
64058
|
+
index += 4;
|
|
63980
64059
|
}
|
|
63981
64060
|
}
|
|
63982
|
-
|
|
63983
|
-
|
|
63984
|
-
|
|
63985
|
-
value = value.toBSON();
|
|
64061
|
+
else if (type === 'object') {
|
|
64062
|
+
if (value[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION) {
|
|
64063
|
+
throw new BSONVersionError();
|
|
63986
64064
|
}
|
|
63987
|
-
const
|
|
63988
|
-
if (
|
|
63989
|
-
|
|
63990
|
-
|
|
63991
|
-
|
|
63992
|
-
|
|
63993
|
-
|
|
63994
|
-
|
|
63995
|
-
|
|
63996
|
-
|
|
63997
|
-
|
|
64065
|
+
const tag = value[bsonType];
|
|
64066
|
+
if (tag === 'ObjectId') {
|
|
64067
|
+
index = serializeObjectId(buffer, key, value, index);
|
|
64068
|
+
}
|
|
64069
|
+
else if (tag === 'Decimal128') {
|
|
64070
|
+
index = serializeDecimal128(buffer, key, value, index);
|
|
64071
|
+
}
|
|
64072
|
+
else if (tag === 'Long' || tag === 'Timestamp') {
|
|
64073
|
+
index = serializeLong(buffer, key, value, index);
|
|
64074
|
+
}
|
|
64075
|
+
else if (tag === 'Double') {
|
|
64076
|
+
index = serializeDouble(buffer, key, value, index);
|
|
64077
|
+
}
|
|
64078
|
+
else if (tag === 'Code') {
|
|
64079
|
+
const codeValue = value;
|
|
64080
|
+
if (codeValue.scope && typeof codeValue.scope === 'object') {
|
|
64081
|
+
buffer[index++] = BSON_DATA_CODE_W_SCOPE;
|
|
64082
|
+
index += ByteUtils.encodeUTF8Into(buffer, key, index);
|
|
64083
|
+
buffer[index++] = 0x00;
|
|
64084
|
+
const codeTotalSizeIndex = index;
|
|
64085
|
+
index += 4;
|
|
64086
|
+
const functionString = codeValue.code;
|
|
64087
|
+
const codeSize = ByteUtils.encodeUTF8Into(buffer, functionString, index + 4) + 1;
|
|
64088
|
+
NumberUtils.setInt32LE(buffer, index, codeSize);
|
|
64089
|
+
buffer[index + 4 + codeSize - 1] = 0;
|
|
64090
|
+
index = index + codeSize + 4;
|
|
64091
|
+
const scope = codeValue.scope;
|
|
64092
|
+
if (path.has(scope)) {
|
|
64093
|
+
throw new BSONError('Cannot convert circular structure to BSON');
|
|
63998
64094
|
}
|
|
64095
|
+
path.add(scope);
|
|
64096
|
+
currentFrame = makeFrame(scope, index, codeTotalSizeIndex, frame, frame.checkKeys, frame.ignoreUndefined);
|
|
64097
|
+
index += 4;
|
|
64098
|
+
}
|
|
64099
|
+
else {
|
|
64100
|
+
buffer[index++] = BSON_DATA_CODE;
|
|
64101
|
+
index += ByteUtils.encodeUTF8Into(buffer, key, index);
|
|
64102
|
+
buffer[index++] = 0x00;
|
|
64103
|
+
const functionString = codeValue.code.toString();
|
|
64104
|
+
const size = ByteUtils.encodeUTF8Into(buffer, functionString, index + 4) + 1;
|
|
64105
|
+
NumberUtils.setInt32LE(buffer, index, size);
|
|
64106
|
+
index = index + 4 + size - 1;
|
|
64107
|
+
buffer[index++] = 0;
|
|
63999
64108
|
}
|
|
64000
64109
|
}
|
|
64001
|
-
if (
|
|
64002
|
-
|
|
64003
|
-
index = serializeNull(buffer, key, value, index);
|
|
64110
|
+
else if (tag === 'Binary') {
|
|
64111
|
+
index = serializeBinary(buffer, key, value, index);
|
|
64004
64112
|
}
|
|
64005
|
-
else if (
|
|
64006
|
-
index =
|
|
64113
|
+
else if (tag === 'BSONSymbol') {
|
|
64114
|
+
index = serializeSymbol(buffer, key, value, index);
|
|
64007
64115
|
}
|
|
64008
|
-
else if (
|
|
64009
|
-
|
|
64116
|
+
else if (tag === 'DBRef') {
|
|
64117
|
+
const dbref = value;
|
|
64118
|
+
const orderedValues = Object.assign({ $ref: dbref.collection, $id: dbref.oid }, dbref.db != null ? { $db: dbref.db } : null, dbref.fields);
|
|
64119
|
+
buffer[index++] = BSON_DATA_OBJECT;
|
|
64120
|
+
index += ByteUtils.encodeUTF8Into(buffer, key, index);
|
|
64121
|
+
buffer[index++] = 0x00;
|
|
64122
|
+
path.add(orderedValues);
|
|
64123
|
+
currentFrame = makeFrame(orderedValues, index, null, frame, false, true);
|
|
64124
|
+
index += 4;
|
|
64010
64125
|
}
|
|
64011
|
-
else if (
|
|
64012
|
-
index =
|
|
64126
|
+
else if (tag === 'BSONRegExp') {
|
|
64127
|
+
index = serializeBSONRegExp(buffer, key, value, index);
|
|
64013
64128
|
}
|
|
64014
|
-
else if (
|
|
64015
|
-
index =
|
|
64129
|
+
else if (tag === 'Int32') {
|
|
64130
|
+
index = serializeInt32(buffer, key, value, index);
|
|
64016
64131
|
}
|
|
64017
|
-
else if (
|
|
64018
|
-
index =
|
|
64132
|
+
else if (tag === 'MinKey' || tag === 'MaxKey') {
|
|
64133
|
+
index = serializeMinMax(buffer, key, value, index);
|
|
64019
64134
|
}
|
|
64020
|
-
else if (
|
|
64021
|
-
|
|
64022
|
-
index = serializeDate(buffer, key, value, index);
|
|
64023
|
-
}
|
|
64024
|
-
else if (value instanceof Uint8Array || isUint8Array(value)) {
|
|
64025
|
-
index = serializeBuffer(buffer, key, value, index);
|
|
64026
|
-
}
|
|
64027
|
-
else if (value instanceof RegExp || isRegExp(value)) {
|
|
64028
|
-
index = serializeRegExp(buffer, key, value, index);
|
|
64029
|
-
}
|
|
64030
|
-
else {
|
|
64031
|
-
index = serializeObject(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
64032
|
-
}
|
|
64033
|
-
}
|
|
64034
|
-
else if (type === 'object') {
|
|
64035
|
-
if (value[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION) {
|
|
64036
|
-
throw new BSONVersionError();
|
|
64037
|
-
}
|
|
64038
|
-
else if (value._bsontype === 'ObjectId') {
|
|
64039
|
-
index = serializeObjectId(buffer, key, value, index);
|
|
64040
|
-
}
|
|
64041
|
-
else if (value._bsontype === 'Decimal128') {
|
|
64042
|
-
index = serializeDecimal128(buffer, key, value, index);
|
|
64043
|
-
}
|
|
64044
|
-
else if (value._bsontype === 'Long' || value._bsontype === 'Timestamp') {
|
|
64045
|
-
index = serializeLong(buffer, key, value, index);
|
|
64046
|
-
}
|
|
64047
|
-
else if (value._bsontype === 'Double') {
|
|
64048
|
-
index = serializeDouble(buffer, key, value, index);
|
|
64049
|
-
}
|
|
64050
|
-
else if (value._bsontype === 'Code') {
|
|
64051
|
-
index = serializeCode(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
64052
|
-
}
|
|
64053
|
-
else if (value._bsontype === 'Binary') {
|
|
64054
|
-
index = serializeBinary(buffer, key, value, index);
|
|
64055
|
-
}
|
|
64056
|
-
else if (value._bsontype === 'BSONSymbol') {
|
|
64057
|
-
index = serializeSymbol(buffer, key, value, index);
|
|
64058
|
-
}
|
|
64059
|
-
else if (value._bsontype === 'DBRef') {
|
|
64060
|
-
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
64061
|
-
}
|
|
64062
|
-
else if (value._bsontype === 'BSONRegExp') {
|
|
64063
|
-
index = serializeBSONRegExp(buffer, key, value, index);
|
|
64064
|
-
}
|
|
64065
|
-
else if (value._bsontype === 'Int32') {
|
|
64066
|
-
index = serializeInt32(buffer, key, value, index);
|
|
64067
|
-
}
|
|
64068
|
-
else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
64069
|
-
index = serializeMinMax(buffer, key, value, index);
|
|
64070
|
-
}
|
|
64071
|
-
else if (typeof value._bsontype !== 'undefined') {
|
|
64072
|
-
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
64073
|
-
}
|
|
64074
|
-
}
|
|
64075
|
-
else if (type === 'function' && serializeFunctions) {
|
|
64076
|
-
index = serializeFunction(buffer, key, value, index);
|
|
64135
|
+
else if (typeof value._bsontype !== 'undefined') {
|
|
64136
|
+
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
64077
64137
|
}
|
|
64078
64138
|
}
|
|
64139
|
+
else if (type === 'function' && serializeFunctions) {
|
|
64140
|
+
index = serializeFunction(buffer, key, value, index);
|
|
64141
|
+
}
|
|
64079
64142
|
}
|
|
64080
|
-
path.delete(object);
|
|
64081
|
-
buffer[index++] = 0x00;
|
|
64082
|
-
const size = index - startingIndex;
|
|
64083
|
-
startingIndex += NumberUtils.setInt32LE(buffer, startingIndex, size);
|
|
64084
64143
|
return index;
|
|
64085
64144
|
}
|
|
64086
64145
|
|
|
@@ -64363,21 +64422,22 @@ function parse(text, options) {
|
|
|
64363
64422
|
return deserializeValue(value, ejsonOptions);
|
|
64364
64423
|
});
|
|
64365
64424
|
}
|
|
64366
|
-
function stringify(value,
|
|
64367
|
-
if (
|
|
64368
|
-
options =
|
|
64369
|
-
|
|
64425
|
+
function stringify(value, replacerOrOptions, spaceOrOptions, options) {
|
|
64426
|
+
if (spaceOrOptions != null && typeof spaceOrOptions === 'object') {
|
|
64427
|
+
options = spaceOrOptions;
|
|
64428
|
+
spaceOrOptions = undefined;
|
|
64370
64429
|
}
|
|
64371
|
-
if (
|
|
64372
|
-
|
|
64373
|
-
|
|
64374
|
-
|
|
64430
|
+
if (replacerOrOptions != null &&
|
|
64431
|
+
typeof replacerOrOptions === 'object' &&
|
|
64432
|
+
!Array.isArray(replacerOrOptions)) {
|
|
64433
|
+
options = replacerOrOptions;
|
|
64434
|
+
replacerOrOptions = undefined;
|
|
64375
64435
|
}
|
|
64376
64436
|
const serializeOptions = Object.assign({ relaxed: true, legacy: false }, options, {
|
|
64377
64437
|
seenObjects: [{ propertyName: '(root)', obj: null }]
|
|
64378
64438
|
});
|
|
64379
64439
|
const doc = serializeValue(value, serializeOptions);
|
|
64380
|
-
return JSON.stringify(doc,
|
|
64440
|
+
return JSON.stringify(doc, replacerOrOptions, spaceOrOptions);
|
|
64381
64441
|
}
|
|
64382
64442
|
function EJSONserialize(value, options) {
|
|
64383
64443
|
options = options || {};
|
|
@@ -64539,7 +64599,7 @@ function serialize(object, options = {}) {
|
|
|
64539
64599
|
if (buffer.length < minInternalBufferSize) {
|
|
64540
64600
|
buffer = ByteUtils.allocate(minInternalBufferSize);
|
|
64541
64601
|
}
|
|
64542
|
-
const serializationIndex = serializeInto(buffer, object, checkKeys, 0,
|
|
64602
|
+
const serializationIndex = serializeInto(buffer, object, checkKeys, 0, serializeFunctions, ignoreUndefined, null);
|
|
64543
64603
|
const finishedBuffer = ByteUtils.allocateUnsafe(serializationIndex);
|
|
64544
64604
|
finishedBuffer.set(buffer.subarray(0, serializationIndex), 0);
|
|
64545
64605
|
return finishedBuffer;
|
|
@@ -64549,7 +64609,7 @@ function serializeWithBufferAndIndex(object, finalBuffer, options = {}) {
|
|
|
64549
64609
|
const serializeFunctions = typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false;
|
|
64550
64610
|
const ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
|
|
64551
64611
|
const startIndex = typeof options.index === 'number' ? options.index : 0;
|
|
64552
|
-
const serializationIndex = serializeInto(buffer, object, checkKeys, 0,
|
|
64612
|
+
const serializationIndex = serializeInto(buffer, object, checkKeys, 0, serializeFunctions, ignoreUndefined, null);
|
|
64553
64613
|
finalBuffer.set(buffer.subarray(0, serializationIndex), startIndex);
|
|
64554
64614
|
return startIndex + serializationIndex - 1;
|
|
64555
64615
|
}
|
|
@@ -65725,7 +65785,7 @@ var src_default = VueToastificationPlugin;
|
|
|
65725
65785
|
(module) {
|
|
65726
65786
|
|
|
65727
65787
|
"use strict";
|
|
65728
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"@mongoosejs/studio","version":"0.5.
|
|
65788
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@mongoosejs/studio","version":"0.5.10","description":"AI-Powered Data Workspace for MongoDB: Turn your MongoDB data into dashboards, maps, and interactive workflows - powered by your Mongoose models and AI.","homepage":"https://mongoosestudio.app/","repository":{"type":"git","url":"https://github.com/mongoosejs/studio"},"license":"Apache-2.0","dependencies":{"@ai-sdk/anthropic":"2.x","@ai-sdk/google":"2.x","@ai-sdk/openai":"2.x","ace-builds":"^1.43.6","ai":"5.x","archetype":"0.13.1","csv-stringify":"6.3.0","ejson":"^2.2.3","extrovert":"^0.2.0","marked":"15.0.12","mpath":"^0.9.0","node-inspect-extracted":"3.x","regexp.escape":"^2.0.1","tailwindcss":"3.4.0","time-commando":"1.0.1","typescript":"^6.0.2","vue":"3.x","vue-toastification":"^2.0.0-rc.5","webpack":"5.x","xss":"^1.0.15"},"peerDependencies":{"@nestjs/common":"10.x || 11.x","mongoose":"7.x || 8.x || ^9.0.0"},"peerDependenciesMeta":{"@nestjs/common":{"optional":true}},"optionalPeerDependencies":{"@mongoosejs/task":"0.5.x || 0.6.x"},"devDependencies":{"@masteringjs/eslint-config":"0.1.1","axios":"1.2.2","dedent":"^1.6.0","eslint":"9.30.0","@nestjs/common":"^11.1.9","express":"4.x","mocha":"10.2.0","mongodb-memory-server":"^11.0.1","mongoose":"9.x","sinon":"^21.0.1"},"scripts":{"lint":"eslint .","seed":"node seed/index.js","start":"node ./local.js","tailwind":"tailwindcss -o ./frontend/public/tw.css","tailwind:watch":"tailwindcss -o ./frontend/public/tw.css --watch","test":"mocha test/*.test.js","test:frontend":"mocha test/frontend/*.test.js","eval:agent":"node eval/agent/run.js"}}');
|
|
65729
65789
|
|
|
65730
65790
|
/***/ }
|
|
65731
65791
|
|