@based/db 0.0.27 → 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
|
@@ -40,8 +40,13 @@ enum SelvaSortOrder {
|
|
|
40
40
|
SELVA_SORT_ORDER_TEXT_DESC,
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
+
struct SelvaSortItem;
|
|
43
44
|
struct SelvaSortCtx;
|
|
44
45
|
|
|
46
|
+
struct SelvaSortIterator {
|
|
47
|
+
struct SelvaSortItem *next;
|
|
48
|
+
};
|
|
49
|
+
|
|
45
50
|
SELVA_EXPORT
|
|
46
51
|
struct SelvaSortCtx *selva_sort_init(enum SelvaSortOrder order);
|
|
47
52
|
|
|
@@ -91,43 +96,45 @@ SELVA_EXPORT
|
|
|
91
96
|
void selva_sort_remove_text(struct SelvaSortCtx *ctx, const char *str, size_t len, const void *p);
|
|
92
97
|
|
|
93
98
|
SELVA_EXPORT
|
|
94
|
-
void selva_sort_foreach_begin(struct SelvaSortCtx *ctx);
|
|
99
|
+
void selva_sort_foreach_begin(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it);
|
|
95
100
|
|
|
96
101
|
SELVA_EXPORT
|
|
97
|
-
void selva_sort_foreach_begin_reverse(struct SelvaSortCtx *ctx);
|
|
102
|
+
void selva_sort_foreach_begin_reverse(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it);
|
|
98
103
|
|
|
99
104
|
SELVA_EXPORT
|
|
100
|
-
void *selva_sort_foreach(struct SelvaSortCtx *ctx);
|
|
105
|
+
void *selva_sort_foreach(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it);
|
|
101
106
|
|
|
102
107
|
SELVA_EXPORT
|
|
103
|
-
void *selva_sort_foreach_reverse(struct SelvaSortCtx *ctx);
|
|
108
|
+
void *selva_sort_foreach_reverse(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it);
|
|
104
109
|
|
|
105
110
|
SELVA_EXPORT
|
|
106
|
-
void *selva_sort_foreach_i64(struct SelvaSortCtx *ctx, int64_t *v);
|
|
111
|
+
void *selva_sort_foreach_i64(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it, int64_t *v);
|
|
107
112
|
|
|
108
113
|
SELVA_EXPORT
|
|
109
|
-
void *selva_sort_foreach_i64_reverse(struct SelvaSortCtx *ctx, int64_t *v);
|
|
114
|
+
void *selva_sort_foreach_i64_reverse(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it, int64_t *v);
|
|
110
115
|
|
|
111
116
|
SELVA_EXPORT
|
|
112
|
-
void *selva_sort_foreach_float(struct SelvaSortCtx *ctx, float *f);
|
|
117
|
+
void *selva_sort_foreach_float(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it, float *f);
|
|
113
118
|
|
|
114
119
|
SELVA_EXPORT
|
|
115
|
-
void *selva_sort_foreach_float_reverse(struct SelvaSortCtx *ctx, float *f);
|
|
120
|
+
void *selva_sort_foreach_float_reverse(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it, float *f);
|
|
116
121
|
|
|
117
122
|
SELVA_EXPORT
|
|
118
|
-
void *selva_sort_foreach_double(struct SelvaSortCtx *ctx, double *d);
|
|
123
|
+
void *selva_sort_foreach_double(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it, double *d);
|
|
119
124
|
|
|
120
125
|
SELVA_EXPORT
|
|
121
|
-
void *selva_sort_foreach_double_reverse(struct SelvaSortCtx *ctx, double *d);
|
|
126
|
+
void *selva_sort_foreach_double_reverse(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it, double *d);
|
|
122
127
|
|
|
123
128
|
SELVA_EXPORT
|
|
124
|
-
void *selva_sort_foreach_buffer(struct SelvaSortCtx *ctx, void **buf, size_t *len);
|
|
129
|
+
void *selva_sort_foreach_buffer(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it, void **buf, size_t *len);
|
|
125
130
|
|
|
126
131
|
SELVA_EXPORT
|
|
127
|
-
void *selva_sort_foreach_buffer_reverse(struct SelvaSortCtx *ctx, void **buf, size_t *len);
|
|
132
|
+
void *selva_sort_foreach_buffer_reverse(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it, void **buf, size_t *len);
|
|
128
133
|
|
|
129
|
-
|
|
130
|
-
|
|
134
|
+
static inline bool selva_sort_foreach_done(struct SelvaSortIterator *it)
|
|
135
|
+
{
|
|
136
|
+
return !it->next;
|
|
137
|
+
}
|
|
131
138
|
|
|
132
139
|
SELVA_EXPORT
|
|
133
140
|
int selva_sort_defrag(struct SelvaSortCtx *ctx);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
#pragma once
|
|
6
6
|
|
|
7
|
+
#include <assert.h>
|
|
7
8
|
#include <sys/types.h>
|
|
8
9
|
#include "selva/_export.h"
|
|
9
10
|
#include "selva/types.h"
|
|
@@ -179,13 +180,16 @@ inline enum SelvaFieldType selva_get_fs_type(const struct SelvaFieldSchema *fs)
|
|
|
179
180
|
* struct SelvaFieldSchema *dst_fs = selva_get_fs_by_node(db, dst, efc->inverse_field);
|
|
180
181
|
*/
|
|
181
182
|
SELVA_EXPORT
|
|
183
|
+
__attribute__((returns_nonnull))
|
|
182
184
|
__attribute__((nonnull))
|
|
183
185
|
inline const struct EdgeFieldConstraint *selva_get_edge_field_constraint(const struct SelvaFieldSchema *fs)
|
|
184
186
|
#ifndef __zig
|
|
185
187
|
{
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
188
|
+
assert(fs->type == SELVA_FIELD_TYPE_REFERENCE ||
|
|
189
|
+
fs->type == SELVA_FIELD_TYPE_REFERENCES ||
|
|
190
|
+
fs->type == SELVA_FIELD_TYPE_WEAK_REFERENCE ||
|
|
191
|
+
fs->type == SELVA_FIELD_TYPE_WEAK_REFERENCES);
|
|
192
|
+
return &fs->edge_constraint;
|
|
189
193
|
}
|
|
190
194
|
#else
|
|
191
195
|
;
|
|
@@ -349,7 +353,7 @@ SELVA_EXPORT
|
|
|
349
353
|
selva_hash128_t selva_node_hash(struct SelvaDb *db, struct SelvaTypeEntry *type, struct SelvaNode *node);
|
|
350
354
|
|
|
351
355
|
SELVA_EXPORT
|
|
352
|
-
|
|
356
|
+
int selva_node_hash_range(struct SelvaDb *db, struct SelvaTypeEntry *type, node_id_t start, node_id_t end, selva_hash128_t *hash_out) __attribute__((nonnull, warn_unused_result));
|
|
353
357
|
|
|
354
358
|
/**
|
|
355
359
|
* @}
|
|
@@ -1,25 +1,33 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright (c) 2024 SAULX
|
|
2
|
+
* Copyright (c) 2024-2025 SAULX
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
#pragma once
|
|
6
6
|
#include "xxhash.h"
|
|
7
|
+
#include "jemalloc_selva.h"
|
|
7
8
|
#include "selva/types.h"
|
|
8
9
|
|
|
9
10
|
typedef struct XXH3_state_s selva_hash_state_t;
|
|
10
11
|
|
|
11
|
-
#define selva_hash_create_state XXH3_createState
|
|
12
12
|
#define selva_hash_reset XXH3_128bits_reset
|
|
13
|
-
#define selva_hash_free_state XXH3_freeState
|
|
14
13
|
#define selva_hash_update XXH3_128bits_update
|
|
15
14
|
|
|
16
15
|
SELVA_EXPORT
|
|
17
|
-
|
|
16
|
+
selva_hash_state_t *selva_hash_create_state(void);
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
SELVA_EXPORT
|
|
19
|
+
inline void selva_hash_free_state(selva_hash_state_t *state)
|
|
20
|
+
#ifndef __zig
|
|
21
|
+
{
|
|
22
|
+
selva_free(state);
|
|
23
|
+
}
|
|
21
24
|
#else
|
|
22
|
-
|
|
25
|
+
;
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
SELVA_EXPORT
|
|
29
|
+
inline selva_hash128_t selva_hash_digest(selva_hash_state_t *hash_state)
|
|
30
|
+
#ifndef __zig
|
|
23
31
|
{
|
|
24
32
|
XXH128_hash_t res;
|
|
25
33
|
|
|
@@ -36,4 +44,6 @@ retry:
|
|
|
36
44
|
|
|
37
45
|
return (selva_hash128_t)res.low64 | (selva_hash128_t)res.high64 << 64;
|
|
38
46
|
}
|
|
47
|
+
#else
|
|
48
|
+
;
|
|
39
49
|
#endif
|
|
@@ -40,8 +40,13 @@ enum SelvaSortOrder {
|
|
|
40
40
|
SELVA_SORT_ORDER_TEXT_DESC,
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
+
struct SelvaSortItem;
|
|
43
44
|
struct SelvaSortCtx;
|
|
44
45
|
|
|
46
|
+
struct SelvaSortIterator {
|
|
47
|
+
struct SelvaSortItem *next;
|
|
48
|
+
};
|
|
49
|
+
|
|
45
50
|
SELVA_EXPORT
|
|
46
51
|
struct SelvaSortCtx *selva_sort_init(enum SelvaSortOrder order);
|
|
47
52
|
|
|
@@ -91,43 +96,45 @@ SELVA_EXPORT
|
|
|
91
96
|
void selva_sort_remove_text(struct SelvaSortCtx *ctx, const char *str, size_t len, const void *p);
|
|
92
97
|
|
|
93
98
|
SELVA_EXPORT
|
|
94
|
-
void selva_sort_foreach_begin(struct SelvaSortCtx *ctx);
|
|
99
|
+
void selva_sort_foreach_begin(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it);
|
|
95
100
|
|
|
96
101
|
SELVA_EXPORT
|
|
97
|
-
void selva_sort_foreach_begin_reverse(struct SelvaSortCtx *ctx);
|
|
102
|
+
void selva_sort_foreach_begin_reverse(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it);
|
|
98
103
|
|
|
99
104
|
SELVA_EXPORT
|
|
100
|
-
void *selva_sort_foreach(struct SelvaSortCtx *ctx);
|
|
105
|
+
void *selva_sort_foreach(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it);
|
|
101
106
|
|
|
102
107
|
SELVA_EXPORT
|
|
103
|
-
void *selva_sort_foreach_reverse(struct SelvaSortCtx *ctx);
|
|
108
|
+
void *selva_sort_foreach_reverse(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it);
|
|
104
109
|
|
|
105
110
|
SELVA_EXPORT
|
|
106
|
-
void *selva_sort_foreach_i64(struct SelvaSortCtx *ctx, int64_t *v);
|
|
111
|
+
void *selva_sort_foreach_i64(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it, int64_t *v);
|
|
107
112
|
|
|
108
113
|
SELVA_EXPORT
|
|
109
|
-
void *selva_sort_foreach_i64_reverse(struct SelvaSortCtx *ctx, int64_t *v);
|
|
114
|
+
void *selva_sort_foreach_i64_reverse(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it, int64_t *v);
|
|
110
115
|
|
|
111
116
|
SELVA_EXPORT
|
|
112
|
-
void *selva_sort_foreach_float(struct SelvaSortCtx *ctx, float *f);
|
|
117
|
+
void *selva_sort_foreach_float(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it, float *f);
|
|
113
118
|
|
|
114
119
|
SELVA_EXPORT
|
|
115
|
-
void *selva_sort_foreach_float_reverse(struct SelvaSortCtx *ctx, float *f);
|
|
120
|
+
void *selva_sort_foreach_float_reverse(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it, float *f);
|
|
116
121
|
|
|
117
122
|
SELVA_EXPORT
|
|
118
|
-
void *selva_sort_foreach_double(struct SelvaSortCtx *ctx, double *d);
|
|
123
|
+
void *selva_sort_foreach_double(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it, double *d);
|
|
119
124
|
|
|
120
125
|
SELVA_EXPORT
|
|
121
|
-
void *selva_sort_foreach_double_reverse(struct SelvaSortCtx *ctx, double *d);
|
|
126
|
+
void *selva_sort_foreach_double_reverse(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it, double *d);
|
|
122
127
|
|
|
123
128
|
SELVA_EXPORT
|
|
124
|
-
void *selva_sort_foreach_buffer(struct SelvaSortCtx *ctx, void **buf, size_t *len);
|
|
129
|
+
void *selva_sort_foreach_buffer(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it, void **buf, size_t *len);
|
|
125
130
|
|
|
126
131
|
SELVA_EXPORT
|
|
127
|
-
void *selva_sort_foreach_buffer_reverse(struct SelvaSortCtx *ctx, void **buf, size_t *len);
|
|
132
|
+
void *selva_sort_foreach_buffer_reverse(struct SelvaSortCtx *ctx, struct SelvaSortIterator *it, void **buf, size_t *len);
|
|
128
133
|
|
|
129
|
-
|
|
130
|
-
|
|
134
|
+
static inline bool selva_sort_foreach_done(struct SelvaSortIterator *it)
|
|
135
|
+
{
|
|
136
|
+
return !it->next;
|
|
137
|
+
}
|
|
131
138
|
|
|
132
139
|
SELVA_EXPORT
|
|
133
140
|
int selva_sort_defrag(struct SelvaSortCtx *ctx);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -7,8 +7,8 @@ export declare class ModifyCtx {
|
|
|
7
7
|
id: number;
|
|
8
8
|
hasSortField: number;
|
|
9
9
|
hasSortText: number;
|
|
10
|
-
queue: Map<(payload: any) => void, ModifyState>;
|
|
11
10
|
ctx: {
|
|
11
|
+
queue?: Map<(payload: any) => void, ModifyState>;
|
|
12
12
|
offsets?: Record<number, number>;
|
|
13
13
|
};
|
|
14
14
|
payload: Uint8Array;
|
|
@@ -14,8 +14,7 @@ export class ModifyCtx {
|
|
|
14
14
|
id = -1;
|
|
15
15
|
hasSortField = -1;
|
|
16
16
|
hasSortText = -1;
|
|
17
|
-
|
|
18
|
-
ctx = {}; // maybe make this different?
|
|
17
|
+
ctx = {};
|
|
19
18
|
payload;
|
|
20
19
|
max;
|
|
21
20
|
buf;
|
|
@@ -95,7 +94,6 @@ export const flushBuffer = (db) => {
|
|
|
95
94
|
const lastIds = {};
|
|
96
95
|
const data = ctx.getData(lastIds);
|
|
97
96
|
const resCtx = ctx.ctx;
|
|
98
|
-
const queue = ctx.queue;
|
|
99
97
|
flushPromise = db.hooks.flushModify(data).then(({ offsets }) => {
|
|
100
98
|
resCtx.offsets = offsets;
|
|
101
99
|
for (const typeId in lastIds) {
|
|
@@ -112,15 +110,15 @@ export const flushBuffer = (db) => {
|
|
|
112
110
|
console.warn('no offset returned, very wrong');
|
|
113
111
|
}
|
|
114
112
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
});
|
|
113
|
+
if (resCtx.queue?.size) {
|
|
114
|
+
const queue = resCtx.queue;
|
|
115
|
+
resCtx.queue = null;
|
|
116
|
+
for (const [resolve, res] of queue) {
|
|
117
|
+
resolve(res.getId());
|
|
118
|
+
}
|
|
122
119
|
}
|
|
123
|
-
db.
|
|
120
|
+
db.writeTime += Date.now() - d;
|
|
121
|
+
db.flushReady();
|
|
124
122
|
});
|
|
125
123
|
ctx.dirtyTypes.clear();
|
|
126
124
|
ctx.dirtyRanges.clear();
|
|
@@ -131,17 +129,14 @@ export const flushBuffer = (db) => {
|
|
|
131
129
|
ctx.ctx = {};
|
|
132
130
|
}
|
|
133
131
|
else {
|
|
134
|
-
db.
|
|
132
|
+
db.flushReady();
|
|
135
133
|
}
|
|
136
134
|
db.isDraining = false;
|
|
137
135
|
return flushPromise;
|
|
138
136
|
};
|
|
139
137
|
export const startDrain = (db) => {
|
|
140
|
-
db.hooks.flushIsReady = new Promise((resolve) => {
|
|
141
|
-
db.hooks.flushReady = resolve;
|
|
142
|
-
});
|
|
143
138
|
db.isDraining = true;
|
|
144
|
-
if (db.
|
|
139
|
+
if (db.flushTime === 0) {
|
|
145
140
|
process.nextTick(() => {
|
|
146
141
|
flushBuffer(db);
|
|
147
142
|
});
|
|
@@ -149,7 +144,7 @@ export const startDrain = (db) => {
|
|
|
149
144
|
else {
|
|
150
145
|
setTimeout(() => {
|
|
151
146
|
flushBuffer(db);
|
|
152
|
-
}, db.
|
|
147
|
+
}, db.flushTime);
|
|
153
148
|
}
|
|
154
149
|
};
|
|
155
150
|
//# sourceMappingURL=flushModify.js.map
|
|
@@ -13,20 +13,22 @@ export type DbClientHooks = {
|
|
|
13
13
|
flushModify(buf: Uint8Array): Promise<{
|
|
14
14
|
offsets: Record<number, number>;
|
|
15
15
|
}>;
|
|
16
|
-
flushIsReady: Promise<any>;
|
|
17
|
-
flushReady: (v?: any) => void;
|
|
18
16
|
getQueryBuf(buf: Uint8Array): Promise<Uint8Array>;
|
|
19
|
-
flushTime: number;
|
|
20
17
|
};
|
|
21
18
|
type DbClientOpts = {
|
|
22
19
|
hooks: DbClientHooks;
|
|
23
20
|
maxModifySize?: number;
|
|
21
|
+
flushTime?: number;
|
|
22
|
+
debug?: boolean;
|
|
24
23
|
};
|
|
25
24
|
type DbClientSchema = StrictSchema & {
|
|
26
25
|
lastId: number;
|
|
27
26
|
};
|
|
28
27
|
export declare class DbClient {
|
|
29
|
-
constructor({ hooks, maxModifySize }: DbClientOpts);
|
|
28
|
+
constructor({ hooks, maxModifySize, flushTime, debug, }: DbClientOpts);
|
|
29
|
+
flushTime: number;
|
|
30
|
+
flushReady: () => void;
|
|
31
|
+
flushIsReady: Promise<void>;
|
|
30
32
|
hooks: DbClientHooks;
|
|
31
33
|
schema: DbClientSchema;
|
|
32
34
|
schemaIsSetValue: boolean;
|
package/dist/src/client/index.js
CHANGED
|
@@ -10,12 +10,29 @@ import { deleteFn } from './modify/delete.js';
|
|
|
10
10
|
import { deepEqual } from '@saulx/utils';
|
|
11
11
|
import { hash } from '@saulx/hash';
|
|
12
12
|
import { expire } from './modify/expire.js';
|
|
13
|
+
import { debugMode } from '../utils.js';
|
|
14
|
+
const makeFlushIsReady = (dbClient) => {
|
|
15
|
+
dbClient.flushIsReady = new Promise((resolve) => {
|
|
16
|
+
dbClient.flushReady = () => {
|
|
17
|
+
resolve();
|
|
18
|
+
makeFlushIsReady(dbClient);
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
};
|
|
13
22
|
export class DbClient {
|
|
14
|
-
constructor({ hooks, maxModifySize = 100 * 1e3 * 1e3 }) {
|
|
23
|
+
constructor({ hooks, maxModifySize = 100 * 1e3 * 1e3, flushTime = 0, debug, }) {
|
|
15
24
|
this.hooks = hooks;
|
|
16
25
|
this.maxModifySize = maxModifySize;
|
|
17
26
|
this.modifyCtx = new ModifyCtx(this);
|
|
27
|
+
this.flushTime = flushTime;
|
|
28
|
+
makeFlushIsReady(this);
|
|
29
|
+
if (debug) {
|
|
30
|
+
debugMode(this);
|
|
31
|
+
}
|
|
18
32
|
}
|
|
33
|
+
flushTime;
|
|
34
|
+
flushReady;
|
|
35
|
+
flushIsReady;
|
|
19
36
|
hooks;
|
|
20
37
|
schema = {
|
|
21
38
|
lastId: 1, // we reserve one for root props
|
|
@@ -185,7 +202,7 @@ export class DbClient {
|
|
|
185
202
|
if (!this.isDraining) {
|
|
186
203
|
startDrain(this);
|
|
187
204
|
}
|
|
188
|
-
await this.
|
|
205
|
+
await this.flushIsReady;
|
|
189
206
|
return;
|
|
190
207
|
}
|
|
191
208
|
schemaIsSet() {
|
|
@@ -20,6 +20,6 @@ export declare class ModifyState {
|
|
|
20
20
|
error?: ModifyError;
|
|
21
21
|
promises?: Promise<any>[];
|
|
22
22
|
getId(): number;
|
|
23
|
-
then(resolve: any, reject: any): Promise<
|
|
23
|
+
then(resolve: any, reject: any): Promise<any>;
|
|
24
24
|
catch(handler: any): this | Promise<unknown>;
|
|
25
25
|
}
|
|
@@ -45,7 +45,6 @@ export class ModifyState {
|
|
|
45
45
|
constructor(typeId, tmpId, db, subMarkers, opts, update = false) {
|
|
46
46
|
this.tmpId = tmpId;
|
|
47
47
|
this.#typeId = typeId;
|
|
48
|
-
this.#buf = db.modifyCtx;
|
|
49
48
|
this.#ctx = db.modifyCtx.ctx;
|
|
50
49
|
this.subMarkers = subMarkers;
|
|
51
50
|
this.update = update;
|
|
@@ -56,7 +55,6 @@ export class ModifyState {
|
|
|
56
55
|
subMarkers;
|
|
57
56
|
update;
|
|
58
57
|
locale;
|
|
59
|
-
#buf;
|
|
60
58
|
#ctx;
|
|
61
59
|
#typeId;
|
|
62
60
|
tmpId;
|
|
@@ -71,26 +69,24 @@ export class ModifyState {
|
|
|
71
69
|
return this.tmpId + offset;
|
|
72
70
|
}
|
|
73
71
|
}
|
|
74
|
-
then(resolve, reject) {
|
|
75
|
-
const promise = new Promise((resolve) => {
|
|
76
|
-
if (this.error) {
|
|
77
|
-
reject(new Error(this.error.toString()));
|
|
78
|
-
}
|
|
79
|
-
else if ('offsets' in this.#ctx) {
|
|
80
|
-
resolve(this.getId());
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
this.#buf.queue.set(resolve, this);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
72
|
+
async then(resolve, reject) {
|
|
86
73
|
if (this.promises?.length) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
74
|
+
await Promise.allSettled(this.promises);
|
|
75
|
+
}
|
|
76
|
+
let promise;
|
|
77
|
+
if (this.error) {
|
|
78
|
+
promise = Promise.reject(new Error(this.error.toString()));
|
|
79
|
+
}
|
|
80
|
+
else if ('offsets' in this.#ctx) {
|
|
81
|
+
promise = Promise.resolve(this.getId());
|
|
90
82
|
}
|
|
91
83
|
else {
|
|
92
|
-
|
|
84
|
+
promise = new Promise((resolve) => {
|
|
85
|
+
this.#ctx.queue ??= new Map();
|
|
86
|
+
this.#ctx.queue.set(resolve, this);
|
|
87
|
+
});
|
|
93
88
|
}
|
|
89
|
+
return promise.then(resolve, reject);
|
|
94
90
|
}
|
|
95
91
|
catch(handler) {
|
|
96
92
|
if (this.error) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ENCODER } from '../../index.js';
|
|
2
2
|
import { BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TIMESTAMP, UINT16, UINT32, UINT8, } from '@based/schema/def';
|
|
3
|
-
import { convertToTimestamp } from '
|
|
3
|
+
import { convertToTimestamp } from '@saulx/utils';
|
|
4
4
|
import { getBuffer } from './binary.js';
|
|
5
5
|
import { ModifyError } from './ModifyRes.js';
|
|
6
6
|
import { RANGE_ERR } from './types.js';
|
|
@@ -10,6 +10,9 @@ map[BINARY] = (ctx, val, def) => {
|
|
|
10
10
|
if (buf === undefined) {
|
|
11
11
|
return new ModifyError(def, val);
|
|
12
12
|
}
|
|
13
|
+
if (!def.validation(val, def)) {
|
|
14
|
+
return new ModifyError(def, val);
|
|
15
|
+
}
|
|
13
16
|
const size = buf.byteLength;
|
|
14
17
|
if (ctx.len + size + 1 > ctx.max) {
|
|
15
18
|
return RANGE_ERR;
|
|
@@ -24,17 +27,27 @@ map[STRING] = (ctx, val, def) => {
|
|
|
24
27
|
if (size + 1 > def.len) {
|
|
25
28
|
return new ModifyError(def, val, `max length of ${def.len - 1},`);
|
|
26
29
|
}
|
|
30
|
+
if (!def.validation(val, def)) {
|
|
31
|
+
return new ModifyError(def, val);
|
|
32
|
+
}
|
|
27
33
|
if (ctx.len + size + 1 > ctx.max) {
|
|
28
34
|
return RANGE_ERR;
|
|
29
35
|
}
|
|
30
36
|
ctx.buf[ctx.len++] = size;
|
|
31
37
|
ctx.buf.set(valBuf, ctx.len);
|
|
32
|
-
|
|
38
|
+
const fullSize = def.len - 1;
|
|
39
|
+
ctx.len += fullSize;
|
|
40
|
+
if (fullSize !== size) {
|
|
41
|
+
ctx.buf.fill(0, ctx.len - (fullSize - size), ctx.len);
|
|
42
|
+
}
|
|
33
43
|
};
|
|
34
44
|
map[BOOLEAN] = (ctx, val, def) => {
|
|
35
45
|
if (ctx.len + 1 > ctx.max) {
|
|
36
46
|
return RANGE_ERR;
|
|
37
47
|
}
|
|
48
|
+
if (!def.validation(val, def)) {
|
|
49
|
+
return new ModifyError(def, val);
|
|
50
|
+
}
|
|
38
51
|
if (val === null) {
|
|
39
52
|
ctx.buf[ctx.len++] = 0;
|
|
40
53
|
}
|
|
@@ -49,6 +62,9 @@ map[ENUM] = (ctx, val, def) => {
|
|
|
49
62
|
if (ctx.len + 1 > ctx.max) {
|
|
50
63
|
return RANGE_ERR;
|
|
51
64
|
}
|
|
65
|
+
if (!def.validation(val, def)) {
|
|
66
|
+
return new ModifyError(def, val);
|
|
67
|
+
}
|
|
52
68
|
if (val === null) {
|
|
53
69
|
ctx.buf[ctx.len++] = 0;
|
|
54
70
|
}
|
|
@@ -63,6 +79,9 @@ map[NUMBER] = (ctx, val, def) => {
|
|
|
63
79
|
if (ctx.len + 8 > ctx.max) {
|
|
64
80
|
return RANGE_ERR;
|
|
65
81
|
}
|
|
82
|
+
if (!def.validation(val, def)) {
|
|
83
|
+
return new ModifyError(def, val);
|
|
84
|
+
}
|
|
66
85
|
const view = new DataView(ctx.buf.buffer, ctx.buf.byteOffset + ctx.len, 8);
|
|
67
86
|
ctx.len += 8;
|
|
68
87
|
view.setFloat64(0, val, true);
|
|
@@ -72,14 +91,21 @@ map[TIMESTAMP] = (ctx, val, def) => {
|
|
|
72
91
|
if (ctx.len + 8 > ctx.max) {
|
|
73
92
|
return RANGE_ERR;
|
|
74
93
|
}
|
|
94
|
+
if (!def.validation(parsedValue, def)) {
|
|
95
|
+
return new ModifyError(def, val);
|
|
96
|
+
}
|
|
75
97
|
const view = new DataView(ctx.buf.buffer, ctx.buf.byteOffset + ctx.len, 8);
|
|
76
98
|
ctx.len += 8;
|
|
77
99
|
view.setFloat64(0, parsedValue, true);
|
|
100
|
+
const ts = view.getFloat64(0);
|
|
78
101
|
};
|
|
79
102
|
map[UINT32] = (ctx, val, def) => {
|
|
80
103
|
if (ctx.len + 4 > ctx.max) {
|
|
81
104
|
return RANGE_ERR;
|
|
82
105
|
}
|
|
106
|
+
if (!def.validation(val, def)) {
|
|
107
|
+
return new ModifyError(def, val);
|
|
108
|
+
}
|
|
83
109
|
ctx.buf[ctx.len++] = val;
|
|
84
110
|
ctx.buf[ctx.len++] = val >>>= 8;
|
|
85
111
|
ctx.buf[ctx.len++] = val >>>= 8;
|
|
@@ -89,6 +115,9 @@ map[UINT16] = (ctx, val, def) => {
|
|
|
89
115
|
if (ctx.len + 2 > ctx.max) {
|
|
90
116
|
return RANGE_ERR;
|
|
91
117
|
}
|
|
118
|
+
if (!def.validation(val, def)) {
|
|
119
|
+
return new ModifyError(def, val);
|
|
120
|
+
}
|
|
92
121
|
ctx.buf[ctx.len++] = val;
|
|
93
122
|
ctx.buf[ctx.len++] = val >>>= 8;
|
|
94
123
|
};
|
|
@@ -96,12 +125,18 @@ map[UINT8] = (ctx, val, def) => {
|
|
|
96
125
|
if (ctx.len + 1 > ctx.max) {
|
|
97
126
|
return RANGE_ERR;
|
|
98
127
|
}
|
|
128
|
+
if (!def.validation(val, def)) {
|
|
129
|
+
return new ModifyError(def, val);
|
|
130
|
+
}
|
|
99
131
|
ctx.buf[ctx.len++] = val;
|
|
100
132
|
};
|
|
101
133
|
map[INT32] = (ctx, val, def) => {
|
|
102
134
|
if (ctx.len + 4 > ctx.max) {
|
|
103
135
|
return RANGE_ERR;
|
|
104
136
|
}
|
|
137
|
+
if (!def.validation(val, def)) {
|
|
138
|
+
return new ModifyError(def, val);
|
|
139
|
+
}
|
|
105
140
|
ctx.buf[ctx.len++] = val;
|
|
106
141
|
ctx.buf[ctx.len++] = val >>>= 8;
|
|
107
142
|
ctx.buf[ctx.len++] = val >>>= 8;
|
|
@@ -111,6 +146,9 @@ map[INT16] = (ctx, val, def) => {
|
|
|
111
146
|
if (ctx.len + 2 > ctx.max) {
|
|
112
147
|
return RANGE_ERR;
|
|
113
148
|
}
|
|
149
|
+
if (!def.validation(val, def)) {
|
|
150
|
+
return new ModifyError(def, val);
|
|
151
|
+
}
|
|
114
152
|
ctx.buf[ctx.len++] = val;
|
|
115
153
|
ctx.buf[ctx.len++] = val >>>= 8;
|
|
116
154
|
};
|
|
@@ -118,12 +156,12 @@ map[INT8] = (ctx, val, def) => {
|
|
|
118
156
|
if (ctx.len + 1 > ctx.max) {
|
|
119
157
|
return RANGE_ERR;
|
|
120
158
|
}
|
|
121
|
-
ctx.buf[ctx.len++] = val;
|
|
122
|
-
};
|
|
123
|
-
export const writeFixedValue = (ctx, val, def, pos) => {
|
|
124
159
|
if (!def.validation(val, def)) {
|
|
125
160
|
return new ModifyError(def, val);
|
|
126
161
|
}
|
|
162
|
+
ctx.buf[ctx.len++] = val;
|
|
163
|
+
};
|
|
164
|
+
export const writeFixedValue = (ctx, val, def, pos) => {
|
|
127
165
|
const len = ctx.len;
|
|
128
166
|
ctx.len = pos;
|
|
129
167
|
const res = map[def.typeIndex](ctx, val, def);
|
|
@@ -131,9 +169,6 @@ export const writeFixedValue = (ctx, val, def, pos) => {
|
|
|
131
169
|
return res;
|
|
132
170
|
};
|
|
133
171
|
export const appendFixedValue = (ctx, val, def) => {
|
|
134
|
-
if (!def.validation(val, def)) {
|
|
135
|
-
return new ModifyError(def, val);
|
|
136
|
-
}
|
|
137
172
|
return map[def.typeIndex](ctx, val, def);
|
|
138
173
|
};
|
|
139
174
|
//# sourceMappingURL=fixed.js.map
|
|
@@ -77,7 +77,6 @@ function _modify(ctx, res, obj, schema, mod, tree, overwrite, unsafe) {
|
|
|
77
77
|
ctx.lastMain = ctx.len;
|
|
78
78
|
ctx.buf.set(schema.mainEmpty, ctx.len);
|
|
79
79
|
ctx.len += schema.mainLen;
|
|
80
|
-
// ctx.buf.fill(0, ctx.len, (ctx.len += schema.mainLen))
|
|
81
80
|
}
|
|
82
81
|
if (typeof val === 'object' && val !== null && 'increment' in val) {
|
|
83
82
|
err = writeFixedValue(ctx, val.increment, def, ctx.lastMain + def.start);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { PropDefEdge } from '@based/schema/def';
|
|
2
2
|
import { ModifyCtx } from '../../flushModify.js';
|
|
3
3
|
import { ModifyErr } from '../types.js';
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function appendEdgeRefs(t: PropDefEdge, ctx: ModifyCtx, value: any[]): ModifyErr;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ModifyState, ModifyError } from '../ModifyRes.js';
|
|
2
|
-
export function
|
|
2
|
+
export function appendEdgeRefs(t, ctx, value) {
|
|
3
3
|
for (let i = 0; i < value.length; i++) {
|
|
4
4
|
let id = value[i];
|
|
5
5
|
if (typeof id !== 'number') {
|
|
@@ -13,6 +13,9 @@ export function appendRefs(t, ctx, value) {
|
|
|
13
13
|
return new ModifyError(t, value);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
+
if (!t.validation(id, t)) {
|
|
17
|
+
return new ModifyError(t, value);
|
|
18
|
+
}
|
|
16
19
|
if (id > 0) {
|
|
17
20
|
ctx.buf[ctx.len++] = id;
|
|
18
21
|
ctx.buf[ctx.len++] = id >>>= 8;
|
|
@@ -24,4 +27,4 @@ export function appendRefs(t, ctx, value) {
|
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
29
|
}
|
|
27
|
-
//# sourceMappingURL=
|
|
30
|
+
//# sourceMappingURL=appendEdgeRefs.js.map
|