@based/db 0.0.33 → 0.0.34

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.
Binary file
Binary file
@@ -148,12 +148,11 @@ export function create(db, type, obj, opts) {
148
148
  flushBuffer(db);
149
149
  return db.create(type, obj, opts);
150
150
  }
151
- // res.error = err
152
- // @ts-ignore
153
- // return Promise.reject(err)
154
- // return res
151
+ res.error = err;
155
152
  throw err;
156
153
  }
154
+ ctx.markTypeDirty(def);
155
+ ctx.markNodeDirty(def, id);
157
156
  if (!db.isDraining) {
158
157
  startDrain(db);
159
158
  }
@@ -53,7 +53,7 @@ export const dbUpdateFromUpsert = (ctx, schema, def, res, promise) => {
53
53
  payload = payload[def.path[i]] = {};
54
54
  }
55
55
  payload[def.path[i]] = result;
56
- return ctx.db.update(schema.type, res.tmpId, payload);
56
+ return ctx.db.update(schema.type, res.getId(), payload);
57
57
  }));
58
58
  };
59
59
  function deleteRefs(def, ctx, schema, modifyOp, refs, parentId) {
@@ -12,9 +12,6 @@ typeIndex, id, modifyOp, ignoreField) => {
12
12
  ctx.field = -1;
13
13
  ctx.id = -1;
14
14
  ctx.lastMain = -1;
15
- if (modifyOp === CREATE) {
16
- ctx.markTypeDirty(schema);
17
- }
18
15
  }
19
16
  if (!ignoreField && ctx.field !== field) {
20
17
  ctx.buf[ctx.len++] = SWITCH_FIELD; // switch field
@@ -23,7 +20,6 @@ typeIndex, id, modifyOp, ignoreField) => {
23
20
  ctx.field = field;
24
21
  }
25
22
  if (ctx.id !== id) {
26
- ctx.markNodeDirty(schema, id);
27
23
  ctx.id = id;
28
24
  ctx.lastMain = -1;
29
25
  ctx.buf[ctx.len++] =
@@ -25,7 +25,7 @@ export function writeText(value, ctx, def, t, res, parentId, modifyOp) {
25
25
  if (!def.seperateTextSort.localeToIndex.has(locale)) {
26
26
  return new ModifyError(t, locale, 'Invalid locale');
27
27
  }
28
- const err = writeString(res.locale, value, ctx, def, t, res.tmpId, modifyOp);
28
+ const err = writeString(locale, value, ctx, def, t, res.tmpId, modifyOp);
29
29
  if (modifyOp === CREATE) {
30
30
  const index = t.prop * (def.localeSize + 1);
31
31
  const langIndex = def.seperateTextSort.localeToIndex.get(locale);
@@ -73,9 +73,10 @@ export const update = (db, type, id, obj, opts) => {
73
73
  flushBuffer(db);
74
74
  return update(db, type, id, obj, opts);
75
75
  }
76
- // res.error = err
76
+ res.error = err;
77
77
  throw err;
78
78
  }
79
+ ctx.markNodeDirty(def, id);
79
80
  if (!db.isDraining) {
80
81
  startDrain(db);
81
82
  }
@@ -43,6 +43,7 @@ export async function upsert(db, type, obj, opts) {
43
43
  else {
44
44
  const obj = res.toObject();
45
45
  const id = Array.isArray(obj) ? obj[0].id : obj.id;
46
+ // don't call update if it's not necessary
46
47
  return db.update(type, id, store.o, opts);
47
48
  }
48
49
  }),
@@ -243,7 +243,7 @@ export const readAllFields = (q, result, offset, end, item, id) => {
243
243
  addField(edgeDef, '', item);
244
244
  }
245
245
  else {
246
- addField(edgeDef, read(result, i + 4, size), item);
246
+ addField(edgeDef, read(result, i + 4, size, true), item);
247
247
  }
248
248
  i += size + 4;
249
249
  }
@@ -341,21 +341,22 @@ export const readAllFields = (q, result, offset, end, item, id) => {
341
341
  addField(prop, '', item);
342
342
  }
343
343
  else {
344
- addField(prop, read(result, i + 4, size), item);
344
+ addField(prop, read(result, i + 4, size, true), item);
345
345
  }
346
346
  i += size + 4;
347
347
  }
348
348
  else if (prop.typeIndex == TEXT) {
349
349
  const size = readUint32(result, i);
350
350
  if (size === 0) {
351
+ // do nothing
351
352
  }
352
353
  else {
353
354
  if (q.lang != 0) {
354
355
  q.include.propsRead[index] = id;
355
- addField(prop, read(result, i + 4, size), item);
356
+ addField(prop, read(result, i + 4, size, false), item);
356
357
  }
357
358
  else {
358
- addField(prop, read(result, i + 4, size), item, false, result[i + 4]);
359
+ addField(prop, read(result, i + 4, size, false), item, false, result[i + 4]);
359
360
  }
360
361
  }
361
362
  i += size + 4;
@@ -4,5 +4,5 @@ export declare const NOT_COMPRESSED = 0;
4
4
  export declare const write: (buf: Uint8Array, value: string, offset: number, noCompression: boolean, lang?: LangCode) => number;
5
5
  export declare const compress: (str: string) => Uint8Array;
6
6
  export declare const decompress: (val: Uint8Array) => string;
7
- export declare const read: (val: Uint8Array, offset: number, len: number) => string;
7
+ export declare const read: (val: Uint8Array, offset: number, len: number, stripCrc32: boolean) => string;
8
8
  export declare const readUtf8: (val: Uint8Array, offset: number, len: number) => string;
@@ -53,19 +53,24 @@ export const compress = (str) => {
53
53
  return nBuffer;
54
54
  };
55
55
  export const decompress = (val) => {
56
- return read(val, 0, val.length);
56
+ return read(val, 0, val.length, false);
57
57
  };
58
- export const read = (val, offset, len) => {
58
+ export const read = (val, offset, len, stripCrc32) => {
59
59
  const type = val[offset + 1];
60
60
  if (type == COMPRESSED) {
61
61
  const origSize = readUint32(val, offset + 2);
62
62
  const newBuffer = getTmpBuffer(origSize);
63
63
  // Browser fallback required for this
64
- native.decompress(val, newBuffer, offset + 6, len - 6);
64
+ native.decompress(val, newBuffer, offset + 6, stripCrc32 ? len - 2 : len - 6);
65
65
  return DECODER.decode(newBuffer);
66
66
  }
67
67
  else if (type == NOT_COMPRESSED) {
68
- return DECODER.decode(val.subarray(offset + 2, len + offset - 4));
68
+ if (stripCrc32) {
69
+ return DECODER.decode(val.subarray(offset + 2, len + offset));
70
+ }
71
+ else {
72
+ return DECODER.decode(val.subarray(offset + 2, len + offset - 4));
73
+ }
69
74
  }
70
75
  return '';
71
76
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@based/db",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",