@hold-baby/bucket-db 0.3.1 → 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 (114) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +331 -62
  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 -9
  14. package/dist/index.js +6 -10
  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 +116 -20
  40. package/package.json +7 -5
  41. package/dist/cache/lru-cache.d.ts +0 -47
  42. package/dist/cache/lru-cache.d.ts.map +0 -1
  43. package/dist/cache/lru-cache.js +0 -110
  44. package/dist/cache/lru-cache.js.map +0 -1
  45. package/dist/core/bucket-db.d.ts +0 -20
  46. package/dist/core/bucket-db.d.ts.map +0 -1
  47. package/dist/core/bucket-db.js +0 -32
  48. package/dist/core/bucket-db.js.map +0 -1
  49. package/dist/core/collection.d.ts +0 -26
  50. package/dist/core/collection.d.ts.map +0 -1
  51. package/dist/core/collection.js +0 -213
  52. package/dist/core/collection.js.map +0 -1
  53. package/dist/core/wal.d.ts +0 -45
  54. package/dist/core/wal.d.ts.map +0 -1
  55. package/dist/core/wal.js +0 -80
  56. package/dist/core/wal.js.map +0 -1
  57. package/dist/index/shard-manager.d.ts +0 -36
  58. package/dist/index/shard-manager.d.ts.map +0 -1
  59. package/dist/index/shard-manager.js +0 -177
  60. package/dist/index/shard-manager.js.map +0 -1
  61. package/dist/index.d.ts.map +0 -1
  62. package/dist/index.js.map +0 -1
  63. package/dist/query/evaluator.d.ts +0 -10
  64. package/dist/query/evaluator.d.ts.map +0 -1
  65. package/dist/query/evaluator.js +0 -127
  66. package/dist/query/evaluator.js.map +0 -1
  67. package/dist/storage/fs-adapter.d.ts +0 -24
  68. package/dist/storage/fs-adapter.d.ts.map +0 -1
  69. package/dist/storage/fs-adapter.js +0 -208
  70. package/dist/storage/fs-adapter.js.map +0 -1
  71. package/dist/storage/memory-adapter.d.ts +0 -22
  72. package/dist/storage/memory-adapter.d.ts.map +0 -1
  73. package/dist/storage/memory-adapter.js +0 -78
  74. package/dist/storage/memory-adapter.js.map +0 -1
  75. package/dist/storage/oss-adapter.d.ts +0 -26
  76. package/dist/storage/oss-adapter.d.ts.map +0 -1
  77. package/dist/storage/oss-adapter.js +0 -145
  78. package/dist/storage/oss-adapter.js.map +0 -1
  79. package/dist/storage/s3-adapter.d.ts +0 -26
  80. package/dist/storage/s3-adapter.d.ts.map +0 -1
  81. package/dist/storage/s3-adapter.js +0 -170
  82. package/dist/storage/s3-adapter.js.map +0 -1
  83. package/dist/types/collection.d.ts +0 -40
  84. package/dist/types/collection.d.ts.map +0 -1
  85. package/dist/types/collection.js +0 -2
  86. package/dist/types/collection.js.map +0 -1
  87. package/dist/types/document.d.ts +0 -18
  88. package/dist/types/document.d.ts.map +0 -1
  89. package/dist/types/document.js +0 -2
  90. package/dist/types/document.js.map +0 -1
  91. package/dist/types/errors.d.ts +0 -32
  92. package/dist/types/errors.d.ts.map +0 -1
  93. package/dist/types/errors.js +0 -48
  94. package/dist/types/errors.js.map +0 -1
  95. package/dist/types/index.d.ts +0 -6
  96. package/dist/types/index.d.ts.map +0 -1
  97. package/dist/types/index.js +0 -3
  98. package/dist/types/index.js.map +0 -1
  99. package/dist/types/query.d.ts +0 -37
  100. package/dist/types/query.d.ts.map +0 -1
  101. package/dist/types/query.js +0 -2
  102. package/dist/types/query.js.map +0 -1
  103. package/dist/types/storage.d.ts +0 -45
  104. package/dist/types/storage.d.ts.map +0 -1
  105. package/dist/types/storage.js +0 -2
  106. package/dist/types/storage.js.map +0 -1
  107. package/dist/utils/hash.d.ts +0 -13
  108. package/dist/utils/hash.d.ts.map +0 -1
  109. package/dist/utils/hash.js +0 -23
  110. package/dist/utils/hash.js.map +0 -1
  111. package/dist/utils/path-validator.d.ts +0 -46
  112. package/dist/utils/path-validator.d.ts.map +0 -1
  113. package/dist/utils/path-validator.js +0 -99
  114. package/dist/utils/path-validator.js.map +0 -1
@@ -1,6 +0,0 @@
1
- export type { Document, InsertDocument, UpdateDocument } from './document.js';
2
- export type { QueryOperator, QueryValue, QueryFilter, QueryOptions, UpdateOptions, } from './query.js';
3
- export type { StorageObject, PutOptions, StorageAdapter, StorageCredentials, StorageAdapterConfig, } from './storage.js';
4
- export type { ICollection, CollectionMeta, IndexShard, ShardMetadata, } from './collection.js';
5
- export { BucketDBError, DocumentNotFoundError, ConcurrentUpdateError, ValidationError, StorageError, } from './errors.js';
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG9E,YAAY,EACV,aAAa,EACb,UAAU,EACV,WAAW,EACX,YAAY,EACZ,aAAa,GACd,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,aAAa,EACb,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,WAAW,EACX,cAAc,EACd,UAAU,EACV,aAAa,GACd,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,YAAY,GACb,MAAM,aAAa,CAAC"}
@@ -1,3 +0,0 @@
1
- // Error classes
2
- export { BucketDBError, DocumentNotFoundError, ConcurrentUpdateError, ValidationError, StorageError, } from './errors.js';
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AA6BA,gBAAgB;AAChB,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,YAAY,GACb,MAAM,aAAa,CAAC"}
@@ -1,37 +0,0 @@
1
- /**
2
- * Supported query operators
3
- */
4
- export type QueryOperator = '$eq' | '$ne' | '$gt' | '$gte' | '$lt' | '$lte' | '$in' | '$nin';
5
- /**
6
- * Query value can be direct value or operator object
7
- */
8
- export type QueryValue<T> = T | {
9
- $eq?: T;
10
- $ne?: T;
11
- $gt?: T;
12
- $gte?: T;
13
- $lt?: T;
14
- $lte?: T;
15
- $in?: T[];
16
- $nin?: T[];
17
- };
18
- /**
19
- * Query filter for type-safe queries
20
- */
21
- export type QueryFilter<T> = {
22
- [K in keyof T]?: QueryValue<T[K]>;
23
- };
24
- /**
25
- * Query options for pagination and sorting
26
- */
27
- export interface QueryOptions {
28
- limit?: number;
29
- offset?: number;
30
- }
31
- /**
32
- * Update options with optimistic locking
33
- */
34
- export interface UpdateOptions {
35
- etag?: string;
36
- }
37
- //# sourceMappingURL=query.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/types/query.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,KAAK,GACL,KAAK,GACL,KAAK,GACL,MAAM,GACN,KAAK,GACL,MAAM,GACN,KAAK,GACL,MAAM,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IACpB,CAAC,GACD;IACE,GAAG,CAAC,EAAE,CAAC,CAAC;IACR,GAAG,CAAC,EAAE,CAAC,CAAC;IACR,GAAG,CAAC,EAAE,CAAC,CAAC;IACR,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,GAAG,CAAC,EAAE,CAAC,CAAC;IACR,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;IACV,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;CACZ,CAAC;AAEN;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAClC,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=query.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/types/query.ts"],"names":[],"mappings":""}
@@ -1,45 +0,0 @@
1
- /**
2
- * Storage object returned by adapter
3
- */
4
- export interface StorageObject {
5
- data: any;
6
- etag: string;
7
- lastModified: Date;
8
- }
9
- /**
10
- * Put options for conditional writes
11
- */
12
- export interface PutOptions {
13
- ifMatch?: string;
14
- ifNoneMatch?: string;
15
- }
16
- /**
17
- * Storage adapter interface (abstraction for S3/OSS)
18
- */
19
- export interface StorageAdapter {
20
- get(key: string): Promise<StorageObject>;
21
- put(key: string, data: any, options?: PutOptions): Promise<{
22
- etag: string;
23
- }>;
24
- delete(key: string): Promise<void>;
25
- exists(key: string): Promise<boolean>;
26
- listKeys(prefix: string): Promise<string[]>;
27
- batchGet(keys: string[]): Promise<Map<string, StorageObject>>;
28
- }
29
- /**
30
- * Storage credentials
31
- */
32
- export interface StorageCredentials {
33
- accessKeyId: string;
34
- secretAccessKey: string;
35
- }
36
- /**
37
- * Storage adapter configuration
38
- */
39
- export interface StorageAdapterConfig {
40
- bucket: string;
41
- region: string;
42
- credentials: StorageCredentials;
43
- endpoint?: string;
44
- }
45
- //# sourceMappingURL=storage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/types/storage.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,IAAI,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACzC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7E,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;CAC/D;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,kBAAkB,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=storage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/types/storage.ts"],"names":[],"mappings":""}
@@ -1,13 +0,0 @@
1
- /**
2
- * Simple string hash function (DJB2 algorithm)
3
- */
4
- export declare function hashString(str: string): number;
5
- /**
6
- * Get shard ID for a document ID
7
- */
8
- export declare function getShardId(docId: string, shardCount: number): number;
9
- /**
10
- * Format shard ID as zero-padded string (e.g., "00", "01", "15")
11
- */
12
- export declare function formatShardId(shardId: number): string;
13
- //# sourceMappingURL=hash.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAM9C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAErD"}
@@ -1,23 +0,0 @@
1
- /**
2
- * Simple string hash function (DJB2 algorithm)
3
- */
4
- export function hashString(str) {
5
- let hash = 5381;
6
- for (let i = 0; i < str.length; i++) {
7
- hash = (hash * 33) ^ str.charCodeAt(i);
8
- }
9
- return hash >>> 0; // Convert to unsigned 32-bit integer
10
- }
11
- /**
12
- * Get shard ID for a document ID
13
- */
14
- export function getShardId(docId, shardCount) {
15
- return hashString(docId) % shardCount;
16
- }
17
- /**
18
- * Format shard ID as zero-padded string (e.g., "00", "01", "15")
19
- */
20
- export function formatShardId(shardId) {
21
- return shardId.toString().padStart(2, '0');
22
- }
23
- //# sourceMappingURL=hash.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,IAAI,IAAI,GAAG,IAAI,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,IAAI,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,qCAAqC;AAC1D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,UAAkB;IAC1D,OAAO,UAAU,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC;AACxC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe;IAC3C,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAC7C,CAAC"}
@@ -1,46 +0,0 @@
1
- /**
2
- * ValidationError for path validation failures
3
- */
4
- export declare class PathValidationError extends Error {
5
- constructor(message: string);
6
- }
7
- /**
8
- * Sanitize and validate path components to prevent directory traversal attacks
9
- * This is for SINGLE path components (like collection names, document IDs)
10
- *
11
- * @param input - Path component to sanitize
12
- * @returns Sanitized path component
13
- * @throws PathValidationError if validation fails
14
- */
15
- export declare function sanitizePathComponent(input: string): string;
16
- /**
17
- * Validate that a target path is within the allowed base path
18
- * Prevents directory traversal attacks by ensuring the resolved path
19
- * doesn't escape the base directory
20
- *
21
- * @param basePath - Base directory path
22
- * @param targetPath - Target path to validate
23
- * @throws PathValidationError if path escapes base directory
24
- */
25
- export declare function validatePathWithinBase(basePath: string, targetPath: string): void;
26
- /**
27
- * Safely join path components with validation
28
- * This is for joining SINGLE components (not full paths with slashes)
29
- *
30
- * @param basePath - Base directory path
31
- * @param components - Path components to join
32
- * @returns Validated full path
33
- * @throws PathValidationError if validation fails
34
- */
35
- export declare function safePathJoin(basePath: string, ...components: string[]): string;
36
- /**
37
- * Safely join a key (which may contain slashes) with base path
38
- * Validates the result doesn't escape base directory
39
- *
40
- * @param basePath - Base directory path
41
- * @param key - Storage key (may contain path separators)
42
- * @returns Validated full path
43
- * @throws PathValidationError if validation fails
44
- */
45
- export declare function safeKeyPath(basePath: string, key: string): string;
46
- //# sourceMappingURL=path-validator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"path-validator.d.ts","sourceRoot":"","sources":["../../src/utils/path-validator.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CA6B3D;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAUjF;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,CAW9E;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAejE"}
@@ -1,99 +0,0 @@
1
- import { join, resolve, relative } from 'path';
2
- /**
3
- * ValidationError for path validation failures
4
- */
5
- export class PathValidationError extends Error {
6
- constructor(message) {
7
- super(message);
8
- this.name = 'PathValidationError';
9
- }
10
- }
11
- /**
12
- * Sanitize and validate path components to prevent directory traversal attacks
13
- * This is for SINGLE path components (like collection names, document IDs)
14
- *
15
- * @param input - Path component to sanitize
16
- * @returns Sanitized path component
17
- * @throws PathValidationError if validation fails
18
- */
19
- export function sanitizePathComponent(input) {
20
- if (!input || typeof input !== 'string') {
21
- throw new PathValidationError('Path component must be a non-empty string');
22
- }
23
- // Remove any path traversal sequences
24
- let sanitized = input.replace(/\.\./g, '');
25
- // Remove directory separators (single components cannot have slashes)
26
- sanitized = sanitized.replace(/[\/\\]/g, '_');
27
- // Only allow alphanumeric, underscore, hyphen, and dot
28
- if (!/^[a-zA-Z0-9_.-]+$/.test(sanitized)) {
29
- throw new PathValidationError(`Invalid characters in path component. Only alphanumeric, underscore, hyphen, and dot are allowed.`);
30
- }
31
- // Prevent excessively long names
32
- if (sanitized.length > 255) {
33
- throw new PathValidationError('Path component exceeds maximum length of 255 characters');
34
- }
35
- // Prevent hidden files (starting with .)
36
- if (sanitized.startsWith('.')) {
37
- throw new PathValidationError('Path component cannot start with a dot');
38
- }
39
- return sanitized;
40
- }
41
- /**
42
- * Validate that a target path is within the allowed base path
43
- * Prevents directory traversal attacks by ensuring the resolved path
44
- * doesn't escape the base directory
45
- *
46
- * @param basePath - Base directory path
47
- * @param targetPath - Target path to validate
48
- * @throws PathValidationError if path escapes base directory
49
- */
50
- export function validatePathWithinBase(basePath, targetPath) {
51
- const normalizedBase = resolve(basePath);
52
- const normalizedTarget = resolve(targetPath);
53
- const relativePath = relative(normalizedBase, normalizedTarget);
54
- // If relative path starts with '..', it's outside the base directory
55
- if (relativePath.startsWith('..') || resolve(normalizedBase, relativePath) !== normalizedTarget) {
56
- throw new PathValidationError('Path traversal detected: target path is outside base directory');
57
- }
58
- }
59
- /**
60
- * Safely join path components with validation
61
- * This is for joining SINGLE components (not full paths with slashes)
62
- *
63
- * @param basePath - Base directory path
64
- * @param components - Path components to join
65
- * @returns Validated full path
66
- * @throws PathValidationError if validation fails
67
- */
68
- export function safePathJoin(basePath, ...components) {
69
- // Sanitize each component
70
- const sanitizedComponents = components.map(sanitizePathComponent);
71
- // Join paths
72
- const fullPath = join(basePath, ...sanitizedComponents);
73
- // Validate the result doesn't escape base path
74
- validatePathWithinBase(basePath, fullPath);
75
- return fullPath;
76
- }
77
- /**
78
- * Safely join a key (which may contain slashes) with base path
79
- * Validates the result doesn't escape base directory
80
- *
81
- * @param basePath - Base directory path
82
- * @param key - Storage key (may contain path separators)
83
- * @returns Validated full path
84
- * @throws PathValidationError if validation fails
85
- */
86
- export function safeKeyPath(basePath, key) {
87
- if (!key || typeof key !== 'string') {
88
- throw new PathValidationError('Key must be a non-empty string');
89
- }
90
- // Check for path traversal patterns
91
- if (key.includes('..')) {
92
- throw new PathValidationError('Key contains path traversal sequence');
93
- }
94
- // Join and validate
95
- const fullPath = join(basePath, key);
96
- validatePathWithinBase(basePath, fullPath);
97
- return fullPath;
98
- }
99
- //# sourceMappingURL=path-validator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"path-validator.js","sourceRoot":"","sources":["../../src/utils/path-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,I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