@based/db 0.0.18 → 0.0.20
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 +89 -6
- package/dist/lib/darwin_aarch64/include/selva/fields.h +28 -39
- package/dist/lib/darwin_aarch64/include/selva/types.h +0 -10
- 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.11.1.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v20.18.1.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v22.13.0.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 +89 -6
- package/dist/lib/linux_aarch64/include/selva/fields.h +28 -39
- package/dist/lib/linux_aarch64/include/selva/types.h +0 -10
- package/dist/lib/linux_aarch64/libjemalloc_selva.so.2 +0 -0
- package/dist/lib/linux_aarch64/libnode-v20.11.1.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v20.18.1.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v22.13.0.node +0 -0
- package/dist/lib/linux_aarch64/libselva.so +0 -0
- package/dist/lib/linux_x86_64/include/selva/db.h +89 -6
- package/dist/lib/linux_x86_64/include/selva/fields.h +28 -39
- package/dist/lib/linux_x86_64/include/selva/types.h +0 -10
- package/dist/lib/linux_x86_64/libjemalloc_selva.so.2 +0 -0
- package/dist/lib/linux_x86_64/libnode-v20.11.1.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v20.18.1.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v22.13.0.node +0 -0
- package/dist/lib/linux_x86_64/libselva.so +0 -0
- package/dist/src/client/index.d.ts +1 -1
- package/dist/src/client/index.js +8 -3
- package/dist/src/client/modify/ModifyRes.d.ts +1 -1
- package/dist/src/client/modify/ModifyRes.js +1 -1
- package/dist/src/client/modify/alias.d.ts +1 -1
- package/dist/src/client/modify/binary.d.ts +1 -1
- package/dist/src/client/modify/cardinality.d.ts +1 -1
- package/dist/src/client/modify/cardinality.js +1 -1
- package/dist/src/client/modify/create.js +2 -2
- package/dist/src/client/modify/delete.js +1 -1
- package/dist/src/client/modify/expire.js +1 -1
- package/dist/src/client/modify/fixed.d.ts +1 -1
- package/dist/src/client/modify/fixed.js +1 -1
- package/dist/src/client/modify/json.d.ts +1 -1
- package/dist/src/client/modify/modify.d.ts +1 -1
- package/dist/src/client/modify/modify.js +1 -1
- package/dist/src/client/modify/references/edge.d.ts +1 -1
- package/dist/src/client/modify/references/edge.js +1 -1
- package/dist/src/client/modify/references/reference.d.ts +1 -1
- package/dist/src/client/modify/references/references.d.ts +1 -1
- package/dist/src/client/modify/references/references.js +1 -1
- package/dist/src/client/modify/setCursor.d.ts +1 -1
- package/dist/src/client/modify/string.d.ts +1 -1
- package/dist/src/client/modify/text.d.ts +1 -1
- package/dist/src/client/modify/text.js +6 -0
- package/dist/src/client/modify/update.js +1 -1
- package/dist/src/client/modify/upsert.js +1 -1
- package/dist/src/client/modify/vector.d.ts +1 -1
- package/dist/src/client/operations.d.ts +2 -1
- package/dist/src/client/operations.js +1 -0
- package/dist/src/client/query/BasedDbQuery.js +1 -1
- package/dist/src/client/query/debug.js +1 -1
- package/dist/src/client/query/display.d.ts +1 -1
- package/dist/src/client/query/display.js +1 -1
- package/dist/src/client/query/filter/createFixedFilterBuffer.d.ts +1 -1
- package/dist/src/client/query/filter/createFixedFilterBuffer.js +1 -2
- package/dist/src/client/query/filter/createReferenceFilter.d.ts +1 -1
- package/dist/src/client/query/filter/createVariableFilterBuffer.d.ts +1 -1
- package/dist/src/client/query/filter/createVariableFilterBuffer.js +1 -1
- package/dist/src/client/query/filter/filter.d.ts +1 -1
- package/dist/src/client/query/filter/filter.js +1 -1
- package/dist/src/client/query/filter/parseFilterValue.d.ts +1 -1
- package/dist/src/client/query/filter/parseFilterValue.js +1 -1
- package/dist/src/client/query/filter/primitiveFilter.d.ts +1 -1
- package/dist/src/client/query/filter/primitiveFilter.js +4 -1
- package/dist/src/client/query/include/props.d.ts +1 -1
- package/dist/src/client/query/include/props.js +1 -1
- package/dist/src/client/query/include/utils.d.ts +1 -1
- package/dist/src/client/query/include/utils.js +1 -1
- package/dist/src/client/query/include/walk.js +1 -1
- package/dist/src/client/query/read/read.js +1 -1
- package/dist/src/client/query/search/index.js +1 -1
- package/dist/src/client/query/subscription/markers.d.ts +1 -1
- package/dist/src/client/query/types.d.ts +1 -1
- package/dist/src/client/query/validation.d.ts +1 -1
- package/dist/src/client/query/validation.js +9 -8
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +0 -1
- package/dist/src/server/index.d.ts +3 -5
- package/dist/src/server/index.js +11 -5
- package/dist/src/server/migrate/worker.js +1 -1
- package/dist/src/server/start.d.ts +0 -1
- package/dist/src/server/start.js +1 -1
- package/dist/src/server/tree.d.ts +1 -1
- package/package.json +2 -2
- package/dist/lib/darwin_aarch64/libxxhash.0.8.2.dylib +0 -0
- package/dist/lib/darwin_aarch64/libxxhash.0.dylib +0 -0
- package/dist/lib/linux_aarch64/libxxhash.so +0 -0
- package/dist/lib/linux_aarch64/libxxhash.so.0.8.2 +0 -0
- package/dist/lib/linux_x86_64/libxxhash.so +0 -0
- package/dist/lib/linux_x86_64/libxxhash.so.0.8.2 +0 -0
- package/dist/src/server/schema/schema.d.ts +0 -3
- package/dist/src/server/schema/schema.js +0 -4
- package/dist/src/server/schema/selvaBuffer.d.ts +0 -4
- package/dist/src/server/schema/selvaBuffer.js +0 -112
- package/dist/src/server/schema/typeDef.d.ts +0 -6
- package/dist/src/server/schema/typeDef.js +0 -337
- package/dist/src/server/schema/types.d.ts +0 -140
- package/dist/src/server/schema/types.js +0 -121
- package/dist/src/server/schema/utils.d.ts +0 -7
- package/dist/src/server/schema/utils.js +0 -34
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ALIAS, TEXT, VECTOR
|
|
1
|
+
import { ALIAS, TEXT, VECTOR } from '@based/schema/def';
|
|
2
2
|
import { EQUAL, EQUAL_CRC32, HAS, HAS_TO_LOWER_CASE, LIKE, MODE_DEFAULT_VAR, MODE_OR_VAR, getVectorFn, } from './types.js';
|
|
3
3
|
import { createFixedFilterBuffer } from './createFixedFilterBuffer.js';
|
|
4
4
|
import { crc32 } from '../../crc32.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { QueryDef, QueryDefFilter } from '../types.js';
|
|
2
|
-
import { SchemaTypeDef } from '
|
|
2
|
+
import { SchemaTypeDef } from '@based/schema/def';
|
|
3
3
|
import { Operator } from './types.js';
|
|
4
4
|
import { Filter, FilterAst } from './types.js';
|
|
5
5
|
import { DbClient } from '../../index.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isPropDef, ID_FIELD_DEF, TEXT, REFERENCE, } from '
|
|
1
|
+
import { isPropDef, ID_FIELD_DEF, TEXT, REFERENCE, } from '@based/schema/def';
|
|
2
2
|
import { primitiveFilter } from './primitiveFilter.js';
|
|
3
3
|
import { IsFilter } from './types.js';
|
|
4
4
|
import { langCodesMap } from '@based/schema';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PropDef, PropDefEdge } from '
|
|
1
|
+
import { PropDef, PropDefEdge } from '@based/schema/def';
|
|
2
2
|
export declare const parseFilterValue: (prop: PropDef | PropDefEdge, value: any) => any;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TIMESTAMP, CREATED, UPDATED, ENUM, BOOLEAN, STRING, BINARY, TEXT, } from '
|
|
1
|
+
import { TIMESTAMP, CREATED, UPDATED, ENUM, BOOLEAN, STRING, BINARY, TEXT, } from '@based/schema/def';
|
|
2
2
|
import { crc32 } from '../../crc32.js';
|
|
3
3
|
import { convertToTimestamp } from '../../timestamp.js';
|
|
4
4
|
// -------------------------------------------
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PropDef, PropDefEdge } from '
|
|
1
|
+
import { PropDef, PropDefEdge } from '@based/schema/def';
|
|
2
2
|
import { QueryDef, QueryDefFilter } from '../types.js';
|
|
3
3
|
import { Filter } from './types.js';
|
|
4
4
|
import { LangCode } from '@based/schema';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { REFERENCE, REFERENCES, REVERSE_SIZE_MAP, } from '
|
|
1
|
+
import { CARDINALITY, REFERENCE, REFERENCES, REVERSE_SIZE_MAP, } from '@based/schema/def';
|
|
2
2
|
import { EQUAL, isNumerical } from './types.js';
|
|
3
3
|
import { createVariableFilterBuffer } from './createVariableFilterBuffer.js';
|
|
4
4
|
import { createFixedFilterBuffer } from './createFixedFilterBuffer.js';
|
|
@@ -27,6 +27,9 @@ export const primitiveFilter = (def, prop, filter, conditions, lang) => {
|
|
|
27
27
|
}
|
|
28
28
|
buf = createFixedFilterBuffer(prop, 4, ctx, value, !isNumerical(ctx.operation));
|
|
29
29
|
}
|
|
30
|
+
else if (prop.typeIndex === CARDINALITY) {
|
|
31
|
+
buf = createFixedFilterBuffer(prop, 2, ctx, value, false);
|
|
32
|
+
}
|
|
30
33
|
else if (propSize) {
|
|
31
34
|
buf = createFixedFilterBuffer(prop, propSize, ctx, value, false);
|
|
32
35
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PropDef, PropDefEdge } from '
|
|
1
|
+
import { PropDef, PropDefEdge } from '@based/schema/def';
|
|
2
2
|
import { QueryDef } from '../types.js';
|
|
3
3
|
export declare const getAll: (props: QueryDef["props"]) => string[];
|
|
4
4
|
export declare const getAllRefs: (props: QueryDef["props"], affix?: string) => string[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PropDef, PropDefEdge, SchemaPropTree } from '
|
|
1
|
+
import { PropDef, PropDefEdge, SchemaPropTree } from '@based/schema/def';
|
|
2
2
|
import { DbClient } from '../../index.js';
|
|
3
3
|
import { QueryDef } from '../types.js';
|
|
4
4
|
export declare const getAllFieldFromObject: (tree: SchemaPropTree | PropDef, arr?: string[]) => string[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isPropDef, REFERENCE, REFERENCES, TEXT, } from '
|
|
1
|
+
import { isPropDef, REFERENCE, REFERENCES, TEXT, } from '@based/schema/def';
|
|
2
2
|
import { createQueryDef } from '../queryDef.js';
|
|
3
3
|
import { isRefDef, QueryDefType } from '../types.js';
|
|
4
4
|
import { getAllFieldFromObject, createOrGetRefQueryDef } from './utils.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ALIAS, ALIASES, BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TEXT, TIMESTAMP, UINT16, UINT32, UINT8, VECTOR, JSON, CARDINALITY, } from '
|
|
1
|
+
import { ALIAS, ALIASES, BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TEXT, TIMESTAMP, UINT16, UINT32, UINT8, VECTOR, JSON, CARDINALITY, } from '@based/schema/def';
|
|
2
2
|
import { read, readUtf8 } from '../../string.js';
|
|
3
3
|
import { readDoubleLE, readFloatLE, readInt16, readInt32, readUint16, readUint32, } from '../../bitWise.js';
|
|
4
4
|
import { inverseLangMap } from '@based/schema';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { langCodesMap } from '@based/schema';
|
|
2
|
-
import { STRING, TEXT, VECTOR } from '
|
|
2
|
+
import { STRING, TEXT, VECTOR } from '@based/schema/def';
|
|
3
3
|
import { getVectorFn } from '../filter/types.js';
|
|
4
4
|
import { searchDoesNotExist, searchIncorrecQueryValue, searchIncorrectType, } from '../validation.js';
|
|
5
5
|
const makeSize = (nr, u8 = false) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PropDef, PropDefEdge } from '
|
|
1
|
+
import { PropDef, PropDefEdge } from '@based/schema/def';
|
|
2
2
|
import { Subscription, SubscriptionMarkerMap, SubscriptionMarkersCheck } from './types.js';
|
|
3
3
|
import { BasedDbQuery } from '../BasedDbQuery.js';
|
|
4
4
|
import { DbClient } from '../../index.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LangCode } from '@based/schema';
|
|
2
|
-
import { PropDef, PropDefEdge, SchemaTypeDef } from '
|
|
2
|
+
import { PropDef, PropDefEdge, SchemaTypeDef } from '@based/schema/def';
|
|
3
3
|
import { FilterOpts } from './filter/types.js';
|
|
4
4
|
import { QueryError } from './validation.js';
|
|
5
5
|
export type MainIncludes = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PropDef, PropDefEdge, SchemaTypeDef } from '
|
|
1
|
+
import { PropDef, PropDefEdge, SchemaTypeDef } from '@based/schema/def';
|
|
2
2
|
import { DbClient } from '../index.js';
|
|
3
3
|
import { Filter } from './query.js';
|
|
4
4
|
import { QueryByAliasObj, QueryDef } from './types.js';
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import picocolors from 'picocolors';
|
|
2
|
-
import { ALIAS, BINARY, BOOLEAN, REFERENCE, REFERENCES, REVERSE_TYPE_INDEX_MAP, STRING, TEXT, TIMESTAMP, VECTOR, } from '
|
|
3
|
-
import { propIsNumerical } from '../../server/schema/utils.js';
|
|
2
|
+
import { ALIAS, BINARY, BOOLEAN, REFERENCE, REFERENCES, REVERSE_TYPE_INDEX_MAP, STRING, TEXT, TIMESTAMP, VECTOR, propIsNumerical, } from '@based/schema/def';
|
|
4
3
|
import { EQUAL, HAS, isNumerical, LIKE, operatorReverseMap, VECTOR_FNS, } from './filter/types.js';
|
|
5
4
|
import { MAX_ID, MAX_ID_VALUE, MAX_IDS_PER_QUERY, MIN_ID_VALUE, } from './thresholds.js';
|
|
6
5
|
import { displayTarget, safeStringify } from './display.js';
|
|
@@ -439,8 +438,9 @@ export const EMPTY_SCHEMA_DEF = {
|
|
|
439
438
|
lastId: 0,
|
|
440
439
|
blockCapacity: 0,
|
|
441
440
|
mainLen: 0,
|
|
442
|
-
buf:
|
|
443
|
-
propNames:
|
|
441
|
+
buf: new Uint8Array([]),
|
|
442
|
+
propNames: new Uint8Array([]),
|
|
443
|
+
packed: new Uint8Array([]),
|
|
444
444
|
props: {},
|
|
445
445
|
locales: {},
|
|
446
446
|
reverseProps: {},
|
|
@@ -452,16 +452,17 @@ export const EMPTY_SCHEMA_DEF = {
|
|
|
452
452
|
hasSeperateSort: false,
|
|
453
453
|
seperateSort: {
|
|
454
454
|
size: 0,
|
|
455
|
-
buffer:
|
|
456
|
-
bufferTmp:
|
|
455
|
+
buffer: new Uint8Array([]),
|
|
456
|
+
bufferTmp: new Uint8Array([]),
|
|
457
457
|
props: [],
|
|
458
458
|
},
|
|
459
459
|
hasSeperateTextSort: false,
|
|
460
460
|
seperateTextSort: {
|
|
461
461
|
size: 0,
|
|
462
|
-
buffer:
|
|
463
|
-
bufferTmp:
|
|
462
|
+
buffer: new Uint8Array([]),
|
|
463
|
+
bufferTmp: new Uint8Array([]),
|
|
464
464
|
props: [],
|
|
465
465
|
},
|
|
466
|
+
localeSize: 0,
|
|
466
467
|
};
|
|
467
468
|
//# sourceMappingURL=validation.js.map
|
package/dist/src/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { compress, decompress } from './client/string.js';
|
|
|
2
2
|
import { ModifyCtx } from './client/operations.js';
|
|
3
3
|
import { DbServer } from './server/index.js';
|
|
4
4
|
import { DbClient } from './client/index.js';
|
|
5
|
-
export * from './server/schema/typeDef.js';
|
|
6
5
|
export * from './client/modify/modify.js';
|
|
7
6
|
export { compress, decompress };
|
|
8
7
|
export { ModifyCtx };
|
package/dist/src/index.js
CHANGED
|
@@ -3,7 +3,6 @@ import { ModifyCtx } from './client/operations.js';
|
|
|
3
3
|
import { DbServer } from './server/index.js';
|
|
4
4
|
import { DbClient } from './client/index.js';
|
|
5
5
|
import picocolors from 'picocolors';
|
|
6
|
-
export * from './server/schema/typeDef.js';
|
|
7
6
|
export * from './client/modify/modify.js';
|
|
8
7
|
export { compress, decompress };
|
|
9
8
|
export { ModifyCtx }; // TODO move this somewhere
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LangName, StrictSchema } from '@based/schema';
|
|
2
|
-
import {
|
|
2
|
+
import { SchemaTypesParsed, SchemaTypesParsedById } from '@based/schema/def';
|
|
3
3
|
import { createTree } from './csmt/index.js';
|
|
4
4
|
import { Worker, MessagePort } from 'node:worker_threads';
|
|
5
5
|
import { TransformFns } from './migrate/index.js';
|
|
@@ -29,10 +29,8 @@ export declare class DbServer {
|
|
|
29
29
|
lastId: number;
|
|
30
30
|
};
|
|
31
31
|
migrating: number;
|
|
32
|
-
schemaTypesParsed:
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
schemaTypesParsedById: Record<number, SchemaTypeDef>;
|
|
32
|
+
schemaTypesParsed: SchemaTypesParsed;
|
|
33
|
+
schemaTypesParsedById: SchemaTypesParsedById;
|
|
36
34
|
fileSystemPath: string;
|
|
37
35
|
maxModifySize: number;
|
|
38
36
|
merkleTree: ReturnType<typeof createTree>;
|
package/dist/src/server/index.js
CHANGED
|
@@ -2,9 +2,9 @@ import native from '../native.js';
|
|
|
2
2
|
import { rm, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
4
|
import { getPropType, langCodesMap, } from '@based/schema';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import {
|
|
6
|
+
// genRootId,
|
|
7
|
+
updateTypeDefs, schemaToSelvaBuffer, } from '@based/schema/def';
|
|
8
8
|
import { start } from './start.js';
|
|
9
9
|
import { foreachDirtyBlock, makeCsmtKey, makeCsmtKeyFromNodeId, } from './tree.js';
|
|
10
10
|
import { save } from './save.js';
|
|
@@ -310,12 +310,18 @@ export class DbServer {
|
|
|
310
310
|
}
|
|
311
311
|
// @ts-ignore This creates an internal type to use for root props
|
|
312
312
|
this.schema.types._root = {
|
|
313
|
-
id:
|
|
313
|
+
id: 1,
|
|
314
314
|
props,
|
|
315
315
|
};
|
|
316
316
|
delete this.schema.props;
|
|
317
317
|
}
|
|
318
|
-
|
|
318
|
+
for (const field in this.schema.types) {
|
|
319
|
+
if (!('id' in this.schema.types[field])) {
|
|
320
|
+
this.schema.lastId++;
|
|
321
|
+
this.schema.types[field].id = this.schema.lastId;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
updateTypeDefs(this.schema, this.schemaTypesParsed, this.schemaTypesParsedById);
|
|
319
325
|
if (!fromStart) {
|
|
320
326
|
writeFile(join(this.fileSystemPath, SCHEMA_FILE), JSON.stringify(this.schema)).catch((err) => console.error(SCHEMA_FILE, err));
|
|
321
327
|
let types = Object.keys(this.schemaTypesParsed);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isMainThread, receiveMessageOnPort, workerData, } from 'node:worker_threads';
|
|
2
2
|
import native from '../../native.js';
|
|
3
3
|
import { BasedDb } from '../../index.js';
|
|
4
|
-
import { REFERENCE, REFERENCES } from '
|
|
4
|
+
import { REFERENCE, REFERENCES } from '@based/schema/def';
|
|
5
5
|
if (isMainThread) {
|
|
6
6
|
console.warn('running worker.ts in mainthread');
|
|
7
7
|
}
|
package/dist/src/server/start.js
CHANGED
|
@@ -9,9 +9,9 @@ import { availableParallelism } from 'node:os';
|
|
|
9
9
|
import exitHook from 'exit-hook';
|
|
10
10
|
import './worker.js';
|
|
11
11
|
import { save } from './save.js';
|
|
12
|
+
import { DEFAULT_BLOCK_CAPACITY } from '@based/schema/def';
|
|
12
13
|
const SCHEMA_FILE = 'schema.json';
|
|
13
14
|
const WRITELOG_FILE = 'writelog.json';
|
|
14
|
-
export const DEFAULT_BLOCK_CAPACITY = 100_000;
|
|
15
15
|
const makeCsmtKey = (typeId, start) => typeId * 4294967296 + start;
|
|
16
16
|
export async function start(db, opts) {
|
|
17
17
|
const path = db.fileSystemPath;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@based/db",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/src/index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"basedDbNative.cjs"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@based/schema": "5.0.0-alpha.
|
|
34
|
+
"@based/schema": "5.0.0-alpha.5",
|
|
35
35
|
"@saulx/hash": "^3.0.0",
|
|
36
36
|
"@saulx/utils": "^4.3.2",
|
|
37
37
|
"exit-hook": "^4.0.0",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { ALIAS, ALIASES, BINARY, BOOLEAN, CREATED, EMPTY_MICRO_BUFFER, ENUM, CARDINALITY, INT16, INT32, INT64, INT8, MICRO_BUFFER, NULL, NUMBER, REFERENCE, REFERENCES, STRING, TEXT, TIMESTAMP, UINT16, UINT32, UINT8, UPDATED, VECTOR, WEAK_REFERENCE, WEAK_REFERENCES, JSON, } from './types.js';
|
|
2
|
-
const selvaTypeMap = [];
|
|
3
|
-
selvaTypeMap[NULL] = 0;
|
|
4
|
-
selvaTypeMap[TIMESTAMP] = 1;
|
|
5
|
-
selvaTypeMap[CREATED] = 1;
|
|
6
|
-
selvaTypeMap[UPDATED] = 1;
|
|
7
|
-
selvaTypeMap[NUMBER] = 4;
|
|
8
|
-
selvaTypeMap[CARDINALITY] = 11;
|
|
9
|
-
selvaTypeMap[INT8] = 20;
|
|
10
|
-
selvaTypeMap[UINT8] = 6;
|
|
11
|
-
selvaTypeMap[INT16] = 21;
|
|
12
|
-
selvaTypeMap[UINT16] = 22;
|
|
13
|
-
selvaTypeMap[INT32] = 23;
|
|
14
|
-
selvaTypeMap[UINT32] = 7;
|
|
15
|
-
selvaTypeMap[INT64] = 24;
|
|
16
|
-
selvaTypeMap[BOOLEAN] = 9;
|
|
17
|
-
selvaTypeMap[ENUM] = 10;
|
|
18
|
-
selvaTypeMap[STRING] = 11;
|
|
19
|
-
selvaTypeMap[TEXT] = 12;
|
|
20
|
-
selvaTypeMap[REFERENCE] = 13;
|
|
21
|
-
selvaTypeMap[REFERENCES] = 14;
|
|
22
|
-
selvaTypeMap[WEAK_REFERENCE] = 15;
|
|
23
|
-
selvaTypeMap[WEAK_REFERENCES] = 16;
|
|
24
|
-
selvaTypeMap[MICRO_BUFFER] = 17;
|
|
25
|
-
selvaTypeMap[ALIAS] = 18;
|
|
26
|
-
selvaTypeMap[ALIASES] = 19;
|
|
27
|
-
selvaTypeMap[BINARY] = 11;
|
|
28
|
-
selvaTypeMap[VECTOR] = 17;
|
|
29
|
-
selvaTypeMap[JSON] = 11;
|
|
30
|
-
const EDGE_FIELD_CONSTRAINT_FLAG_DEPENDENT = 0x01;
|
|
31
|
-
function sepPropCount(props) {
|
|
32
|
-
return props.filter((prop) => prop.separate).length;
|
|
33
|
-
}
|
|
34
|
-
function makeEdgeConstraintFlags(prop) {
|
|
35
|
-
return prop.dependent ? EDGE_FIELD_CONSTRAINT_FLAG_DEPENDENT : 0x00;
|
|
36
|
-
}
|
|
37
|
-
const propDefBuffer = (schema, prop, isEdge) => {
|
|
38
|
-
const type = prop.typeIndex;
|
|
39
|
-
const selvaType = selvaTypeMap[type];
|
|
40
|
-
if (prop.len && (type === MICRO_BUFFER || type === VECTOR)) {
|
|
41
|
-
const buf = Buffer.allocUnsafe(3);
|
|
42
|
-
buf[0] = selvaType;
|
|
43
|
-
buf.writeUint16LE(prop.len, 1);
|
|
44
|
-
return [...buf.values()];
|
|
45
|
-
}
|
|
46
|
-
else if (type === REFERENCE || type === REFERENCES) {
|
|
47
|
-
const buf = Buffer.allocUnsafe(9);
|
|
48
|
-
const dstType = schema[prop.inverseTypeName];
|
|
49
|
-
let eschema = [];
|
|
50
|
-
// @ts-ignore
|
|
51
|
-
buf[0] = selvaType + 2 * !!isEdge; // field type
|
|
52
|
-
buf[1] = makeEdgeConstraintFlags(prop); // flags
|
|
53
|
-
buf.writeUInt16LE(dstType.id, 2); // dst_node_type
|
|
54
|
-
buf.writeUint32LE(0, 5); // schema_len
|
|
55
|
-
if (!isEdge) {
|
|
56
|
-
prop.inverseTypeId = dstType.id;
|
|
57
|
-
prop.inversePropNumber = dstType.props[prop.inversePropName].prop;
|
|
58
|
-
buf[4] = prop.inversePropNumber;
|
|
59
|
-
if (prop.edges) {
|
|
60
|
-
const props = Object.values(prop.edges);
|
|
61
|
-
eschema = props
|
|
62
|
-
.map((prop) => propDefBuffer(schema, prop, true))
|
|
63
|
-
.flat(1);
|
|
64
|
-
eschema.unshift(0, 0, 0, 0, sepPropCount(props), 0);
|
|
65
|
-
buf.writeUint32LE(eschema.length, 5);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return [...buf.values(), ...eschema];
|
|
69
|
-
}
|
|
70
|
-
else if (type === STRING ||
|
|
71
|
-
type === BINARY ||
|
|
72
|
-
type === CARDINALITY ||
|
|
73
|
-
type === JSON) {
|
|
74
|
-
return [selvaType, prop.len < 50 ? prop.len : 0];
|
|
75
|
-
}
|
|
76
|
-
{
|
|
77
|
-
return [selvaType];
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
function makeBlockCapacityBuffer(blockCapacity) {
|
|
81
|
-
const buf = Buffer.allocUnsafe(4);
|
|
82
|
-
buf.writeInt32LE(blockCapacity);
|
|
83
|
-
return buf;
|
|
84
|
-
}
|
|
85
|
-
// todo rewrite
|
|
86
|
-
export function schemaToSelvaBuffer(schema) {
|
|
87
|
-
return Object.values(schema).map((t, i) => {
|
|
88
|
-
const props = Object.values(t.props);
|
|
89
|
-
const rest = [];
|
|
90
|
-
let refFields = 0;
|
|
91
|
-
for (const f of props) {
|
|
92
|
-
if (f.separate) {
|
|
93
|
-
if (f.typeIndex === REFERENCE || f.typeIndex === REFERENCES) {
|
|
94
|
-
refFields++;
|
|
95
|
-
}
|
|
96
|
-
rest.push(f);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
rest.sort((a, b) => a.prop - b.prop);
|
|
100
|
-
return Buffer.from([
|
|
101
|
-
...makeBlockCapacityBuffer(t.blockCapacity).values(),
|
|
102
|
-
1 + sepPropCount(props),
|
|
103
|
-
1 + refFields,
|
|
104
|
-
...propDefBuffer(schema, {
|
|
105
|
-
...EMPTY_MICRO_BUFFER,
|
|
106
|
-
len: t.mainLen === 0 ? 1 : t.mainLen,
|
|
107
|
-
}),
|
|
108
|
-
...rest.map((f) => propDefBuffer(schema, f)).flat(1),
|
|
109
|
-
]);
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
//# sourceMappingURL=selvaBuffer.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { SchemaObject, StrictSchemaType, SchemaLocales } from '@based/schema';
|
|
2
|
-
import { SchemaTypeDef } from './types.js';
|
|
3
|
-
import { DbClient } from '../../client/index.js';
|
|
4
|
-
import { DbServer } from '../index.js';
|
|
5
|
-
export declare const updateTypeDefs: (db: DbClient | DbServer) => void;
|
|
6
|
-
export declare const createSchemaTypeDef: (typeName: string, type: StrictSchemaType | SchemaObject, parsed: DbClient["schemaTypesParsed"], locales: Partial<SchemaLocales>, result?: Partial<SchemaTypeDef>, path?: string[], top?: boolean) => SchemaTypeDef;
|