@based/db 0.0.71 → 0.1.1
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/LICENSE +201 -0
- package/README.md +105 -77
- package/dist/lib/darwin_aarch64/include/libdeflate.h +23 -0
- package/dist/lib/darwin_aarch64/include/selva/db.h +0 -41
- package/dist/lib/darwin_aarch64/include/selva/fast_linear_search.h +6 -2
- package/dist/lib/darwin_aarch64/include/selva/fields.h +52 -37
- package/dist/lib/darwin_aarch64/include/selva/gmtime.h +137 -0
- package/dist/lib/darwin_aarch64/include/selva/mblen.h +40 -0
- package/dist/lib/darwin_aarch64/include/selva/selva_string.h +8 -5
- package/dist/lib/darwin_aarch64/include/selva/thread.h +37 -0
- package/dist/lib/darwin_aarch64/include/selva/types.h +18 -4
- 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-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/darwin_aarch64/libxxhash.dylib +0 -0
- package/dist/lib/linux_aarch64/include/libdeflate.h +23 -0
- package/dist/lib/linux_aarch64/include/selva/db.h +0 -41
- package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +6 -2
- package/dist/lib/linux_aarch64/include/selva/fields.h +52 -37
- package/dist/lib/linux_aarch64/include/selva/gmtime.h +137 -0
- package/dist/lib/linux_aarch64/include/selva/mblen.h +40 -0
- package/dist/lib/linux_aarch64/include/selva/selva_string.h +8 -5
- package/dist/lib/linux_aarch64/include/selva/thread.h +37 -0
- package/dist/lib/linux_aarch64/include/selva/types.h +18 -4
- package/dist/lib/linux_aarch64/libdeflate.so +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/include/libdeflate.h +23 -0
- package/dist/lib/linux_x86_64/include/selva/db.h +0 -41
- package/dist/lib/linux_x86_64/include/selva/fast_linear_search.h +6 -2
- package/dist/lib/linux_x86_64/include/selva/fields.h +52 -37
- package/dist/lib/linux_x86_64/include/selva/gmtime.h +137 -0
- package/dist/lib/linux_x86_64/include/selva/mblen.h +40 -0
- package/dist/lib/linux_x86_64/include/selva/selva_string.h +8 -5
- package/dist/lib/linux_x86_64/include/selva/thread.h +37 -0
- package/dist/lib/linux_x86_64/include/selva/types.h +18 -4
- package/dist/lib/linux_x86_64/libdeflate.so +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/index.d.ts +16 -21
- package/dist/src/client/index.js +48 -59
- package/dist/src/client/modify/Ctx.d.ts +38 -0
- package/dist/src/client/modify/Ctx.js +30 -0
- package/dist/src/client/modify/Tmp.d.ts +19 -0
- package/dist/src/client/modify/Tmp.js +67 -0
- package/dist/src/client/modify/create/index.d.ts +6 -0
- package/dist/src/client/modify/create/index.js +191 -0
- package/dist/src/client/modify/create/mark.d.ts +7 -0
- package/dist/src/client/modify/create/mark.js +42 -0
- package/dist/src/client/modify/cursor.d.ts +10 -0
- package/dist/src/client/modify/cursor.js +48 -0
- package/dist/src/client/modify/delete/index.d.ts +2 -0
- package/dist/src/client/modify/delete/index.js +39 -0
- package/dist/src/client/modify/drain.d.ts +7 -0
- package/dist/src/client/modify/drain.js +77 -0
- package/dist/src/client/modify/edges/binary.d.ts +3 -0
- package/dist/src/client/modify/edges/binary.js +28 -0
- package/dist/src/client/modify/edges/cardinality.d.ts +3 -0
- package/dist/src/client/modify/edges/cardinality.js +15 -0
- package/dist/src/client/modify/edges/header.d.ts +5 -0
- package/dist/src/client/modify/edges/header.js +21 -0
- package/dist/src/client/modify/edges/index.d.ts +3 -0
- package/dist/src/client/modify/edges/index.js +128 -0
- package/dist/src/client/modify/edges/reference.d.ts +3 -0
- package/dist/src/client/modify/edges/reference.js +31 -0
- package/dist/src/client/modify/edges/references.d.ts +3 -0
- package/dist/src/client/modify/edges/references.js +38 -0
- package/dist/src/client/modify/edges/separate.d.ts +3 -0
- package/dist/src/client/modify/edges/separate.js +24 -0
- package/dist/src/client/modify/edges/string.d.ts +3 -0
- package/dist/src/client/modify/edges/string.js +30 -0
- package/dist/src/client/modify/error.d.ts +7 -0
- package/dist/src/client/modify/error.js +68 -0
- package/dist/src/client/modify/expire/index.d.ts +2 -0
- package/dist/src/client/modify/expire/index.js +31 -0
- package/dist/src/client/modify/props/alias.d.ts +3 -0
- package/dist/src/client/modify/props/alias.js +26 -0
- package/dist/src/client/modify/props/binary.d.ts +5 -0
- package/dist/src/client/modify/props/binary.js +52 -0
- package/dist/src/client/modify/props/cardinality.d.ts +4 -0
- package/dist/src/client/modify/props/cardinality.js +46 -0
- package/dist/src/client/modify/props/delete.d.ts +3 -0
- package/dist/src/client/modify/props/delete.js +13 -0
- package/dist/src/client/modify/props/fixed.d.ts +4 -0
- package/dist/src/client/modify/props/fixed.js +105 -0
- package/dist/src/client/modify/props/increment.d.ts +3 -0
- package/dist/src/client/modify/props/increment.js +28 -0
- package/dist/src/client/modify/props/json.d.ts +3 -0
- package/dist/src/client/modify/props/json.js +5 -0
- package/dist/src/client/modify/props/main.d.ts +4 -0
- package/dist/src/client/modify/props/main.js +22 -0
- package/dist/src/client/modify/props/object.d.ts +3 -0
- package/dist/src/client/modify/props/object.js +37 -0
- package/dist/src/client/modify/props/reference.d.ts +6 -0
- package/dist/src/client/modify/props/reference.js +92 -0
- package/dist/src/client/modify/props/references.d.ts +3 -0
- package/dist/src/client/modify/props/references.js +231 -0
- package/dist/src/client/modify/props/separate.d.ts +3 -0
- package/dist/src/client/modify/props/separate.js +43 -0
- package/dist/src/client/modify/props/string.d.ts +5 -0
- package/dist/src/client/modify/props/string.js +51 -0
- package/dist/src/client/modify/props/text.d.ts +3 -0
- package/dist/src/client/modify/props/text.js +35 -0
- package/dist/src/client/modify/props/vector.d.ts +3 -0
- package/dist/src/client/modify/props/vector.js +48 -0
- package/dist/src/client/modify/resize.d.ts +3 -0
- package/dist/src/client/modify/resize.js +20 -0
- package/dist/src/client/modify/types.d.ts +3 -4
- package/dist/src/client/modify/types.js +2 -1
- package/dist/src/client/modify/uint.d.ts +7 -0
- package/dist/src/client/modify/uint.js +27 -0
- package/dist/src/client/modify/update/index.d.ts +3 -0
- package/dist/src/client/modify/update/index.js +75 -0
- package/dist/src/client/modify/upsert/index.d.ts +3 -0
- package/dist/src/client/modify/{upsert.js → upsert/index.js} +4 -4
- package/dist/src/client/modify/validate.d.ts +6 -0
- package/dist/src/client/modify/validate.js +24 -0
- package/dist/src/client/query/BasedDbQuery.d.ts +17 -14
- package/dist/src/client/query/BasedDbQuery.js +90 -93
- package/dist/src/client/query/{BasedIterable.d.ts → BasedQueryResponse.d.ts} +5 -4
- package/dist/src/client/query/{BasedIterable.js → BasedQueryResponse.js} +15 -10
- package/dist/src/client/query/aggregates/aggregation.d.ts +5 -3
- package/dist/src/client/query/aggregates/aggregation.js +105 -48
- package/dist/src/client/query/aggregates/types.d.ts +33 -11
- package/dist/src/client/query/aggregates/types.js +29 -11
- 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 +21 -4
- package/dist/src/client/query/filter/FilterBranch.js +2 -2
- package/dist/src/client/query/filter/convertFilter.d.ts +3 -2
- package/dist/src/client/query/filter/convertFilter.js +13 -1
- package/dist/src/client/query/filter/createFixedFilterBuffer.js +16 -30
- package/dist/src/client/query/filter/createReferenceFilter.js +6 -20
- package/dist/src/client/query/filter/createVariableFilterBuffer.js +15 -32
- package/dist/src/client/query/filter/parseFilterValue.js +3 -11
- package/dist/src/client/query/filter/primitiveFilter.js +1 -1
- package/dist/src/client/query/filter/toBuffer.js +9 -15
- package/dist/src/client/query/filter/types.d.ts +6 -6
- package/dist/src/client/query/filter/types.js +8 -8
- package/dist/src/client/query/include/include.d.ts +3 -0
- package/dist/src/client/query/include/include.js +58 -0
- package/dist/src/client/query/include/props.d.ts +7 -7
- package/dist/src/client/query/include/props.js +26 -21
- package/dist/src/client/query/include/toByteCode.js +188 -0
- package/dist/src/client/query/include/utils.d.ts +3 -1
- package/dist/src/client/query/include/utils.js +13 -0
- package/dist/src/client/query/include/walk.d.ts +2 -2
- package/dist/src/client/query/include/walk.js +38 -23
- package/dist/src/client/query/query.d.ts +2 -3
- package/dist/src/client/query/query.js +2 -3
- package/dist/src/client/query/queryDef.d.ts +4 -2
- package/dist/src/client/query/queryDef.js +3 -5
- package/dist/src/client/query/queryDefToReadSchema.d.ts +3 -0
- package/dist/src/client/query/queryDefToReadSchema.js +126 -0
- package/dist/src/client/query/registerQuery.js +15 -4
- package/dist/src/client/query/search/index.d.ts +2 -1
- package/dist/src/client/query/search/index.js +9 -2
- package/dist/src/client/query/sort.js +3 -0
- package/dist/src/client/query/subscription/index.d.ts +1 -1
- package/dist/src/client/query/subscription/index.js +2 -2
- package/dist/src/client/query/subscription/types.d.ts +1 -1
- package/dist/src/client/query/thresholds.d.ts +1 -1
- package/dist/src/client/query/thresholds.js +1 -1
- package/dist/src/client/query/toByteCode/{toBuffer.js → toByteCode.js} +8 -8
- package/dist/src/client/query/types.d.ts +40 -25
- package/dist/src/client/query/types.js +2 -6
- package/dist/src/client/query/validation.d.ts +6 -0
- package/dist/src/client/query/validation.js +31 -7
- package/dist/src/client/setLocalClientSchema.js +6 -10
- package/dist/src/client/string.d.ts +3 -7
- package/dist/src/client/string.js +18 -47
- package/dist/src/hooks.d.ts +2 -3
- package/dist/src/hooks.js +14 -9
- package/dist/src/index.d.ts +3 -5
- package/dist/src/index.js +4 -6
- package/dist/src/native.d.ts +3 -2
- package/dist/src/native.js +9 -8
- package/dist/src/server/IoWorker.js +2 -3
- package/dist/src/server/QueryWorker.js +1 -1
- package/dist/src/server/blocks.js +5 -4
- package/dist/src/server/dbHash.js +1 -1
- package/dist/src/server/index.d.ts +4 -6
- package/dist/src/server/index.js +63 -96
- package/dist/src/server/migrate/index.d.ts +2 -4
- package/dist/src/server/migrate/index.js +32 -16
- package/dist/src/server/migrate/worker.js +2 -27
- package/dist/src/server/save.js +3 -2
- package/dist/src/server/schema.js +9 -19
- package/dist/src/server/start.d.ts +1 -0
- package/dist/src/server/start.js +18 -10
- package/dist/src/server/tree.d.ts +20 -0
- package/dist/src/server/tree.js +17 -2
- package/dist/src/server/workers/DbWorker.d.ts +1 -0
- package/dist/src/server/workers/DbWorker.js +8 -1
- package/dist/src/server/workers/io_worker.js +1 -1
- package/dist/src/server/workers/worker.js +9 -4
- package/dist/src/table.d.ts +4 -0
- package/dist/src/table.js +97 -0
- package/package.json +18 -17
- package/dist/lib/darwin_aarch64/include/selva/worker_ctx.h +0 -29
- package/dist/lib/linux_aarch64/include/selva/worker_ctx.h +0 -29
- package/dist/lib/linux_x86_64/include/selva/worker_ctx.h +0 -29
- package/dist/src/client/flushModify.d.ts +0 -36
- package/dist/src/client/flushModify.js +0 -197
- package/dist/src/client/modify/ModifyRes.d.ts +0 -23
- package/dist/src/client/modify/ModifyRes.js +0 -101
- package/dist/src/client/modify/alias.d.ts +0 -4
- package/dist/src/client/modify/alias.js +0 -57
- package/dist/src/client/modify/binary.d.ts +0 -6
- package/dist/src/client/modify/binary.js +0 -80
- package/dist/src/client/modify/cardinality.d.ts +0 -6
- package/dist/src/client/modify/cardinality.js +0 -63
- package/dist/src/client/modify/create.d.ts +0 -5
- package/dist/src/client/modify/create.js +0 -228
- package/dist/src/client/modify/delete.d.ts +0 -4
- package/dist/src/client/modify/delete.js +0 -47
- package/dist/src/client/modify/expire.d.ts +0 -3
- package/dist/src/client/modify/expire.js +0 -25
- package/dist/src/client/modify/fixed.d.ts +0 -5
- package/dist/src/client/modify/fixed.js +0 -235
- package/dist/src/client/modify/index.d.ts +0 -4
- package/dist/src/client/modify/index.js +0 -4
- package/dist/src/client/modify/json.d.ts +0 -4
- package/dist/src/client/modify/json.js +0 -26
- package/dist/src/client/modify/modify.d.ts +0 -5
- package/dist/src/client/modify/modify.js +0 -134
- package/dist/src/client/modify/references/appendEdgeRefs.d.ts +0 -4
- package/dist/src/client/modify/references/appendEdgeRefs.js +0 -33
- package/dist/src/client/modify/references/edge.d.ts +0 -5
- package/dist/src/client/modify/references/edge.js +0 -336
- package/dist/src/client/modify/references/getEdgeSize.d.ts +0 -3
- package/dist/src/client/modify/references/getEdgeSize.js +0 -27
- package/dist/src/client/modify/references/reference.d.ts +0 -11
- package/dist/src/client/modify/references/reference.js +0 -124
- package/dist/src/client/modify/references/references.d.ts +0 -16
- package/dist/src/client/modify/references/references.js +0 -316
- package/dist/src/client/modify/setCursor.d.ts +0 -5
- package/dist/src/client/modify/setCursor.js +0 -33
- package/dist/src/client/modify/string.d.ts +0 -5
- package/dist/src/client/modify/string.js +0 -71
- package/dist/src/client/modify/text.d.ts +0 -8
- package/dist/src/client/modify/text.js +0 -69
- package/dist/src/client/modify/update.d.ts +0 -6
- package/dist/src/client/modify/update.js +0 -90
- package/dist/src/client/modify/upsert.d.ts +0 -3
- package/dist/src/client/modify/vector.d.ts +0 -4
- package/dist/src/client/modify/vector.js +0 -53
- package/dist/src/client/query/include/toBuffer.js +0 -123
- package/dist/src/client/query/read/read.d.ts +0 -9
- package/dist/src/client/query/read/read.js +0 -483
- /package/dist/src/client/query/include/{toBuffer.d.ts → toByteCode.d.ts} +0 -0
- /package/dist/src/client/query/toByteCode/{toBuffer.d.ts → toByteCode.d.ts} +0 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { DELETE, DELETE_TEXT_FIELD, RANGE_ERR, UPDATE, } from '../types.js';
|
|
2
|
+
import { FULL_CURSOR_SIZE, PROP_CURSOR_SIZE, writePropCursor, } from '../cursor.js';
|
|
3
|
+
import { reserve } from '../resize.js';
|
|
4
|
+
import { ENCODER, writeUint32 } from '@based/utils';
|
|
5
|
+
import { write } from '../../string.js';
|
|
6
|
+
import { writeU8, writeU8Array } from '../uint.js';
|
|
7
|
+
import { markString } from '../create/mark.js';
|
|
8
|
+
import { validate } from '../validate.js';
|
|
9
|
+
export const deleteString = (ctx, def, lang) => {
|
|
10
|
+
if (ctx.operation !== UPDATE) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (!lang) {
|
|
14
|
+
reserve(ctx, PROP_CURSOR_SIZE + 1);
|
|
15
|
+
writePropCursor(ctx, def);
|
|
16
|
+
writeU8(ctx, DELETE);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
reserve(ctx, PROP_CURSOR_SIZE + 2);
|
|
20
|
+
writePropCursor(ctx, def);
|
|
21
|
+
writeU8(ctx, DELETE_TEXT_FIELD);
|
|
22
|
+
writeU8(ctx, lang);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export const writeString = (ctx, def, val, lang) => {
|
|
26
|
+
const isUint8 = val instanceof Uint8Array;
|
|
27
|
+
if (val === null || val === '' || (isUint8 && val.byteLength === 0)) {
|
|
28
|
+
deleteString(ctx, def, lang);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
validate(def, val);
|
|
32
|
+
let size = isUint8 ? val.byteLength : ENCODER.encode(val).byteLength + 6;
|
|
33
|
+
reserve(ctx, FULL_CURSOR_SIZE + 11 + size);
|
|
34
|
+
writePropCursor(ctx, def);
|
|
35
|
+
writeU8(ctx, ctx.operation);
|
|
36
|
+
const index = ctx.index;
|
|
37
|
+
ctx.index += 4;
|
|
38
|
+
if (isUint8) {
|
|
39
|
+
writeU8Array(ctx, val);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
size = write(ctx, val, ctx.index, def.compression === 0, lang);
|
|
43
|
+
if (size === null) {
|
|
44
|
+
throw RANGE_ERR;
|
|
45
|
+
}
|
|
46
|
+
ctx.index += size;
|
|
47
|
+
}
|
|
48
|
+
writeUint32(ctx.array, size, index);
|
|
49
|
+
markString(ctx, def);
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=string.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { deleteString, writeString } from './string.js';
|
|
2
|
+
import { markTextValue, markTextObj } from '../create/mark.js';
|
|
3
|
+
export const writeText = (ctx, def, val) => {
|
|
4
|
+
if (val === null) {
|
|
5
|
+
deleteString(ctx, def, ctx.locale);
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (typeof val === 'string' || val instanceof Uint8Array) {
|
|
9
|
+
if (!ctx.locale) {
|
|
10
|
+
throw [def, val];
|
|
11
|
+
}
|
|
12
|
+
if (!ctx.schema.separateTextSort.localeToIndex.has(ctx.locale)) {
|
|
13
|
+
throw [def, val, 'Invalid locale'];
|
|
14
|
+
}
|
|
15
|
+
writeString(ctx, def, val, ctx.locale);
|
|
16
|
+
markTextValue(ctx, def, ctx.locale, true);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (typeof val === 'object') {
|
|
20
|
+
markTextObj(ctx);
|
|
21
|
+
for (const lang in val) {
|
|
22
|
+
const langU8 = ctx.schema.separateTextSort.localeStringToIndex.get(lang);
|
|
23
|
+
if (!langU8) {
|
|
24
|
+
throw [def, val, 'Invalid locale'];
|
|
25
|
+
}
|
|
26
|
+
const text = val[lang];
|
|
27
|
+
const locale = langU8[1];
|
|
28
|
+
writeString(ctx, def, text, locale);
|
|
29
|
+
markTextValue(ctx, def, locale, false);
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
throw [def, val];
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=text.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { deleteProp } from './delete.js';
|
|
2
|
+
import { validate } from '../validate.js';
|
|
3
|
+
import { PROP_CURSOR_SIZE, writePropCursor } from '../cursor.js';
|
|
4
|
+
import { reserve } from '../resize.js';
|
|
5
|
+
import { writeU8 } from '../uint.js';
|
|
6
|
+
export const writeVector = (ctx, def, val) => {
|
|
7
|
+
if (val === null) {
|
|
8
|
+
deleteProp(ctx, def);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
validate(def, val);
|
|
12
|
+
if (val.byteLength === 0) {
|
|
13
|
+
deleteProp(ctx, def);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
reserve(ctx, PROP_CURSOR_SIZE + 9 + val.byteLength);
|
|
17
|
+
writePropCursor(ctx, def);
|
|
18
|
+
writeU8(ctx, ctx.operation);
|
|
19
|
+
let size = Math.min(val.byteLength, def.len);
|
|
20
|
+
let padding = 0;
|
|
21
|
+
if (ctx.index % 4 != 0) {
|
|
22
|
+
padding = ctx.index % 4;
|
|
23
|
+
}
|
|
24
|
+
size -= padding;
|
|
25
|
+
let tmp = size + 4;
|
|
26
|
+
// 16-bits would be enough but the zig expects 32-bits
|
|
27
|
+
ctx.array[ctx.index++] = tmp;
|
|
28
|
+
ctx.array[ctx.index++] = tmp >>>= 8;
|
|
29
|
+
ctx.array[ctx.index++] = tmp >>>= 8;
|
|
30
|
+
ctx.array[ctx.index++] = tmp >>>= 8;
|
|
31
|
+
ctx.array[ctx.index++] = padding;
|
|
32
|
+
ctx.array[ctx.index++] = 0;
|
|
33
|
+
ctx.array[ctx.index++] = 0;
|
|
34
|
+
ctx.array[ctx.index++] = 0;
|
|
35
|
+
ctx.array.set(new Uint8Array(val.buffer).subarray(0, size), ctx.index - padding);
|
|
36
|
+
ctx.index += size;
|
|
37
|
+
// let size = Math.min(val.byteLength, def.len)
|
|
38
|
+
// let padding = 0
|
|
39
|
+
// if (ctx.index % 4 !== 0) {
|
|
40
|
+
// padding = ctx.index % 4
|
|
41
|
+
// size -= padding
|
|
42
|
+
// }
|
|
43
|
+
// writeU32(ctx, size + 4)
|
|
44
|
+
// writeU8(ctx, padding)
|
|
45
|
+
// writePadding(ctx, 3 - padding)
|
|
46
|
+
// writeU8Array(ctx, new Uint8Array(val.buffer).subarray(0, size))
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=vector.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RANGE_ERR } from './types.js';
|
|
2
|
+
export const resize = (ctx, size) => {
|
|
3
|
+
if (size > ctx.max) {
|
|
4
|
+
throw RANGE_ERR;
|
|
5
|
+
}
|
|
6
|
+
if (size > ctx.size) {
|
|
7
|
+
const avail = ctx.array.buffer.maxByteLength;
|
|
8
|
+
const affix = avail - ctx.max;
|
|
9
|
+
const required = size + affix;
|
|
10
|
+
const double = Math.max(required, ctx.size * 2);
|
|
11
|
+
const length = Math.min(avail, double);
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
ctx.array.buffer.resize(length);
|
|
14
|
+
ctx.size = length - affix;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export const reserve = (ctx, size) => {
|
|
18
|
+
resize(ctx, ctx.index + size);
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=resize.js.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { LangName } from '@based/schema';
|
|
2
|
-
import { ModifyError } from './ModifyRes.js';
|
|
3
2
|
export declare const CREATE = 3;
|
|
4
3
|
export declare const UPDATE = 6;
|
|
5
4
|
export declare const UPDATE_PARTIAL = 5;
|
|
@@ -22,7 +21,6 @@ export declare const MOD_OPS_TO_STRING: Record<ModifyOp, 'create' | 'update'>;
|
|
|
22
21
|
export declare const enum SIZE {
|
|
23
22
|
DEFAULT_CURSOR = 11
|
|
24
23
|
}
|
|
25
|
-
export type ModifyErr = typeof RANGE_ERR | ModifyError | void;
|
|
26
24
|
export type ModifyOpts = {
|
|
27
25
|
unsafe?: boolean;
|
|
28
26
|
locale?: LangName;
|
|
@@ -36,8 +34,9 @@ export declare const NOEDGE_NOINDEX_TMPID = 4;
|
|
|
36
34
|
export declare const EDGE_NOINDEX_TMPID = 5;
|
|
37
35
|
export declare const EDGE_INDEX_TMPID = 6;
|
|
38
36
|
export declare const NOEDGE_INDEX_TMPID = 7;
|
|
39
|
-
export declare const REF_OP_UPDATE = 1;
|
|
40
37
|
export declare const REF_OP_OVERWRITE = 0;
|
|
38
|
+
export declare const REF_OP_UPDATE = 1;
|
|
39
|
+
export declare const REF_OP_DELETE = 2;
|
|
41
40
|
export declare const REF_OP_PUT_OVERWRITE = 3;
|
|
42
41
|
export declare const REF_OP_PUT_ADD = 4;
|
|
43
|
-
export type
|
|
42
|
+
export type RefOp = typeof REF_OP_OVERWRITE | typeof REF_OP_UPDATE;
|
|
@@ -29,8 +29,9 @@ export const NOEDGE_NOINDEX_TMPID = 4;
|
|
|
29
29
|
export const EDGE_NOINDEX_TMPID = 5;
|
|
30
30
|
export const EDGE_INDEX_TMPID = 6;
|
|
31
31
|
export const NOEDGE_INDEX_TMPID = 7;
|
|
32
|
-
export const REF_OP_UPDATE = 1;
|
|
33
32
|
export const REF_OP_OVERWRITE = 0;
|
|
33
|
+
export const REF_OP_UPDATE = 1;
|
|
34
|
+
export const REF_OP_DELETE = 2;
|
|
34
35
|
export const REF_OP_PUT_OVERWRITE = 3;
|
|
35
36
|
export const REF_OP_PUT_ADD = 4;
|
|
36
37
|
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Ctx } from './Ctx.js';
|
|
2
|
+
export declare const writeU64: (ctx: Ctx, val: number) => void;
|
|
3
|
+
export declare const writeU32: (ctx: Ctx, val: number) => void;
|
|
4
|
+
export declare const writePadding: (ctx: Ctx, padding: number) => void;
|
|
5
|
+
export declare const writeU16: (ctx: Ctx, val: number) => void;
|
|
6
|
+
export declare const writeU8: (ctx: Ctx, val: number) => void;
|
|
7
|
+
export declare const writeU8Array: (ctx: Ctx, val: Uint8Array) => void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { writeInt64, writeUint16, writeUint32 } from '@based/utils';
|
|
2
|
+
export const writeU64 = (ctx, val) => {
|
|
3
|
+
writeInt64(ctx.array, val, ctx.index);
|
|
4
|
+
ctx.index += 8;
|
|
5
|
+
};
|
|
6
|
+
export const writeU32 = (ctx, val) => {
|
|
7
|
+
writeUint32(ctx.array, val, ctx.index);
|
|
8
|
+
ctx.index += 4;
|
|
9
|
+
};
|
|
10
|
+
export const writePadding = (ctx, padding) => {
|
|
11
|
+
while (padding--) {
|
|
12
|
+
ctx.array[ctx.index++] = 0;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
export const writeU16 = (ctx, val) => {
|
|
16
|
+
writeUint16(ctx.array, val, ctx.index);
|
|
17
|
+
ctx.index += 2;
|
|
18
|
+
};
|
|
19
|
+
export const writeU8 = (ctx, val) => {
|
|
20
|
+
ctx.array[ctx.index] = val;
|
|
21
|
+
ctx.index += 1;
|
|
22
|
+
};
|
|
23
|
+
export const writeU8Array = (ctx, val) => {
|
|
24
|
+
ctx.array.set(val, ctx.index);
|
|
25
|
+
ctx.index += val.byteLength;
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=uint.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { UPDATE, UPDATE_PARTIAL } from '../types.js';
|
|
2
|
+
import { getValidSchema, validateId, validatePayload } from '../validate.js';
|
|
3
|
+
import { langCodesMap } from '@based/schema';
|
|
4
|
+
import { handleError } from '../error.js';
|
|
5
|
+
import { Tmp } from '../Tmp.js';
|
|
6
|
+
import { writeObject } from '../props/object.js';
|
|
7
|
+
import { reserve } from '../resize.js';
|
|
8
|
+
import { FULL_CURSOR_SIZE, PROP_CURSOR_SIZE, writeMainCursor, writeNodeCursor, writeTypeCursor, } from '../cursor.js';
|
|
9
|
+
import { getByPath, writeUint32 } from '@based/utils';
|
|
10
|
+
import { writeU16, writeU8 } from '../uint.js';
|
|
11
|
+
import { writeFixed } from '../props/fixed.js';
|
|
12
|
+
import { schedule } from '../drain.js';
|
|
13
|
+
const writeUpdateTs = (ctx, payload) => {
|
|
14
|
+
if (ctx.schema.updateTs) {
|
|
15
|
+
const updateTs = Date.now();
|
|
16
|
+
for (const def of ctx.schema.updateTs) {
|
|
17
|
+
if (getByPath(payload, def.path) !== undefined) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
ctx.main.set(def, updateTs);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const writeMergeMain = (ctx) => {
|
|
25
|
+
if (ctx.main.size) {
|
|
26
|
+
reserve(ctx, PROP_CURSOR_SIZE + 5 + ctx.main.size * 4);
|
|
27
|
+
writeMainCursor(ctx);
|
|
28
|
+
writeU8(ctx, UPDATE_PARTIAL);
|
|
29
|
+
const index = ctx.index;
|
|
30
|
+
ctx.index += 4;
|
|
31
|
+
const start = ctx.index;
|
|
32
|
+
for (const [def, val] of ctx.main) {
|
|
33
|
+
writeU16(ctx, def.start);
|
|
34
|
+
writeU16(ctx, def.len);
|
|
35
|
+
writeFixed(ctx, def, val);
|
|
36
|
+
}
|
|
37
|
+
writeUint32(ctx.array, ctx.index - start, index);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const writeUpdate = (ctx, payload) => {
|
|
41
|
+
reserve(ctx, FULL_CURSOR_SIZE);
|
|
42
|
+
writeTypeCursor(ctx);
|
|
43
|
+
writeNodeCursor(ctx);
|
|
44
|
+
writeObject(ctx, ctx.schema.tree, payload);
|
|
45
|
+
writeUpdateTs(ctx, payload);
|
|
46
|
+
writeMergeMain(ctx);
|
|
47
|
+
};
|
|
48
|
+
export function update(db, type, id, payload, opts) {
|
|
49
|
+
const schema = getValidSchema(db, type);
|
|
50
|
+
const ctx = db.modifyCtx;
|
|
51
|
+
try {
|
|
52
|
+
validatePayload(payload);
|
|
53
|
+
validateId(id);
|
|
54
|
+
if (schema.hooks?.update) {
|
|
55
|
+
payload = schema.hooks.update(payload) || payload;
|
|
56
|
+
}
|
|
57
|
+
ctx.id = id;
|
|
58
|
+
ctx.schema = schema;
|
|
59
|
+
ctx.operation = UPDATE;
|
|
60
|
+
ctx.overwrite = opts?.overwrite;
|
|
61
|
+
ctx.locale = opts?.locale && langCodesMap.get(opts.locale);
|
|
62
|
+
ctx.start = ctx.index;
|
|
63
|
+
if (ctx.main.size) {
|
|
64
|
+
ctx.main.clear();
|
|
65
|
+
}
|
|
66
|
+
writeUpdate(ctx, payload);
|
|
67
|
+
const tmp = new Tmp(ctx, id);
|
|
68
|
+
schedule(db, ctx);
|
|
69
|
+
return tmp;
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
return handleError(db, ctx, update, arguments, e);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { deepMerge } from '@saulx/utils';
|
|
2
1
|
import { ALIAS, isPropDef } from '@based/schema/def';
|
|
2
|
+
import { deepMerge } from '@based/utils';
|
|
3
3
|
const filterAliases = (obj, tree) => {
|
|
4
4
|
let aliases;
|
|
5
5
|
for (const key in obj) {
|
|
@@ -23,7 +23,7 @@ const filterAliases = (obj, tree) => {
|
|
|
23
23
|
}
|
|
24
24
|
return aliases;
|
|
25
25
|
};
|
|
26
|
-
export
|
|
26
|
+
export const upsert = (db, type, obj, opts) => {
|
|
27
27
|
const tree = db.schemaTypesParsed[type].tree;
|
|
28
28
|
const aliases = filterAliases(obj, tree);
|
|
29
29
|
const q = db.query(type, aliases);
|
|
@@ -50,5 +50,5 @@ export async function upsert(db, type, obj, opts) {
|
|
|
50
50
|
};
|
|
51
51
|
db.upserting.set(q.id, store);
|
|
52
52
|
return store.p;
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PropDef, PropDefEdge } from '@based/schema/def';
|
|
2
|
+
import { DbClient } from '../../index.js';
|
|
3
|
+
export declare const validate: (def: PropDef | PropDefEdge, val: any) => void;
|
|
4
|
+
export declare const validatePayload: (payload: any) => void;
|
|
5
|
+
export declare const validateId: (id: number) => void;
|
|
6
|
+
export declare const getValidSchema: (db: DbClient, type: string) => import("@based/schema/def").SchemaTypeDef;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isValidId } from '@based/schema/def';
|
|
2
|
+
export const validate = (def, val) => {
|
|
3
|
+
if (!def.validation(val, def)) {
|
|
4
|
+
throw [def, val];
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
export const validatePayload = (payload) => {
|
|
8
|
+
if (typeof payload !== 'object' || payload === null) {
|
|
9
|
+
throw 'Invalid payload';
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export const validateId = (id) => {
|
|
13
|
+
if (!isValidId(id)) {
|
|
14
|
+
throw 'Invalid id';
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export const getValidSchema = (db, type) => {
|
|
18
|
+
const schema = db.schemaTypesParsed[type];
|
|
19
|
+
if (schema) {
|
|
20
|
+
return schema;
|
|
21
|
+
}
|
|
22
|
+
throw `Unknown type: ${type}. Did you mean on of: ${Object.keys(db.schemaTypesParsed).join(', ')}`;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { QueryDef, QueryTarget, Operator, QueryByAliasObj, LangFallback } from './query.js';
|
|
2
|
-
import { BasedQueryResponse } from './
|
|
1
|
+
import { QueryDef, QueryTarget, Operator, QueryByAliasObj, LangFallback, IncludeOpts } from './query.js';
|
|
2
|
+
import { BasedQueryResponse } from './BasedQueryResponse.js';
|
|
3
3
|
import { Search } from './search/index.js';
|
|
4
4
|
import { OnData, OnError } from './subscription/index.js';
|
|
5
5
|
import { DbClient } from '../index.js';
|
|
6
6
|
import { LangName } from '@based/schema';
|
|
7
|
-
import {
|
|
7
|
+
import { FilterBranchFn, FilterOpts } from './filter/types.js';
|
|
8
|
+
import { StepInput, aggFnOptions } from './aggregates/types.js';
|
|
9
|
+
import { ReaderSchema } from '@based/protocol/db-read';
|
|
8
10
|
export { QueryByAliasObj };
|
|
9
11
|
export type SelectFn = (field: string) => BasedDbReferenceQuery;
|
|
10
12
|
export type BranchInclude = (select: SelectFn) => any;
|
|
@@ -19,35 +21,36 @@ export declare class QueryBranch<T> {
|
|
|
19
21
|
constructor(db: DbClient, def?: QueryDef);
|
|
20
22
|
sort(field: string, order?: 'asc' | 'desc'): T;
|
|
21
23
|
filter<O extends Operator>(field: string, operator?: O | boolean, value?: any, opts?: FilterOpts<O>): T;
|
|
22
|
-
filterBatch(f: FilterAst): this;
|
|
23
24
|
search(query: string, ...fields: Search[]): T;
|
|
24
25
|
search(query: ArrayBufferView, field: string, opts?: Omit<FilterOpts, 'lowerCase'>): T;
|
|
25
|
-
groupBy(field: string): T;
|
|
26
|
+
groupBy(field: string, step?: StepInput): T;
|
|
26
27
|
count(field?: string): T;
|
|
27
|
-
sum(...fields:
|
|
28
|
+
sum(...fields: string[]): T;
|
|
28
29
|
cardinality(field: string): T;
|
|
29
|
-
stddev(...
|
|
30
|
-
var(...
|
|
31
|
-
avg(...fields:
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
stddev(...args: (string | aggFnOptions)[]): T;
|
|
31
|
+
var(...args: (string | aggFnOptions)[]): T;
|
|
32
|
+
avg(...fields: string[]): T;
|
|
33
|
+
harmonicMean(...fields: string[]): T;
|
|
34
|
+
max(...fields: string[]): T;
|
|
35
|
+
min(...fields: string[]): T;
|
|
34
36
|
or(fn: FilterBranchFn): T;
|
|
35
37
|
or(field: string, operator?: Operator | boolean, value?: any, opts?: FilterOpts): T;
|
|
36
38
|
range(start: number, end?: number): T;
|
|
37
|
-
include(...fields: (string | BranchInclude | string[])[]): T;
|
|
39
|
+
include(...fields: (string | BranchInclude | IncludeOpts | (string | IncludeOpts)[])[]): T;
|
|
38
40
|
}
|
|
39
41
|
export declare class BasedDbReferenceQuery extends QueryBranch<BasedDbReferenceQuery> {
|
|
40
42
|
}
|
|
41
43
|
declare class GetPromise extends Promise<BasedQueryResponse> {
|
|
42
44
|
toObject(): Promise<any>;
|
|
43
|
-
toJSON(): Promise<string>;
|
|
45
|
+
toJSON(replacer?: (this: any, key: string, value: any) => any, space?: string | number): Promise<string>;
|
|
44
46
|
inspect(depth?: number, raw?: boolean): GetPromise;
|
|
45
47
|
}
|
|
46
48
|
export declare class BasedDbQuery extends QueryBranch<BasedDbQuery> {
|
|
47
49
|
#private;
|
|
48
50
|
skipValidation: boolean;
|
|
49
51
|
target: QueryTarget;
|
|
50
|
-
|
|
52
|
+
readSchema: ReaderSchema;
|
|
53
|
+
constructor(db: DbClient, type: string, rawTarget?: QueryByAliasObj | number | Promise<number> | Uint32Array | (QueryByAliasObj | number)[], skipValidation?: boolean);
|
|
51
54
|
reset(): void;
|
|
52
55
|
id: number;
|
|
53
56
|
get(): GetPromise;
|