@based/db 0.0.31 → 0.0.33

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.
Files changed (83) hide show
  1. package/README.md +565 -3
  2. package/dist/lib/darwin_aarch64/include/selva/db.h +1 -1
  3. package/dist/lib/darwin_aarch64/include/selva/fields.h +0 -2
  4. package/dist/lib/darwin_aarch64/libdeflate.dylib +0 -0
  5. package/dist/lib/darwin_aarch64/libjemalloc_selva.2.dylib +0 -0
  6. package/dist/lib/darwin_aarch64/libnode-v20.node +0 -0
  7. package/dist/lib/darwin_aarch64/libnode-v21.node +0 -0
  8. package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
  9. package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
  10. package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
  11. package/dist/lib/linux_aarch64/include/selva/db.h +1 -1
  12. package/dist/lib/linux_aarch64/include/selva/fields.h +0 -2
  13. package/dist/lib/linux_aarch64/libnode-v20.node +0 -0
  14. package/dist/lib/linux_aarch64/libnode-v21.node +0 -0
  15. package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
  16. package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
  17. package/dist/lib/linux_aarch64/libselva.so +0 -0
  18. package/dist/lib/linux_x86_64/include/selva/db.h +1 -1
  19. package/dist/lib/linux_x86_64/include/selva/fields.h +0 -2
  20. package/dist/lib/linux_x86_64/libnode-v20.node +0 -0
  21. package/dist/lib/linux_x86_64/libnode-v21.node +0 -0
  22. package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
  23. package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
  24. package/dist/lib/linux_x86_64/libselva.so +0 -0
  25. package/dist/src/client/flushModify.js +5 -4
  26. package/dist/src/client/index.d.ts +3 -2
  27. package/dist/src/client/modify/binary.js +1 -1
  28. package/dist/src/client/modify/cardinality.js +1 -1
  29. package/dist/src/client/modify/references/appendEdgeRefs.js +3 -0
  30. package/dist/src/client/modify/references/edge.js +6 -0
  31. package/dist/src/client/modify/references/getEdgeSize.js +1 -1
  32. package/dist/src/client/modify/string.js +10 -4
  33. package/dist/src/client/modify/text.js +1 -9
  34. package/dist/src/client/modify/types.d.ts +1 -0
  35. package/dist/src/client/modify/types.js +1 -0
  36. package/dist/src/client/modify/upsert.js +33 -21
  37. package/dist/src/client/query/BasedDbQuery.js +1 -1
  38. package/dist/src/client/query/BasedIterable.d.ts +2 -2
  39. package/dist/src/client/query/BasedIterable.js +7 -1
  40. package/dist/src/client/query/debug.js +3 -2
  41. package/dist/src/client/query/display.js +1 -1
  42. package/dist/src/client/query/filter/createFixedFilterBuffer.js +1 -1
  43. package/dist/src/client/query/filter/createVariableFilterBuffer.js +1 -1
  44. package/dist/src/client/query/filter/parseFilterValue.js +1 -2
  45. package/dist/src/client/query/queryDef.js +2 -2
  46. package/dist/src/client/query/read/read.js +4 -14
  47. package/dist/src/client/query/registerQuery.js +1 -1
  48. package/dist/src/client/query/search/index.js +1 -1
  49. package/dist/src/client/query/toBuffer.js +11 -15
  50. package/dist/src/client/query/types.d.ts +7 -0
  51. package/dist/src/client/query/types.js +8 -0
  52. package/dist/src/client/query/validation.d.ts +1 -1
  53. package/dist/src/client/query/validation.js +4 -5
  54. package/dist/src/client/string.js +1 -3
  55. package/dist/src/index.d.ts +1 -0
  56. package/dist/src/index.js +5 -1
  57. package/dist/src/native.d.ts +1 -2
  58. package/dist/src/native.js +2 -5
  59. package/dist/src/server/csmt/draw-dot.d.ts +3 -1
  60. package/dist/src/server/csmt/draw-dot.js +7 -2
  61. package/dist/src/server/csmt/memebership-proof.d.ts +1 -1
  62. package/dist/src/server/csmt/tree-utils.d.ts +4 -4
  63. package/dist/src/server/csmt/tree.d.ts +1 -1
  64. package/dist/src/server/csmt/tree.js +1 -1
  65. package/dist/src/server/csmt/types.d.ts +10 -10
  66. package/dist/src/server/dbHash.js +1 -1
  67. package/dist/src/server/index.d.ts +6 -2
  68. package/dist/src/server/index.js +28 -13
  69. package/dist/src/server/migrate/worker.js +11 -0
  70. package/dist/src/server/save.js +3 -2
  71. package/dist/src/server/start.js +9 -5
  72. package/dist/src/utils.d.ts +0 -10
  73. package/dist/src/utils.js +0 -152
  74. package/package.json +3 -3
  75. package/dist/lib/darwin_aarch64/include/selva/xxhash64.h +0 -23
  76. package/dist/lib/linux_aarch64/include/selva/xxhash64.h +0 -23
  77. package/dist/lib/linux_x86_64/include/selva/xxhash64.h +0 -23
  78. package/dist/src/client/query/subscription/markers.d.ts +0 -10
  79. package/dist/src/client/query/subscription/markers.js +0 -213
  80. package/dist/src/client/query/subscription/run.d.ts +0 -5
  81. package/dist/src/client/query/subscription/run.js +0 -76
  82. package/dist/src/client/tmpBuffer.d.ts +0 -3
  83. package/dist/src/client/tmpBuffer.js +0 -20
@@ -1,23 +0,0 @@
1
- #pragma once
2
- #ifndef XXHASH64_H
3
- #define XXHASH64_H
4
-
5
- #include <stdlib.h>
6
- #include <stdint.h>
7
- #include "selva/_export.h"
8
- #include "cdefs.h"
9
-
10
-
11
- /**
12
- * @brief Wrapper function that computes the 64-bit hash of a given input string using the xxHash algorithm.
13
- *
14
- * Takes a string as input and returns a 64-bit hash value.
15
- *
16
- * @param s The input string to be hashed.
17
- * @return A 64-bit hash value of the input string.
18
- */
19
-
20
- SELVA_EXPORT
21
- uint64_t xxHash64(const char *s, size_t len);
22
-
23
- #endif
@@ -1,23 +0,0 @@
1
- #pragma once
2
- #ifndef XXHASH64_H
3
- #define XXHASH64_H
4
-
5
- #include <stdlib.h>
6
- #include <stdint.h>
7
- #include "selva/_export.h"
8
- #include "cdefs.h"
9
-
10
-
11
- /**
12
- * @brief Wrapper function that computes the 64-bit hash of a given input string using the xxHash algorithm.
13
- *
14
- * Takes a string as input and returns a 64-bit hash value.
15
- *
16
- * @param s The input string to be hashed.
17
- * @return A 64-bit hash value of the input string.
18
- */
19
-
20
- SELVA_EXPORT
21
- uint64_t xxHash64(const char *s, size_t len);
22
-
23
- #endif
@@ -1,10 +0,0 @@
1
- import { PropDef, PropDefEdge } from '@based/schema/def';
2
- import { Subscription, SubscriptionMarkerMap, SubscriptionMarkersCheck } from './types.js';
3
- import { BasedDbQuery } from '../BasedDbQuery.js';
4
- import { DbClient } from '../../index.js';
5
- export declare const getSubscriptionMarkers: (db: DbClient, typeId: number, id: number, isCreate: boolean) => SubscriptionMarkersCheck | false;
6
- export declare const checkSubscriptionMarkers: (db: DbClient, m: SubscriptionMarkersCheck, prop: PropDef | PropDefEdge) => void;
7
- export declare const createSubscriptionMarkerMap: () => SubscriptionMarkerMap;
8
- export declare const addSubscriptionMarkers: (q: BasedDbQuery, subscription: Subscription) => void;
9
- export declare const resetSubscriptionMarkers: (db: DbClient) => void;
10
- export declare const deleteSubscriptionMarkers: (q: BasedDbQuery) => void;
@@ -1,213 +0,0 @@
1
- import { startSubscription } from './run.js';
2
- export const getSubscriptionMarkers = (db, typeId, id, isCreate) => {
3
- if (!(typeId in db.subscriptionMarkers)) {
4
- return false;
5
- }
6
- const t = db.subscriptionMarkers[typeId];
7
- let subMarkersCheck = false;
8
- if (!isCreate) {
9
- if (t.ids.has(id)) {
10
- const idMarkers = t.ids.get(id);
11
- subMarkersCheck = { ids: idMarkers, collection: false };
12
- }
13
- }
14
- if (t.collection) {
15
- if (!subMarkersCheck) {
16
- subMarkersCheck = { ids: false, collection: t.collection };
17
- }
18
- else {
19
- subMarkersCheck.collection = t.collection;
20
- }
21
- }
22
- return subMarkersCheck;
23
- };
24
- export const checkSubscriptionMarkers = (db, m, prop) => {
25
- let newSub = false;
26
- if (m.ids) {
27
- const markers = m.ids;
28
- if (prop.separate) {
29
- const propSubs = markers.props[prop.prop];
30
- if (propSubs) {
31
- for (const s of propSubs) {
32
- if (!s.inProgress) {
33
- newSub = true;
34
- db.subscriptionsToRun.push(s);
35
- }
36
- }
37
- }
38
- }
39
- else {
40
- const propSubs = markers.main[prop.start];
41
- if (propSubs) {
42
- for (const s of propSubs) {
43
- if (!s.inProgress) {
44
- newSub = true;
45
- db.subscriptionsToRun.push(s);
46
- }
47
- }
48
- }
49
- }
50
- }
51
- if (m.collection) {
52
- const markers = m.collection;
53
- if (prop.separate) {
54
- const propSubs = markers.props[prop.prop];
55
- // @ts-ignore
56
- if (propSubs && !propSubs.__handled) {
57
- // @ts-ignore
58
- propSubs.__handled = true;
59
- for (const s of propSubs) {
60
- if (!s.inProgress) {
61
- newSub = true;
62
- db.subscriptionsToRun.push(s);
63
- }
64
- }
65
- }
66
- }
67
- else {
68
- const propSubs = markers.main[prop.start];
69
- // @ts-ignore
70
- if (propSubs && !propSubs.__handled) {
71
- // @ts-ignore
72
- propSubs.__handled = true;
73
- for (const s of propSubs) {
74
- if (!s.inProgress) {
75
- newSub = true;
76
- db.subscriptionsToRun.push(s);
77
- }
78
- }
79
- }
80
- }
81
- }
82
- if (newSub && !db.subscriptionsInProgress) {
83
- startSubscription(db);
84
- }
85
- };
86
- export const createSubscriptionMarkerMap = () => {
87
- return {};
88
- };
89
- const getFilterFields = (filter, results = {
90
- main: new Set(),
91
- props: new Set(),
92
- }) => {
93
- const conditions = filter.conditions;
94
- if (conditions) {
95
- conditions.forEach((v, k) => {
96
- if (k === 0) {
97
- for (const buf of v) {
98
- const x = buf[4] | (buf[5] << 8);
99
- results.main.add(x);
100
- }
101
- }
102
- else {
103
- results.props.add(k);
104
- }
105
- });
106
- }
107
- if (filter.or) {
108
- getFilterFields(filter.or, results);
109
- }
110
- return results;
111
- };
112
- // resetting subs is a copy for now
113
- export const addSubscriptionMarkers = (q, subscription) => {
114
- const typeId = q.def.schema.id;
115
- if (!q.db.subscriptionMarkers[typeId]) {
116
- q.db.subscriptionMarkers[typeId] = {
117
- ids: new Map(),
118
- collection: {
119
- main: {},
120
- props: {},
121
- },
122
- };
123
- }
124
- const markerType = q.db.subscriptionMarkers[typeId];
125
- if ('id' in q.def.target) {
126
- const id = q.def.target.id;
127
- if (!markerType.ids.has(id)) {
128
- markerType.ids.set(id, {
129
- main: {},
130
- props: {},
131
- });
132
- }
133
- const marker = markerType.ids.get(id);
134
- const props = q.def.include.props;
135
- const main = q.def.include.main;
136
- for (const [p] of props.entries()) {
137
- if (!(p in marker.props)) {
138
- marker.props[p] = [];
139
- }
140
- const markerProps = marker.props[p];
141
- markerProps.push(subscription);
142
- }
143
- for (const p in main.include) {
144
- if (!(p in marker.main)) {
145
- marker.main[p] = [];
146
- }
147
- const markerProps = marker.main[p];
148
- markerProps.push(subscription);
149
- }
150
- }
151
- else if ('alias' in q.def.target) {
152
- // later
153
- }
154
- else {
155
- const props = q.def.include.props;
156
- const main = q.def.include.main;
157
- const marker = markerType.collection;
158
- for (const [p] of props.entries()) {
159
- if (!(p in marker.props)) {
160
- marker.props[p] = [];
161
- }
162
- marker.props[p].push(subscription);
163
- }
164
- for (const p in main.include) {
165
- if (!(p in marker.main)) {
166
- marker.main[p] = [];
167
- }
168
- marker.main[p].push(subscription);
169
- }
170
- if (q.def.filter) {
171
- const r = getFilterFields(q.def.filter);
172
- r.main.forEach((k) => {
173
- const p = String(k);
174
- if (!(p in marker.main)) {
175
- marker.main[p] = [];
176
- // @ts-ignore
177
- marker.main[p].__handled = false;
178
- }
179
- if (!main.include[p]) {
180
- marker.main[p].push(subscription);
181
- }
182
- });
183
- r.props.forEach((k) => {
184
- const p = String(k);
185
- if (!(p in marker.props)) {
186
- marker.props[p] = [];
187
- // @ts-ignore
188
- marker.props[p].__handled = false;
189
- }
190
- if (!props.has(k)) {
191
- marker.props[p].push(subscription);
192
- }
193
- });
194
- }
195
- }
196
- };
197
- export const resetSubscriptionMarkers = (db) => {
198
- for (const typeId in db.subscriptionMarkers) {
199
- const t = db.subscriptionMarkers[typeId];
200
- for (const k in t.collection.main) {
201
- // @ts-ignore
202
- t.collection.main[k].__handled = false;
203
- }
204
- for (const k in t.collection.props) {
205
- // @ts-ignore
206
- t.collection.props[k].__handled = false;
207
- }
208
- }
209
- };
210
- export const deleteSubscriptionMarkers = (q) => {
211
- // derp
212
- };
213
- //# sourceMappingURL=markers.js.map
@@ -1,5 +0,0 @@
1
- import { Subscription } from './types.js';
2
- import { DbClient } from '../../index.js';
3
- export declare const resultsAreEqual: (a: Uint8Array, b: Uint8Array) => boolean;
4
- export declare const runSubscription: (subscription: Subscription) => void;
5
- export declare const startSubscription: (db: DbClient) => void;
@@ -1,76 +0,0 @@
1
- import { BasedQueryResponse } from '../BasedIterable.js';
2
- import { resetSubscriptionMarkers } from './markers.js';
3
- export const resultsAreEqual = (a, b) => {
4
- const aLen = a.byteLength;
5
- const bLen = b.byteLength;
6
- if (aLen != bLen) {
7
- return false;
8
- }
9
- if (a[aLen - 4] != b[bLen - 4])
10
- return false;
11
- if (a[aLen - 3] != b[bLen - 3])
12
- return false;
13
- if (a[aLen - 2] != b[bLen - 2])
14
- return false;
15
- if (a[aLen - 1] != b[bLen - 1])
16
- return false;
17
- return true;
18
- };
19
- const EMPTY = new Uint8Array(4);
20
- export const runSubscription = (subscription) => {
21
- if (!subscription.inProgress) {
22
- subscription.inProgress = true;
23
- const q = subscription.query;
24
- const buf = q.buffer;
25
- const d = performance.now();
26
- q.db.hooks
27
- .getQueryBuf(buf)
28
- .then((res) => {
29
- if (subscription.closed) {
30
- return;
31
- }
32
- subscription.inProgress = false;
33
- let err = null;
34
- let buf;
35
- if (res instanceof Error) {
36
- err = res;
37
- buf = EMPTY;
38
- }
39
- else {
40
- buf = res;
41
- }
42
- if (subscription.res) {
43
- if (resultsAreEqual(subscription.res.result, buf)) {
44
- return;
45
- }
46
- subscription.res.execTime = performance.now() - d;
47
- subscription.res.result = buf;
48
- subscription.res.end = buf.byteLength;
49
- }
50
- else {
51
- subscription.res = new BasedQueryResponse(q.id, q.def, buf, performance.now() - d);
52
- }
53
- subscription.subs.forEach((fn) => {
54
- fn(subscription.res, err);
55
- });
56
- })
57
- .catch((err) => {
58
- subscription.inProgress = false;
59
- console.error('Subscription getQuery errors', err);
60
- });
61
- }
62
- };
63
- export const startSubscription = (db) => {
64
- if (!db.subscriptionsInProgress) {
65
- db.subscriptionsInProgress = true;
66
- setTimeout(() => {
67
- db.subscriptionsToRun.forEach((s) => {
68
- runSubscription(s);
69
- });
70
- db.subscriptionsToRun = [];
71
- resetSubscriptionMarkers(db);
72
- db.subscriptionsInProgress = false;
73
- }, db.subscriptonThrottleMs);
74
- }
75
- };
76
- //# sourceMappingURL=run.js.map
@@ -1,3 +0,0 @@
1
- export default function makeTmpBuffer(initialSize: number): {
2
- getUint8Array: (size: number) => Uint8Array;
3
- };
@@ -1,20 +0,0 @@
1
- export default function makeTmpBuffer(initialSize) {
2
- // @ts-ignore
3
- let tmpBuffer = new ArrayBuffer(initialSize, { maxByteLength: initialSize });
4
- return {
5
- getUint8Array: (size) => {
6
- const opts = {
7
- maxByteLength: Math.min(Math.round(1.5 * size), 274877906944)
8
- };
9
- // @ts-ignore
10
- if (tmpBuffer.maxByteLength < size) {
11
- // @ts-ignore
12
- tmpBuffer = new ArrayBuffer(size, opts);
13
- }
14
- // @ts-ignore
15
- tmpBuffer.resize(size);
16
- return new Uint8Array(tmpBuffer);
17
- }
18
- };
19
- }
20
- //# sourceMappingURL=tmpBuffer.js.map