@based/db 0.0.28 → 0.0.29
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/README.md +1 -399
- package/dist/lib/darwin_aarch64/include/selva/db.h +8 -4
- package/dist/lib/darwin_aarch64/include/selva/selva_hash128.h +17 -7
- package/dist/lib/darwin_aarch64/include/selva/sort.h +21 -14
- package/dist/lib/darwin_aarch64/libdeflate.dylib +0 -0
- package/dist/lib/darwin_aarch64/libjemalloc_selva.2.dylib +0 -0
- package/dist/lib/darwin_aarch64/libnode-v20.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v21.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
- package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
- package/dist/lib/darwin_aarch64/libxxhash.dylib +0 -0
- package/dist/lib/linux_aarch64/include/selva/db.h +8 -4
- package/dist/lib/linux_aarch64/include/selva/selva_hash128.h +17 -7
- package/dist/lib/linux_aarch64/include/selva/sort.h +21 -14
- package/dist/lib/linux_aarch64/libdeflate.so +0 -0
- package/dist/lib/linux_aarch64/libjemalloc_selva.so.2 +0 -0
- package/dist/lib/linux_aarch64/libnode-v20.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v21.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
- package/dist/lib/linux_aarch64/libselva.so +0 -0
- package/dist/lib/linux_x86_64/include/selva/db.h +8 -4
- package/dist/lib/linux_x86_64/include/selva/selva_hash128.h +17 -7
- package/dist/lib/linux_x86_64/include/selva/sort.h +21 -14
- package/dist/lib/linux_x86_64/libjemalloc_selva.so.2 +0 -0
- package/dist/lib/linux_x86_64/libnode-v20.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v21.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
- package/dist/lib/linux_x86_64/libselva.so +0 -0
- package/dist/src/client/flushModify.d.ts +1 -1
- package/dist/src/client/flushModify.js +12 -17
- package/dist/src/client/index.d.ts +6 -4
- package/dist/src/client/index.js +19 -2
- package/dist/src/client/modify/ModifyRes.d.ts +1 -1
- package/dist/src/client/modify/ModifyRes.js +14 -18
- package/dist/src/client/modify/fixed.js +43 -8
- package/dist/src/client/modify/modify.js +0 -1
- package/dist/src/client/modify/references/{appendRefs.d.ts → appendEdgeRefs.d.ts} +1 -1
- package/dist/src/client/modify/references/{appendRefs.js → appendEdgeRefs.js} +5 -2
- package/dist/src/client/modify/references/edge.js +182 -175
- package/dist/src/client/modify/references/reference.js +4 -8
- package/dist/src/client/modify/references/references.js +18 -14
- package/dist/src/client/modify/string.js +0 -3
- package/dist/src/client/modify/text.js +11 -3
- package/dist/src/client/modify/types.d.ts +11 -0
- package/dist/src/client/modify/types.js +10 -0
- package/dist/src/client/modify/update.js +4 -1
- package/dist/src/client/modify/vector.js +13 -4
- package/dist/src/client/query/BasedDbQuery.d.ts +1 -1
- package/dist/src/client/query/BasedDbQuery.js +2 -2
- package/dist/src/client/query/BasedIterable.d.ts +1 -1
- package/dist/src/client/query/BasedIterable.js +7 -2
- package/dist/src/client/query/filter/createFixedFilterBuffer.d.ts +2 -1
- package/dist/src/client/query/filter/createFixedFilterBuffer.js +11 -28
- package/dist/src/client/query/filter/createReferenceFilter.d.ts +2 -1
- package/dist/src/client/query/filter/createReferenceFilter.js +10 -9
- package/dist/src/client/query/filter/createVariableFilterBuffer.d.ts +2 -1
- package/dist/src/client/query/filter/createVariableFilterBuffer.js +8 -10
- package/dist/src/client/query/filter/parseFilterValue.js +1 -1
- package/dist/src/client/query/filter/primitiveFilter.js +9 -9
- package/dist/src/client/query/filter/toBuffer.js +0 -15
- package/dist/src/client/query/filter/types.d.ts +1 -0
- package/dist/src/client/query/filter/types.js +1 -0
- package/dist/src/client/query/include/walk.js +0 -1
- package/dist/src/client/query/read/read.js +4 -4
- package/dist/src/client/query/search/index.js +11 -15
- package/dist/src/client/query/subscription/markers.js +1 -2
- package/dist/src/client/query/subscription/run.js +0 -2
- package/dist/src/client/query/thresholds.d.ts +0 -2
- package/dist/src/client/query/thresholds.js +0 -2
- package/dist/src/client/query/toBuffer.js +16 -42
- package/dist/src/client/query/types.d.ts +3 -2
- package/dist/src/client/query/validation.d.ts +1 -3
- package/dist/src/client/query/validation.js +6 -18
- package/dist/src/client/string.d.ts +2 -0
- package/dist/src/client/string.js +9 -13
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +7 -15
- package/dist/src/native.d.ts +1 -1
- package/dist/src/native.js +3 -3
- package/dist/src/server/csmt/draw-dot.js +2 -2
- package/dist/src/server/csmt/tree.js +57 -6
- package/dist/src/server/csmt/types.d.ts +5 -0
- package/dist/src/server/index.d.ts +4 -3
- package/dist/src/server/index.js +44 -44
- package/dist/src/server/migrate/index.js +47 -29
- package/dist/src/server/migrate/worker.js +2 -2
- package/dist/src/server/save.js +40 -28
- package/dist/src/server/start.js +7 -19
- package/dist/src/server/tree.d.ts +2 -0
- package/dist/src/server/tree.js +34 -2
- package/dist/src/server/worker.js +3 -3
- package/dist/src/utils.d.ts +3 -1
- package/dist/src/utils.js +43 -19
- package/package.json +9 -3
- package/dist/lib/darwin_aarch64/include/selva/base64.h +0 -59
- package/dist/lib/darwin_aarch64/include/selva/base64url.h +0 -59
- package/dist/lib/linux_aarch64/include/selva/base64.h +0 -59
- package/dist/lib/linux_aarch64/include/selva/base64url.h +0 -59
- package/dist/lib/linux_x86_64/include/selva/base64.h +0 -59
- package/dist/lib/linux_x86_64/include/selva/base64url.h +0 -59
- package/dist/src/client/timestamp.d.ts +0 -1
- package/dist/src/client/timestamp.js +0 -68
|
@@ -6,7 +6,7 @@ import { getBuffer, writeBinaryRaw } from '../binary.js';
|
|
|
6
6
|
import { ModifyError, ModifyState } from '../ModifyRes.js';
|
|
7
7
|
import { DECREMENT, INCREMENT, RANGE_ERR, UPDATE, UPDATE_PARTIAL, } from '../types.js';
|
|
8
8
|
import { appendFixedValue } from '../fixed.js';
|
|
9
|
-
import {
|
|
9
|
+
import { appendEdgeRefs } from './appendEdgeRefs.js';
|
|
10
10
|
function valueOperation(value) {
|
|
11
11
|
if (typeof value === 'object' && value !== null) {
|
|
12
12
|
if (value.increment > 0) {
|
|
@@ -24,172 +24,194 @@ export function writeEdges(t, ref, ctx) {
|
|
|
24
24
|
let mainFields;
|
|
25
25
|
let mainSize = 0;
|
|
26
26
|
let hasIncr = false;
|
|
27
|
-
for (const key in
|
|
28
|
-
if (key
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
for (const key in ref) {
|
|
28
|
+
if (key === 'id' || key === '$index') {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const edge = t.edges?.[key];
|
|
32
|
+
if (!edge) {
|
|
33
|
+
return new ModifyError(t, key, `Does not exist`);
|
|
34
|
+
}
|
|
35
|
+
let value = ref[key];
|
|
36
|
+
if (edge.separate === true) {
|
|
37
|
+
if (ctx.len + 2 > ctx.max) {
|
|
38
|
+
return RANGE_ERR;
|
|
39
|
+
}
|
|
40
|
+
ctx.buf[ctx.len++] = UPDATE;
|
|
41
|
+
ctx.buf[ctx.len++] = edge.prop;
|
|
42
|
+
/*
|
|
43
|
+
Seperate fields:
|
|
44
|
+
|
|
45
|
+
| Offset | Field | Size (bytes)| Description |
|
|
46
|
+
|---------|-------------|-------------|---------------------------------------|
|
|
47
|
+
| 0 | modify op | 1 | Modify operation identifier |
|
|
48
|
+
| 1 | prop | 1 | Field identifier |
|
|
49
|
+
| 2 | type | 1 | Indicates MICRO_BUFFER type |
|
|
50
|
+
| 3 | size | 4 | Size of the data in bytes |
|
|
51
|
+
| 7 | data | Variable | Content |
|
|
52
|
+
*/
|
|
53
|
+
if (edge.typeIndex === BINARY) {
|
|
54
|
+
let size = 0;
|
|
55
|
+
// add null
|
|
56
|
+
if (value === null) {
|
|
57
|
+
size = 0;
|
|
34
58
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
| Offset | Field | Size (bytes)| Description |
|
|
41
|
-
|---------|-------------|-------------|---------------------------------------|
|
|
42
|
-
| 0 | modify op | 1 | Modify operation identifier |
|
|
43
|
-
| 1 | prop | 1 | Field identifier |
|
|
44
|
-
| 2 | type | 1 | Indicates MICRO_BUFFER type |
|
|
45
|
-
| 3 | size | 4 | Size of the data in bytes |
|
|
46
|
-
| 7 | data | Variable | Content |
|
|
47
|
-
*/
|
|
48
|
-
if (edge.typeIndex === BINARY) {
|
|
49
|
-
let size = 0;
|
|
50
|
-
if (value === null) {
|
|
51
|
-
size = 0;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
const buf = getBuffer(value);
|
|
55
|
-
if (!buf) {
|
|
56
|
-
return new ModifyError(edge, value);
|
|
57
|
-
}
|
|
58
|
-
size = buf.byteLength;
|
|
59
|
-
}
|
|
60
|
-
if (ctx.len + EDGE_HEADER_SIZE + size > ctx.max) {
|
|
61
|
-
return RANGE_ERR;
|
|
62
|
-
}
|
|
63
|
-
ctx.buf[ctx.len++] = STRING;
|
|
64
|
-
if (size) {
|
|
65
|
-
writeBinaryRaw(value, ctx);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
ctx.buf[ctx.len++] = 0;
|
|
69
|
-
ctx.buf[ctx.len++] = 0;
|
|
70
|
-
ctx.buf[ctx.len++] = 0;
|
|
71
|
-
ctx.buf[ctx.len++] = 0;
|
|
59
|
+
else {
|
|
60
|
+
const buf = getBuffer(value);
|
|
61
|
+
if (!buf || !edge.validation(buf, edge)) {
|
|
62
|
+
return new ModifyError(edge, value);
|
|
72
63
|
}
|
|
64
|
+
size = buf.byteLength;
|
|
65
|
+
value = buf;
|
|
66
|
+
}
|
|
67
|
+
if (ctx.len + EDGE_HEADER_SIZE + size > ctx.max) {
|
|
68
|
+
return RANGE_ERR;
|
|
69
|
+
}
|
|
70
|
+
ctx.buf[ctx.len++] = STRING;
|
|
71
|
+
if (size) {
|
|
72
|
+
writeBinaryRaw(value, ctx);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
ctx.buf[ctx.len++] = 0;
|
|
76
|
+
ctx.buf[ctx.len++] = 0;
|
|
77
|
+
ctx.buf[ctx.len++] = 0;
|
|
78
|
+
ctx.buf[ctx.len++] = 0;
|
|
73
79
|
}
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
}
|
|
81
|
+
else if (edge.typeIndex === STRING) {
|
|
82
|
+
let size = 0;
|
|
83
|
+
// add null
|
|
84
|
+
if (value !== null) {
|
|
85
|
+
if (!edge.validation(value, edge)) {
|
|
76
86
|
return new ModifyError(edge, value);
|
|
77
87
|
}
|
|
78
|
-
|
|
79
|
-
|
|
88
|
+
const isBuffer = value instanceof Uint8Array;
|
|
89
|
+
size = isBuffer
|
|
90
|
+
? value.byteLength
|
|
91
|
+
: ENCODER.encode(value).byteLength + 6;
|
|
92
|
+
if (ctx.len + EDGE_HEADER_SIZE + size > ctx.max) {
|
|
80
93
|
return RANGE_ERR;
|
|
81
94
|
}
|
|
82
95
|
ctx.buf[ctx.len++] = STRING;
|
|
83
|
-
|
|
84
|
-
let sizeU32 = size;
|
|
85
|
-
ctx.buf[ctx.len++] = sizeU32;
|
|
86
|
-
ctx.buf[ctx.len++] = sizeU32 >>>= 8;
|
|
87
|
-
ctx.buf[ctx.len++] = sizeU32 >>>= 8;
|
|
88
|
-
ctx.buf[ctx.len++] = sizeU32 >>>= 8;
|
|
89
|
-
ctx.len += size;
|
|
96
|
+
size = write(ctx.buf, value, ctx.len + 4, edge.compression === 0);
|
|
90
97
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
ctx.buf[ctx.len++] = value >>>= 8;
|
|
104
|
-
ctx.buf[ctx.len++] = value >>>= 8;
|
|
105
|
-
ctx.buf[ctx.len++] = value >>>= 8;
|
|
98
|
+
let sizeU32 = size;
|
|
99
|
+
ctx.buf[ctx.len++] = sizeU32;
|
|
100
|
+
ctx.buf[ctx.len++] = sizeU32 >>>= 8;
|
|
101
|
+
ctx.buf[ctx.len++] = sizeU32 >>>= 8;
|
|
102
|
+
ctx.buf[ctx.len++] = sizeU32 >>>= 8;
|
|
103
|
+
ctx.len += size;
|
|
104
|
+
}
|
|
105
|
+
else if (edge.typeIndex === REFERENCE) {
|
|
106
|
+
// add null
|
|
107
|
+
if (typeof value !== 'number') {
|
|
108
|
+
if (value instanceof ModifyState) {
|
|
109
|
+
value = value.tmpId;
|
|
106
110
|
}
|
|
107
111
|
else {
|
|
108
112
|
return new ModifyError(edge, value);
|
|
109
113
|
}
|
|
110
114
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return new ModifyError(edge, value);
|
|
114
|
-
}
|
|
115
|
-
let size = value.length * 4;
|
|
116
|
-
if (ctx.len + EDGE_HEADER_SIZE + size > ctx.max) {
|
|
117
|
-
return RANGE_ERR;
|
|
118
|
-
}
|
|
119
|
-
ctx.buf[ctx.len++] = REFERENCES;
|
|
120
|
-
ctx.buf[ctx.len++] = size;
|
|
121
|
-
ctx.buf[ctx.len++] = size >>>= 8;
|
|
122
|
-
ctx.buf[ctx.len++] = size >>>= 8;
|
|
123
|
-
ctx.buf[ctx.len++] = size >>>= 8;
|
|
124
|
-
appendRefs(edge, ctx, value);
|
|
115
|
+
if (!edge.validation(value, edge)) {
|
|
116
|
+
return new ModifyError(edge, value);
|
|
125
117
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
ctx.buf[ctx.len++] = CARDINALITY;
|
|
136
|
-
writeHllBuf(value, ctx, edge, size);
|
|
118
|
+
if (value > 0) {
|
|
119
|
+
ctx.buf[ctx.len++] = REFERENCE;
|
|
120
|
+
ctx.buf[ctx.len++] = value;
|
|
121
|
+
ctx.buf[ctx.len++] = value >>>= 8;
|
|
122
|
+
ctx.buf[ctx.len++] = value >>>= 8;
|
|
123
|
+
ctx.buf[ctx.len++] = value >>>= 8;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
return new ModifyError(edge, value);
|
|
137
127
|
}
|
|
138
128
|
}
|
|
139
|
-
else {
|
|
140
|
-
|
|
141
|
-
if (
|
|
129
|
+
else if (edge.typeIndex === REFERENCES) {
|
|
130
|
+
// add null
|
|
131
|
+
if (!Array.isArray(value)) {
|
|
142
132
|
return new ModifyError(edge, value);
|
|
143
133
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
134
|
+
let size = value.length * 4;
|
|
135
|
+
if (ctx.len + EDGE_HEADER_SIZE + size > ctx.max) {
|
|
136
|
+
return RANGE_ERR;
|
|
147
137
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
138
|
+
ctx.buf[ctx.len++] = REFERENCES;
|
|
139
|
+
ctx.buf[ctx.len++] = size;
|
|
140
|
+
ctx.buf[ctx.len++] = size >>>= 8;
|
|
141
|
+
ctx.buf[ctx.len++] = size >>>= 8;
|
|
142
|
+
ctx.buf[ctx.len++] = size >>>= 8;
|
|
143
|
+
const err = appendEdgeRefs(edge, ctx, value);
|
|
144
|
+
if (err) {
|
|
145
|
+
return err;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else if (edge.typeIndex === CARDINALITY) {
|
|
149
|
+
// add null
|
|
150
|
+
if (!Array.isArray(value)) {
|
|
151
|
+
value = [value];
|
|
152
|
+
}
|
|
153
|
+
const len = value.length;
|
|
154
|
+
let size = 4 + len * 8;
|
|
155
|
+
if (ctx.len + size + EDGE_HEADER_SIZE > ctx.max) {
|
|
156
|
+
return RANGE_ERR;
|
|
157
|
+
}
|
|
158
|
+
ctx.buf[ctx.len++] = CARDINALITY;
|
|
159
|
+
writeHllBuf(value, ctx, edge, size);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
const op = valueOperation(value);
|
|
164
|
+
if (op === 0) {
|
|
165
|
+
return new ModifyError(edge, value);
|
|
166
|
+
}
|
|
167
|
+
if (op != UPDATE) {
|
|
168
|
+
hasIncr = true;
|
|
169
|
+
value = value.increment;
|
|
170
|
+
}
|
|
171
|
+
if (!hasIncr && t.edgeMainLen == edge.len) {
|
|
172
|
+
/*
|
|
173
|
+
Full main update:
|
|
174
|
+
|
|
175
|
+
| Offset | Field | Size (bytes)| Description |
|
|
176
|
+
|---------|-------------|-------------|---------------------------------------|
|
|
177
|
+
| 0 | modify op | 1 | Modify operation identifier |
|
|
178
|
+
| 1 | prop | 1 | Field identifier (0) |
|
|
179
|
+
| 2 | type | 1 | Indicates MICRO_BUFFER type |
|
|
180
|
+
| 3 | mainSize | 4 | Size of the main data in bytes |
|
|
181
|
+
| 7 | main buffer | Variable | Main data content |
|
|
182
|
+
*/
|
|
183
|
+
if (ctx.len + 7 + edge.len > ctx.max) {
|
|
184
|
+
return RANGE_ERR;
|
|
185
|
+
}
|
|
186
|
+
ctx.buf[ctx.len++] = UPDATE;
|
|
187
|
+
ctx.buf[ctx.len++] = 0;
|
|
188
|
+
ctx.buf[ctx.len++] = MICRO_BUFFER;
|
|
189
|
+
const size = edge.len;
|
|
190
|
+
let sizeU32 = size;
|
|
191
|
+
ctx.buf[ctx.len++] = sizeU32;
|
|
192
|
+
ctx.buf[ctx.len++] = sizeU32 >>>= 8;
|
|
193
|
+
ctx.buf[ctx.len++] = sizeU32 >>>= 8;
|
|
194
|
+
ctx.buf[ctx.len++] = sizeU32 >>>= 8;
|
|
195
|
+
const err = appendFixedValue(ctx, value, edge);
|
|
196
|
+
if (err) {
|
|
197
|
+
return err;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
mainSize += edge.len;
|
|
202
|
+
if (!mainFields) {
|
|
203
|
+
mainFields = [edge, value, op];
|
|
176
204
|
}
|
|
177
205
|
else {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
else if (mainFields[len - i - 3].start < edge.start) {
|
|
190
|
-
mainFields.splice(len - i, 0, edge, value, op);
|
|
191
|
-
break;
|
|
192
|
-
}
|
|
206
|
+
const len = mainFields.length;
|
|
207
|
+
for (let i = 0; i < len; i += 3) {
|
|
208
|
+
if (edge.start < mainFields[i].start) {
|
|
209
|
+
mainFields.splice(i, 0, edge, value, op);
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
else if (mainFields[len - i - 3].start < edge.start) {
|
|
213
|
+
mainFields.splice(len - i, 0, edge, value, op);
|
|
214
|
+
break;
|
|
193
215
|
}
|
|
194
216
|
}
|
|
195
217
|
}
|
|
@@ -246,13 +268,6 @@ export function writeEdges(t, ref, ctx) {
|
|
|
246
268
|
| 13 | propType | 1 | Prop typeIndex |
|
|
247
269
|
| ... | ... | ... | Additional (start, len) pairs |
|
|
248
270
|
| X | main | len | Actual main content |
|
|
249
|
-
|
|
250
|
-
### Notes:
|
|
251
|
-
- The number of `(start, len, operation)` pairs is not explicitly stored
|
|
252
|
-
but **derived** from the structure.
|
|
253
|
-
- Parsing logic must determine the end of pairs by computing:
|
|
254
|
-
`Pairs End Offset = (size - mainSize)`
|
|
255
|
-
Sections are processed until the `MAIN` data block begins.
|
|
256
271
|
*/
|
|
257
272
|
const mainFieldsStartSize = mainFields.length * 2;
|
|
258
273
|
if (ctx.len + 7 + mainSize + mainFieldsStartSize > ctx.max) {
|
|
@@ -261,48 +276,40 @@ export function writeEdges(t, ref, ctx) {
|
|
|
261
276
|
ctx.buf[ctx.len++] = UPDATE_PARTIAL;
|
|
262
277
|
ctx.buf[ctx.len++] = 0;
|
|
263
278
|
ctx.buf[ctx.len++] = MICRO_BUFFER;
|
|
264
|
-
|
|
265
|
-
ctx.buf[ctx.len++] =
|
|
266
|
-
ctx.buf[ctx.len++] =
|
|
267
|
-
ctx.buf[ctx.len++] =
|
|
268
|
-
ctx.buf[ctx.len++] =
|
|
269
|
-
|
|
270
|
-
ctx.buf[ctx.len++] =
|
|
271
|
-
ctx.buf[ctx.len++] = mainTotal >>>= 8;
|
|
279
|
+
const size = mainFieldsStartSize + t.edgeMainLen;
|
|
280
|
+
ctx.buf[ctx.len++] = size;
|
|
281
|
+
ctx.buf[ctx.len++] = size >>> 8;
|
|
282
|
+
ctx.buf[ctx.len++] = size >>> 16;
|
|
283
|
+
ctx.buf[ctx.len++] = size >>> 24;
|
|
284
|
+
ctx.buf[ctx.len++] = t.edgeMainLen;
|
|
285
|
+
ctx.buf[ctx.len++] = t.edgeMainLen >>> 8;
|
|
272
286
|
// Index of start of fields
|
|
273
287
|
const sIndex = ctx.len;
|
|
274
288
|
ctx.len += mainFieldsStartSize;
|
|
275
|
-
// this has to be replaced
|
|
276
289
|
// Add zeroes
|
|
277
290
|
ctx.buf.fill(0, ctx.len, ctx.len + t.edgeMainLen);
|
|
278
291
|
// Keep track of written bytes from append fixed
|
|
279
|
-
let writtenFields = 0;
|
|
280
|
-
// do this different...
|
|
281
292
|
let startMain = ctx.len;
|
|
282
293
|
for (let i = 0; i < mainFields.length; i += 3) {
|
|
283
294
|
const edge = mainFields[i];
|
|
284
295
|
const value = mainFields[i + 1];
|
|
285
296
|
const op = mainFields[i + 2];
|
|
286
|
-
const sIndexI = i + sIndex;
|
|
287
|
-
|
|
288
|
-
ctx.buf[sIndexI] = start;
|
|
289
|
-
ctx.buf[sIndexI +
|
|
290
|
-
|
|
291
|
-
ctx.buf[sIndexI + 2] = len;
|
|
292
|
-
ctx.buf[sIndexI + 3] = len >>>= 8;
|
|
297
|
+
const sIndexI = i * 2 + sIndex;
|
|
298
|
+
ctx.buf[sIndexI] = edge.start;
|
|
299
|
+
ctx.buf[sIndexI + 1] = edge.start >>> 8;
|
|
300
|
+
ctx.buf[sIndexI + 2] = edge.len;
|
|
301
|
+
ctx.buf[sIndexI + 3] = edge.len >>> 8;
|
|
293
302
|
ctx.buf[sIndexI + 4] = op;
|
|
294
303
|
ctx.buf[sIndexI + 5] = edge.typeIndex;
|
|
295
304
|
ctx.len = startMain + edge.start;
|
|
296
|
-
|
|
297
|
-
writtenFields = edge.start + edge.len;
|
|
298
|
-
}
|
|
305
|
+
// Add null support (defaults)
|
|
299
306
|
const err = appendFixedValue(ctx, value, edge);
|
|
300
307
|
if (err) {
|
|
301
308
|
return err;
|
|
302
309
|
}
|
|
303
310
|
}
|
|
304
|
-
// Correction
|
|
305
|
-
ctx.len
|
|
311
|
+
// Correction append fixed value writes the len
|
|
312
|
+
ctx.len = startMain + t.edgeMainLen;
|
|
306
313
|
}
|
|
307
314
|
}
|
|
308
315
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ModifyError, ModifyState } from '../ModifyRes.js';
|
|
2
2
|
import { setCursor } from '../setCursor.js';
|
|
3
|
-
import { DELETE, RANGE_ERR } from '../types.js';
|
|
3
|
+
import { DELETE, RANGE_ERR, EDGE_NOINDEX_TMPID, NOEDGE_NOINDEX_TMPID, EDGE_NOINDEX_REALID, NOEDGE_INDEX_REALID, } from '../types.js';
|
|
4
4
|
import { writeEdges } from './edge.js';
|
|
5
5
|
import { dbUpdateFromUpsert } from './references.js';
|
|
6
6
|
function writeRef(id, ctx, schema, def, parentId, modifyOp, hasEdges, isTmpId) {
|
|
@@ -11,10 +11,10 @@ function writeRef(id, ctx, schema, def, parentId, modifyOp, hasEdges, isTmpId) {
|
|
|
11
11
|
setCursor(ctx, schema, def.prop, def.typeIndex, parentId, modifyOp);
|
|
12
12
|
ctx.buf[ctx.len++] = modifyOp;
|
|
13
13
|
if (isTmpId) {
|
|
14
|
-
ctx.buf[ctx.len++] = hasEdges ?
|
|
14
|
+
ctx.buf[ctx.len++] = hasEdges ? EDGE_NOINDEX_TMPID : NOEDGE_NOINDEX_TMPID;
|
|
15
15
|
}
|
|
16
16
|
else {
|
|
17
|
-
ctx.buf[ctx.len++] = hasEdges ?
|
|
17
|
+
ctx.buf[ctx.len++] = hasEdges ? EDGE_NOINDEX_REALID : NOEDGE_INDEX_REALID;
|
|
18
18
|
}
|
|
19
19
|
ctx.buf[ctx.len++] = id;
|
|
20
20
|
ctx.buf[ctx.len++] = id >>>= 8;
|
|
@@ -42,7 +42,6 @@ function singleReferenceEdges(ref, ctx, schema, def, parentId, modifyOp) {
|
|
|
42
42
|
// TODO SINGLE REF
|
|
43
43
|
if (id > 0) {
|
|
44
44
|
if (def.edgesSeperateCnt === 0 && def.edgeMainLen === 0) {
|
|
45
|
-
// edgeMainLen, edgesSeperateCnt
|
|
46
45
|
return writeRef(id, ctx, schema, def, parentId, modifyOp, false, isTmpId);
|
|
47
46
|
}
|
|
48
47
|
else {
|
|
@@ -50,10 +49,7 @@ function singleReferenceEdges(ref, ctx, schema, def, parentId, modifyOp) {
|
|
|
50
49
|
if (err) {
|
|
51
50
|
return err;
|
|
52
51
|
}
|
|
53
|
-
//
|
|
54
|
-
// const edgesLen = getEdgeSize(def, ref)
|
|
55
|
-
// edgeMainLen can be done better
|
|
56
|
-
// TODO REOMVE - SEEMS REDUNDANT
|
|
52
|
+
// TODO REMOVE - SEEMS REDUNDANT
|
|
57
53
|
if (ctx.len + 4 > ctx.max) {
|
|
58
54
|
return RANGE_ERR;
|
|
59
55
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { REFERENCES } from '@based/schema/def';
|
|
2
2
|
import { ModifyError, ModifyState } from '../ModifyRes.js';
|
|
3
3
|
import { setCursor } from '../setCursor.js';
|
|
4
|
-
import { DELETE, RANGE_ERR } from '../types.js';
|
|
4
|
+
import { DELETE, EDGE_INDEX_REALID, EDGE_INDEX_TMPID, EDGE_NOINDEX_REALID, EDGE_NOINDEX_TMPID, NOEDGE_INDEX_REALID, NOEDGE_INDEX_TMPID, NOEDGE_NOINDEX_REALID, NOEDGE_NOINDEX_TMPID, RANGE_ERR, REF_OP_UPDATE, } from '../types.js';
|
|
5
5
|
import { writeEdges } from './edge.js';
|
|
6
6
|
export function writeReferences(value, ctx, schema, def, res, mod) {
|
|
7
7
|
if (typeof value !== 'object') {
|
|
@@ -28,13 +28,9 @@ export function writeReferences(value, ctx, schema, def, res, mod) {
|
|
|
28
28
|
err = deleteRefs(def, ctx, schema, mod, val, res.tmpId);
|
|
29
29
|
}
|
|
30
30
|
else if (key === 'update') {
|
|
31
|
-
// and add add: []
|
|
32
|
-
// replace this with update
|
|
33
31
|
err = updateRefs(def, ctx, schema, mod, val, res.tmpId, 1);
|
|
34
32
|
}
|
|
35
33
|
else if (key === 'add') {
|
|
36
|
-
// and add add: []
|
|
37
|
-
// replace this with update
|
|
38
34
|
err = updateRefs(def, ctx, schema, mod, val, res.tmpId, 1);
|
|
39
35
|
}
|
|
40
36
|
else if (key === 'upsert') {
|
|
@@ -104,7 +100,6 @@ function updateRefs(def, ctx, schema, mod, refs, parentId, op) {
|
|
|
104
100
|
if (nrOrErr) {
|
|
105
101
|
if (typeof nrOrErr === 'number') {
|
|
106
102
|
if (nrOrErr === refs.length) {
|
|
107
|
-
// reset
|
|
108
103
|
ctx.len = initpos;
|
|
109
104
|
}
|
|
110
105
|
else if (ctx.len + 2 > ctx.max) {
|
|
@@ -128,7 +123,8 @@ function appendRefs(def, ctx, modifyOp, refs, op, remaining) {
|
|
|
128
123
|
let i = refs.length - remaining;
|
|
129
124
|
let totalpos = ctx.len;
|
|
130
125
|
ctx.len += 4;
|
|
131
|
-
|
|
126
|
+
// if it just did a PUT, it should ADD not overwrite the remaining
|
|
127
|
+
ctx.buf[ctx.len++] = i === 0 ? op : REF_OP_UPDATE;
|
|
132
128
|
ctx.buf[ctx.len++] = remaining;
|
|
133
129
|
ctx.buf[ctx.len++] = remaining >>>= 8;
|
|
134
130
|
ctx.buf[ctx.len++] = remaining >>>= 8;
|
|
@@ -183,12 +179,12 @@ function appendRefs(def, ctx, modifyOp, refs, op, remaining) {
|
|
|
183
179
|
if (!def.validation(id, def)) {
|
|
184
180
|
return new ModifyError(def, refs);
|
|
185
181
|
}
|
|
186
|
-
if (hasEdges) {
|
|
182
|
+
if (hasEdges && typeof ref === 'object' && !(ref instanceof ModifyState)) {
|
|
187
183
|
if (index === undefined) {
|
|
188
184
|
if (ctx.len + 9 > ctx.max) {
|
|
189
185
|
return RANGE_ERR;
|
|
190
186
|
}
|
|
191
|
-
ctx.buf[ctx.len++] = isTmpId ?
|
|
187
|
+
ctx.buf[ctx.len++] = isTmpId ? EDGE_NOINDEX_TMPID : EDGE_NOINDEX_REALID;
|
|
192
188
|
ctx.buf[ctx.len++] = id;
|
|
193
189
|
ctx.buf[ctx.len++] = id >>>= 8;
|
|
194
190
|
ctx.buf[ctx.len++] = id >>>= 8;
|
|
@@ -198,7 +194,7 @@ function appendRefs(def, ctx, modifyOp, refs, op, remaining) {
|
|
|
198
194
|
if (ctx.len + 13 > ctx.max) {
|
|
199
195
|
return RANGE_ERR;
|
|
200
196
|
}
|
|
201
|
-
ctx.buf[ctx.len++] = isTmpId ?
|
|
197
|
+
ctx.buf[ctx.len++] = isTmpId ? EDGE_INDEX_TMPID : EDGE_INDEX_REALID;
|
|
202
198
|
ctx.buf[ctx.len++] = id;
|
|
203
199
|
ctx.buf[ctx.len++] = id >>>= 8;
|
|
204
200
|
ctx.buf[ctx.len++] = id >>>= 8;
|
|
@@ -227,7 +223,9 @@ function appendRefs(def, ctx, modifyOp, refs, op, remaining) {
|
|
|
227
223
|
if (ctx.len + 5 > ctx.max) {
|
|
228
224
|
return RANGE_ERR;
|
|
229
225
|
}
|
|
230
|
-
ctx.buf[ctx.len++] = isTmpId
|
|
226
|
+
ctx.buf[ctx.len++] = isTmpId
|
|
227
|
+
? NOEDGE_NOINDEX_TMPID
|
|
228
|
+
: NOEDGE_NOINDEX_REALID;
|
|
231
229
|
ctx.buf[ctx.len++] = id;
|
|
232
230
|
ctx.buf[ctx.len++] = id >>>= 8;
|
|
233
231
|
ctx.buf[ctx.len++] = id >>>= 8;
|
|
@@ -237,7 +235,7 @@ function appendRefs(def, ctx, modifyOp, refs, op, remaining) {
|
|
|
237
235
|
if (ctx.len + 9 > ctx.max) {
|
|
238
236
|
return RANGE_ERR;
|
|
239
237
|
}
|
|
240
|
-
ctx.buf[ctx.len++] = isTmpId ?
|
|
238
|
+
ctx.buf[ctx.len++] = isTmpId ? NOEDGE_INDEX_TMPID : NOEDGE_INDEX_REALID;
|
|
241
239
|
ctx.buf[ctx.len++] = id;
|
|
242
240
|
ctx.buf[ctx.len++] = id >>>= 8;
|
|
243
241
|
ctx.buf[ctx.len++] = id >>>= 8;
|
|
@@ -260,6 +258,9 @@ function appendRefs(def, ctx, modifyOp, refs, op, remaining) {
|
|
|
260
258
|
}
|
|
261
259
|
function putRefs(def, ctx, modifyOp, refs, op) {
|
|
262
260
|
let size = refs.length * 4 + 1;
|
|
261
|
+
if (refs.length === 0) {
|
|
262
|
+
return 0;
|
|
263
|
+
}
|
|
263
264
|
ctx.buf[ctx.len++] = modifyOp;
|
|
264
265
|
ctx.buf[ctx.len++] = size;
|
|
265
266
|
ctx.buf[ctx.len++] = size >>>= 8;
|
|
@@ -272,7 +273,7 @@ function putRefs(def, ctx, modifyOp, refs, op) {
|
|
|
272
273
|
let ref = refs[i];
|
|
273
274
|
if (typeof ref === 'number') {
|
|
274
275
|
if (!def.validation(ref, def)) {
|
|
275
|
-
|
|
276
|
+
return new ModifyError(def, ref);
|
|
276
277
|
}
|
|
277
278
|
else {
|
|
278
279
|
ctx.buf[ctx.len++] = ref;
|
|
@@ -286,9 +287,12 @@ function putRefs(def, ctx, modifyOp, refs, op) {
|
|
|
286
287
|
return ref.error;
|
|
287
288
|
}
|
|
288
289
|
ref = ref.getId();
|
|
289
|
-
if (!
|
|
290
|
+
if (!ref) {
|
|
290
291
|
break;
|
|
291
292
|
}
|
|
293
|
+
if (!def.validation(ref, def)) {
|
|
294
|
+
return new ModifyError(def, ref);
|
|
295
|
+
}
|
|
292
296
|
ctx.buf[ctx.len++] = ref;
|
|
293
297
|
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
294
298
|
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
@@ -25,9 +25,6 @@ export function writeString(lang, value, ctx, def, t, parentId, modifyOp) {
|
|
|
25
25
|
? value.byteLength
|
|
26
26
|
: ENCODER.encode(value).byteLength + 6;
|
|
27
27
|
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 11 + size > ctx.max) {
|
|
28
|
-
// +10 OR +11, the original check was +20 but
|
|
29
|
-
// there are 10 addtional bytes in this scope
|
|
30
|
-
// 5 compression size
|
|
31
28
|
return RANGE_ERR;
|
|
32
29
|
}
|
|
33
30
|
if (modifyOp === CREATE) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { langCodesMap } from '@based/schema';
|
|
2
1
|
import { CREATE, UPDATE, RANGE_ERR, DELETE, } from './types.js';
|
|
3
2
|
import { writeString } from './string.js';
|
|
4
3
|
import { ModifyError } from './ModifyRes.js';
|
|
@@ -14,9 +13,18 @@ export function writeText(value, ctx, def, t, res, parentId, modifyOp) {
|
|
|
14
13
|
}
|
|
15
14
|
return;
|
|
16
15
|
}
|
|
17
|
-
// todo proper fallback as well
|
|
18
16
|
if ((value && typeof value !== 'object') || value === null) {
|
|
19
|
-
|
|
17
|
+
let locale = res.locale;
|
|
18
|
+
if (!locale) {
|
|
19
|
+
// TODO: Add def lang option...
|
|
20
|
+
for (const localeCode of def.seperateTextSort.localeToIndex.keys()) {
|
|
21
|
+
locale = localeCode;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (!def.seperateTextSort.localeToIndex.has(locale)) {
|
|
26
|
+
return new ModifyError(t, locale, 'Invalid locale');
|
|
27
|
+
}
|
|
20
28
|
if (value == null) {
|
|
21
29
|
// @ts-ignore
|
|
22
30
|
value = '';
|
|
@@ -26,3 +26,14 @@ export type ModifyOpts = {
|
|
|
26
26
|
locale?: LangName;
|
|
27
27
|
overwrite?: boolean;
|
|
28
28
|
};
|
|
29
|
+
export declare const NOEDGE_NOINDEX_REALID = 0;
|
|
30
|
+
export declare const EDGE_NOINDEX_REALID = 1;
|
|
31
|
+
export declare const EDGE_INDEX_REALID = 2;
|
|
32
|
+
export declare const NOEDGE_INDEX_REALID = 3;
|
|
33
|
+
export declare const NOEDGE_NOINDEX_TMPID = 4;
|
|
34
|
+
export declare const EDGE_NOINDEX_TMPID = 5;
|
|
35
|
+
export declare const EDGE_INDEX_TMPID = 6;
|
|
36
|
+
export declare const NOEDGE_INDEX_TMPID = 7;
|
|
37
|
+
export declare const REF_OP_UPDATE = 1;
|
|
38
|
+
export declare const REF_OP_OVERWRITE = 0;
|
|
39
|
+
export type REF_OP = typeof REF_OP_OVERWRITE | typeof REF_OP_UPDATE;
|
|
@@ -14,4 +14,14 @@ export const SWITCH_TYPE = 2;
|
|
|
14
14
|
export const SWITCH_FIELD = 0;
|
|
15
15
|
export const SWITCH_ID_CREATE = 9;
|
|
16
16
|
export const SWITCH_ID_UPDATE = 1;
|
|
17
|
+
export const NOEDGE_NOINDEX_REALID = 0;
|
|
18
|
+
export const EDGE_NOINDEX_REALID = 1;
|
|
19
|
+
export const EDGE_INDEX_REALID = 2;
|
|
20
|
+
export const NOEDGE_INDEX_REALID = 3;
|
|
21
|
+
export const NOEDGE_NOINDEX_TMPID = 4;
|
|
22
|
+
export const EDGE_NOINDEX_TMPID = 5;
|
|
23
|
+
export const EDGE_INDEX_TMPID = 6;
|
|
24
|
+
export const NOEDGE_INDEX_TMPID = 7;
|
|
25
|
+
export const REF_OP_UPDATE = 1;
|
|
26
|
+
export const REF_OP_OVERWRITE = 0;
|
|
17
27
|
//# sourceMappingURL=types.js.map
|