@based/db 0.1.3 → 0.1.5

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 (100) hide show
  1. package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
  2. package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
  3. package/dist/lib/darwin_aarch64/libnode-v24.node +0 -0
  4. package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
  5. package/dist/lib/linux_aarch64/include/cdefs.h +320 -0
  6. package/dist/lib/linux_aarch64/include/jemalloc.h +468 -0
  7. package/dist/lib/linux_aarch64/include/libdeflate.h +345 -0
  8. package/dist/lib/linux_aarch64/include/libdeflate_strings.h +35 -0
  9. package/dist/lib/linux_aarch64/include/linker_set.h +109 -0
  10. package/dist/lib/linux_aarch64/include/queue.h +627 -0
  11. package/dist/lib/linux_aarch64/include/selva/_export.h +7 -0
  12. package/dist/lib/linux_aarch64/include/selva/align.h +9 -0
  13. package/dist/lib/linux_aarch64/include/selva/backoff_timeout.h +29 -0
  14. package/dist/lib/linux_aarch64/include/selva/bitmap.h +95 -0
  15. package/dist/lib/linux_aarch64/include/selva/colvec.h +71 -0
  16. package/dist/lib/linux_aarch64/include/selva/crc32c.h +17 -0
  17. package/dist/lib/linux_aarch64/include/selva/ctime.h +135 -0
  18. package/dist/lib/linux_aarch64/include/selva/db.h +430 -0
  19. package/dist/lib/linux_aarch64/include/selva/endian.h +301 -0
  20. package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +27 -0
  21. package/dist/lib/linux_aarch64/include/selva/fast_memcmp.h +18 -0
  22. package/dist/lib/linux_aarch64/include/selva/fast_memmem.h +11 -0
  23. package/dist/lib/linux_aarch64/include/selva/fast_parsei.h +36 -0
  24. package/dist/lib/linux_aarch64/include/selva/fields.h +379 -0
  25. package/dist/lib/linux_aarch64/include/selva/gmtime.h +137 -0
  26. package/dist/lib/linux_aarch64/include/selva/hll.h +85 -0
  27. package/dist/lib/linux_aarch64/include/selva/lpf.h +28 -0
  28. package/dist/lib/linux_aarch64/include/selva/mblen.h +40 -0
  29. package/dist/lib/linux_aarch64/include/selva/membar.h +32 -0
  30. package/dist/lib/linux_aarch64/include/selva/node_id_set.h +43 -0
  31. package/dist/lib/linux_aarch64/include/selva/poptop.h +114 -0
  32. package/dist/lib/linux_aarch64/include/selva/selva_hash128.h +49 -0
  33. package/dist/lib/linux_aarch64/include/selva/selva_lang.h +105 -0
  34. package/dist/lib/linux_aarch64/include/selva/selva_math.h +37 -0
  35. package/dist/lib/linux_aarch64/include/selva/selva_string.h +683 -0
  36. package/dist/lib/linux_aarch64/include/selva/sort.h +140 -0
  37. package/dist/lib/linux_aarch64/include/selva/strsearch.h +43 -0
  38. package/dist/lib/linux_aarch64/include/selva/thread.h +37 -0
  39. package/dist/lib/linux_aarch64/include/selva/timestamp.h +25 -0
  40. package/dist/lib/linux_aarch64/include/selva/types.h +119 -0
  41. package/dist/lib/linux_aarch64/include/selva/vector.h +35 -0
  42. package/dist/lib/linux_aarch64/include/selva_error.h +140 -0
  43. package/dist/lib/linux_aarch64/include/selva_lang_code.h +160 -0
  44. package/dist/lib/linux_aarch64/include/tree.h +852 -0
  45. package/dist/lib/linux_aarch64/libdeflate.so +0 -0
  46. package/dist/lib/linux_aarch64/libjemalloc_selva.so.2 +0 -0
  47. package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
  48. package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
  49. package/dist/lib/linux_aarch64/libnode-v24.node +0 -0
  50. package/dist/lib/linux_aarch64/libselva.so +0 -0
  51. package/dist/lib/linux_aarch64/libxxhash.so.0 +0 -0
  52. package/dist/lib/linux_x86_64/include/cdefs.h +320 -0
  53. package/dist/lib/linux_x86_64/include/jemalloc.h +468 -0
  54. package/dist/lib/linux_x86_64/include/libdeflate.h +345 -0
  55. package/dist/lib/linux_x86_64/include/libdeflate_strings.h +35 -0
  56. package/dist/lib/linux_x86_64/include/linker_set.h +109 -0
  57. package/dist/lib/linux_x86_64/include/queue.h +627 -0
  58. package/dist/lib/linux_x86_64/include/selva/_export.h +7 -0
  59. package/dist/lib/linux_x86_64/include/selva/align.h +9 -0
  60. package/dist/lib/linux_x86_64/include/selva/backoff_timeout.h +29 -0
  61. package/dist/lib/linux_x86_64/include/selva/bitmap.h +95 -0
  62. package/dist/lib/linux_x86_64/include/selva/colvec.h +71 -0
  63. package/dist/lib/linux_x86_64/include/selva/crc32c.h +17 -0
  64. package/dist/lib/linux_x86_64/include/selva/ctime.h +135 -0
  65. package/dist/lib/linux_x86_64/include/selva/db.h +430 -0
  66. package/dist/lib/linux_x86_64/include/selva/endian.h +301 -0
  67. package/dist/lib/linux_x86_64/include/selva/fast_linear_search.h +27 -0
  68. package/dist/lib/linux_x86_64/include/selva/fast_memcmp.h +18 -0
  69. package/dist/lib/linux_x86_64/include/selva/fast_memmem.h +11 -0
  70. package/dist/lib/linux_x86_64/include/selva/fast_parsei.h +36 -0
  71. package/dist/lib/linux_x86_64/include/selva/fields.h +379 -0
  72. package/dist/lib/linux_x86_64/include/selva/gmtime.h +137 -0
  73. package/dist/lib/linux_x86_64/include/selva/hll.h +85 -0
  74. package/dist/lib/linux_x86_64/include/selva/lpf.h +28 -0
  75. package/dist/lib/linux_x86_64/include/selva/mblen.h +40 -0
  76. package/dist/lib/linux_x86_64/include/selva/membar.h +32 -0
  77. package/dist/lib/linux_x86_64/include/selva/node_id_set.h +43 -0
  78. package/dist/lib/linux_x86_64/include/selva/poptop.h +114 -0
  79. package/dist/lib/linux_x86_64/include/selva/selva_hash128.h +49 -0
  80. package/dist/lib/linux_x86_64/include/selva/selva_lang.h +105 -0
  81. package/dist/lib/linux_x86_64/include/selva/selva_math.h +37 -0
  82. package/dist/lib/linux_x86_64/include/selva/selva_string.h +683 -0
  83. package/dist/lib/linux_x86_64/include/selva/sort.h +140 -0
  84. package/dist/lib/linux_x86_64/include/selva/strsearch.h +43 -0
  85. package/dist/lib/linux_x86_64/include/selva/thread.h +37 -0
  86. package/dist/lib/linux_x86_64/include/selva/timestamp.h +25 -0
  87. package/dist/lib/linux_x86_64/include/selva/types.h +119 -0
  88. package/dist/lib/linux_x86_64/include/selva/vector.h +35 -0
  89. package/dist/lib/linux_x86_64/include/selva_error.h +140 -0
  90. package/dist/lib/linux_x86_64/include/selva_lang_code.h +160 -0
  91. package/dist/lib/linux_x86_64/include/tree.h +852 -0
  92. package/dist/lib/linux_x86_64/libdeflate.so +0 -0
  93. package/dist/lib/linux_x86_64/libjemalloc_selva.so.2 +0 -0
  94. package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
  95. package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
  96. package/dist/lib/linux_x86_64/libnode-v24.node +0 -0
  97. package/dist/lib/linux_x86_64/libselva.so +0 -0
  98. package/dist/lib/linux_x86_64/libxxhash.so.0 +0 -0
  99. package/dist/src/server/migrate/worker.js +87 -84
  100. package/package.json +1 -1
@@ -10,101 +10,104 @@ if (isMainThread) {
10
10
  console.warn('running worker.ts in mainthread');
11
11
  }
12
12
  else if (workerData?.isDbMigrateWorker) {
13
- const { from, to, fromSchema, toSchema, channel, workerState, transformFns } = workerData;
14
- const fromCtx = native.externalFromInt(from);
15
- const toCtx = native.externalFromInt(to);
16
- native.createThreadCtx(fromCtx, native.getThreadId());
17
- native.createThreadCtx(toCtx, native.getThreadId());
18
- const fromDb = new BasedDb({ path: null });
19
- const toDb = new BasedDb({ path: null });
20
- fromDb.server.dbCtxExternal = fromCtx;
21
- toDb.server.dbCtxExternal = toCtx;
22
- setSchemaOnServer(fromDb.server, deSerialize(fromSchema));
23
- setSchemaOnServer(toDb.server, deSerialize(toSchema));
24
- setLocalClientSchema(fromDb.client, fromDb.server.schema);
25
- setLocalClientSchema(toDb.client, toDb.server.schema);
26
- try {
27
- const map = {};
28
- for (const type in fromDb.server.schemaTypesParsed) {
29
- const { id, props } = fromDb.server.schemaTypesParsed[type];
30
- const include = [];
31
- const includeRaw = [];
32
- for (const path in props) {
33
- const prop = props[path];
34
- if (prop.typeIndex === REFERENCE || prop.typeIndex === REFERENCES) {
35
- include.push(`${path}.id`);
36
- if (prop.edges) {
37
- for (const key in prop.edges) {
38
- const edge = prop.edges[key];
39
- if (edge.typeIndex === REFERENCE ||
40
- edge.typeIndex === REFERENCES) {
41
- include.push(`${path}.${key}.id`);
42
- }
43
- else if (edge.typeIndex === CARDINALITY) {
44
- includeRaw.push(`${path}.${key}`);
45
- }
46
- else {
47
- include.push(`${path}.${key}`);
13
+ ;
14
+ (async () => {
15
+ const { from, to, fromSchema, toSchema, channel, workerState, transformFns, } = workerData;
16
+ const fromCtx = native.externalFromInt(from);
17
+ const toCtx = native.externalFromInt(to);
18
+ native.createThreadCtx(fromCtx, native.getThreadId());
19
+ native.createThreadCtx(toCtx, native.getThreadId());
20
+ const fromDb = new BasedDb({ path: null });
21
+ const toDb = new BasedDb({ path: null });
22
+ fromDb.server.dbCtxExternal = fromCtx;
23
+ toDb.server.dbCtxExternal = toCtx;
24
+ setSchemaOnServer(fromDb.server, deSerialize(fromSchema));
25
+ setSchemaOnServer(toDb.server, deSerialize(toSchema));
26
+ setLocalClientSchema(fromDb.client, fromDb.server.schema);
27
+ setLocalClientSchema(toDb.client, toDb.server.schema);
28
+ try {
29
+ const map = {};
30
+ for (const type in fromDb.server.schemaTypesParsed) {
31
+ const { id, props } = fromDb.server.schemaTypesParsed[type];
32
+ const include = [];
33
+ const includeRaw = [];
34
+ for (const path in props) {
35
+ const prop = props[path];
36
+ if (prop.typeIndex === REFERENCE || prop.typeIndex === REFERENCES) {
37
+ include.push(`${path}.id`);
38
+ if (prop.edges) {
39
+ for (const key in prop.edges) {
40
+ const edge = prop.edges[key];
41
+ if (edge.typeIndex === REFERENCE ||
42
+ edge.typeIndex === REFERENCES) {
43
+ include.push(`${path}.${key}.id`);
44
+ }
45
+ else if (edge.typeIndex === CARDINALITY) {
46
+ includeRaw.push(`${path}.${key}`);
47
+ }
48
+ else {
49
+ include.push(`${path}.${key}`);
50
+ }
48
51
  }
49
52
  }
50
53
  }
54
+ else if (prop.typeIndex === CARDINALITY) {
55
+ includeRaw.push(path);
56
+ }
57
+ else {
58
+ include.push(path);
59
+ }
51
60
  }
52
- else if (prop.typeIndex === CARDINALITY) {
53
- includeRaw.push(path);
54
- }
55
- else {
56
- include.push(path);
57
- }
61
+ map[id] = { type, include, includeRaw };
58
62
  }
59
- map[id] = { type, include, includeRaw };
60
- }
61
- for (const type in transformFns) {
62
- const fnOrNull = transformFns[type];
63
- transformFns[type] = eval(`(${fnOrNull})`);
64
- }
65
- while (true) {
66
- let msg;
67
- while ((msg = receiveMessageOnPort(channel))) {
68
- const leafData = msg.message;
69
- const { type, include, includeRaw } = map[leafData.typeId];
70
- const typeTransformFn = transformFns[type];
71
- const query = fromDb
72
- .query(type)
73
- .range(leafData.start - 1, leafData.end)
74
- .include(include);
75
- for (const rawProp of includeRaw) {
76
- query.include(rawProp, { raw: true });
77
- }
78
- const nodes = query._getSync(fromCtx);
79
- if (typeTransformFn) {
80
- for (const node of nodes) {
81
- const res = typeTransformFn(node);
82
- if (res === null) {
83
- continue;
84
- }
85
- if (Array.isArray(res)) {
86
- toDb.create(res[0], res[1] || node, { unsafe: true });
87
- }
88
- else {
89
- toDb.create(type, res || node, { unsafe: true });
63
+ for (const type in transformFns) {
64
+ const fnOrNull = transformFns[type];
65
+ transformFns[type] = eval(`(${fnOrNull})`);
66
+ }
67
+ while (true) {
68
+ let msg;
69
+ while ((msg = receiveMessageOnPort(channel))) {
70
+ const leafData = msg.message;
71
+ const { type, include, includeRaw } = map[leafData.typeId];
72
+ const typeTransformFn = transformFns[type];
73
+ const query = fromDb
74
+ .query(type)
75
+ .range(leafData.start - 1, leafData.end)
76
+ .include(include);
77
+ for (const rawProp of includeRaw) {
78
+ query.include(rawProp, { raw: true });
79
+ }
80
+ const nodes = query._getSync(fromCtx);
81
+ if (typeTransformFn) {
82
+ for (const node of nodes) {
83
+ const res = typeTransformFn(node);
84
+ if (res === null) {
85
+ continue;
86
+ }
87
+ if (Array.isArray(res)) {
88
+ toDb.create(res[0], res[1] || node, { unsafe: true });
89
+ }
90
+ else {
91
+ toDb.create(type, res || node, { unsafe: true });
92
+ }
90
93
  }
91
94
  }
92
- }
93
- else if (type in toDb.server.schemaTypesParsed) {
94
- for (const node of nodes) {
95
- toDb.create(type, node, { unsafe: true });
95
+ else if (type in toDb.server.schemaTypesParsed) {
96
+ for (const node of nodes) {
97
+ toDb.create(type, node, { unsafe: true });
98
+ }
96
99
  }
97
100
  }
101
+ await toDb.drain();
102
+ native.membarSyncWrite();
103
+ setToSleep(workerState);
98
104
  }
99
- await toDb.drain();
100
- native.membarSyncWrite();
101
- setToSleep(workerState);
102
105
  }
103
- }
104
- catch (e) {
105
- console.error(e);
106
- throw e;
107
- }
106
+ catch (e) {
107
+ console.error(e);
108
+ throw e;
109
+ }
110
+ })();
108
111
  }
109
112
  else {
110
113
  console.info('incorrect worker db migrate');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@based/db",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "main": "./dist/src/index.js",
6
6
  "scripts": {