mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-01-18 21:17:59 +00:00
Show BSON types correctly
This commit is contained in:
parent
b58a2ca84f
commit
ae811bc0d5
102
frontend/package-lock.json
generated
102
frontend/package-lock.json
generated
@ -7,6 +7,9 @@
|
|||||||
"": {
|
"": {
|
||||||
"name": "frontend",
|
"name": "frontend",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
|
"dependencies": {
|
||||||
|
"bson": "^4.7.2"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/vite-plugin-svelte": "^1.0.1",
|
"@sveltejs/vite-plugin-svelte": "^1.0.1",
|
||||||
"eslint": "^8.31.0",
|
"eslint": "^8.31.0",
|
||||||
@ -409,6 +412,25 @@
|
|||||||
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
|
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/base64-js": {
|
||||||
|
"version": "1.5.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
|
||||||
|
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "patreon",
|
||||||
|
"url": "https://www.patreon.com/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "consulting",
|
||||||
|
"url": "https://feross.org/support"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"node_modules/brace-expansion": {
|
"node_modules/brace-expansion": {
|
||||||
"version": "1.1.11",
|
"version": "1.1.11",
|
||||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||||
@ -419,6 +441,40 @@
|
|||||||
"concat-map": "0.0.1"
|
"concat-map": "0.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/bson": {
|
||||||
|
"version": "4.7.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/bson/-/bson-4.7.2.tgz",
|
||||||
|
"integrity": "sha512-Ry9wCtIZ5kGqkJoi6aD8KjxFZEx78guTQDnpXWiNthsxzrxAK/i8E6pCHAIZTbaEFWcOCvbecMukfK7XUvyLpQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"buffer": "^5.6.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/buffer": {
|
||||||
|
"version": "5.7.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
|
||||||
|
"integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "patreon",
|
||||||
|
"url": "https://www.patreon.com/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "consulting",
|
||||||
|
"url": "https://feross.org/support"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"base64-js": "^1.3.1",
|
||||||
|
"ieee754": "^1.1.13"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/call-bind": {
|
"node_modules/call-bind": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
|
||||||
@ -1888,6 +1944,25 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/ieee754": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "patreon",
|
||||||
|
"url": "https://www.patreon.com/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "consulting",
|
||||||
|
"url": "https://feross.org/support"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"node_modules/ignore": {
|
"node_modules/ignore": {
|
||||||
"version": "5.2.4",
|
"version": "5.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz",
|
||||||
@ -3496,6 +3571,11 @@
|
|||||||
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
|
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"base64-js": {
|
||||||
|
"version": "1.5.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
|
||||||
|
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="
|
||||||
|
},
|
||||||
"brace-expansion": {
|
"brace-expansion": {
|
||||||
"version": "1.1.11",
|
"version": "1.1.11",
|
||||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||||
@ -3506,6 +3586,23 @@
|
|||||||
"concat-map": "0.0.1"
|
"concat-map": "0.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"bson": {
|
||||||
|
"version": "4.7.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/bson/-/bson-4.7.2.tgz",
|
||||||
|
"integrity": "sha512-Ry9wCtIZ5kGqkJoi6aD8KjxFZEx78guTQDnpXWiNthsxzrxAK/i8E6pCHAIZTbaEFWcOCvbecMukfK7XUvyLpQ==",
|
||||||
|
"requires": {
|
||||||
|
"buffer": "^5.6.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"buffer": {
|
||||||
|
"version": "5.7.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
|
||||||
|
"integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
|
||||||
|
"requires": {
|
||||||
|
"base64-js": "^1.3.1",
|
||||||
|
"ieee754": "^1.1.13"
|
||||||
|
}
|
||||||
|
},
|
||||||
"call-bind": {
|
"call-bind": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
|
||||||
@ -4523,6 +4620,11 @@
|
|||||||
"has-symbols": "^1.0.2"
|
"has-symbols": "^1.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"ieee754": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA=="
|
||||||
|
},
|
||||||
"ignore": {
|
"ignore": {
|
||||||
"version": "5.2.4",
|
"version": "5.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz",
|
||||||
|
@ -21,5 +21,8 @@
|
|||||||
"nodejs",
|
"nodejs",
|
||||||
"svelte3"
|
"svelte3"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"bson": "^4.7.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import { isBsonBuiltin, isDate } from '../utils';
|
||||||
import Grid from './grid.svelte';
|
import Grid from './grid.svelte';
|
||||||
|
|
||||||
export let data = [];
|
export let data = [];
|
||||||
@ -16,12 +17,13 @@
|
|||||||
let items = [];
|
let items = [];
|
||||||
|
|
||||||
$: if (data) {
|
$: if (data) {
|
||||||
|
// items = dissectObject(data).map(item => ({ ...item, menu: getRootMenu(item.key, item) }));
|
||||||
items = [];
|
items = [];
|
||||||
|
|
||||||
if (Array.isArray(data)) {
|
if (Array.isArray(data)) {
|
||||||
for (const item of data) {
|
for (const item of data) {
|
||||||
const newItem = {};
|
const newItem = {};
|
||||||
newItem.key = item[key];
|
newItem.key = stringifyValue(item[key]);
|
||||||
newItem.type = getType(item[key]);
|
newItem.type = getType(item[key]);
|
||||||
newItem.children = dissectObject(item);
|
newItem.children = dissectObject(item);
|
||||||
newItem.menu = getRootMenu(key, item[key]);
|
newItem.menu = getRootMenu(key, item[key]);
|
||||||
@ -34,7 +36,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getType(value) {
|
function getType(value) {
|
||||||
if (Array.isArray(value)) {
|
if (isBsonBuiltin(value)) {
|
||||||
|
return value._bsontype;
|
||||||
|
}
|
||||||
|
else if (isDate(value)) {
|
||||||
|
return 'Date';
|
||||||
|
}
|
||||||
|
else if (Array.isArray(value)) {
|
||||||
return `array (${value.length} item${value.length === 1 ? '' : 's'})`;
|
return `array (${value.length} item${value.length === 1 ? '' : 's'})`;
|
||||||
}
|
}
|
||||||
else if (typeof value === 'number') {
|
else if (typeof value === 'number') {
|
||||||
@ -43,9 +51,6 @@
|
|||||||
}
|
}
|
||||||
return 'integer';
|
return 'integer';
|
||||||
}
|
}
|
||||||
// else if (new Date(value).toString() !== 'Invalid Date') {
|
|
||||||
// return 'date';
|
|
||||||
// }
|
|
||||||
else if (value === null) {
|
else if (value === null) {
|
||||||
return 'null';
|
return 'null';
|
||||||
}
|
}
|
||||||
@ -58,12 +63,40 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stringifyValue(value) {
|
||||||
|
if (isBsonBuiltin(value)) {
|
||||||
|
value = value.inspect?.();
|
||||||
|
if (value.startsWith('new ')) {
|
||||||
|
value = value.slice(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value.startsWith('Int32(')) {
|
||||||
|
value = value.slice(6, -1);
|
||||||
|
}
|
||||||
|
else if (value.startsWith('Double(')) {
|
||||||
|
value = value.slice(7, -1);
|
||||||
|
}
|
||||||
|
else if (value.startsWith('Binary(Buffer.from(')) {
|
||||||
|
value = `BinData(${JSON.stringify(value.sub_type || 0)}, ${value.slice(18, -1)}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (isDate(value)) {
|
||||||
|
value = value.toString();
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
function dissectObject(object) {
|
function dissectObject(object) {
|
||||||
const entries = [ ...Array.isArray(object) ? object.entries() : Object.entries(object) ];
|
const entries = [ ...Array.isArray(object) ? object.entries() : Object.entries(object) ];
|
||||||
return entries.map(([ key, value ]) => {
|
return entries.map(([ key, value ]) => {
|
||||||
key = key + '';
|
|
||||||
const type = getType(value);
|
const type = getType(value);
|
||||||
const child = { key, value, type, menu: value?.menu };
|
key = key + '';
|
||||||
|
const child = {
|
||||||
|
key,
|
||||||
|
type,
|
||||||
|
value: stringifyValue(value),
|
||||||
|
menu: value?.menu,
|
||||||
|
};
|
||||||
|
|
||||||
if (type.startsWith('object') || type.startsWith('array')) {
|
if (type.startsWith('object') || type.startsWith('array')) {
|
||||||
child.children = dissectObject(value);
|
child.children = dissectObject(value);
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import Grid from '../../../components/grid.svelte';
|
import Grid from '../../../components/grid.svelte';
|
||||||
import { applicationSettings, views } from '../../../stores';
|
import { applicationSettings, views } from '../../../stores';
|
||||||
|
import { EJSON } from 'bson';
|
||||||
|
|
||||||
export let collection;
|
export let collection;
|
||||||
|
|
||||||
@ -36,8 +37,10 @@
|
|||||||
|
|
||||||
async function submitQuery() {
|
async function submitQuery() {
|
||||||
activePath = [];
|
activePath = [];
|
||||||
result = await FindItems(collection.hostKey, collection.dbKey, collection.key, JSON.stringify(form));
|
const newResult = await FindItems(collection.hostKey, collection.dbKey, collection.key, JSON.stringify(form));
|
||||||
if (result) {
|
if (newResult) {
|
||||||
|
newResult.results = newResult.results?.map(s => EJSON.parse(s, { relaxed: false }));
|
||||||
|
result = newResult;
|
||||||
submittedForm = JSON.parse(JSON.stringify(form));
|
submittedForm = JSON.parse(JSON.stringify(form));
|
||||||
}
|
}
|
||||||
resetFocus();
|
resetFocus();
|
||||||
|
@ -48,3 +48,16 @@ export function randomString(length = 12) {
|
|||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isBsonBuiltin(value) {
|
||||||
|
return (
|
||||||
|
(typeof value === 'object') &&
|
||||||
|
(value !== null) &&
|
||||||
|
(typeof value._bsontype === 'string') &&
|
||||||
|
(typeof value.inspect === 'function')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isDate(value) {
|
||||||
|
return (value instanceof Date) && !isNaN(value.getTime());
|
||||||
|
}
|
||||||
|
@ -18,7 +18,7 @@ export namespace app {
|
|||||||
}
|
}
|
||||||
export class findResult {
|
export class findResult {
|
||||||
total: number;
|
total: number;
|
||||||
results: any;
|
results: string[];
|
||||||
|
|
||||||
static createFrom(source: any = {}) {
|
static createFrom(source: any = {}) {
|
||||||
return new findResult(source);
|
return new findResult(source);
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
type findResult struct {
|
type findResult struct {
|
||||||
Total int64 `json:"total"`
|
Total int64 `json:"total"`
|
||||||
Results interface{} `json:"results"`
|
Results []string `json:"results"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) FindItems(hostKey, dbKey, collKey string, formJson string) findResult {
|
func (a *App) FindItems(hostKey, dbKey, collKey string, formJson string) findResult {
|
||||||
@ -123,7 +123,23 @@ func (a *App) FindItems(hostKey, dbKey, collKey string, formJson string) findRes
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
out.Results = results
|
out.Results = make([]string, 0)
|
||||||
out.Total = total
|
out.Total = total
|
||||||
|
for _, r := range results {
|
||||||
|
marshalled, err := bson.MarshalExtJSON(r, true, true)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
|
Type: runtime.ErrorDialog,
|
||||||
|
Title: "Failed to marshal BSON",
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
out.Results = append(out.Results, string(marshalled))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(out.Results)
|
||||||
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user