@hold-baby/bucket-db 0.3.0 → 0.5.0

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 (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +503 -19
  3. package/dist/bucket-db.d.ts +25 -0
  4. package/dist/bucket-db.js +36 -0
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +133 -0
  7. package/dist/collection.d.ts +78 -0
  8. package/dist/collection.js +321 -0
  9. package/dist/doctor.d.ts +7 -0
  10. package/dist/doctor.js +100 -0
  11. package/dist/errors.d.ts +59 -0
  12. package/dist/errors.js +57 -0
  13. package/dist/index.d.ts +13 -0
  14. package/dist/index.js +6 -0
  15. package/dist/keys.d.ts +12 -0
  16. package/dist/keys.js +31 -0
  17. package/dist/query.d.ts +16 -0
  18. package/dist/query.js +133 -0
  19. package/dist/snapshot.d.ts +16 -0
  20. package/dist/snapshot.js +40 -0
  21. package/dist/storage/adapter.d.ts +75 -0
  22. package/dist/storage/adapter.js +27 -0
  23. package/dist/storage/fs.d.ts +28 -0
  24. package/dist/storage/fs.js +175 -0
  25. package/dist/storage/memory.d.ts +18 -0
  26. package/dist/storage/memory.js +49 -0
  27. package/dist/storage/s3/adapters.d.ts +38 -0
  28. package/dist/storage/s3/adapters.js +65 -0
  29. package/dist/storage/s3/client.d.ts +52 -0
  30. package/dist/storage/s3/client.js +231 -0
  31. package/dist/storage/s3/credentials.d.ts +17 -0
  32. package/dist/storage/s3/credentials.js +42 -0
  33. package/dist/storage/s3/sigv4.d.ts +32 -0
  34. package/dist/storage/s3/sigv4.js +75 -0
  35. package/dist/types.d.ts +55 -0
  36. package/dist/types.js +1 -0
  37. package/dist/url.d.ts +16 -0
  38. package/dist/url.js +66 -0
  39. package/llms.txt +142 -0
  40. package/package.json +20 -7
  41. package/src/cache/lru-cache.ts +0 -131
  42. package/src/core/bucket-db.ts +0 -47
  43. package/src/core/collection.ts +0 -278
  44. package/src/core/wal.ts +0 -106
  45. package/src/index/shard-manager.ts +0 -197
  46. package/src/index.ts +0 -37
  47. package/src/query/evaluator.ts +0 -143
  48. package/src/storage/ali-oss.d.ts +0 -43
  49. package/src/storage/fs-adapter.ts +0 -248
  50. package/src/storage/memory-adapter.ts +0 -105
  51. package/src/storage/oss-adapter.ts +0 -164
  52. package/src/storage/s3-adapter.ts +0 -200
  53. package/src/types/collection.ts +0 -43
  54. package/src/types/document.ts +0 -22
  55. package/src/types/errors.ts +0 -49
  56. package/src/types/index.ts +0 -37
  57. package/src/types/query.ts +0 -50
  58. package/src/types/storage.ts +0 -46
  59. package/src/utils/hash.ts +0 -24
  60. package/src/utils/path-validator.ts +0 -119
  61. package/tests/core/bucket-db.test.d.ts +0 -2
  62. package/tests/core/bucket-db.test.d.ts.map +0 -1
  63. package/tests/core/bucket-db.test.js +0 -34
  64. package/tests/core/bucket-db.test.js.map +0 -1
  65. package/tests/core/bucket-db.test.ts +0 -50
  66. package/tests/core/collection.test.d.ts +0 -2
  67. package/tests/core/collection.test.d.ts.map +0 -1
  68. package/tests/core/collection.test.js +0 -148
  69. package/tests/core/collection.test.js.map +0 -1
  70. package/tests/core/collection.test.ts +0 -195
  71. package/tests/core/dbpath.test.ts +0 -52
  72. package/tests/index/shard-manager.test.d.ts +0 -2
  73. package/tests/index/shard-manager.test.d.ts.map +0 -1
  74. package/tests/index/shard-manager.test.js +0 -106
  75. package/tests/index/shard-manager.test.js.map +0 -1
  76. package/tests/index/shard-manager.test.ts +0 -129
  77. package/tests/query/evaluator.test.d.ts +0 -2
  78. package/tests/query/evaluator.test.d.ts.map +0 -1
  79. package/tests/query/evaluator.test.js +0 -87
  80. package/tests/query/evaluator.test.js.map +0 -1
  81. package/tests/query/evaluator.test.ts +0 -104
  82. package/tests/storage/fs-adapter.test.ts +0 -111
  83. package/tests/storage/memory-adapter.test.d.ts +0 -2
  84. package/tests/storage/memory-adapter.test.d.ts.map +0 -1
  85. package/tests/storage/memory-adapter.test.js +0 -65
  86. package/tests/storage/memory-adapter.test.js.map +0 -1
  87. package/tests/storage/memory-adapter.test.ts +0 -84
  88. package/tests/storage/oss-adapter.test.d.ts +0 -2
  89. package/tests/storage/oss-adapter.test.d.ts.map +0 -1
  90. package/tests/storage/oss-adapter.test.js +0 -34
  91. package/tests/storage/oss-adapter.test.js.map +0 -1
  92. package/tests/storage/oss-adapter.test.ts +0 -40
  93. package/tests/storage/s3-adapter.test.d.ts +0 -2
  94. package/tests/storage/s3-adapter.test.d.ts.map +0 -1
  95. package/tests/storage/s3-adapter.test.js +0 -51
  96. package/tests/storage/s3-adapter.test.js.map +0 -1
  97. package/tests/storage/s3-adapter.test.ts +0 -62
  98. package/tests/utils/hash.test.d.ts +0 -2
  99. package/tests/utils/hash.test.d.ts.map +0 -1
  100. package/tests/utils/hash.test.js +0 -36
  101. package/tests/utils/hash.test.js.map +0 -1
  102. package/tests/utils/hash.test.ts +0 -42
  103. package/tsconfig.json +0 -12
@@ -1,62 +0,0 @@
1
- import { describe, test, expect, beforeEach } from 'bun:test';
2
- import { S3Adapter } from '../../src/storage/s3-adapter';
3
- import { StorageError } from '../../src/index.js';
4
-
5
- // Skip tests if no AWS credentials available
6
- const skipIfNoCredentials = process.env.AWS_ACCESS_KEY_ID ? test : test.skip;
7
-
8
- describe('S3Adapter', () => {
9
- let adapter: S3Adapter;
10
-
11
- beforeEach(() => {
12
- adapter = new S3Adapter({
13
- bucket: process.env.TEST_S3_BUCKET || 'test-bucket',
14
- region: process.env.AWS_REGION || 'us-east-1',
15
- credentials: {
16
- accessKeyId: process.env.AWS_ACCESS_KEY_ID || 'test',
17
- secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || 'test',
18
- },
19
- endpoint: process.env.S3_ENDPOINT, // For LocalStack
20
- });
21
- });
22
-
23
- skipIfNoCredentials('put and get object', async () => {
24
- const data = { name: 'test', value: 123 };
25
- const { etag } = await adapter.put('test/key1.json', data);
26
-
27
- expect(etag).toBeDefined();
28
-
29
- const result = await adapter.get('test/key1.json');
30
- expect(result.data).toEqual(data);
31
- expect(result.etag).toBe(etag);
32
- });
33
-
34
- skipIfNoCredentials('exists returns true for existing key', async () => {
35
- await adapter.put('test/key1.json', { test: true });
36
- expect(await adapter.exists('test/key1.json')).toBe(true);
37
- });
38
-
39
- skipIfNoCredentials('delete removes object', async () => {
40
- await adapter.put('test/key1.json', { test: true });
41
- await adapter.delete('test/key1.json');
42
- expect(await adapter.exists('test/key1.json')).toBe(false);
43
- });
44
-
45
- skipIfNoCredentials('put with ifMatch optimistic locking', async () => {
46
- const { etag: etag1 } = await adapter.put('test/key1.json', { version: 1 });
47
- const { etag: etag2 } = await adapter.put('test/key1.json', { version: 2 }, { ifMatch: etag1 });
48
-
49
- expect(etag2).toBeDefined();
50
- expect(etag2).not.toBe(etag1);
51
- });
52
-
53
- test('adapter structure is correct', () => {
54
- expect(adapter).toBeDefined();
55
- expect(typeof adapter.get).toBe('function');
56
- expect(typeof adapter.put).toBe('function');
57
- expect(typeof adapter.delete).toBe('function');
58
- expect(typeof adapter.exists).toBe('function');
59
- expect(typeof adapter.listKeys).toBe('function');
60
- expect(typeof adapter.batchGet).toBe('function');
61
- });
62
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=hash.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hash.test.d.ts","sourceRoot":"","sources":["hash.test.ts"],"names":[],"mappings":""}
@@ -1,36 +0,0 @@
1
- import { describe, test, expect } from 'bun:test';
2
- import { hashString, getShardId } from '../../src/utils/hash';
3
- describe('Hash Utilities', () => {
4
- test('hashString produces consistent results', () => {
5
- const hash1 = hashString('test-id-123');
6
- const hash2 = hashString('test-id-123');
7
- expect(hash1).toBe(hash2);
8
- });
9
- test('hashString produces different results for different inputs', () => {
10
- const hash1 = hashString('id-1');
11
- const hash2 = hashString('id-2');
12
- expect(hash1).not.toBe(hash2);
13
- });
14
- test('getShardId returns value within range', () => {
15
- const shardId = getShardId('test-id', 16);
16
- expect(shardId).toBeGreaterThanOrEqual(0);
17
- expect(shardId).toBeLessThan(16);
18
- });
19
- test('getShardId is deterministic', () => {
20
- const shardId1 = getShardId('test-id', 16);
21
- const shardId2 = getShardId('test-id', 16);
22
- expect(shardId1).toBe(shardId2);
23
- });
24
- test('getShardId distributes across shards', () => {
25
- const shardCounts = new Map();
26
- const shardCount = 16;
27
- // Generate 1000 IDs and count distribution
28
- for (let i = 0; i < 1000; i++) {
29
- const shardId = getShardId(`id-${i}`, shardCount);
30
- shardCounts.set(shardId, (shardCounts.get(shardId) || 0) + 1);
31
- }
32
- // Each shard should have at least some documents (rough distribution)
33
- expect(shardCounts.size).toBeGreaterThan(10);
34
- });
35
- });
36
- //# sourceMappingURL=hash.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hash.test.js","sourceRoot":"","sources":["hash.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAE9D,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,IAAI,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAClD,MAAM,KAAK,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;QACxC,MAAM,KAAK,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;QACxC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,4DAA4D,EAAE,GAAG,EAAE;QACtE,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;QACjC,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;QACjC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,IA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ilities', () => {
5
- test('hashString produces consistent results', () => {
6
- const hash1 = hashString('test-id-123');
7
- const hash2 = hashString('test-id-123');
8
- expect(hash1).toBe(hash2);
9
- });
10
-
11
- test('hashString produces different results for different inputs', () => {
12
- const hash1 = hashString('id-1');
13
- const hash2 = hashString('id-2');
14
- expect(hash1).not.toBe(hash2);
15
- });
16
-
17
- test('getShardId returns value within range', () => {
18
- const shardId = getShardId('test-id', 16);
19
- expect(shardId).toBeGreaterThanOrEqual(0);
20
- expect(shardId).toBeLessThan(16);
21
- });
22
-
23
- test('getShardId is deterministic', () => {
24
- const shardId1 = getShardId('test-id', 16);
25
- const shardId2 = getShardId('test-id', 16);
26
- expect(shardId1).toBe(shardId2);
27
- });
28
-
29
- test('getShardId distributes across shards', () => {
30
- const shardCounts = new Map<number, number>();
31
- const shardCount = 16;
32
-
33
- // Generate 1000 IDs and count distribution
34
- for (let i = 0; i < 1000; i++) {
35
- const shardId = getShardId(`id-${i}`, shardCount);
36
- shardCounts.set(shardId, (shardCounts.get(shardId) || 0) + 1);
37
- }
38
-
39
- // Each shard should have at least some documents (rough distribution)
40
- expect(shardCounts.size).toBeGreaterThan(10);
41
- });
42
- });
package/tsconfig.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- "rootDir": "./src"
6
- },
7
- "include": ["src/**/*"],
8
- "exclude": ["node_modules", "dist", "tests"],
9
- "references": [
10
- { "path": "../types" }
11
- ]
12
- }