@based/db 0.0.41 → 0.0.43
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/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/libnode-v24.node +0 -0
- package/dist/lib/darwin_aarch64/libselva.dylib +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/libnode-v24.node +0 -0
- package/dist/lib/linux_aarch64/libselva.so +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/libnode-v24.node +0 -0
- package/dist/lib/linux_x86_64/libselva.so +0 -0
- package/dist/src/client/modify/references/appendEdgeRefs.d.ts +3 -3
- package/dist/src/client/modify/references/appendEdgeRefs.js +1 -1
- package/dist/src/client/query/aggregates/aggregation.d.ts +1 -0
- package/dist/src/client/query/aggregates/aggregation.js +26 -0
- package/dist/src/client/query/toBuffer.js +4 -7
- package/dist/src/client/query/types.d.ts +2 -1
- package/dist/src/client/query/types.js +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/server/index.d.ts +4 -0
- package/dist/src/server/index.js +3 -0
- package/dist/src/server/start.js +1 -1
- package/dist/src/utils.js +1 -1
- package/package.json +1 -1
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PropDefEdge } from '@based/schema/def';
|
|
2
|
-
import { ModifyCtx } from '../../flushModify.js';
|
|
3
|
-
import { ModifyErr } from '../types.js';
|
|
1
|
+
import type { PropDefEdge } from '@based/schema/def';
|
|
2
|
+
import type { ModifyCtx } from '../../flushModify.js';
|
|
3
|
+
import type { ModifyErr } from '../types.js';
|
|
4
4
|
export declare function appendEdgeRefs(t: PropDefEdge, ctx: ModifyCtx, value: any[]): ModifyErr;
|
|
@@ -3,3 +3,4 @@ import { AggregateType } from './types.js';
|
|
|
3
3
|
export declare const aggregateToBuffer: (aggregates: QueryDefAggregation) => Uint8Array;
|
|
4
4
|
export declare const groupBy: (def: QueryDef, field: string) => void;
|
|
5
5
|
export declare const addAggregate: (type: AggregateType, def: QueryDef, fields: (string | string[])[]) => void;
|
|
6
|
+
export declare const isRootCountOnly: (def: QueryDef, filterSize: number) => boolean;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { writeUint16 } from '@saulx/utils';
|
|
2
|
+
import { QueryDefType } from '../types.js';
|
|
2
3
|
import { UINT32 } from '@based/schema/def';
|
|
3
4
|
import { aggregationFieldDoesNotExist } from '../validation.js';
|
|
4
5
|
export const aggregateToBuffer = (aggregates) => {
|
|
@@ -107,4 +108,29 @@ export const addAggregate = (type, def, fields) => {
|
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
};
|
|
111
|
+
export const isRootCountOnly = (def, filterSize) => {
|
|
112
|
+
if (filterSize != 0) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
if (def.type !== QueryDefType.Root) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
if (def.aggregate.groupBy) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
if (def.aggregate.aggregates.size !== 1) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
if (!def.aggregate.aggregates.has(255)) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
const aggs = def.aggregate.aggregates.get(255);
|
|
128
|
+
if (aggs.length !== 1) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
if (aggs[0].type !== 2 /* AggregateType.COUNT */) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
return true;
|
|
135
|
+
};
|
|
110
136
|
//# sourceMappingURL=aggregation.js.map
|
|
@@ -4,7 +4,7 @@ import { includeToBuffer } from './include/toBuffer.js';
|
|
|
4
4
|
import { filterToBuffer } from './query.js';
|
|
5
5
|
import { searchToBuffer } from './search/index.js';
|
|
6
6
|
import { ENCODER } from '@saulx/utils';
|
|
7
|
-
import { aggregateToBuffer } from './aggregates/aggregation.js';
|
|
7
|
+
import { aggregateToBuffer, isRootCountOnly } from './aggregates/aggregation.js';
|
|
8
8
|
const byteSize = (arr) => {
|
|
9
9
|
return arr.reduce((a, b) => {
|
|
10
10
|
return a + b.byteLength;
|
|
@@ -33,9 +33,6 @@ export function defToBuffer(db, def) {
|
|
|
33
33
|
edgesSize = byteSize(edges);
|
|
34
34
|
}
|
|
35
35
|
const size = (edges ? edgesSize + 3 : 0) + byteSize(include);
|
|
36
|
-
// ---------------------------------------
|
|
37
|
-
// move down and will handle size after store the size Var
|
|
38
|
-
// only for references | edges
|
|
39
36
|
if (def.aggregate) {
|
|
40
37
|
const aggregateSize = def.aggregate.size || 0;
|
|
41
38
|
if (aggregateSize === 0) {
|
|
@@ -43,7 +40,9 @@ export function defToBuffer(db, def) {
|
|
|
43
40
|
}
|
|
44
41
|
const filterSize = def.filter.size || 0;
|
|
45
42
|
const buf = new Uint8Array(16 + filterSize + aggregateSize);
|
|
46
|
-
buf[0] =
|
|
43
|
+
buf[0] = isRootCountOnly(def, filterSize)
|
|
44
|
+
? QueryType.aggregatesCountType
|
|
45
|
+
: QueryType.aggregates;
|
|
47
46
|
buf[1] = def.schema.idUint8[0];
|
|
48
47
|
buf[2] = def.schema.idUint8[1];
|
|
49
48
|
buf[3] = def.range.offset;
|
|
@@ -66,8 +65,6 @@ export function defToBuffer(db, def) {
|
|
|
66
65
|
result.push(buf);
|
|
67
66
|
// ignore this for now...
|
|
68
67
|
// result.push(...include)
|
|
69
|
-
// console.log('toBuffer > result: ', result)
|
|
70
|
-
// later this has to be a branch
|
|
71
68
|
return result;
|
|
72
69
|
}
|
|
73
70
|
if (def.type === QueryDefType.Root) {
|
|
@@ -5,6 +5,7 @@ export var QueryType;
|
|
|
5
5
|
QueryType[QueryType["default"] = 2] = "default";
|
|
6
6
|
QueryType[QueryType["alias"] = 3] = "alias";
|
|
7
7
|
QueryType[QueryType["aggregates"] = 4] = "aggregates";
|
|
8
|
+
QueryType[QueryType["aggregatesCountType"] = 5] = "aggregatesCountType";
|
|
8
9
|
})(QueryType || (QueryType = {}));
|
|
9
10
|
var QueryDefType;
|
|
10
11
|
(function (QueryDefType) {
|
package/dist/src/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export { ModifyCtx };
|
|
|
8
8
|
export { DbClient, DbServer };
|
|
9
9
|
export { xxHash64 } from './client/xxHash64.js';
|
|
10
10
|
export { crc32 } from './client/crc32.js';
|
|
11
|
+
export { default as createHash } from './server/dbHash.js';
|
|
11
12
|
export * from './client/query/serialize.js';
|
|
12
13
|
export * from './utils.js';
|
|
13
14
|
export * from './client/query/query.js';
|
package/dist/src/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export { ModifyCtx }; // TODO move this somewhere
|
|
|
11
11
|
export { DbClient, DbServer };
|
|
12
12
|
export { xxHash64 } from './client/xxHash64.js';
|
|
13
13
|
export { crc32 } from './client/crc32.js';
|
|
14
|
+
export { default as createHash } from './server/dbHash.js';
|
|
14
15
|
export * from './client/query/serialize.js';
|
|
15
16
|
export * from './utils.js';
|
|
16
17
|
export * from './client/query/query.js';
|
|
@@ -30,6 +30,7 @@ export declare class DbServer {
|
|
|
30
30
|
dbCtxExternal: any;
|
|
31
31
|
schema: StrictSchema & {
|
|
32
32
|
lastId: number;
|
|
33
|
+
hash?: number;
|
|
33
34
|
};
|
|
34
35
|
migrating: number;
|
|
35
36
|
schemaTypesParsed: SchemaTypesParsed;
|
|
@@ -88,12 +89,15 @@ export declare class DbServer {
|
|
|
88
89
|
getSortIndex(typeId: number, field: number, start: number, lang: number): SortIndex;
|
|
89
90
|
migrateSchema(schema: StrictSchema, transform?: Record<string, (node: Record<string, any>) => Record<string, any> | [string, Record<string, any>]>): Promise<StrictSchema & {
|
|
90
91
|
lastId: number;
|
|
92
|
+
hash?: number;
|
|
91
93
|
}>;
|
|
92
94
|
createSortIndexBuffer(typeId: number, field: number, start: number, lang: number): SortIndex;
|
|
93
95
|
setSchema(strictSchema: StrictSchema, fromStart?: boolean, transformFns?: TransformFns): (StrictSchema & {
|
|
94
96
|
lastId: number;
|
|
97
|
+
hash?: number;
|
|
95
98
|
}) | Promise<StrictSchema & {
|
|
96
99
|
lastId: number;
|
|
100
|
+
hash?: number;
|
|
97
101
|
}>;
|
|
98
102
|
modify(buf: Uint8Array): Record<number, number>;
|
|
99
103
|
addToQueryQueue(resolve: any, buf: any): void;
|
package/dist/src/server/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
12
12
|
import { setTimeout } from 'node:timers/promises';
|
|
13
13
|
import { migrate } from './migrate/index.js';
|
|
14
14
|
import { debugServer, schemaLooseEqual } from '../utils.js';
|
|
15
|
+
import { hash } from '@saulx/hash';
|
|
15
16
|
export const SCHEMA_FILE = 'schema.json';
|
|
16
17
|
export const WRITELOG_FILE = 'writelog.json';
|
|
17
18
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -339,6 +340,8 @@ export class DbServer {
|
|
|
339
340
|
}
|
|
340
341
|
}
|
|
341
342
|
updateTypeDefs(this.schema, this.schemaTypesParsed, this.schemaTypesParsedById);
|
|
343
|
+
const { hash: _, ...schemaWithoutHash } = this.schema;
|
|
344
|
+
this.schema.hash = hash(schemaWithoutHash);
|
|
342
345
|
if (!fromStart) {
|
|
343
346
|
writeFile(join(this.fileSystemPath, SCHEMA_FILE), JSON.stringify(this.schema)).catch((err) => console.error('!!!', SCHEMA_FILE, err));
|
|
344
347
|
let types = Object.keys(this.schemaTypesParsed);
|
package/dist/src/server/start.js
CHANGED
|
@@ -47,7 +47,7 @@ export async function start(db, opts) {
|
|
|
47
47
|
const schema = await readFile(join(path, SCHEMA_FILE));
|
|
48
48
|
if (schema) {
|
|
49
49
|
// Prop need to not call setting in selva
|
|
50
|
-
db.setSchema(JSON.parse(schema.toString()), true);
|
|
50
|
+
await db.setSchema(JSON.parse(schema.toString()), true);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
catch (err) {
|
package/dist/src/utils.js
CHANGED
|
@@ -43,7 +43,7 @@ export const debugMode = (target, getInfo = null) => {
|
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
45
|
export const debugServer = (server) => debugMode(server, () => `p: ${server.processingQueries} m: ${server.modifyQueue.length} q: ${server.queryQueue.size}`);
|
|
46
|
-
const exclude = new Set(['id', 'lastId']);
|
|
46
|
+
const exclude = new Set(['id', 'lastId', 'hash']);
|
|
47
47
|
export const schemaLooseEqual = (a, b, key) => {
|
|
48
48
|
if (a === b) {
|
|
49
49
|
return true;
|