@nxgt/shared-storage 1.0.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.
@@ -0,0 +1,46 @@
1
+ import type { CursorPaginationParams } from '@nxgt/shared/helpers';
2
+ import { type mongo, mongoose } from '@nxgt/shared-mongo';
3
+ export type GridFSBucketNames = 'avatars' | 'uploads' | 'images' | 'videos' | 'files' | string;
4
+ export interface IBucketOptions {
5
+ bucketName?: GridFSBucketNames;
6
+ bucket?: mongoose.mongo.GridFSBucket;
7
+ }
8
+ export declare class GridFSService {
9
+ uploads: mongoose.mongo.GridFSBucket;
10
+ avatars: mongoose.mongo.GridFSBucket;
11
+ images: mongoose.mongo.GridFSBucket;
12
+ videos: mongoose.mongo.GridFSBucket;
13
+ files: mongoose.mongo.GridFSBucket;
14
+ buckets: Record<GridFSBucketNames, mongoose.mongo.GridFSBucket>;
15
+ constructor();
16
+ paginate(filter?: mongoose.mongo.Filter<mongoose.mongo.GridFSFile>, options?: CursorPaginationParams & IBucketOptions): Promise<{
17
+ data: mongo.GridFSFile[];
18
+ metadata: {
19
+ startCursor: string | null | undefined;
20
+ endCursor: string | null | undefined;
21
+ hasNextPage: boolean;
22
+ totalElements: number;
23
+ };
24
+ }>;
25
+ findById(id: string, options?: IBucketOptions): Promise<mongoose.mongo.GridFSFile | null>;
26
+ find(filter?: mongoose.mongo.Filter<mongoose.mongo.GridFSFile>, options?: mongoose.mongo.FindOptions & IBucketOptions): Promise<mongo.GridFSFile[]>;
27
+ delete(id: string, options?: IBucketOptions): Promise<void>;
28
+ download(id: string, { user, ...options }?: IBucketOptions & {
29
+ user?: string;
30
+ }): Promise<mongo.GridFSBucketReadStream>;
31
+ rename(id: string, name: string, { user, ...options }?: IBucketOptions & {
32
+ user?: string;
33
+ }): Promise<mongo.GridFSFile>;
34
+ upload(file: File, options?: IBucketOptions & {
35
+ metadata?: object;
36
+ }): Promise<mongo.ObjectId>;
37
+ private bucket;
38
+ /**
39
+ * Determines the category for a given file MIME type.
40
+ * This is a private helper method.
41
+ * @param mimetype The MIME type of the file.
42
+ * @returns A string representing the file type category (e.g., 'images', 'documents', 'other').
43
+ */
44
+ private resolveFileTypeCategory;
45
+ }
46
+ //# sourceMappingURL=gridfs.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gridfs.service.d.ts","sourceRoot":"","sources":["../../src/services/gridfs.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEnE,OAAO,EAAE,KAAK,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAM1D,MAAM,MAAM,iBAAiB,GAC1B,SAAS,GACT,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,MAAM,CAAC;AAEV,MAAM,WAAW,cAAc;IAC9B,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,MAAM,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC;CACrC;AAED,qBAAa,aAAa;IACzB,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC;IACrC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC;IACrC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC;IACpC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC;IACpC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC;IAEnC,OAAO,EAAE,MAAM,CAAC,iBAAiB,EAAE,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;;IA+B1D,QAAQ,CACb,MAAM,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,EACzD,OAAO,CAAC,EAAE,sBAAsB,GAAG,cAAc;;;;;;;;;IAiF5C,QAAQ,CACb,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC;IAOtC,IAAI,CACT,MAAM,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,EACzD,OAAO,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,WAAW,GAAG,cAAc;IAOhD,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3D,QAAQ,CACb,EAAE,EAAE,MAAM,EACV,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,GAAE,cAAc,GAAG;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAO;IA0BxD,MAAM,CACX,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,GAAE,cAAc,GAAG;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAO,GAC3D,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC;IA8BtB,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE;IAmCzE,OAAO,CAAC,MAAM;IAed;;;;;OAKG;IACH,OAAO,CAAC,uBAAuB;CA+B/B"}
@@ -0,0 +1,5 @@
1
+ export * from './create-lazy-storage';
2
+ export * from './gridfs.service';
3
+ export * from './minio.service';
4
+ export * from './storage.service';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { Client, type ICopyDestinationOptions, type ICopySourceOptions, type ItemBucketMetadata, type RemoveOptions } from 'minio';
2
+ type PreSignRequestParams = Record<string, string>;
3
+ type PutObjectResult = Awaited<ReturnType<Client['putObject']>>;
4
+ type CopyObjectResult = Awaited<ReturnType<Client['copyObject']>>;
5
+ type ListObjectsResult = ReturnType<Client['listObjects']>;
6
+ import { type S3ClientWriteBody } from './storage.service';
7
+ export type MinioPutBody = Parameters<Client['putObject']>[2];
8
+ export type GetObjectOptions = Parameters<Client['getObject']>[2];
9
+ export type ListObjectQueryOptions = Parameters<Client['listObjects']>[3];
10
+ export declare class MinioService {
11
+ minio: Client;
12
+ private bucket;
13
+ private logger;
14
+ constructor(bucket?: string);
15
+ ensureBucketExists(bucket?: string): Promise<void>;
16
+ convert(body: S3ClientWriteBody): Promise<MinioPutBody>;
17
+ putObject(key: string, body: MinioPutBody, size?: number, metadata?: ItemBucketMetadata): Promise<PutObjectResult>;
18
+ getObject(key: string, options?: GetObjectOptions): Promise<import("node:stream").Readable>;
19
+ fPutObject(key: string, filePath: string, metadata?: ItemBucketMetadata): Promise<PutObjectResult>;
20
+ fGetObject(key: string, filePath: string, options?: GetObjectOptions): Promise<void>;
21
+ findUploadId(key: string): Promise<string | undefined>;
22
+ copyObject(source: Omit<ICopySourceOptions, 'Bucket'> & {
23
+ Bucket?: string;
24
+ }, destination: Omit<ICopyDestinationOptions, 'Bucket'> & {
25
+ Bucket?: string;
26
+ }): Promise<CopyObjectResult>;
27
+ deleteObject(key: string, options?: RemoveOptions): Promise<void>;
28
+ listObjects(prefix?: string, recursive?: boolean, options?: ListObjectQueryOptions): Promise<ListObjectsResult>;
29
+ listObjectsV2(prefix?: string, recursive?: boolean, startAfter?: string): Promise<import("minio").BucketStream<import("minio").BucketItem>>;
30
+ /**
31
+ * Presigned GET URL supporting response-header overrides (e.g.
32
+ * `response-content-disposition`) — Bun's native `S3Client.presign()`
33
+ * (used by `StorageService.presing()`) has no equivalent, so callers that
34
+ * need per-request Content-Disposition/Content-Type overrides (attachment
35
+ * vs inline downloads) must go through this instead.
36
+ */
37
+ presignedGetObject(key: string, expiresIn?: number, respHeaders?: PreSignRequestParams): Promise<string>;
38
+ presignedPutObject(key: string, expiresIn?: number): Promise<string>;
39
+ bucketExists(bucket?: string): Promise<boolean>;
40
+ makeBucket(bucket?: string): Promise<void>;
41
+ }
42
+ export {};
43
+ //# sourceMappingURL=minio.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"minio.service.d.ts","sourceRoot":"","sources":["../../src/services/minio.service.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,MAAM,EAGN,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,MAAM,OAAO,CAAC;AAIf,KAAK,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAQnD,KAAK,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;AAChE,KAAK,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;AAClE,KAAK,iBAAiB,GAAG,UAAU,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;AAE3D,OAAO,EAAkB,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE3E,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9D,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,MAAM,MAAM,sBAAsB,GAAG,UAAU,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAE1E,qBAAa,YAAY;IACxB,KAAK,EAAE,M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OAMG;IACG,kBAAkB,CACvB,GAAG,EAAE,MAAM,EACX,SAAS,SAAmB,EAC5B,WAAW,GAAE,oBAAyB;IAajC,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,SAAmB;IAO5D,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM;IAK5B,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM;CAIhC"}
@@ -0,0 +1,28 @@
1
+ import { S3Client, type S3FilePresignOptions, type S3ListObjectsOptions, type S3Options } from 'bun';
2
+ import { MinioService } from './minio.service';
3
+ export declare const S3_CREDENTIALS: {
4
+ endpoint: string;
5
+ bucket: string;
6
+ accessKeyId: string;
7
+ secretAccessKey: string;
8
+ };
9
+ export type S3ClientWriteBody = Parameters<S3Client['write']>[1];
10
+ export declare class StorageService {
11
+ s3: S3Client;
12
+ private bucket;
13
+ private logger;
14
+ minio: MinioService;
15
+ constructor(bucket?: string);
16
+ write(key: string, body: S3ClientWriteBody, options?: S3Options): Promise<number>;
17
+ list(input?: S3ListObjectsOptions, options?: S3Options): Promise<Bun.S3ListObjectsResponse>;
18
+ file(key: string, options?: S3Options): Bun.S3File;
19
+ exists(key: string, options?: S3Options): Promise<boolean>;
20
+ presing(key: string, options?: S3FilePresignOptions): string;
21
+ delete(key: string, options?: S3Options): Promise<void>;
22
+ size(key: string, options?: S3Options): Promise<number>;
23
+ stat(key: string, options?: S3Options): Promise<Bun.S3Stats>;
24
+ unlink(key: string, options?: S3Options): Promise<void>;
25
+ fetch(input: string, { bucket, ...options }?: BunFetchRequestInit & Pick<S3Options, 'bucket'>): Promise<Response>;
26
+ private ensureExists;
27
+ }
28
+ //# sourceMappingURL=storage.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.service.d.ts","sourceRoot":"","sources":["../../src/services/storage.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAEN,QAAQ,EACR,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,SAAS,EACd,MAAM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6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "README.md",
11
+ "package.json"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js",
17
+ "default": "./dist/index.js"
18
+ },
19
+ "./package.json": "./package.json"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/softistx/nxgt-core.git",
24
+ "directory": "packages/shared-storage"
25
+ },
26
+ "publishConfig": {
27
+ "registry": "https://registry.npmjs.org",
28
+ "access": "public"
29
+ },
30
+ "scripts": {
31
+ "build": "bun run ../../build.ts",
32
+ "typecheck": "tsc --noEmit"
33
+ },
34
+ "nxgt": {
35
+ "entrypoints": [
36
+ "src/index.ts"
37
+ ]
38
+ },
39
+ "dependencies": {
40
+ "@nxgt/i18n": "1.0.0",
41
+ "@nxgt/shared": "1.0.0",
42
+ "@nxgt/shared-exceptions": "1.0.0",
43
+ "@nxgt/shared-logging": "1.0.0",
44
+ "@nxgt/shared-mongo": "1.0.0",
45
+ "bson": "^7.3.2",
46
+ "lodash": "^4.18.1",
47
+ "minio": "^8.0.7",
48
+ "zod": "^4.4.3"
49
+ },
50
+ "devDependencies": {
51
+ "@types/bun": "^1.4.0",
52
+ "@types/lodash": "^4.17.25"
53
+ },
54
+ "peerDependencies": {
55
+ "typescript": "^6.0.3"
56
+ }
57
+ }