@based/db 0.0.28 → 0.0.29

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 (105) hide show
  1. package/README.md +1 -399
  2. package/dist/lib/darwin_aarch64/include/selva/db.h +8 -4
  3. package/dist/lib/darwin_aarch64/include/selva/selva_hash128.h +17 -7
  4. package/dist/lib/darwin_aarch64/include/selva/sort.h +21 -14
  5. package/dist/lib/darwin_aarch64/libdeflate.dylib +0 -0
  6. package/dist/lib/darwin_aarch64/libjemalloc_selva.2.dylib +0 -0
  7. package/dist/lib/darwin_aarch64/libnode-v20.node +0 -0
  8. package/dist/lib/darwin_aarch64/libnode-v21.node +0 -0
  9. package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
  10. package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
  11. package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
  12. package/dist/lib/darwin_aarch64/libxxhash.dylib +0 -0
  13. package/dist/lib/linux_aarch64/include/selva/db.h +8 -4
  14. package/dist/lib/linux_aarch64/include/selva/selva_hash128.h +17 -7
  15. package/dist/lib/linux_aarch64/include/selva/sort.h +21 -14
  16. package/dist/lib/linux_aarch64/libdeflate.so +0 -0
  17. package/dist/lib/linux_aarch64/libjemalloc_selva.so.2 +0 -0
  18. package/dist/lib/linux_aarch64/libnode-v20.node +0 -0
  19. package/dist/lib/linux_aarch64/libnode-v21.node +0 -0
  20. package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
  21. package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
  22. package/dist/lib/linux_aarch64/libselva.so +0 -0
  23. package/dist/lib/linux_x86_64/include/selva/db.h +8 -4
  24. package/dist/lib/linux_x86_64/include/selva/selva_hash128.h +17 -7
  25. package/dist/lib/linux_x86_64/include/selva/sort.h +21 -14
  26. package/dist/lib/linux_x86_64/libjemalloc_selva.so.2 +0 -0
  27. package/dist/lib/linux_x86_64/libnode-v20.node +0 -0
  28. package/dist/lib/linux_x86_64/libnode-v21.node +0 -0
  29. package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
  30. package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
  31. package/dist/lib/linux_x86_64/libselva.so +0 -0
  32. package/dist/src/client/flushModify.d.ts +1 -1
  33. package/dist/src/client/flushModify.js +12 -17
  34. package/dist/src/client/index.d.ts +6 -4
  35. package/dist/src/client/index.js +19 -2
  36. package/dist/src/client/modify/ModifyRes.d.ts +1 -1
  37. package/dist/src/client/modify/ModifyRes.js +14 -18
  38. package/dist/src/client/modify/fixed.js +43 -8
  39. package/dist/src/client/modify/modify.js +0 -1
  40. package/dist/src/client/modify/references/{appendRefs.d.ts → appendEdgeRefs.d.ts} +1 -1
  41. package/dist/src/client/modify/references/{appendRefs.js → appendEdgeRefs.js} +5 -2
  42. package/dist/src/client/modify/references/edge.js +182 -175
  43. package/dist/src/client/modify/references/reference.js +4 -8
  44. package/dist/src/client/modify/references/references.js +18 -14
  45. package/dist/src/client/modify/string.js +0 -3
  46. package/dist/src/client/modify/text.js +11 -3
  47. package/dist/src/client/modify/types.d.ts +11 -0
  48. package/dist/src/client/modify/types.js +10 -0
  49. package/dist/src/client/modify/update.js +4 -1
  50. package/dist/src/client/modify/vector.js +13 -4
  51. package/dist/src/client/query/BasedDbQuery.d.ts +1 -1
  52. package/dist/src/client/query/BasedDbQuery.js +2 -2
  53. package/dist/src/client/query/BasedIterable.d.ts +1 -1
  54. package/dist/src/client/query/BasedIterable.js +7 -2
  55. package/dist/src/client/query/filter/createFixedFilterBuffer.d.ts +2 -1
  56. package/dist/src/client/query/filter/createFixedFilterBuffer.js +11 -28
  57. package/dist/src/client/query/filter/createReferenceFilter.d.ts +2 -1
  58. package/dist/src/client/query/filter/createReferenceFilter.js +10 -9
  59. package/dist/src/client/query/filter/createVariableFilterBuffer.d.ts +2 -1
  60. package/dist/src/client/query/filter/createVariableFilterBuffer.js +8 -10
  61. package/dist/src/client/query/filter/parseFilterValue.js +1 -1
  62. package/dist/src/client/query/filter/primitiveFilter.js +9 -9
  63. package/dist/src/client/query/filter/toBuffer.js +0 -15
  64. package/dist/src/client/query/filter/types.d.ts +1 -0
  65. package/dist/src/client/query/filter/types.js +1 -0
  66. package/dist/src/client/query/include/walk.js +0 -1
  67. package/dist/src/client/query/read/read.js +4 -4
  68. package/dist/src/client/query/search/index.js +11 -15
  69. package/dist/src/client/query/subscription/markers.js +1 -2
  70. package/dist/src/client/query/subscription/run.js +0 -2
  71. package/dist/src/client/query/thresholds.d.ts +0 -2
  72. package/dist/src/client/query/thresholds.js +0 -2
  73. package/dist/src/client/query/toBuffer.js +16 -42
  74. package/dist/src/client/query/types.d.ts +3 -2
  75. package/dist/src/client/query/validation.d.ts +1 -3
  76. package/dist/src/client/query/validation.js +6 -18
  77. package/dist/src/client/string.d.ts +2 -0
  78. package/dist/src/client/string.js +9 -13
  79. package/dist/src/index.d.ts +1 -1
  80. package/dist/src/index.js +7 -15
  81. package/dist/src/native.d.ts +1 -1
  82. package/dist/src/native.js +3 -3
  83. package/dist/src/server/csmt/draw-dot.js +2 -2
  84. package/dist/src/server/csmt/tree.js +57 -6
  85. package/dist/src/server/csmt/types.d.ts +5 -0
  86. package/dist/src/server/index.d.ts +4 -3
  87. package/dist/src/server/index.js +44 -44
  88. package/dist/src/server/migrate/index.js +47 -29
  89. package/dist/src/server/migrate/worker.js +2 -2
  90. package/dist/src/server/save.js +40 -28
  91. package/dist/src/server/start.js +7 -19
  92. package/dist/src/server/tree.d.ts +2 -0
  93. package/dist/src/server/tree.js +34 -2
  94. package/dist/src/server/worker.js +3 -3
  95. package/dist/src/utils.d.ts +3 -1
  96. package/dist/src/utils.js +43 -19
  97. package/package.json +9 -3
  98. package/dist/lib/darwin_aarch64/include/selva/base64.h +0 -59
  99. package/dist/lib/darwin_aarch64/include/selva/base64url.h +0 -59
  100. package/dist/lib/linux_aarch64/include/selva/base64.h +0 -59
  101. package/dist/lib/linux_aarch64/include/selva/base64url.h +0 -59
  102. package/dist/lib/linux_x86_64/include/selva/base64.h +0 -59
  103. package/dist/lib/linux_x86_64/include/selva/base64url.h +0 -59
  104. package/dist/src/client/timestamp.d.ts +0 -1
  105. package/dist/src/client/timestamp.js +0 -68
package/dist/src/utils.js CHANGED
@@ -1,7 +1,49 @@
1
- import { encodeBase64 } from '@saulx/utils';
1
+ import { inspect } from 'node:util';
2
+ import picocolors from 'picocolors';
2
3
  const native = typeof window === 'undefined' ? (await import('./native.js')).default : null;
3
4
  export const DECODER = new TextDecoder('utf-8');
4
5
  export const ENCODER = new TextEncoder();
6
+ export const debugMode = (target, getInfo = null) => {
7
+ const opts = { showHidden: false, depth: null, colors: true };
8
+ const info = (v) => (typeof v === 'object' ? inspect(v, opts) : v);
9
+ const proto = target.constructor.prototype;
10
+ const keys = new Set([
11
+ ...Object.keys(Object.getOwnPropertyDescriptors(proto)),
12
+ ...Object.keys(target),
13
+ ]);
14
+ const colors = [
15
+ 'red',
16
+ 'green',
17
+ 'yellow',
18
+ 'blue',
19
+ 'magenta',
20
+ 'cyan',
21
+ 'redBright',
22
+ 'greenBright',
23
+ 'yellowBright',
24
+ 'blueBright',
25
+ 'magentaBright',
26
+ 'cyanBright',
27
+ ];
28
+ let colorKey = 0;
29
+ for (const key of keys) {
30
+ const fn = target[key];
31
+ if (typeof fn === 'function') {
32
+ let cnt = 0;
33
+ const color = colors[colorKey++ % colors.length];
34
+ target[key] = function () {
35
+ const arr = [picocolors[color](`[${key}:${++cnt}]`)];
36
+ const add = getInfo?.(key);
37
+ if (add)
38
+ arr.push(add);
39
+ arr.push(...arguments);
40
+ console.info(arr.map(info).join(' '));
41
+ return fn.apply(target, arguments);
42
+ };
43
+ }
44
+ }
45
+ };
46
+ export const debugServer = (server) => debugMode(server, () => `p: ${server.processingQueries} m: ${server.modifyQueue.length} q: ${server.queryQueue.size}`);
5
47
  export const equals = (aB, bB) => {
6
48
  const len = aB.byteLength;
7
49
  if (len != bB.byteLength) {
@@ -82,24 +124,6 @@ export const hexToBuf = (s) => {
82
124
  }
83
125
  return buf;
84
126
  };
85
- function base64OutLen(n, lineMax) {
86
- let olen;
87
- /* This version would be with padding but we don't pad */
88
- //olen = n * 4 / 3 + 4; /* 3-byte blocks to 4-byte */
89
- olen = ((4 * n) / 3 + 3) & ~3;
90
- olen += lineMax > 0 ? olen / lineMax : 0; // line feeds
91
- return olen;
92
- }
93
- export const base64encode = (a, lineMax = 72) => {
94
- // TODO Could fallback to @saulx/utils if native is not available
95
- const tmp = new Uint8Array(base64OutLen(a.byteLength, lineMax));
96
- if ((a.length < 10 && lineMax === 72) || !native) {
97
- return encodeBase64(a);
98
- }
99
- else {
100
- return DECODER.decode(native.base64encode(tmp, a, lineMax));
101
- }
102
- };
103
127
  export const readDoubleLE = (val, offset) => {
104
128
  const low = (val[offset] |
105
129
  (val[offset + 1] << 8) |
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@based/db",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",
7
7
  "scripts": {
8
8
  "build": "make -C clibs && npm run build-zig && tsc",
9
+ "build-ts": "tsc",
9
10
  "build-zig": "npx tsx scripts/zig_cross_compile.ts",
11
+ "build-linux_aarch64": "(cd clibs && podman run --rm -v \"$PWD/../../..:/usr/src/based-db\" based-db-clibs-build-linux_aarch64)",
12
+ "build-release-debug": "(cd clibs && ./build-release.sh) && npm run build-zig -- release debug && tsc",
10
13
  "build-release": "(cd clibs && ./build-release.sh) && npm run build-zig -- release && tsc",
11
14
  "watch": "npx tsc --watch",
12
15
  "clean-selva": "make -C clibs clean",
@@ -18,7 +21,10 @@
18
21
  "test-gdb": "npm run build && LOCPATH=../locale/locale-x86_64-gnu/locale gdb -ex run --args node ./scripts/test.js",
19
22
  "test-fast": "LOCPATH=../locale/locale-x86_64-gnu/locale node ./scripts/test.js",
20
23
  "test-fast-linux_aarch64": "podman run --rm -v \"$PWD/../..:/usr/src/based-db\" based-db-clibs-build-linux_aarch64 sh -c '\\. \"/usr/local/nvm/nvm.sh\"; cd /usr/src/based-db/packages/db; npm run test-fast'",
24
+ "test-fast-linux_aarch64-gdb": "podman run --rm -v \"$PWD/../..:/usr/src/based-db\" based-db-clibs-build-linux_aarch64 sh -c '\\. \"/usr/local/nvm/nvm.sh\"; cd /usr/src/based-db/packages/db; LOCPATH=../locale/locale-x86_64-gnu/locale gdb -ex run --args node ./scripts/test.js'",
25
+ "test-fast-linux_aarch64-valgrind": "podman run --rm -v \"$PWD/../..:/usr/src/based-db\" based-db-clibs-build-linux_aarch64 sh -c '\\. \"/usr/local/nvm/nvm.sh\"; cd /usr/src/based-db/packages/db; LOCPATH=../locale/locale-aarch64-gnu/locale valgrind --leak-check=full node ./scripts/test.js references:update2'",
21
26
  "test-zig": "npm run build-zig -- debug && tsc && npm run test-fast",
27
+ "test-zig-debug": "npm run build-zig -- debug && tsc && LOCPATH=../locale/locale-x86_64-gnu/locale ./scripts/lldb-node ./scripts/test.js",
22
28
  "test-ts": "tsc && node ./scripts/test.js",
23
29
  "perf": "npm run build && node benchmarks/references.js && node benchmarks/transfermarkt/transfermarkt-based.js"
24
30
  },
@@ -32,9 +38,9 @@
32
38
  "basedDbNative.cjs"
33
39
  ],
34
40
  "dependencies": {
35
- "@based/schema": "5.0.0-alpha.9",
41
+ "@based/schema": "5.0.0-alpha.10",
36
42
  "@saulx/hash": "^3.0.0",
37
- "@saulx/utils": "^6.1.1",
43
+ "@saulx/utils": "^6.4.0",
38
44
  "exit-hook": "^4.0.0",
39
45
  "picocolors": "^1.1.0",
40
46
  "@based/crc32c": "^1.0.0"
@@ -1,59 +0,0 @@
1
- /*
2
- * Base64 encoding/decoding (RFC1341)
3
- * Copyright (c) 2021-2025 SAULX
4
- * Copyright (c) 2005-2011, Jouni Malinen <j@w1.fi>
5
- * SPDX-License-Identifier: BSD-3-Clause
6
- */
7
- #pragma once
8
-
9
- #include "selva/_export.h"
10
-
11
- SELVA_EXPORT
12
- size_t base64_encode_s(char *out, const char *str_in, size_t len, size_t line_max)
13
- __attribute__((access(write_only, 1), access(read_only, 2, 3)));
14
-
15
- /**
16
- * base64_encode - Base64 encode
17
- * Caller is responsible for freeing the returned buffer. Returned buffer is
18
- * nul terminated to make it easier to use as a C string. The nul terminator is
19
- * not included in out_len.
20
- * @parma str_in Data to be encoded
21
- * @param len Length of the data to be encoded
22
- * @param out_len Pointer to output length variable, or NULL if not used
23
- * @returns Allocated buffer of out_len bytes of encoded data,
24
- * or %NULL on failure
25
- */
26
- [[nodiscard]]
27
- SELVA_EXPORT
28
- char * base64_encode(const char *str_in, size_t len, size_t *out_len)
29
- __attribute__((access(read_only, 1, 2), access(read_only, 3)));
30
-
31
- /**
32
- * Base64 decode.
33
- * Caller is responsible for freeing the returned buffer.
34
- * @param str_in Data to be decoded
35
- * @param len Length of the data to be decoded
36
- * @param out_len Pointer to output length variable
37
- * @returns Allocated buffer of out_len bytes of decoded data, or NULL on failure
38
- */
39
- [[nodiscard]]
40
- SELVA_EXPORT
41
- char * base64_decode(const char *str_in, size_t len, size_t *out_len)
42
- __attribute__((access(read_only, 1, 2), access(write_only, 3)));
43
-
44
- /**
45
- * Calculate the required buffer size of a string of n bytes.
46
- * @param line_max is the max line length. 0 = no limit; 72 = typical.
47
- */
48
- static inline size_t base64_out_len(size_t n, size_t line_max) {
49
- size_t olen;
50
-
51
- /* This version would be with padding but we don't pad */
52
- #if 0
53
- olen = n * 4 / 3 + 4; /* 3-byte blocks to 4-byte */
54
- #endif
55
- olen = ((4 * n / 3) + 3) & ~3;
56
- olen += line_max > 0 ? olen / line_max : 0; /* line feeds */
57
-
58
- return olen;
59
- }
@@ -1,59 +0,0 @@
1
- /*
2
- * Base64url encoding/decoding (RFC4648)
3
- * Copyright (c) 2021-2025 SAULX
4
- * Copyright (c) 2005-2011, Jouni Malinen <j@w1.fi>
5
- * SPDX-License-Identifier: BSD-3-Clause
6
- */
7
- #pragma once
8
-
9
- #include "selva/_export.h"
10
-
11
- SELVA_EXPORT
12
- size_t base64url_encode_s(char *out, const char *str_in, size_t len, size_t line_max)
13
- __attribute__((access(write_only, 1), access(read_only, 2, 3)));
14
-
15
- /**
16
- * base64url_encode - Base64url encode
17
- * Caller is responsible for freeing the returned buffer. Returned buffer is
18
- * nul terminated to make it easier to use as a C string. The nul terminator is
19
- * not included in out_len.
20
- * @parma str_in Data to be encoded
21
- * @param len Length of the data to be encoded
22
- * @param out_len Pointer to output length variable, or NULL if not used
23
- * @returns Allocated buffer of out_len bytes of encoded data,
24
- * or %NULL on failure
25
- */
26
- [[nodiscard]]
27
- SELVA_EXPORT
28
- char * base64url_encode(const char *str_in, size_t len, size_t *out_len)
29
- __attribute__((access(read_only, 1, 2), access(read_only, 3)));
30
-
31
- /**
32
- * Base64url decode.
33
- * Caller is responsible for freeing the returned buffer.
34
- * @param str_in Data to be decoded
35
- * @param len Length of the data to be decoded
36
- * @param out_len Pointer to output length variable
37
- * @returns Allocated buffer of out_len bytes of decoded data, or NULL on failure
38
- */
39
- [[nodiscard]]
40
- SELVA_EXPORT
41
- char * base64url_decode(const char *str_in, size_t len, size_t *out_len)
42
- __attribute__((access(read_only, 1, 2), access(write_only, 3)));
43
-
44
- /**
45
- * Calculate the required buffer size of a string of n bytes.
46
- * @param line_max is the max line length. 0 = no limit; 72 = typical.
47
- */
48
- static inline size_t base64url_out_len(size_t n, size_t line_max) {
49
- size_t olen;
50
-
51
- /* This version would be with padding but we don't pad */
52
- #if 0
53
- olen = n * 4 / 3 + 4; /* 3-byte blocks to 4-byte */
54
- #endif
55
- olen = ((4 * n / 3) + 3) & ~3;
56
- olen += line_max > 0 ? olen / line_max : 0; /* line feeds */
57
-
58
- return olen;
59
- }
@@ -1,59 +0,0 @@
1
- /*
2
- * Base64 encoding/decoding (RFC1341)
3
- * Copyright (c) 2021-2025 SAULX
4
- * Copyright (c) 2005-2011, Jouni Malinen <j@w1.fi>
5
- * SPDX-License-Identifier: BSD-3-Clause
6
- */
7
- #pragma once
8
-
9
- #include "selva/_export.h"
10
-
11
- SELVA_EXPORT
12
- size_t base64_encode_s(char *out, const char *str_in, size_t len, size_t line_max)
13
- __attribute__((access(write_only, 1), access(read_only, 2, 3)));
14
-
15
- /**
16
- * base64_encode - Base64 encode
17
- * Caller is responsible for freeing the returned buffer. Returned buffer is
18
- * nul terminated to make it easier to use as a C string. The nul terminator is
19
- * not included in out_len.
20
- * @parma str_in Data to be encoded
21
- * @param len Length of the data to be encoded
22
- * @param out_len Pointer to output length variable, or NULL if not used
23
- * @returns Allocated buffer of out_len bytes of encoded data,
24
- * or %NULL on failure
25
- */
26
- [[nodiscard]]
27
- SELVA_EXPORT
28
- char * base64_encode(const char *str_in, size_t len, size_t *out_len)
29
- __attribute__((access(read_only, 1, 2), access(read_only, 3)));
30
-
31
- /**
32
- * Base64 decode.
33
- * Caller is responsible for freeing the returned buffer.
34
- * @param str_in Data to be decoded
35
- * @param len Length of the data to be decoded
36
- * @param out_len Pointer to output length variable
37
- * @returns Allocated buffer of out_len bytes of decoded data, or NULL on failure
38
- */
39
- [[nodiscard]]
40
- SELVA_EXPORT
41
- char * base64_decode(const char *str_in, size_t len, size_t *out_len)
42
- __attribute__((access(read_only, 1, 2), access(write_only, 3)));
43
-
44
- /**
45
- * Calculate the required buffer size of a string of n bytes.
46
- * @param line_max is the max line length. 0 = no limit; 72 = typical.
47
- */
48
- static inline size_t base64_out_len(size_t n, size_t line_max) {
49
- size_t olen;
50
-
51
- /* This version would be with padding but we don't pad */
52
- #if 0
53
- olen = n * 4 / 3 + 4; /* 3-byte blocks to 4-byte */
54
- #endif
55
- olen = ((4 * n / 3) + 3) & ~3;
56
- olen += line_max > 0 ? olen / line_max : 0; /* line feeds */
57
-
58
- return olen;
59
- }
@@ -1,59 +0,0 @@
1
- /*
2
- * Base64url encoding/decoding (RFC4648)
3
- * Copyright (c) 2021-2025 SAULX
4
- * Copyright (c) 2005-2011, Jouni Malinen <j@w1.fi>
5
- * SPDX-License-Identifier: BSD-3-Clause
6
- */
7
- #pragma once
8
-
9
- #include "selva/_export.h"
10
-
11
- SELVA_EXPORT
12
- size_t base64url_encode_s(char *out, const char *str_in, size_t len, size_t line_max)
13
- __attribute__((access(write_only, 1), access(read_only, 2, 3)));
14
-
15
- /**
16
- * base64url_encode - Base64url encode
17
- * Caller is responsible for freeing the returned buffer. Returned buffer is
18
- * nul terminated to make it easier to use as a C string. The nul terminator is
19
- * not included in out_len.
20
- * @parma str_in Data to be encoded
21
- * @param len Length of the data to be encoded
22
- * @param out_len Pointer to output length variable, or NULL if not used
23
- * @returns Allocated buffer of out_len bytes of encoded data,
24
- * or %NULL on failure
25
- */
26
- [[nodiscard]]
27
- SELVA_EXPORT
28
- char * base64url_encode(const char *str_in, size_t len, size_t *out_len)
29
- __attribute__((access(read_only, 1, 2), access(read_only, 3)));
30
-
31
- /**
32
- * Base64url decode.
33
- * Caller is responsible for freeing the returned buffer.
34
- * @param str_in Data to be decoded
35
- * @param len Length of the data to be decoded
36
- * @param out_len Pointer to output length variable
37
- * @returns Allocated buffer of out_len bytes of decoded data, or NULL on failure
38
- */
39
- [[nodiscard]]
40
- SELVA_EXPORT
41
- char * base64url_decode(const char *str_in, size_t len, size_t *out_len)
42
- __attribute__((access(read_only, 1, 2), access(write_only, 3)));
43
-
44
- /**
45
- * Calculate the required buffer size of a string of n bytes.
46
- * @param line_max is the max line length. 0 = no limit; 72 = typical.
47
- */
48
- static inline size_t base64url_out_len(size_t n, size_t line_max) {
49
- size_t olen;
50
-
51
- /* This version would be with padding but we don't pad */
52
- #if 0
53
- olen = n * 4 / 3 + 4; /* 3-byte blocks to 4-byte */
54
- #endif
55
- olen = ((4 * n / 3) + 3) & ~3;
56
- olen += line_max > 0 ? olen / line_max : 0; /* line feeds */
57
-
58
- return olen;
59
- }
@@ -1,59 +0,0 @@
1
- /*
2
- * Base64 encoding/decoding (RFC1341)
3
- * Copyright (c) 2021-2025 SAULX
4
- * Copyright (c) 2005-2011, Jouni Malinen <j@w1.fi>
5
- * SPDX-License-Identifier: BSD-3-Clause
6
- */
7
- #pragma once
8
-
9
- #include "selva/_export.h"
10
-
11
- SELVA_EXPORT
12
- size_t base64_encode_s(char *out, const char *str_in, size_t len, size_t line_max)
13
- __attribute__((access(write_only, 1), access(read_only, 2, 3)));
14
-
15
- /**
16
- * base64_encode - Base64 encode
17
- * Caller is responsible for freeing the returned buffer. Returned buffer is
18
- * nul terminated to make it easier to use as a C string. The nul terminator is
19
- * not included in out_len.
20
- * @parma str_in Data to be encoded
21
- * @param len Length of the data to be encoded
22
- * @param out_len Pointer to output length variable, or NULL if not used
23
- * @returns Allocated buffer of out_len bytes of encoded data,
24
- * or %NULL on failure
25
- */
26
- [[nodiscard]]
27
- SELVA_EXPORT
28
- char * base64_encode(const char *str_in, size_t len, size_t *out_len)
29
- __attribute__((access(read_only, 1, 2), access(read_only, 3)));
30
-
31
- /**
32
- * Base64 decode.
33
- * Caller is responsible for freeing the returned buffer.
34
- * @param str_in Data to be decoded
35
- * @param len Length of the data to be decoded
36
- * @param out_len Pointer to output length variable
37
- * @returns Allocated buffer of out_len bytes of decoded data, or NULL on failure
38
- */
39
- [[nodiscard]]
40
- SELVA_EXPORT
41
- char * base64_decode(const char *str_in, size_t len, size_t *out_len)
42
- __attribute__((access(read_only, 1, 2), access(write_only, 3)));
43
-
44
- /**
45
- * Calculate the required buffer size of a string of n bytes.
46
- * @param line_max is the max line length. 0 = no limit; 72 = typical.
47
- */
48
- static inline size_t base64_out_len(size_t n, size_t line_max) {
49
- size_t olen;
50
-
51
- /* This version would be with padding but we don't pad */
52
- #if 0
53
- olen = n * 4 / 3 + 4; /* 3-byte blocks to 4-byte */
54
- #endif
55
- olen = ((4 * n / 3) + 3) & ~3;
56
- olen += line_max > 0 ? olen / line_max : 0; /* line feeds */
57
-
58
- return olen;
59
- }
@@ -1,59 +0,0 @@
1
- /*
2
- * Base64url encoding/decoding (RFC4648)
3
- * Copyright (c) 2021-2025 SAULX
4
- * Copyright (c) 2005-2011, Jouni Malinen <j@w1.fi>
5
- * SPDX-License-Identifier: BSD-3-Clause
6
- */
7
- #pragma once
8
-
9
- #include "selva/_export.h"
10
-
11
- SELVA_EXPORT
12
- size_t base64url_encode_s(char *out, const char *str_in, size_t len, size_t line_max)
13
- __attribute__((access(write_only, 1), access(read_only, 2, 3)));
14
-
15
- /**
16
- * base64url_encode - Base64url encode
17
- * Caller is responsible for freeing the returned buffer. Returned buffer is
18
- * nul terminated to make it easier to use as a C string. The nul terminator is
19
- * not included in out_len.
20
- * @parma str_in Data to be encoded
21
- * @param len Length of the data to be encoded
22
- * @param out_len Pointer to output length variable, or NULL if not used
23
- * @returns Allocated buffer of out_len bytes of encoded data,
24
- * or %NULL on failure
25
- */
26
- [[nodiscard]]
27
- SELVA_EXPORT
28
- char * base64url_encode(const char *str_in, size_t len, size_t *out_len)
29
- __attribute__((access(read_only, 1, 2), access(read_only, 3)));
30
-
31
- /**
32
- * Base64url decode.
33
- * Caller is responsible for freeing the returned buffer.
34
- * @param str_in Data to be decoded
35
- * @param len Length of the data to be decoded
36
- * @param out_len Pointer to output length variable
37
- * @returns Allocated buffer of out_len bytes of decoded data, or NULL on failure
38
- */
39
- [[nodiscard]]
40
- SELVA_EXPORT
41
- char * base64url_decode(const char *str_in, size_t len, size_t *out_len)
42
- __attribute__((access(read_only, 1, 2), access(write_only, 3)));
43
-
44
- /**
45
- * Calculate the required buffer size of a string of n bytes.
46
- * @param line_max is the max line length. 0 = no limit; 72 = typical.
47
- */
48
- static inline size_t base64url_out_len(size_t n, size_t line_max) {
49
- size_t olen;
50
-
51
- /* This version would be with padding but we don't pad */
52
- #if 0
53
- olen = n * 4 / 3 + 4; /* 3-byte blocks to 4-byte */
54
- #endif
55
- olen = ((4 * n / 3) + 3) & ~3;
56
- olen += line_max > 0 ? olen / line_max : 0; /* line feeds */
57
-
58
- return olen;
59
- }
@@ -1 +0,0 @@
1
- export declare const convertToTimestamp: (value: string | Date | number) => number;
@@ -1,68 +0,0 @@
1
- const timeToNumber = (ex) => {
2
- if (ex === 's') {
3
- return 1000;
4
- }
5
- if (ex === 'm') {
6
- return 1000 * 60;
7
- }
8
- if (ex === 'h') {
9
- return 1000 * 60 * 60;
10
- }
11
- if (ex === 'd') {
12
- return 1000 * 60 * 60 * 24;
13
- }
14
- if (ex === 'y') {
15
- return 31556952000;
16
- }
17
- return 1;
18
- };
19
- export const convertToTimestamp = (value) => {
20
- if (value instanceof Date) {
21
- return value.valueOf();
22
- }
23
- if (typeof value === 'string') {
24
- if (value === 'now') {
25
- return Date.now();
26
- }
27
- // MAKE THIS INTO A UTIL
28
- const y = value.replace(/([+-])/g, ' $1 ');
29
- const arr = y.split(/ +/);
30
- let newValue = 0;
31
- let now;
32
- let op = 1;
33
- for (const seg of arr) {
34
- if (seg === '-') {
35
- op = -1;
36
- }
37
- else if (seg === '+') {
38
- op = 1;
39
- }
40
- else {
41
- var v = 0;
42
- if (seg === 'now') {
43
- if (!now) {
44
- now = Date.now();
45
- }
46
- v = now;
47
- }
48
- else if (/[smhdy]$/.test(seg)) {
49
- const ex = seg[seg.length - 1];
50
- const number = parseInt(seg, 10);
51
- v = number * timeToNumber(ex);
52
- }
53
- else if (seg) {
54
- v = new Date(seg).valueOf();
55
- }
56
- if (op === -1) {
57
- newValue -= v;
58
- }
59
- else {
60
- newValue += v;
61
- }
62
- }
63
- }
64
- return newValue;
65
- }
66
- return value;
67
- };
68
- //# sourceMappingURL=timestamp.js.map