Skip to content

Commit

Permalink
added @muze-nl/od-jsontag, removed unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
poef committed Mar 19, 2024
1 parent b102701 commit d6a84d8
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 1,309 deletions.
5 changes: 5 additions & 0 deletions example/command-log.jsontag
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{"id":"f551ba01-7668-4964-9918-06a1117a2aab","name":"addPerson","value":{"name":"Some Stormtrooper","gender":"male","homeworld":<link>"http://swapi.co/api/planets/1/"}}
{"id":"d6a9161d-9c7b-4e33-af23-51cc25d97c71","name":"addUnknown","value":{"name":"Some Stormtrooper","gender":"male","homeworld":<link>"http://swapi.co/api/planets/1/"}}
{"id":"4ea25598-7c22-4a5a-a958-f1d0b72a0e27","name":"addPerson","timestamp":<date>"2024-03-19","author":"someone","value":{"name":"Dave the Stormtrooper","gender":"male","homeworld":<link>"http://swapi.co/api/planets/1/"}}
{"id":"99bb60ad-8052-42ae-95ef-dee8c09cec89","name":"addPerson","timestamp":<date>"2024-03-19","author":"someone","value":{"name":"Dave the Stormtrooper","gender":"male","homeworld":<link>"http://swapi.co/api/planets/1/"}}
{"id":"369eb47b-87cf-47a2-8c24-82e325596636","name":"addPerson","timestamp":<date>"2024-03-19","author":"someone","value":{"name":"Dave the Stormtrooper","gender":"male","homeworld":<link>"http://swapi.co/api/planets/1/"}}
10 changes: 10 additions & 0 deletions example/command-status.jsontag
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{"command":"f551ba01-7668-4964-9918-06a1117a2aab","code":202,"status":"accepted"}
{"command":"f551ba01-7668-4964-9918-06a1117a2aab","code":200,"status":"done"}
{"command":"d6a9161d-9c7b-4e33-af23-51cc25d97c71","code":202,"status":"accepted"}
{"command":"d6a9161d-9c7b-4e33-af23-51cc25d97c71","status":"failed","code":404,"message":"Command addUnknown not found","details":null}
{"command":"4ea25598-7c22-4a5a-a958-f1d0b72a0e27","code":202,"status":"accepted"}
{"command":"4ea25598-7c22-4a5a-a958-f1d0b72a0e27","status":"failed","code":null,"message":"The requested module '@muze-nl/od-jsontag/src/serialize.mjs' does not provide an export named 'stringif'","details":null}
{"command":"99bb60ad-8052-42ae-95ef-dee8c09cec89","code":202,"status":"accepted"}
{"command":"99bb60ad-8052-42ae-95ef-dee8c09cec89","status":"failed","code":null,"message":"FastJSONTag.setAttribute is not a function","details":null}
{"command":"369eb47b-87cf-47a2-8c24-82e325596636","code":202,"status":"accepted"}
{"command":"369eb47b-87cf-47a2-8c24-82e325596636","code":200,"status":"done"}
270 changes: 270 additions & 0 deletions example/data.jsontag

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions example/run-command.mjs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { v4 as uuid } from 'uuid'
import JSONTag from '@muze-nl/jsontag'

// run command to localhost:3000

let id = uuid()
let timestamp = new Date().toISOString()
timestamp = timestamp.substring(0, timestamp.indexOf('T'))
let commandStr = `{
"id": "${id}",
"name": "addPerson",
"timestamp": <date>"${timestamp}",
"author":"someone",
"value": {
"name": "Some Stormtrooper",
"name": "Dave the Stormtrooper",
"gender": "male",
"homeworld": <link>"http://swapi.co/api/planets/1/"
}
}`


async function main() {
let response = await fetch('http://localhost:3000/command', {
method: 'POST',
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@muze-nl/simplystore",
"version": "0.6.4",
"version": "0.6.5",
"main": "src/server.mjs",
"type": "module",
"scripts": {
Expand All @@ -17,9 +17,10 @@
"homepage": "https://github.com/simplyedit/simplystore#readme",
"dependencies": {
"@muze-nl/jsontag": "^0.9.1",
"jaqt": "^0.6.2",
"@muze-nl/od-jsontag": "^0.1.1",
"codemirror": "^6.0.1",
"express": "^4.18.1",
"jaqt": "^0.6.2",
"json-pointer": "^0.6.2",
"jsonpath-plus": "^7.2.0",
"vm2": "^3.9.13",
Expand All @@ -37,4 +38,4 @@
"www/",
"scripts/"
]
}
}
35 changes: 11 additions & 24 deletions src/command-worker-module.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import JSONTag from '@muze-nl/jsontag'
import {source, isChanged, getIndex} from './symbols.mjs'
import fastParse from './fastParse.mjs'
import {stringToSAB,resultSetStringify} from './fastStringify.mjs'
import {source, isChanged, getIndex, resultSet} from '@muze-nl/od-jsontag/src/symbols.mjs'
import parse from '@muze-nl/od-jsontag/src/parse.mjs'
import serialize, {stringify} from '@muze-nl/od-jsontag/src/serialize.mjs'
import * as FastJSONTag from '@muze-nl/od-jsontag/src/jsontag.mjs'
import writeFileAtomic from 'write-file-atomic'
import {_,from,not,anyOf,allOf,asc,desc,sum,count,avg,max,min} from 'jaqt'

let commands = {}
let resultSet = []
let resultArr = []
let dataspace
let datafile
let meta = {}
Expand All @@ -20,7 +21,7 @@ export const metaIdProxy = {
meta.index.id.forEach((ref,id) => {
callback({
deref: () => {
return resultSet[ref]
return resultArr[ref]
}
},id)
})
Expand All @@ -34,15 +35,15 @@ export const metaIdProxy = {
}
} else {
let line = meta.index.id.get(id)
resultSet[line] = ref
resultArr[line] = ref
}
},
get: (id) => {
let index = meta.index.id.get(id)
if (index || index===0) {
return {
deref: () => {
return resultSet[index]
return resultArr[index]
}
}
}
Expand All @@ -52,22 +53,9 @@ export const metaIdProxy = {
}
}

export const FastJSONTag = {
getType: (obj) => JSONTag.getType(obj?.[source]),
getAttribute: (obj, attr) => JSONTag.getAttribute(obj?.[source],attr),
setAttribute: (obj, attr, value) => {
if (!obj) return
obj[isChanged] = true
return JSONTag.setAttribute(obj[source], attr, value)
},
getAttributes: (obj) => JSONTag.getAttributes(obj?.[source]),
getAttributeString: (obj) => JSONTag.getAttributesString(obj?.[source]),
getTypeString: (obj) => JSONTag.getTypeString(obj?.[source])
}

export async function initialize(task) {
resultSet = fastParse(task.data, task.meta, false) // false means mutable
dataspace = resultSet[0]
dataspace = parse(task.data, task.meta, false) // false means mutable
resultArr = dataspace[resultSet]
meta = task.meta
metaProxy.index.id = metaIdProxy
datafile = task.datafile
Expand All @@ -90,8 +78,7 @@ export default async function runCommand(commandStr, request) {
//TODO: if command/task makes no changes, skip updating data.jsontag and writing it, skip response.data
FastJSONTag.setAttribute(dataspace, 'command', task.id)

const strData = resultSetStringify(resultSet)
const uint8sab = stringToSAB(strData)
const uint8sab = serialize(dataspace)
response.data = uint8sab
response.meta = {
index: {
Expand Down
Loading

0 comments on commit d6a84d8

Please sign in to comment.