@based/db 0.0.25 → 0.0.26
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/dist/lib/darwin_aarch64/include/selva/db.h +37 -3
- package/dist/lib/darwin_aarch64/include/selva/fields.h +3 -3
- 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/linux_aarch64/include/selva/db.h +37 -3
- package/dist/lib/linux_aarch64/include/selva/fields.h +3 -3
- 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 +37 -3
- package/dist/lib/linux_x86_64/include/selva/fields.h +3 -3
- 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.js +5 -1
- package/dist/src/client/index.d.ts +12 -6
- package/dist/src/client/index.js +33 -1
- package/dist/src/client/modify/create.js +17 -1
- package/dist/src/client/modify/fixed.js +52 -3
- package/dist/src/client/modify/modify.js +3 -1
- package/dist/src/client/modify/references/edge.js +3 -1
- package/dist/src/client/modify/upsert.js +1 -1
- package/dist/src/client/operations.d.ts +32 -0
- package/dist/src/client/operations.js +137 -0
- package/dist/src/client/query/BasedDbQuery.js +3 -0
- package/dist/src/client/query/BasedIterable.js +10 -3
- package/dist/src/client/query/aggregation.d.ts +3 -0
- package/dist/src/client/query/aggregation.js +9 -0
- package/dist/src/client/query/display.js +12 -2
- package/dist/src/client/query/filter/toBuffer.js +2 -2
- package/dist/src/client/query/query.d.ts +1 -1
- package/dist/src/client/query/query.js +1 -1
- package/dist/src/client/query/queryDef.js +0 -1
- package/dist/src/client/query/read/read.js +9 -4
- package/dist/src/client/query/toBuffer.js +2 -2
- package/dist/src/client/query/types.d.ts +4 -3
- package/dist/src/client/query/validation.js +5 -1
- package/dist/src/client/string.js +1 -1
- package/dist/src/index.d.ts +4 -1
- package/dist/src/index.js +11 -2
- package/dist/src/native.d.ts +1 -1
- package/dist/src/native.js +2 -2
- package/dist/src/server/csmt/tree.js +2 -2
- package/dist/src/server/index.d.ts +1 -1
- package/dist/src/server/index.js +27 -2
- package/dist/src/server/save.js +19 -11
- package/dist/src/server/start.js +0 -2
- package/dist/src/utils.d.ts +6 -0
- package/dist/src/utils.js +81 -9
- package/package.json +4 -4
|
@@ -71,6 +71,16 @@ struct SelvaTypeEntry *selva_get_type_by_index(const struct SelvaDb *db, node_ty
|
|
|
71
71
|
SELVA_EXPORT
|
|
72
72
|
struct SelvaTypeEntry *selva_get_type_by_node(const struct SelvaDb *db, struct SelvaNode *node) __attribute__((nonnull, pure));
|
|
73
73
|
|
|
74
|
+
SELVA_EXPORT
|
|
75
|
+
inline block_id_t selva_get_block_capacity(const struct SelvaTypeEntry *te)
|
|
76
|
+
#if !__zig
|
|
77
|
+
{
|
|
78
|
+
return te->blocks->block_capacity;
|
|
79
|
+
}
|
|
80
|
+
#else
|
|
81
|
+
;
|
|
82
|
+
#endif
|
|
83
|
+
|
|
74
84
|
/**
|
|
75
85
|
* Get the node schema for type.
|
|
76
86
|
*/
|
|
@@ -298,7 +308,29 @@ size_t selva_node_count(const struct SelvaTypeEntry *type) __attribute__((nonnul
|
|
|
298
308
|
* Get the node id of of node.
|
|
299
309
|
*/
|
|
300
310
|
SELVA_EXPORT
|
|
301
|
-
|
|
311
|
+
__attribute__((nonnull, pure))
|
|
312
|
+
inline node_id_t selva_get_node_id(const struct SelvaNode *node)
|
|
313
|
+
#if !__zig
|
|
314
|
+
{
|
|
315
|
+
return node->node_id;
|
|
316
|
+
}
|
|
317
|
+
#else
|
|
318
|
+
;
|
|
319
|
+
#endif
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Get the type of of node.
|
|
323
|
+
*/
|
|
324
|
+
SELVA_EXPORT
|
|
325
|
+
__attribute__((nonnull, pure))
|
|
326
|
+
inline node_type_t selva_get_node_type(const struct SelvaNode *node)
|
|
327
|
+
#if !__zig
|
|
328
|
+
{
|
|
329
|
+
return node->type;
|
|
330
|
+
}
|
|
331
|
+
#else
|
|
332
|
+
;
|
|
333
|
+
#endif
|
|
302
334
|
|
|
303
335
|
/**
|
|
304
336
|
* \addtogroup node_hash
|
|
@@ -332,15 +364,17 @@ size_t selva_alias_count(const struct SelvaAliases *aliases);
|
|
|
332
364
|
/**
|
|
333
365
|
* Set new alias.
|
|
334
366
|
* @param name is copied.
|
|
367
|
+
* @returns the previous node_id the alias was pointing to; Otherwise 0.
|
|
335
368
|
*/
|
|
336
369
|
SELVA_EXPORT
|
|
337
|
-
|
|
370
|
+
node_id_t selva_set_alias(struct SelvaAliases *aliases, node_id_t dest, const char *name_str, size_t name_len);
|
|
338
371
|
|
|
339
372
|
/**
|
|
340
373
|
* Delete alias by name.
|
|
374
|
+
* @return the destination node_id the alias was pointing to; 0 if SELVA_ENOENT.
|
|
341
375
|
*/
|
|
342
376
|
SELVA_EXPORT
|
|
343
|
-
|
|
377
|
+
node_id_t selva_del_alias_by_name(struct SelvaAliases *aliases, const char *name_str, size_t name_len);
|
|
344
378
|
|
|
345
379
|
/**
|
|
346
380
|
* Delete all aliases pointing to dest.
|
|
@@ -266,10 +266,10 @@ int selva_fields_get_text(
|
|
|
266
266
|
size_t *len);
|
|
267
267
|
|
|
268
268
|
SELVA_EXPORT
|
|
269
|
-
struct SelvaNodeReference *selva_fields_get_reference(struct SelvaDb *db, struct SelvaNode *node,
|
|
269
|
+
struct SelvaNodeReference *selva_fields_get_reference(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs);
|
|
270
270
|
|
|
271
271
|
SELVA_EXPORT
|
|
272
|
-
struct SelvaNodeReferences *selva_fields_get_references(struct SelvaDb *db, struct SelvaNode *node,
|
|
272
|
+
struct SelvaNodeReferences *selva_fields_get_references(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs);
|
|
273
273
|
|
|
274
274
|
SELVA_EXPORT
|
|
275
275
|
struct SelvaNodeWeakReference selva_fields_get_weak_reference(struct SelvaDb *db, struct SelvaFields *fields, field_t field);
|
|
@@ -309,7 +309,7 @@ int selva_fields_del(struct SelvaDb *db, struct SelvaNode *node, const struct Se
|
|
|
309
309
|
* Delete an edge from a references field.
|
|
310
310
|
*/
|
|
311
311
|
SELVA_EXPORT
|
|
312
|
-
int selva_fields_del_ref(struct SelvaDb *db, struct SelvaNode *node,
|
|
312
|
+
int selva_fields_del_ref(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs, node_id_t dst_node_id);
|
|
313
313
|
|
|
314
314
|
SELVA_EXPORT
|
|
315
315
|
void selva_fields_clear_references(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -71,6 +71,16 @@ struct SelvaTypeEntry *selva_get_type_by_index(const struct SelvaDb *db, node_ty
|
|
|
71
71
|
SELVA_EXPORT
|
|
72
72
|
struct SelvaTypeEntry *selva_get_type_by_node(const struct SelvaDb *db, struct SelvaNode *node) __attribute__((nonnull, pure));
|
|
73
73
|
|
|
74
|
+
SELVA_EXPORT
|
|
75
|
+
inline block_id_t selva_get_block_capacity(const struct SelvaTypeEntry *te)
|
|
76
|
+
#if !__zig
|
|
77
|
+
{
|
|
78
|
+
return te->blocks->block_capacity;
|
|
79
|
+
}
|
|
80
|
+
#else
|
|
81
|
+
;
|
|
82
|
+
#endif
|
|
83
|
+
|
|
74
84
|
/**
|
|
75
85
|
* Get the node schema for type.
|
|
76
86
|
*/
|
|
@@ -298,7 +308,29 @@ size_t selva_node_count(const struct SelvaTypeEntry *type) __attribute__((nonnul
|
|
|
298
308
|
* Get the node id of of node.
|
|
299
309
|
*/
|
|
300
310
|
SELVA_EXPORT
|
|
301
|
-
|
|
311
|
+
__attribute__((nonnull, pure))
|
|
312
|
+
inline node_id_t selva_get_node_id(const struct SelvaNode *node)
|
|
313
|
+
#if !__zig
|
|
314
|
+
{
|
|
315
|
+
return node->node_id;
|
|
316
|
+
}
|
|
317
|
+
#else
|
|
318
|
+
;
|
|
319
|
+
#endif
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Get the type of of node.
|
|
323
|
+
*/
|
|
324
|
+
SELVA_EXPORT
|
|
325
|
+
__attribute__((nonnull, pure))
|
|
326
|
+
inline node_type_t selva_get_node_type(const struct SelvaNode *node)
|
|
327
|
+
#if !__zig
|
|
328
|
+
{
|
|
329
|
+
return node->type;
|
|
330
|
+
}
|
|
331
|
+
#else
|
|
332
|
+
;
|
|
333
|
+
#endif
|
|
302
334
|
|
|
303
335
|
/**
|
|
304
336
|
* \addtogroup node_hash
|
|
@@ -332,15 +364,17 @@ size_t selva_alias_count(const struct SelvaAliases *aliases);
|
|
|
332
364
|
/**
|
|
333
365
|
* Set new alias.
|
|
334
366
|
* @param name is copied.
|
|
367
|
+
* @returns the previous node_id the alias was pointing to; Otherwise 0.
|
|
335
368
|
*/
|
|
336
369
|
SELVA_EXPORT
|
|
337
|
-
|
|
370
|
+
node_id_t selva_set_alias(struct SelvaAliases *aliases, node_id_t dest, const char *name_str, size_t name_len);
|
|
338
371
|
|
|
339
372
|
/**
|
|
340
373
|
* Delete alias by name.
|
|
374
|
+
* @return the destination node_id the alias was pointing to; 0 if SELVA_ENOENT.
|
|
341
375
|
*/
|
|
342
376
|
SELVA_EXPORT
|
|
343
|
-
|
|
377
|
+
node_id_t selva_del_alias_by_name(struct SelvaAliases *aliases, const char *name_str, size_t name_len);
|
|
344
378
|
|
|
345
379
|
/**
|
|
346
380
|
* Delete all aliases pointing to dest.
|
|
@@ -266,10 +266,10 @@ int selva_fields_get_text(
|
|
|
266
266
|
size_t *len);
|
|
267
267
|
|
|
268
268
|
SELVA_EXPORT
|
|
269
|
-
struct SelvaNodeReference *selva_fields_get_reference(struct SelvaDb *db, struct SelvaNode *node,
|
|
269
|
+
struct SelvaNodeReference *selva_fields_get_reference(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs);
|
|
270
270
|
|
|
271
271
|
SELVA_EXPORT
|
|
272
|
-
struct SelvaNodeReferences *selva_fields_get_references(struct SelvaDb *db, struct SelvaNode *node,
|
|
272
|
+
struct SelvaNodeReferences *selva_fields_get_references(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs);
|
|
273
273
|
|
|
274
274
|
SELVA_EXPORT
|
|
275
275
|
struct SelvaNodeWeakReference selva_fields_get_weak_reference(struct SelvaDb *db, struct SelvaFields *fields, field_t field);
|
|
@@ -309,7 +309,7 @@ int selva_fields_del(struct SelvaDb *db, struct SelvaNode *node, const struct Se
|
|
|
309
309
|
* Delete an edge from a references field.
|
|
310
310
|
*/
|
|
311
311
|
SELVA_EXPORT
|
|
312
|
-
int selva_fields_del_ref(struct SelvaDb *db, struct SelvaNode *node,
|
|
312
|
+
int selva_fields_del_ref(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs, node_id_t dst_node_id);
|
|
313
313
|
|
|
314
314
|
SELVA_EXPORT
|
|
315
315
|
void selva_fields_clear_references(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -71,6 +71,16 @@ struct SelvaTypeEntry *selva_get_type_by_index(const struct SelvaDb *db, node_ty
|
|
|
71
71
|
SELVA_EXPORT
|
|
72
72
|
struct SelvaTypeEntry *selva_get_type_by_node(const struct SelvaDb *db, struct SelvaNode *node) __attribute__((nonnull, pure));
|
|
73
73
|
|
|
74
|
+
SELVA_EXPORT
|
|
75
|
+
inline block_id_t selva_get_block_capacity(const struct SelvaTypeEntry *te)
|
|
76
|
+
#if !__zig
|
|
77
|
+
{
|
|
78
|
+
return te->blocks->block_capacity;
|
|
79
|
+
}
|
|
80
|
+
#else
|
|
81
|
+
;
|
|
82
|
+
#endif
|
|
83
|
+
|
|
74
84
|
/**
|
|
75
85
|
* Get the node schema for type.
|
|
76
86
|
*/
|
|
@@ -298,7 +308,29 @@ size_t selva_node_count(const struct SelvaTypeEntry *type) __attribute__((nonnul
|
|
|
298
308
|
* Get the node id of of node.
|
|
299
309
|
*/
|
|
300
310
|
SELVA_EXPORT
|
|
301
|
-
|
|
311
|
+
__attribute__((nonnull, pure))
|
|
312
|
+
inline node_id_t selva_get_node_id(const struct SelvaNode *node)
|
|
313
|
+
#if !__zig
|
|
314
|
+
{
|
|
315
|
+
return node->node_id;
|
|
316
|
+
}
|
|
317
|
+
#else
|
|
318
|
+
;
|
|
319
|
+
#endif
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Get the type of of node.
|
|
323
|
+
*/
|
|
324
|
+
SELVA_EXPORT
|
|
325
|
+
__attribute__((nonnull, pure))
|
|
326
|
+
inline node_type_t selva_get_node_type(const struct SelvaNode *node)
|
|
327
|
+
#if !__zig
|
|
328
|
+
{
|
|
329
|
+
return node->type;
|
|
330
|
+
}
|
|
331
|
+
#else
|
|
332
|
+
;
|
|
333
|
+
#endif
|
|
302
334
|
|
|
303
335
|
/**
|
|
304
336
|
* \addtogroup node_hash
|
|
@@ -332,15 +364,17 @@ size_t selva_alias_count(const struct SelvaAliases *aliases);
|
|
|
332
364
|
/**
|
|
333
365
|
* Set new alias.
|
|
334
366
|
* @param name is copied.
|
|
367
|
+
* @returns the previous node_id the alias was pointing to; Otherwise 0.
|
|
335
368
|
*/
|
|
336
369
|
SELVA_EXPORT
|
|
337
|
-
|
|
370
|
+
node_id_t selva_set_alias(struct SelvaAliases *aliases, node_id_t dest, const char *name_str, size_t name_len);
|
|
338
371
|
|
|
339
372
|
/**
|
|
340
373
|
* Delete alias by name.
|
|
374
|
+
* @return the destination node_id the alias was pointing to; 0 if SELVA_ENOENT.
|
|
341
375
|
*/
|
|
342
376
|
SELVA_EXPORT
|
|
343
|
-
|
|
377
|
+
node_id_t selva_del_alias_by_name(struct SelvaAliases *aliases, const char *name_str, size_t name_len);
|
|
344
378
|
|
|
345
379
|
/**
|
|
346
380
|
* Delete all aliases pointing to dest.
|
|
@@ -266,10 +266,10 @@ int selva_fields_get_text(
|
|
|
266
266
|
size_t *len);
|
|
267
267
|
|
|
268
268
|
SELVA_EXPORT
|
|
269
|
-
struct SelvaNodeReference *selva_fields_get_reference(struct SelvaDb *db, struct SelvaNode *node,
|
|
269
|
+
struct SelvaNodeReference *selva_fields_get_reference(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs);
|
|
270
270
|
|
|
271
271
|
SELVA_EXPORT
|
|
272
|
-
struct SelvaNodeReferences *selva_fields_get_references(struct SelvaDb *db, struct SelvaNode *node,
|
|
272
|
+
struct SelvaNodeReferences *selva_fields_get_references(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs);
|
|
273
273
|
|
|
274
274
|
SELVA_EXPORT
|
|
275
275
|
struct SelvaNodeWeakReference selva_fields_get_weak_reference(struct SelvaDb *db, struct SelvaFields *fields, field_t field);
|
|
@@ -309,7 +309,7 @@ int selva_fields_del(struct SelvaDb *db, struct SelvaNode *node, const struct Se
|
|
|
309
309
|
* Delete an edge from a references field.
|
|
310
310
|
*/
|
|
311
311
|
SELVA_EXPORT
|
|
312
|
-
int selva_fields_del_ref(struct SelvaDb *db, struct SelvaNode *node,
|
|
312
|
+
int selva_fields_del_ref(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs, node_id_t dst_node_id);
|
|
313
313
|
|
|
314
314
|
SELVA_EXPORT
|
|
315
315
|
void selva_fields_clear_references(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
// TODO This definitely shouldn't be copy-pasted here from server/tree.ts
|
|
2
|
+
const makeCsmtKeyFromNodeId = (typeId, blockCapacity, nodeId) => {
|
|
3
|
+
const tmp = nodeId - +!(nodeId % blockCapacity);
|
|
4
|
+
return typeId * 4294967296 + ((tmp / blockCapacity) | 0) * blockCapacity + 1;
|
|
5
|
+
};
|
|
2
6
|
export class ModifyCtx {
|
|
3
7
|
constructor(db) {
|
|
4
8
|
this.max = db.maxModifySize;
|
|
@@ -22,12 +22,14 @@ type DbClientOpts = {
|
|
|
22
22
|
hooks: DbClientHooks;
|
|
23
23
|
maxModifySize?: number;
|
|
24
24
|
};
|
|
25
|
+
type DbClientSchema = StrictSchema & {
|
|
26
|
+
lastId: number;
|
|
27
|
+
};
|
|
25
28
|
export declare class DbClient {
|
|
26
29
|
constructor({ hooks, maxModifySize }: DbClientOpts);
|
|
27
30
|
hooks: DbClientHooks;
|
|
28
|
-
schema:
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
+
schema: DbClientSchema;
|
|
32
|
+
schemaIsSetValue: boolean;
|
|
31
33
|
schemaTypesParsed: Record<string, SchemaTypeDef>;
|
|
32
34
|
schemaTypesParsedById: Record<number, SchemaTypeDef>;
|
|
33
35
|
writeTime: number;
|
|
@@ -45,9 +47,7 @@ export declare class DbClient {
|
|
|
45
47
|
subscriptionsToRun: SubscriptionsToRun;
|
|
46
48
|
schemaChecksum: number;
|
|
47
49
|
setSchema(schema: Schema, fromStart?: boolean, transformFns?: TransformFns): Promise<StrictSchema>;
|
|
48
|
-
putLocalSchema(schema: any):
|
|
49
|
-
lastId: number;
|
|
50
|
-
};
|
|
50
|
+
putLocalSchema(schema: any): DbClientSchema;
|
|
51
51
|
create(type: string, obj?: CreateObj, opts?: ModifyOpts): ModifyRes;
|
|
52
52
|
copy(type: string, target: number | ModifyRes, objOrTransformFn?: Record<string, any> | ((item: Record<string, any>) => Promise<any>)): Promise<ModifyRes>;
|
|
53
53
|
query(type: string, id?: number | ModifyRes | (number | ModifyRes)[] | QueryByAliasObj | QueryByAliasObj[] | Uint32Array): BasedDbQuery;
|
|
@@ -64,5 +64,11 @@ export declare class DbClient {
|
|
|
64
64
|
stop(): void;
|
|
65
65
|
drain(): Promise<number>;
|
|
66
66
|
isModified(): Promise<void>;
|
|
67
|
+
schemaIsSet(): Promise<true>;
|
|
68
|
+
listeners?: {
|
|
69
|
+
schema?: Set<(schema: DbClientSchema) => void>;
|
|
70
|
+
};
|
|
71
|
+
on(event: 'schema', cb: (schema: DbClientSchema) => void): void;
|
|
72
|
+
off(event: 'schema', cb: (schema: DbClientSchema) => void): void;
|
|
67
73
|
}
|
|
68
74
|
export {};
|
package/dist/src/client/index.js
CHANGED
|
@@ -17,11 +17,11 @@ export class DbClient {
|
|
|
17
17
|
this.modifyCtx = new ModifyCtx(this);
|
|
18
18
|
}
|
|
19
19
|
hooks;
|
|
20
|
-
// schema
|
|
21
20
|
schema = {
|
|
22
21
|
lastId: 1, // we reserve one for root props
|
|
23
22
|
types: {},
|
|
24
23
|
};
|
|
24
|
+
schemaIsSetValue = false;
|
|
25
25
|
schemaTypesParsed = {};
|
|
26
26
|
schemaTypesParsedById = {};
|
|
27
27
|
// modify
|
|
@@ -38,6 +38,7 @@ export class DbClient {
|
|
|
38
38
|
subscriptionsToRun = [];
|
|
39
39
|
schemaChecksum;
|
|
40
40
|
async setSchema(schema, fromStart, transformFns) {
|
|
41
|
+
this.schemaIsSetValue = true;
|
|
41
42
|
const checksum = hash(schema);
|
|
42
43
|
if (checksum === this.schemaChecksum) {
|
|
43
44
|
return this.schema;
|
|
@@ -48,6 +49,7 @@ export class DbClient {
|
|
|
48
49
|
return this.putLocalSchema(remoteSchema);
|
|
49
50
|
}
|
|
50
51
|
putLocalSchema(schema) {
|
|
52
|
+
this.schemaIsSetValue = true;
|
|
51
53
|
if (deepEqual(this.schema, schema)) {
|
|
52
54
|
return this.schema;
|
|
53
55
|
}
|
|
@@ -61,6 +63,11 @@ export class DbClient {
|
|
|
61
63
|
updateTypeDefs(this.schema, this.schemaTypesParsed, this.schemaTypesParsedById);
|
|
62
64
|
// Adds bidrectional refs on defs
|
|
63
65
|
schemaToSelvaBuffer(this.schemaTypesParsed);
|
|
66
|
+
if (this.listeners?.schema) {
|
|
67
|
+
for (const cb of this.listeners.schema) {
|
|
68
|
+
cb(this.schema);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
64
71
|
return this.schema;
|
|
65
72
|
}
|
|
66
73
|
create(type, obj = {}, opts) {
|
|
@@ -166,6 +173,9 @@ export class DbClient {
|
|
|
166
173
|
}
|
|
167
174
|
// For more advanced / internal usage - use isModified instead for most cases
|
|
168
175
|
async drain() {
|
|
176
|
+
if (this.upserting.size) {
|
|
177
|
+
await Promise.all(Array.from(this.upserting).map(([, { p }]) => p));
|
|
178
|
+
}
|
|
169
179
|
await flushBuffer(this);
|
|
170
180
|
const t = this.writeTime;
|
|
171
181
|
this.writeTime = 0;
|
|
@@ -178,5 +188,27 @@ export class DbClient {
|
|
|
178
188
|
await this.hooks.flushIsReady;
|
|
179
189
|
return;
|
|
180
190
|
}
|
|
191
|
+
schemaIsSet() {
|
|
192
|
+
return new Promise((resolve) => {
|
|
193
|
+
if (this.schemaIsSetValue) {
|
|
194
|
+
resolve(true);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
setTimeout(() => {
|
|
198
|
+
// TODO use subscription when its done
|
|
199
|
+
resolve(this.schemaIsSet());
|
|
200
|
+
}, 12);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
listeners;
|
|
205
|
+
on(event, cb) {
|
|
206
|
+
this.listeners ??= {};
|
|
207
|
+
this.listeners[event] ??= new Set();
|
|
208
|
+
this.listeners[event].add(cb);
|
|
209
|
+
}
|
|
210
|
+
off(event, cb) {
|
|
211
|
+
this.listeners?.[event]?.delete(cb);
|
|
212
|
+
}
|
|
181
213
|
}
|
|
182
214
|
//# sourceMappingURL=index.js.map
|
|
@@ -30,7 +30,8 @@ const appendCreate = (ctx, def, obj, res, unsafe) => {
|
|
|
30
30
|
ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
|
|
31
31
|
ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
|
|
32
32
|
ctx.lastMain = ctx.len;
|
|
33
|
-
ctx.buf.
|
|
33
|
+
ctx.buf.set(def.mainEmpty, ctx.len);
|
|
34
|
+
ctx.len += def.mainLen;
|
|
34
35
|
}
|
|
35
36
|
err = writeFixedValue(ctx, createTs, prop, ctx.lastMain + prop.start);
|
|
36
37
|
if (err) {
|
|
@@ -38,6 +39,21 @@ const appendCreate = (ctx, def, obj, res, unsafe) => {
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
}
|
|
42
|
+
else if (ctx.lastMain === -1 && !def.mainEmptyAllZeroes) {
|
|
43
|
+
// this is there to handle different defaults
|
|
44
|
+
if (ctx.lastMain === -1) {
|
|
45
|
+
let mainLenU32 = def.mainLen;
|
|
46
|
+
setCursor(ctx, def, 0, MICRO_BUFFER, res.tmpId, CREATE);
|
|
47
|
+
ctx.buf[ctx.len++] = CREATE;
|
|
48
|
+
ctx.buf[ctx.len++] = mainLenU32;
|
|
49
|
+
ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
|
|
50
|
+
ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
|
|
51
|
+
ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
|
|
52
|
+
ctx.lastMain = ctx.len;
|
|
53
|
+
ctx.buf.set(def.mainEmpty, ctx.len);
|
|
54
|
+
ctx.len += def.mainLen;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
41
57
|
if (def.hasSeperateSort) {
|
|
42
58
|
if (ctx.hasSortField !== def.seperateSort.size - 1) {
|
|
43
59
|
if (ctx.len + 3 > ctx.max) {
|
|
@@ -84,6 +84,9 @@ map[TIMESTAMP] = (ctx, val, def) => {
|
|
|
84
84
|
if (ctx.len + 8 > ctx.max) {
|
|
85
85
|
return RANGE_ERR;
|
|
86
86
|
}
|
|
87
|
+
if (val < 0) {
|
|
88
|
+
return new ModifyError(def, val);
|
|
89
|
+
}
|
|
87
90
|
const view = new DataView(ctx.buf.buffer, ctx.buf.byteOffset + ctx.len, 8);
|
|
88
91
|
ctx.len += 8;
|
|
89
92
|
view.setFloat64(0, parsedValue, true);
|
|
@@ -95,6 +98,9 @@ map[UINT32] = (ctx, val, def) => {
|
|
|
95
98
|
if (ctx.len + 4 > ctx.max) {
|
|
96
99
|
return RANGE_ERR;
|
|
97
100
|
}
|
|
101
|
+
if (val > 4294967295 || val < 0) {
|
|
102
|
+
return new ModifyError(def, val);
|
|
103
|
+
}
|
|
98
104
|
ctx.buf[ctx.len++] = val;
|
|
99
105
|
ctx.buf[ctx.len++] = val >>>= 8;
|
|
100
106
|
ctx.buf[ctx.len++] = val >>>= 8;
|
|
@@ -107,6 +113,9 @@ map[UINT16] = (ctx, val, def) => {
|
|
|
107
113
|
if (ctx.len + 2 > ctx.max) {
|
|
108
114
|
return RANGE_ERR;
|
|
109
115
|
}
|
|
116
|
+
if (val > 65535 || val < 0) {
|
|
117
|
+
return new ModifyError(def, val);
|
|
118
|
+
}
|
|
110
119
|
ctx.buf[ctx.len++] = val;
|
|
111
120
|
ctx.buf[ctx.len++] = val >>>= 8;
|
|
112
121
|
};
|
|
@@ -117,11 +126,51 @@ map[UINT8] = (ctx, val, def) => {
|
|
|
117
126
|
if (ctx.len + 1 > ctx.max) {
|
|
118
127
|
return RANGE_ERR;
|
|
119
128
|
}
|
|
129
|
+
if (val > 255 || val < 0) {
|
|
130
|
+
return new ModifyError(def, val);
|
|
131
|
+
}
|
|
132
|
+
ctx.buf[ctx.len++] = val;
|
|
133
|
+
};
|
|
134
|
+
map[INT32] = (ctx, val, def) => {
|
|
135
|
+
if (typeof val !== 'number') {
|
|
136
|
+
return new ModifyError(def, val);
|
|
137
|
+
}
|
|
138
|
+
if (ctx.len + 4 > ctx.max) {
|
|
139
|
+
return RANGE_ERR;
|
|
140
|
+
}
|
|
141
|
+
if (val > 2147483647 || val < -2147483648) {
|
|
142
|
+
return new ModifyError(def, val);
|
|
143
|
+
}
|
|
144
|
+
ctx.buf[ctx.len++] = val;
|
|
145
|
+
ctx.buf[ctx.len++] = val >>>= 8;
|
|
146
|
+
ctx.buf[ctx.len++] = val >>>= 8;
|
|
147
|
+
ctx.buf[ctx.len++] = val >>>= 8;
|
|
148
|
+
};
|
|
149
|
+
map[INT16] = (ctx, val, def) => {
|
|
150
|
+
if (typeof val !== 'number') {
|
|
151
|
+
return new ModifyError(def, val);
|
|
152
|
+
}
|
|
153
|
+
if (ctx.len + 2 > ctx.max) {
|
|
154
|
+
return RANGE_ERR;
|
|
155
|
+
}
|
|
156
|
+
if (val > 32767 || val < -32768) {
|
|
157
|
+
return new ModifyError(def, val);
|
|
158
|
+
}
|
|
159
|
+
ctx.buf[ctx.len++] = val;
|
|
160
|
+
ctx.buf[ctx.len++] = val >>>= 8;
|
|
161
|
+
};
|
|
162
|
+
map[INT8] = (ctx, val, def) => {
|
|
163
|
+
if (typeof val !== 'number') {
|
|
164
|
+
return new ModifyError(def, val);
|
|
165
|
+
}
|
|
166
|
+
if (ctx.len + 1 > ctx.max) {
|
|
167
|
+
return RANGE_ERR;
|
|
168
|
+
}
|
|
169
|
+
if (val > 127 || val < -128) {
|
|
170
|
+
return new ModifyError(def, val);
|
|
171
|
+
}
|
|
120
172
|
ctx.buf[ctx.len++] = val;
|
|
121
173
|
};
|
|
122
|
-
map[INT32] = map[UINT32];
|
|
123
|
-
map[INT16] = map[UINT16];
|
|
124
|
-
map[INT8] = map[UINT8];
|
|
125
174
|
export const writeFixedValue = (ctx, val, def, pos) => {
|
|
126
175
|
const len = ctx.len;
|
|
127
176
|
ctx.len = pos;
|
|
@@ -75,7 +75,9 @@ function _modify(ctx, res, obj, schema, mod, tree, overwrite, unsafe) {
|
|
|
75
75
|
ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
|
|
76
76
|
ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
|
|
77
77
|
ctx.lastMain = ctx.len;
|
|
78
|
-
ctx.buf.
|
|
78
|
+
ctx.buf.set(schema.mainEmpty, ctx.len);
|
|
79
|
+
ctx.len += schema.mainLen;
|
|
80
|
+
// ctx.buf.fill(0, ctx.len, (ctx.len += schema.mainLen))
|
|
79
81
|
}
|
|
80
82
|
if (typeof val === 'object' && val !== null && 'increment' in val) {
|
|
81
83
|
err = writeFixedValue(ctx, val.increment, def, ctx.lastMain + def.start);
|
|
@@ -75,7 +75,8 @@ export function writeEdges(t, ref, ctx) {
|
|
|
75
75
|
if (typeof value !== 'string') {
|
|
76
76
|
return new ModifyError(edge, value);
|
|
77
77
|
}
|
|
78
|
-
if (ctx.len + EDGE_HEADER_SIZE + ENCODER.encode(value).byteLength >
|
|
78
|
+
if (ctx.len + EDGE_HEADER_SIZE + ENCODER.encode(value).byteLength >
|
|
79
|
+
ctx.max) {
|
|
79
80
|
return RANGE_ERR;
|
|
80
81
|
}
|
|
81
82
|
ctx.buf[ctx.len++] = STRING;
|
|
@@ -271,6 +272,7 @@ export function writeEdges(t, ref, ctx) {
|
|
|
271
272
|
// Index of start of fields
|
|
272
273
|
const sIndex = ctx.len;
|
|
273
274
|
ctx.len += mainFieldsStartSize;
|
|
275
|
+
// this has to be replaced
|
|
274
276
|
// Add zeroes
|
|
275
277
|
ctx.buf.fill(0, ctx.len, ctx.len + t.edgeMainLen);
|
|
276
278
|
// Keep track of written bytes from append fixed
|
|
@@ -2,7 +2,7 @@ import { ALIAS } from '@based/schema/def';
|
|
|
2
2
|
export async function upsert(db, type, obj, opts) {
|
|
3
3
|
const tree = db.schemaTypesParsed[type].tree;
|
|
4
4
|
let q;
|
|
5
|
-
let id =
|
|
5
|
+
let id = type;
|
|
6
6
|
for (const key in obj) {
|
|
7
7
|
if (tree[key].typeIndex === ALIAS) {
|
|
8
8
|
id += `${key}:${obj[key]};`;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PropDef, SchemaTypeDef } from '@based/schema/def';
|
|
2
|
+
import { DbClient } from './index.js';
|
|
3
|
+
import { ModifyState } from './modify/ModifyRes.js';
|
|
4
|
+
export declare class ModifyCtx {
|
|
5
|
+
constructor(db: DbClient);
|
|
6
|
+
len: number;
|
|
7
|
+
id: number;
|
|
8
|
+
hasSortField: number;
|
|
9
|
+
hasSortText: number;
|
|
10
|
+
queue: Map<(payload: any) => void, ModifyState>;
|
|
11
|
+
ctx: {
|
|
12
|
+
offsets?: Record<number, number>;
|
|
13
|
+
};
|
|
14
|
+
payload: Uint8Array;
|
|
15
|
+
max: number;
|
|
16
|
+
buf: Uint8Array;
|
|
17
|
+
field: number;
|
|
18
|
+
prefix0: number;
|
|
19
|
+
prefix1: number;
|
|
20
|
+
lastMain: number;
|
|
21
|
+
mergeMain: (PropDef | any)[] | null;
|
|
22
|
+
mergeMainSize: number;
|
|
23
|
+
db: DbClient;
|
|
24
|
+
dirtyRanges: Set<number>;
|
|
25
|
+
dirtyTypes: Map<number, number>;
|
|
26
|
+
markNodeDirty(schema: SchemaTypeDef, nodeId: number): void;
|
|
27
|
+
markTypeDirty(schema: SchemaTypeDef): void;
|
|
28
|
+
updateMax(): void;
|
|
29
|
+
getData(lastIds: Record<number, number>): Uint8Array;
|
|
30
|
+
}
|
|
31
|
+
export declare const flushBuffer: (db: DbClient) => Promise<void>;
|
|
32
|
+
export declare const startDrain: (db: DbClient) => void;
|