@muze-nl/simplystore 0.4.0 → 0.4.1
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/package.json +1 -1
- package/src/commands.mjs +2 -2
- package/src/share.mjs +22 -39
- package/.eslintrc.cjs +0 -15
- package/package.json~ +0 -33
- package/test/produce.mjs +0 -79
- package/test/share.mjs +0 -18
- package/test/test.jsontag +0 -20
- package/www/assets/css/style.css +0 -2296
- package/www/assets/feather-sprite.svg +0 -1
- package/www/assets/img/simplystore-narrow-white.svg +0 -138
- package/www/assets/img/simplystore-narrow.svg +0 -138
- package/www/assets/img/simplystore-white.svg +0 -153
- package/www/assets/img/simplystore.svg +0 -153
- package/www/codemirror/AUTHORS +0 -979
- package/www/codemirror/CHANGELOG.md +0 -2208
- package/www/codemirror/CONTRIBUTING.md +0 -92
- package/www/codemirror/LICENSE +0 -21
- package/www/codemirror/README.md +0 -47
- package/www/codemirror/addon/lint/javascript-lint.js +0 -65
- package/www/codemirror/addon/lint/lint.css +0 -79
- package/www/codemirror/addon/lint/lint.js +0 -291
- package/www/codemirror/lib/codemirror.css +0 -344
- package/www/codemirror/lib/codemirror.js +0 -9874
- package/www/codemirror/mode/javascript/javascript.js +0 -960
- package/www/codemirror/package.json +0 -52
- package/www/codemirror/theme/material-ocean.css +0 -141
- package/www/index.html +0 -359
package/package.json
CHANGED
package/src/commands.mjs
CHANGED
package/src/share.mjs
CHANGED
|
@@ -5,34 +5,24 @@ const handler = function(root, index, buffer)
|
|
|
5
5
|
return {
|
|
6
6
|
get(target, key, receiver)
|
|
7
7
|
{
|
|
8
|
-
//@FIXME: array.length needs to be handled
|
|
9
|
-
//@FIXME: array functions need to be handled
|
|
10
8
|
let keyNumber = index.key[key]
|
|
11
9
|
if (root[keyNumber]) {
|
|
12
10
|
let keyStart = root[keyNumber].s + root.s
|
|
13
11
|
let keyEnd = root[keyNumber].e + root.s
|
|
14
|
-
|
|
12
|
+
subobjecten hoeven niet geparsed...
|
|
15
13
|
if (root[keyNumber].c) {
|
|
16
14
|
// object
|
|
17
15
|
return new jsontagProxy(root[keyNumber], index, buffer)
|
|
18
16
|
}
|
|
19
17
|
return JSON.parse(buffer.slice(keyStart,keyEnd))
|
|
20
18
|
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
set() {
|
|
24
|
-
throw new Error('This data is immutable')
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
deleteProperty() {
|
|
28
|
-
throw new Error('This data is immutable')
|
|
29
|
-
},
|
|
19
|
+
}
|
|
30
20
|
|
|
31
21
|
has(target, key)
|
|
32
22
|
{
|
|
33
23
|
let keyNumber = index.key[key]
|
|
34
24
|
return typeof root[keyNumber] !== 'undefined'
|
|
35
|
-
}
|
|
25
|
+
}
|
|
36
26
|
|
|
37
27
|
ownKeys(target)
|
|
38
28
|
{
|
|
@@ -41,16 +31,21 @@ const handler = function(root, index, buffer)
|
|
|
41
31
|
}
|
|
42
32
|
}
|
|
43
33
|
|
|
44
|
-
export
|
|
45
|
-
|
|
34
|
+
export class jsontagProxy extends proxy
|
|
35
|
+
{
|
|
36
|
+
constructor(root, index, buffer)
|
|
37
|
+
{
|
|
38
|
+
super({}, handler(root, index, buffer))
|
|
39
|
+
}
|
|
40
|
+
|
|
46
41
|
}
|
|
47
42
|
|
|
48
|
-
export function share(data)
|
|
43
|
+
export default function share(data)
|
|
49
44
|
{
|
|
50
45
|
let jsontag = JSONTag.stringify(data)
|
|
51
46
|
let buffer = new SharedArrayBuffer(jsontag.length)
|
|
52
47
|
let dv = new DataView(buffer)
|
|
53
|
-
let
|
|
48
|
+
let encode = new TextEncoder('utf-8')
|
|
54
49
|
let root = {}
|
|
55
50
|
let index = {
|
|
56
51
|
key: {},
|
|
@@ -58,12 +53,11 @@ export function share(data)
|
|
|
58
53
|
types: {}
|
|
59
54
|
}
|
|
60
55
|
let current = 0
|
|
61
|
-
let seen = new Map()
|
|
62
56
|
|
|
63
57
|
function getKey(key) {
|
|
64
58
|
let l;
|
|
65
59
|
if (typeof index.key[key] == 'undefined') {
|
|
66
|
-
l = Object.keys(index.key)
|
|
60
|
+
l = Object.keys(index.key)
|
|
67
61
|
index.key[key] = l
|
|
68
62
|
index.reverse[l] = key
|
|
69
63
|
}
|
|
@@ -72,7 +66,7 @@ export function share(data)
|
|
|
72
66
|
|
|
73
67
|
function getType(type) {
|
|
74
68
|
if (typeof index.types[type] == 'undefined') {
|
|
75
|
-
|
|
69
|
+
l = Object.keys(index.types);
|
|
76
70
|
index.types[type] = l
|
|
77
71
|
}
|
|
78
72
|
|
|
@@ -80,10 +74,6 @@ export function share(data)
|
|
|
80
74
|
|
|
81
75
|
function store(container, key, value) {
|
|
82
76
|
let l = getKey(key)
|
|
83
|
-
if (seen.has(value)) {
|
|
84
|
-
container[l] = seen.get(value)
|
|
85
|
-
return
|
|
86
|
-
}
|
|
87
77
|
container[l] = {
|
|
88
78
|
s: current
|
|
89
79
|
}
|
|
@@ -94,25 +84,24 @@ export function share(data)
|
|
|
94
84
|
s: current,
|
|
95
85
|
c: {}
|
|
96
86
|
}
|
|
97
|
-
|
|
87
|
+
attributes.forEach((v,k) => {
|
|
98
88
|
let l = getKey(k)
|
|
99
89
|
let t = getType('string')
|
|
100
90
|
container.a.c[k] = {
|
|
101
91
|
s: current,
|
|
102
92
|
t
|
|
103
93
|
}
|
|
104
|
-
v = JSON.stringify(
|
|
105
|
-
let
|
|
94
|
+
let v = JSON.stringify(value)
|
|
95
|
+
let (r,w) = encoder.encodeInto(v, dv, current)
|
|
106
96
|
current += w
|
|
107
97
|
container.a.c[k].e = current
|
|
108
98
|
})
|
|
109
99
|
}
|
|
110
|
-
let type = JSONTag.getType(
|
|
100
|
+
let type = JSONTag.getType(node)
|
|
111
101
|
let t = getType(type)
|
|
112
102
|
container.t = t
|
|
113
103
|
let v = JSON.stringify(value)
|
|
114
|
-
let
|
|
115
|
-
let {r,w} = encoder.encodeInto(v, uint8buffer, current)
|
|
104
|
+
let (r,w) = encoder.encodeInto(v, dv, current)
|
|
116
105
|
current+= w
|
|
117
106
|
container.e = current
|
|
118
107
|
}
|
|
@@ -120,15 +109,10 @@ export function share(data)
|
|
|
120
109
|
|
|
121
110
|
function walk(node, parentKey, parent, save)
|
|
122
111
|
{
|
|
123
|
-
if (seen.has(node)) {
|
|
124
|
-
Object.assign(save, seen.get(node))
|
|
125
|
-
return
|
|
126
|
-
}
|
|
127
112
|
let type = JSONTag.getType(node)
|
|
128
113
|
let t = getType(type)
|
|
129
114
|
switch (type) {
|
|
130
115
|
case 'array':
|
|
131
|
-
seen.set(node,save)
|
|
132
116
|
save.s = current
|
|
133
117
|
save.t = t
|
|
134
118
|
save.c = []
|
|
@@ -136,11 +120,10 @@ export function share(data)
|
|
|
136
120
|
save.e = current
|
|
137
121
|
break
|
|
138
122
|
case 'object':
|
|
139
|
-
seen.set(node, save)
|
|
140
123
|
save.s = current
|
|
141
124
|
save.c = []
|
|
142
125
|
save.t = t
|
|
143
|
-
Object.entries(node).forEach((
|
|
126
|
+
Object.entries(node).forEach((k,v) => walk(v, k, node, save.c))
|
|
144
127
|
save.e = current
|
|
145
128
|
break
|
|
146
129
|
default:
|
|
@@ -150,9 +133,9 @@ export function share(data)
|
|
|
150
133
|
}
|
|
151
134
|
|
|
152
135
|
walk(data, null, null, root)
|
|
153
|
-
|
|
136
|
+
|
|
154
137
|
return {
|
|
155
|
-
root:
|
|
138
|
+
root: new jsontagProxy(root, index, buffer),
|
|
156
139
|
index,
|
|
157
140
|
buffer
|
|
158
141
|
}
|
package/.eslintrc.cjs
DELETED
package/package.json~
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@muze-nl/simplystore",
|
|
3
|
-
"version": "0.3.7",
|
|
4
|
-
"main": "src/server.mjs",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"start": "node src/run.mjs",
|
|
8
|
-
"test": "tap test/*.mjs"
|
|
9
|
-
},
|
|
10
|
-
"author": "auke@muze.nl",
|
|
11
|
-
"license": "MIT",
|
|
12
|
-
"repository": {
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/simplyedit/simplystore.git"
|
|
15
|
-
},
|
|
16
|
-
"bugs": "https://github.com/simplyedit/simplystore/issues",
|
|
17
|
-
"homepage": "https://github.com/simplyedit/simplystore#readme",
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"@muze-nl/jsontag": "^0.8.5",
|
|
20
|
-
"array-where-select": "^0.4.0",
|
|
21
|
-
"codemirror": "^6.0.1",
|
|
22
|
-
"express": "^4.18.1",
|
|
23
|
-
"json-pointer": "^0.6.2",
|
|
24
|
-
"jsonpath-plus": "^7.2.0",
|
|
25
|
-
"piscina": "^4.1.0",
|
|
26
|
-
"vm2": "^3.9.13"
|
|
27
|
-
},
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"eslint": "^8.48.0",
|
|
30
|
-
"process": "^0.11.10",
|
|
31
|
-
"tap": "^16.3.8"
|
|
32
|
-
}
|
|
33
|
-
}
|
package/test/produce.mjs
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import tap from 'tap'
|
|
2
|
-
import fs from 'fs'
|
|
3
|
-
import JSONTag from '@muze-nl/jsontag'
|
|
4
|
-
import {produce,index} from '../src/produce.mjs'
|
|
5
|
-
import {deepFreeze} from '../src/util.mjs'
|
|
6
|
-
|
|
7
|
-
let data = deepFreeze(JSONTag.parse(fs.readFileSync('./test/test.jsontag','utf-8')))
|
|
8
|
-
|
|
9
|
-
tap.test('data is frozen', t => {
|
|
10
|
-
t.throws(() => {
|
|
11
|
-
data.persons.foo = 'bar'
|
|
12
|
-
})
|
|
13
|
-
t.notHas(data.persons, {foo:'bar'})
|
|
14
|
-
t.end()
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
tap.test('produce can create new data', t => {
|
|
18
|
-
let newData = produce(data, (draft) => {
|
|
19
|
-
draft.persons.foo = 'bar'
|
|
20
|
-
})
|
|
21
|
-
t.has(newData.persons, {foo:'bar'})
|
|
22
|
-
t.end()
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
tap.test('produce does not change base data', t => {
|
|
26
|
-
let newData = produce(data, (draft) => {
|
|
27
|
-
console.log('Persons draft',draft.persons, Object.isFrozen(draft.persons))
|
|
28
|
-
draft.persons.foo = 'bar'
|
|
29
|
-
})
|
|
30
|
-
t.notHas(data.persons, {foo:'bar'})
|
|
31
|
-
t.end()
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
tap.test('produce handles array access', t => {
|
|
35
|
-
let newData = produce(data, (draft) => {
|
|
36
|
-
draft.persons[0].name = 'Jan'
|
|
37
|
-
})
|
|
38
|
-
t.equal(newData.persons[0].name, 'Jan')
|
|
39
|
-
t.end()
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
tap.test('produce handles array functions', t => {
|
|
43
|
-
let newData = produce(data, (draft) => {
|
|
44
|
-
draft.persons.push({
|
|
45
|
-
name: 'Jan'
|
|
46
|
-
})
|
|
47
|
-
})
|
|
48
|
-
t.equal(newData.persons[2].name, 'Jan')
|
|
49
|
-
t.same(data.persons[2],null)
|
|
50
|
-
t.end()
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
tap.test('produce can use array.indexOf inside', t => {
|
|
54
|
-
let newData = produce(data, (draft) => {
|
|
55
|
-
let p = draft.persons[1] // this returns a proxy
|
|
56
|
-
let i = draft.persons.indexOf(p) // this is passed on to the baseState/clone, which has values without proxy
|
|
57
|
-
t.equal(i,1) // so this no longer fails, as indexOf automatically calls getRealValue on all params
|
|
58
|
-
})
|
|
59
|
-
t.end()
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
tap.test('produce does not alter unaccessed objects', t => {
|
|
63
|
-
let newData = produce(data, (draft) => {
|
|
64
|
-
draft.persons.foo = 'bar'
|
|
65
|
-
})
|
|
66
|
-
t.equal(data.persons[0],newData.persons[0])
|
|
67
|
-
t.equal(data.persons[1],newData.persons[1])
|
|
68
|
-
t.notEqual(data.persons,newData.persons)
|
|
69
|
-
t.end()
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
tap.test('proxies get re-used', t => {
|
|
73
|
-
let newData = produce(data, (draft) => {
|
|
74
|
-
let p1 = draft.persons[0]
|
|
75
|
-
let p2 = draft.persons[0]
|
|
76
|
-
t.equal(p1,p2)
|
|
77
|
-
})
|
|
78
|
-
t.end()
|
|
79
|
-
})
|
package/test/share.mjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import tap from 'tap'
|
|
2
|
-
import {share} from '../src/share.mjs'
|
|
3
|
-
import JSONTag from '@muze-nl/jsontag'
|
|
4
|
-
import fs from 'fs'
|
|
5
|
-
|
|
6
|
-
let data = JSONTag.parse(fs.readFileSync('./test/test.jsontag','utf-8'))
|
|
7
|
-
|
|
8
|
-
tap.test('create shared array buffer', t => {
|
|
9
|
-
let shared = share(data)
|
|
10
|
-
console.log(shared)
|
|
11
|
-
let decoder = new TextDecoder()
|
|
12
|
-
let uint8buffer = new Uint8Array(shared.buffer)
|
|
13
|
-
let str = decoder.decode(uint8buffer)
|
|
14
|
-
console.log('string',str)
|
|
15
|
-
|
|
16
|
-
t.end()
|
|
17
|
-
})
|
|
18
|
-
|
package/test/test.jsontag
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"persons": [
|
|
3
|
-
<object id="john" class="Person">{
|
|
4
|
-
"name": "John",
|
|
5
|
-
"lastName": "Doe",
|
|
6
|
-
"dob": <date>"1972-09-20",
|
|
7
|
-
"foaf": [
|
|
8
|
-
<link>"jane"
|
|
9
|
-
]
|
|
10
|
-
},
|
|
11
|
-
<object id="jane" class="Person">{
|
|
12
|
-
"name": "Jane",
|
|
13
|
-
"lastName": "Doe",
|
|
14
|
-
"dob": <date>"1986-01-01",
|
|
15
|
-
"foaf": [
|
|
16
|
-
<link>"john"
|
|
17
|
-
]
|
|
18
|
-
}
|
|
19
|
-
]
|
|
20
|
-
}
|