@based/db 0.0.70 → 0.0.71
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/hll.h +1 -1
- 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/libnode-v24.node +0 -0
- package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
- package/dist/lib/linux_aarch64/include/selva/hll.h +1 -1
- 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/libnode-v24.node +0 -0
- package/dist/lib/linux_aarch64/libselva.so +0 -0
- package/dist/lib/linux_x86_64/include/selva/hll.h +1 -1
- 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/libnode-v24.node +0 -0
- package/dist/lib/linux_x86_64/libselva.so +0 -0
- package/dist/src/client/modify/references/edge.js +20 -6
- package/dist/src/client/modify/references/reference.js +21 -9
- package/dist/src/client/modify/references/references.js +9 -1
- package/dist/src/client/query/BasedDbQuery.d.ts +1 -1
- package/dist/src/client/query/BasedDbQuery.js +4 -4
- package/dist/src/client/query/aggregates/types.d.ts +1 -1
- package/dist/src/client/query/aggregates/types.js +1 -1
- package/dist/src/client/query/validation.js +1 -1
- package/dist/src/server/save.js +7 -6
- package/dist/src/server/schema.js +8 -6
- package/dist/src/types.d.ts +1 -1
- package/package.json +2 -2
|
@@ -19,7 +19,7 @@ uint8_t *hll_count(struct selva_string *hllss);
|
|
|
19
19
|
SELVA_EXPORT
|
|
20
20
|
void hll_array_union(struct selva_string *res, struct selva_string *hll_array, size_t count);
|
|
21
21
|
SELVA_EXPORT
|
|
22
|
-
void hll_union(
|
|
22
|
+
void hll_union(struct selva_string *, struct selva_string *);
|
|
23
23
|
|
|
24
24
|
// size_t actual_cols[13] = { 79, 159, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200 };
|
|
25
25
|
// float raw_estimate_data[13][200] =
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -19,7 +19,7 @@ uint8_t *hll_count(struct selva_string *hllss);
|
|
|
19
19
|
SELVA_EXPORT
|
|
20
20
|
void hll_array_union(struct selva_string *res, struct selva_string *hll_array, size_t count);
|
|
21
21
|
SELVA_EXPORT
|
|
22
|
-
void hll_union(
|
|
22
|
+
void hll_union(struct selva_string *, struct selva_string *);
|
|
23
23
|
|
|
24
24
|
// size_t actual_cols[13] = { 79, 159, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200 };
|
|
25
25
|
// float raw_estimate_data[13][200] =
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -19,7 +19,7 @@ uint8_t *hll_count(struct selva_string *hllss);
|
|
|
19
19
|
SELVA_EXPORT
|
|
20
20
|
void hll_array_union(struct selva_string *res, struct selva_string *hll_array, size_t count);
|
|
21
21
|
SELVA_EXPORT
|
|
22
|
-
void hll_union(
|
|
22
|
+
void hll_union(struct selva_string *, struct selva_string *);
|
|
23
23
|
|
|
24
24
|
// size_t actual_cols[13] = { 79, 159, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200 };
|
|
25
25
|
// float raw_estimate_data[13][200] =
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -7,6 +7,7 @@ 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
9
|
import { appendEdgeRefs } from './appendEdgeRefs.js';
|
|
10
|
+
import { writeUint32 } from '@saulx/utils';
|
|
10
11
|
function valueOperation(value) {
|
|
11
12
|
if (typeof value === 'object' && value !== null) {
|
|
12
13
|
if (value.increment > 0) {
|
|
@@ -24,6 +25,15 @@ export function writeEdges(t, ref, ctx) {
|
|
|
24
25
|
let mainFields;
|
|
25
26
|
let mainSize = 0;
|
|
26
27
|
let hasIncr = false;
|
|
28
|
+
if (t.hasDefaultEdges) {
|
|
29
|
+
for (const key in t.edges) {
|
|
30
|
+
if (t.edges[key].separate === true &&
|
|
31
|
+
(!(key in ref) || ref[key] === undefined)) {
|
|
32
|
+
const edge = t.edges[key];
|
|
33
|
+
ref[key] = edge.default;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
27
37
|
for (const key in ref) {
|
|
28
38
|
if (key === 'id' || key === '$index') {
|
|
29
39
|
continue;
|
|
@@ -224,7 +234,9 @@ export function writeEdges(t, ref, ctx) {
|
|
|
224
234
|
}
|
|
225
235
|
}
|
|
226
236
|
}
|
|
227
|
-
if
|
|
237
|
+
// double check if has default edges has mainfields - add extra thing
|
|
238
|
+
if (mainFields || t.hasDefaultEdges) {
|
|
239
|
+
// add all
|
|
228
240
|
// Single field in main buffer can immediately setup the main buffer
|
|
229
241
|
if (!hasIncr && mainSize === t.edgeMainLen) {
|
|
230
242
|
/*
|
|
@@ -245,10 +257,8 @@ export function writeEdges(t, ref, ctx) {
|
|
|
245
257
|
ctx.buf[ctx.len++] = 0;
|
|
246
258
|
ctx.buf[ctx.len++] = MICRO_BUFFER;
|
|
247
259
|
let sizeU32 = mainSize;
|
|
248
|
-
ctx.buf
|
|
249
|
-
ctx.
|
|
250
|
-
ctx.buf[ctx.len++] = sizeU32 >>>= 8;
|
|
251
|
-
ctx.buf[ctx.len++] = sizeU32 >>>= 8;
|
|
260
|
+
writeUint32(ctx.buf, sizeU32, ctx.len);
|
|
261
|
+
ctx.len += 4;
|
|
252
262
|
for (let i = 0; i < mainFields.length; i += 3) {
|
|
253
263
|
const edge = mainFields[i];
|
|
254
264
|
const err = appendFixedValue(ctx, mainFields[i + 1], edge, UPDATE);
|
|
@@ -258,6 +268,9 @@ export function writeEdges(t, ref, ctx) {
|
|
|
258
268
|
}
|
|
259
269
|
}
|
|
260
270
|
else {
|
|
271
|
+
if (!mainFields) {
|
|
272
|
+
mainFields = [];
|
|
273
|
+
}
|
|
261
274
|
/*
|
|
262
275
|
Partial main update:
|
|
263
276
|
|
|
@@ -293,7 +306,8 @@ export function writeEdges(t, ref, ctx) {
|
|
|
293
306
|
const sIndex = ctx.len;
|
|
294
307
|
ctx.len += mainFieldsStartSize;
|
|
295
308
|
// Add zeroes
|
|
296
|
-
ctx.buf.
|
|
309
|
+
ctx.buf.set(t.edgeMainEmpty, ctx.len);
|
|
310
|
+
// ctx.buf.fill(0, ctx.len, ctx.len + t.edgeMainLen)
|
|
297
311
|
// Keep track of written bytes from append fixed
|
|
298
312
|
let startMain = ctx.len;
|
|
299
313
|
for (let i = 0; i < mainFields.length; i += 3) {
|
|
@@ -24,7 +24,7 @@ function writeRef(id, ctx, schema, def, parentId, modifyOp, hasEdges, isTmpId) {
|
|
|
24
24
|
ctx.buf[ctx.len++] = id >>>= 8;
|
|
25
25
|
ctx.buf[ctx.len++] = id >>>= 8;
|
|
26
26
|
}
|
|
27
|
-
function singleReferenceEdges(ref, ctx, schema, def, parentId, modifyOp) {
|
|
27
|
+
function singleReferenceEdges(ref, ctx, schema, def, parentId, modifyOp, processDefaultEdges) {
|
|
28
28
|
let id = ref.id;
|
|
29
29
|
let isTmpId;
|
|
30
30
|
if (typeof id !== 'number') {
|
|
@@ -77,23 +77,35 @@ export function writeReference(value, ctx, schema, def, res, modifyOp) {
|
|
|
77
77
|
}
|
|
78
78
|
setCursor(ctx, schema, def.prop, def.typeIndex, res.tmpId, modifyOp);
|
|
79
79
|
ctx.buf[ctx.len++] = DELETE;
|
|
80
|
+
return;
|
|
80
81
|
}
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
const processDefaultEdges = def.hasDefaultEdges;
|
|
83
|
+
if (typeof value === 'number') {
|
|
84
|
+
if (processDefaultEdges) {
|
|
85
|
+
value = { id: value };
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
return writeRef(value, ctx, schema, def, res.tmpId, modifyOp, false, false);
|
|
89
|
+
}
|
|
83
90
|
}
|
|
84
|
-
|
|
91
|
+
if (value instanceof ModifyState) {
|
|
85
92
|
if (value.error) {
|
|
86
93
|
return value.error;
|
|
87
94
|
}
|
|
88
95
|
const id = value.getId();
|
|
89
|
-
if (
|
|
90
|
-
|
|
96
|
+
if (processDefaultEdges) {
|
|
97
|
+
value = { id: id || value.tmpId };
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
if (id) {
|
|
101
|
+
return writeRef(id, ctx, schema, def, res.tmpId, modifyOp, false, false);
|
|
102
|
+
}
|
|
103
|
+
return writeRef(value.tmpId, ctx, schema, def, res.tmpId, modifyOp, false, true);
|
|
91
104
|
}
|
|
92
|
-
return writeRef(value.tmpId, ctx, schema, def, res.tmpId, modifyOp, false, true);
|
|
93
105
|
}
|
|
94
|
-
|
|
106
|
+
if (typeof value === 'object') {
|
|
95
107
|
if (def.edges) {
|
|
96
|
-
return singleReferenceEdges(value, ctx, schema, def, res.tmpId, modifyOp);
|
|
108
|
+
return singleReferenceEdges(value, ctx, schema, def, res.tmpId, modifyOp, processDefaultEdges);
|
|
97
109
|
}
|
|
98
110
|
else if (typeof value.id === 'number') {
|
|
99
111
|
return writeRef(value.id, ctx, schema, def, res.tmpId, modifyOp, false, false);
|
|
@@ -130,10 +130,18 @@ function appendRefs(def, ctx, modifyOp, refs, op, remaining) {
|
|
|
130
130
|
ctx.buf[ctx.len++] = remaining >>>= 8;
|
|
131
131
|
ctx.buf[ctx.len++] = remaining >>>= 8;
|
|
132
132
|
for (; i < refs.length; i++) {
|
|
133
|
-
|
|
133
|
+
let ref = refs[i];
|
|
134
134
|
let id;
|
|
135
135
|
let index;
|
|
136
136
|
let isTmpId;
|
|
137
|
+
if (def.hasDefaultEdges) {
|
|
138
|
+
if (typeof ref !== 'object') {
|
|
139
|
+
ref = { id: ref };
|
|
140
|
+
}
|
|
141
|
+
else if (ref instanceof ModifyState) {
|
|
142
|
+
ref = { id: ref };
|
|
143
|
+
}
|
|
144
|
+
}
|
|
137
145
|
if (typeof ref === 'object') {
|
|
138
146
|
if (ref instanceof ModifyState) {
|
|
139
147
|
if (ref.error) {
|
|
@@ -25,7 +25,7 @@ export declare class QueryBranch<T> {
|
|
|
25
25
|
groupBy(field: string): T;
|
|
26
26
|
count(field?: string): T;
|
|
27
27
|
sum(...fields: (string | string[])[]): T;
|
|
28
|
-
cardinality(
|
|
28
|
+
cardinality(field: string): T;
|
|
29
29
|
stddev(...fields: (string | string[])[]): T;
|
|
30
30
|
var(...fields: (string | string[])[]): T;
|
|
31
31
|
avg(...fields: (string | string[])[]): T;
|
|
@@ -173,18 +173,18 @@ export class QueryBranch {
|
|
|
173
173
|
// @ts-ignore
|
|
174
174
|
return this;
|
|
175
175
|
}
|
|
176
|
-
cardinality(
|
|
177
|
-
if (
|
|
176
|
+
cardinality(field) {
|
|
177
|
+
if (field.length === 0) {
|
|
178
178
|
throw new Error('Empty cardinality() called');
|
|
179
179
|
}
|
|
180
180
|
if (this.queryCommands) {
|
|
181
181
|
this.queryCommands.push({
|
|
182
182
|
method: 'cardinality',
|
|
183
|
-
args:
|
|
183
|
+
args: [field],
|
|
184
184
|
});
|
|
185
185
|
}
|
|
186
186
|
else {
|
|
187
|
-
addAggregate(AggregateType.CARDINALITY, this.def,
|
|
187
|
+
addAggregate(AggregateType.CARDINALITY, this.def, [field]);
|
|
188
188
|
}
|
|
189
189
|
// @ts-ignore
|
|
190
190
|
return this;
|
|
@@ -11,7 +11,7 @@ export declare enum AggregateType {
|
|
|
11
11
|
export declare const enum AccumulatorSize {
|
|
12
12
|
SUM = 8,
|
|
13
13
|
COUNT = 4,
|
|
14
|
-
CARDINALITY =
|
|
14
|
+
CARDINALITY = 4,
|
|
15
15
|
STDDEV = 24,// count (u64) + sum (f64) + sum_sq (f64) = 8 + 8 + 8 = 24
|
|
16
16
|
AVERAGE = 16,// count (u64) + sum (f64) = 16
|
|
17
17
|
VARIANCE = 24,// count (u64) + sum (f64) + sum_sq (f64) = 8 + 8 + 8 = 24
|
|
@@ -12,7 +12,7 @@ export var AggregateType;
|
|
|
12
12
|
export const aggregateTypeMap = new Map([
|
|
13
13
|
[
|
|
14
14
|
AggregateType.CARDINALITY,
|
|
15
|
-
{ resultsSize: 4, accumulatorSize:
|
|
15
|
+
{ resultsSize: 4, accumulatorSize: 4 /* AccumulatorSize.CARDINALITY */ },
|
|
16
16
|
],
|
|
17
17
|
[
|
|
18
18
|
AggregateType.COUNT,
|
package/dist/src/server/save.js
CHANGED
|
@@ -2,17 +2,18 @@ import native from '../native.js';
|
|
|
2
2
|
import { isMainThread } from 'node:worker_threads';
|
|
3
3
|
import { writeFile } from 'node:fs/promises';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
-
import { VerifTree, destructureTreeKey
|
|
5
|
+
import { VerifTree, destructureTreeKey } from './tree.js';
|
|
6
6
|
import { saveBlock, foreachBlock, foreachDirtyBlock, saveBlocks, } from './blocks.js';
|
|
7
7
|
import { writeFileSync } from 'node:fs';
|
|
8
8
|
import { bufToHex } from '@saulx/utils';
|
|
9
9
|
import { COMMON_SDB_FILE, WRITELOG_FILE } from '../types.js';
|
|
10
10
|
function hasPartialTypes(db) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
for (const id in db.schemaTypesParsedById) {
|
|
12
|
+
if (db.schemaTypesParsedById[id].partial) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
14
15
|
}
|
|
15
|
-
return
|
|
16
|
+
return false;
|
|
16
17
|
}
|
|
17
18
|
function inhibitSave(db, { skipDirtyCheck, forceFullDump, skipMigrationCheck }) {
|
|
18
19
|
// RFE isMainThread needed??
|
|
@@ -138,7 +139,7 @@ export async function save(db, opts = {}) {
|
|
|
138
139
|
blocks.push({
|
|
139
140
|
filepath,
|
|
140
141
|
typeId,
|
|
141
|
-
start
|
|
142
|
+
start,
|
|
142
143
|
});
|
|
143
144
|
});
|
|
144
145
|
}
|
|
@@ -15,12 +15,14 @@ export const setSchemaOnServer = (server, schema) => {
|
|
|
15
15
|
server.schemaTypesParsedById = schemaTypesParsedById;
|
|
16
16
|
};
|
|
17
17
|
export const writeSchemaFile = async (server, schema) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
if (server.fileSystemPath) {
|
|
19
|
+
const schemaFilePath = join(server.fileSystemPath, SCHEMA_FILE);
|
|
20
|
+
try {
|
|
21
|
+
await writeFile(schemaFilePath, serialize(schema));
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
throw new Error(`Error writing schema to a file path ${schemaFilePath}}`);
|
|
25
|
+
}
|
|
24
26
|
}
|
|
25
27
|
};
|
|
26
28
|
export const setNativeSchema = (server, schema) => {
|
package/dist/src/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare const SCHEMA_FILE = "schema.bin";
|
|
|
3
3
|
export declare const WRITELOG_FILE = "writelog.json";
|
|
4
4
|
export declare const COMMON_SDB_FILE = "common.sdb";
|
|
5
5
|
export type BasedDbOpts = {
|
|
6
|
-
path: string;
|
|
6
|
+
path: string | null;
|
|
7
7
|
maxModifySize?: number;
|
|
8
8
|
debug?: boolean | 'server' | 'client';
|
|
9
9
|
saveIntervalInSeconds?: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@based/db",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.71",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/src/index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"basedDbNative.cjs"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@based/schema": "5.0.0-alpha.
|
|
42
|
+
"@based/schema": "5.0.0-alpha.27",
|
|
43
43
|
"@saulx/hash": "^3.0.0",
|
|
44
44
|
"@saulx/utils": "^6.7.2",
|
|
45
45
|
"exit-hook": "^4.0.0",
|