feat: JSONB
This commit is contained in:
parent
a439c65413
commit
66dc1b58af
|
@ -1,6 +1,7 @@
|
|||
import {gather} from '@latus/core';
|
||||
|
||||
export {default as Resource} from './resource';
|
||||
export * as JSONB from './jsonb';
|
||||
export {default as JsonResource} from './json-resource';
|
||||
|
||||
export default {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import merge from 'deepmerge';
|
||||
|
||||
import {parse} from './jsonb';
|
||||
import Resource from './resource';
|
||||
|
||||
export default class JsonResource extends Resource {
|
||||
|
@ -48,19 +49,7 @@ export default class JsonResource extends Resource {
|
|||
}
|
||||
|
||||
static async read(uri) {
|
||||
const buffer = await super.read(uri);
|
||||
let string;
|
||||
if ('client' === process.env.SIDE) {
|
||||
const decoder = new TextDecoder();
|
||||
string = decoder.decode(buffer);
|
||||
}
|
||||
else {
|
||||
// eslint-disable-next-line global-require
|
||||
const {StringDecoder} = require('string_decoder');
|
||||
const decoder = new StringDecoder();
|
||||
string = decoder.end(buffer);
|
||||
}
|
||||
return this.extendJson(JSON.parse(string));
|
||||
return this.extendJson(parse(await super.read(uri)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
16
packages/resource/src/jsonb.js
Normal file
16
packages/resource/src/jsonb.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
export const bufferify = (value) => Buffer.from(JSON.stringify(value));
|
||||
|
||||
export const parse = (buffer) => {
|
||||
let string;
|
||||
if ('client' === process.env.SIDE) {
|
||||
const decoder = new TextDecoder();
|
||||
string = decoder.decode(buffer);
|
||||
}
|
||||
else {
|
||||
// eslint-disable-next-line global-require
|
||||
const {StringDecoder} = require('string_decoder');
|
||||
const decoder = new StringDecoder();
|
||||
string = decoder.end(buffer);
|
||||
}
|
||||
return JSON.parse(string);
|
||||
};
|
Loading…
Reference in New Issue
Block a user