arbase
Advanced tools
Comparing version 0.0.2 to 0.1.0
{ | ||
"name": "arbase", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Arbase is a tool to create object-based APIs on top of arweave in mere minutes", | ||
@@ -29,6 +29,9 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"@hapi/boom": "^8.0.1", | ||
"@hapi/joi": "^16.1.4", | ||
"arlang": "^0.1.3", | ||
"arweave": "^1.4.1" | ||
"arweave": "^1.4.1", | ||
"base-x": "^3.0.7", | ||
"protons": "^1.0.1" | ||
} | ||
} |
@@ -5,2 +5,3 @@ 'use strict' | ||
const $arql = arlang.short('sym') | ||
const Boom = require('@hapi/boom') | ||
@@ -20,4 +21,4 @@ const queue = require('../queue')() | ||
function fetchTransaction (id) { | ||
// TODO: get json | ||
function fetchTransaction (arweave, id) { | ||
return arweave.transactions.get(id) | ||
} | ||
@@ -40,8 +41,21 @@ | ||
async function fetchEntry (arweave, entry, id) { | ||
const create = await arweave.arql($arql('= id $1', id)) | ||
let initial | ||
const initial = validateEntry(entry, await fetchTransaction(create), true) | ||
try { | ||
initial = validateEntry(entry, await fetchTransaction(arweave, id), true) | ||
} catch (err) { | ||
if (err.type === 'TX_NOT_FOUND') { | ||
throw Boom.notFound('Block base transaction not found') | ||
} | ||
if (err.type === 'TX_INVALID') { | ||
throw Boom.notFound('Supplied block base transaction ID invalid') | ||
} | ||
throw err | ||
} | ||
let data = initial.data | ||
const txs = await arweave.arql($arql('& (= block $1) (= child "#")', id)) | ||
const {data: txs, live} = await arweave.arql($arql('& (= block $1) (= child "#")', id)) | ||
@@ -62,3 +76,3 @@ queue.init(id, 3, 50) | ||
return data | ||
return {data, live} | ||
} | ||
@@ -101,3 +115,3 @@ | ||
const txs = await arweave.arql($arql('& (= block $1) (= child $2)', id, list)) | ||
const {data: txs, live} = await arweave.arql($arql('& (= block $1) (= child $2)', id, list)) | ||
@@ -118,3 +132,3 @@ queue.init(id, 3, 50) | ||
return data.filter(Boolean) | ||
return {data: data.filter(Boolean), live} | ||
} | ||
@@ -121,0 +135,0 @@ |
@@ -12,3 +12,3 @@ 'use strict' | ||
async function entryCreate (arweave, entry, val) { | ||
const tx = await createTx(val) | ||
const tx = await createTx(val, arweave) | ||
@@ -19,3 +19,3 @@ return tx | ||
async function entryModify (arweave, entry, id, diff) { | ||
const tx = await createTx(diff) | ||
const tx = await createTx(diff, arweave) | ||
tx.addTag('block', id) | ||
@@ -28,3 +28,3 @@ tx.addTag('child', '#') | ||
async function entryDelete (arweave, entry, id, diff) { | ||
const tx = await createTx({$delete: true}) | ||
const tx = await createTx({$delete: true}, arweave) | ||
tx.addTag('block', id) | ||
@@ -37,3 +37,3 @@ tx.addTag('child', '#') | ||
async function listAppend (arweave, entry, id, targetList, targetId) { | ||
const tx = await createTx({ op: 'append', target: targetId }) | ||
const tx = await createTx({ op: 'append', target: targetId }, arweave) | ||
tx.addTag('block', id) | ||
@@ -46,3 +46,3 @@ tx.addTag('child', targetList) | ||
async function listRemove (arweave, entry, id, targetList, targetId) { | ||
const tx = await createTx({ op: 'delete', target: targetId }) | ||
const tx = await createTx({ op: 'delete', target: targetId }, arweave) | ||
tx.addTag('block', id) | ||
@@ -49,0 +49,0 @@ tx.addTag('child', targetList) |
@@ -17,2 +17,4 @@ 'use strict' | ||
// TODO: compact and fix to be fully recursivly flat | ||
function compileBaseSchemaValidator (entry) { // TODO: fix recursion | ||
@@ -44,2 +46,37 @@ let out = {} | ||
function compileSchemaAttr (attr) { | ||
if (!attr.typeObj.compileBaseSchemaValidator) { | ||
// later, when we fix recursion | ||
return 'false' | ||
} | ||
let out = attr.typeObj.compileBaseSchemaValidator() | ||
if (attr.maxSize) { | ||
out += `.length(${attr.maxSize})` | ||
} | ||
if (attr.notNull) { | ||
out += '.required()' | ||
} | ||
return out | ||
} | ||
function compileBaseSchemaMessage (name, attrs) { | ||
let out = [`message ${name} {`] | ||
for (const attrId in attrs) { // eslint-disable-line guard-for-in | ||
const attr = attrs[attrId] | ||
if (!attr.isList) { | ||
out.push(`${attr.typeObj.protobufSchemaType} ${attrId} = ${attr.id};`) | ||
} | ||
} | ||
out.push('}') | ||
return out.join('') | ||
} | ||
function compiler (config, tree, current, ...parents) { | ||
@@ -79,13 +116,21 @@ if (!current) { | ||
notNull: attr.notNull | ||
} | ||
}, | ||
validator: compileSchemaAttr(attr) | ||
} | ||
attributes.push(obj) | ||
attribute[id] = obj | ||
attribute[id] = attributes.push(obj) - 1 | ||
} | ||
const fullName = (ns ? ('@' + ns) : '') + name | ||
const fullNameSafe = encodeURI(fullName).replace('%', 'a') | ||
const message = compileBaseSchemaMessage(fullNameSafe, entry.attributes) | ||
const obj = { | ||
fullName, | ||
fullNameSafe, | ||
name, | ||
ns, | ||
validator, | ||
message, | ||
attribute, | ||
@@ -96,5 +141,3 @@ attributes | ||
if (!outMap[ns]) { outMap[ns] = {} } | ||
outMap[ns][name] = obj | ||
out.push(obj) | ||
outMap[ns][name] = out.push(obj) - 1 | ||
} | ||
@@ -104,3 +147,3 @@ | ||
if (!entry.startsWith('@')) { | ||
out.push(compileSchema(tree, tree[entry], entry, null)) | ||
compileSchema(tree, tree[entry], entry, null) | ||
} | ||
@@ -110,4 +153,4 @@ } | ||
return { | ||
entries: out, | ||
entry: outMap | ||
entry: outMap, | ||
entries: out | ||
} | ||
@@ -114,0 +157,0 @@ } |
@@ -6,10 +6,10 @@ 'use strict' | ||
const compiler = require('./compiler') | ||
const render = require('./render') | ||
module.exports = async (src, process) => { | ||
module.exports = async (src) => { | ||
const contents = await loader(src) | ||
const processor = require(process + '/' + require(process + '/package.json').compile) | ||
validator(contents) | ||
const compiled = compiler({}, contents) | ||
const processed = processor(compiled, require('./helper')) | ||
return processed | ||
const rendered = render(compiled) | ||
return rendered | ||
} |
@@ -16,2 +16,3 @@ 'use strict' | ||
const attributeSchema = Joi.object({ // TODO: make 2 validators, one for list one for normal attr | ||
id: Joi.number().integer().required(), | ||
type: Joi.string().required(), | ||
@@ -18,0 +19,0 @@ maxSize: Joi.number().integer(), |
'use strict' | ||
const x = require('base-x') | ||
const b = x('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-') | ||
module.exports = { | ||
compileBaseSchemaValidator: () => { | ||
return `Joi.string()` // TODO: add something about format so it's a valid blockId | ||
return `Joi.string().regex(/[a-zA-Z0-9_-]{43}/)` | ||
}, | ||
resolve: async (main, value) => { | ||
protobufSchemaType: 'bytes', | ||
decode: (val) => b.encode(val), | ||
encode: (val) => b.decode(val), | ||
resolve: async (main, obj, value) => { | ||
const res = await main.arweave.fetch(value) | ||
@@ -9,0 +17,0 @@ return { |
@@ -6,3 +6,5 @@ 'use strict' | ||
return `Joi.number()` // TODO: min max? | ||
} | ||
}, | ||
protobufSchemaType: 'int64' | ||
} |
@@ -6,3 +6,5 @@ 'use strict' | ||
return `Joi.string()` // TODO: max len? | ||
} | ||
}, | ||
protobufSchemaType: 'string' | ||
} |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
35736
23
922
3
6
+ Added@hapi/boom@^8.0.1
+ Addedbase-x@^3.0.7
+ Addedprotons@^1.0.1
+ Added@hapi/boom@8.0.1(transitive)
+ Addedbase-x@3.0.9(transitive)
+ Addedbuffer@5.7.1(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedprotocol-buffers-schema@3.6.0(transitive)
+ Addedprotons@1.2.1(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsigned-varint@2.0.1(transitive)
+ Addedvarint@5.0.2(transitive)