@zs-soft/storage-engine 0.10.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.
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # StorageEngine
2
+
3
+ This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 21.0.0.
4
+
5
+ ## Code scaffolding
6
+
7
+ Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
8
+
9
+ ```bash
10
+ ng generate component component-name
11
+ ```
12
+
13
+ For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
14
+
15
+ ```bash
16
+ ng generate --help
17
+ ```
18
+
19
+ ## Building
20
+
21
+ To build the library, run:
22
+
23
+ ```bash
24
+ ng build storage-engine
25
+ ```
26
+
27
+ This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
28
+
29
+ ### Publishing the Library
30
+
31
+ Once the project is built, you can publish your library by following these steps:
32
+
33
+ 1. Navigate to the `dist` directory:
34
+
35
+ ```bash
36
+ cd dist/storage-engine
37
+ ```
38
+
39
+ 2. Run the `npm publish` command to publish your library to the npm registry:
40
+ ```bash
41
+ npm publish
42
+ ```
43
+
44
+ ## Running unit tests
45
+
46
+ To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
47
+
48
+ ```bash
49
+ ng test
50
+ ```
51
+
52
+ ## Running end-to-end tests
53
+
54
+ For end-to-end (e2e) testing, run:
55
+
56
+ ```bash
57
+ ng e2e
58
+ ```
59
+
60
+ Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
61
+
62
+ ## Additional Resources
63
+
64
+ For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
@@ -0,0 +1,71 @@
1
+ import * as i0 from '@angular/core';
2
+ import { inject, Injectable } from '@angular/core';
3
+ import { StorageEngine } from '@zs-soft/core-api';
4
+
5
+ class Storage {
6
+ engine = inject(StorageEngine);
7
+ upload(path, file, options) {
8
+ return this.engine.upload(path, file, options);
9
+ }
10
+ download(path) {
11
+ return this.engine.download(path);
12
+ }
13
+ getDownloadUrl(path) {
14
+ return this.engine.getDownloadUrl(path);
15
+ }
16
+ getMetadata(path) {
17
+ return this.engine.getMetadata(path);
18
+ }
19
+ list(path, options) {
20
+ return this.engine.list(path, options);
21
+ }
22
+ delete(path, options) {
23
+ return this.engine.delete(path, options);
24
+ }
25
+ exists(path) {
26
+ return this.engine.exists(path);
27
+ }
28
+ copy(sourcePath, destinationPath) {
29
+ return this.engine.copy(sourcePath, destinationPath);
30
+ }
31
+ move(sourcePath, destinationPath) {
32
+ return this.engine.move(sourcePath, destinationPath);
33
+ }
34
+ /**
35
+ * Generate a safe file path with timestamp and random suffix
36
+ */
37
+ generatePath(folder, fileName) {
38
+ const timestamp = Date.now();
39
+ const randomSuffix = Math.random().toString(36).substring(2, 8);
40
+ const sanitizedName = fileName.replace(/[^a-zA-Z0-9.-]/g, '_');
41
+ return `${folder}/${timestamp}_${randomSuffix}_${sanitizedName}`;
42
+ }
43
+ /**
44
+ * Validate file before upload
45
+ */
46
+ validateFile(file, allowedTypes, maxSizeBytes) {
47
+ if (allowedTypes && !allowedTypes.includes(file.type)) {
48
+ throw new Error(`File type ${file.type} not allowed. Allowed: ${allowedTypes.join(', ')}`);
49
+ }
50
+ if (maxSizeBytes && file.size > maxSizeBytes) {
51
+ throw new Error(`File size ${file.size} exceeds maximum ${maxSizeBytes} bytes`);
52
+ }
53
+ return true;
54
+ }
55
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: Storage, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
56
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: Storage });
57
+ }
58
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: Storage, decorators: [{
59
+ type: Injectable
60
+ }] });
61
+
62
+ /*
63
+ * Public API Surface of storage-engine
64
+ */
65
+
66
+ /**
67
+ * Generated bundle index. Do not edit.
68
+ */
69
+
70
+ export { Storage };
71
+ //# sourceMappingURL=zs-soft-storage-engine.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zs-soft-storage-engine.mjs","sources":["../../../projects/storage-engine/src/lib/storage.ts","../../../projects/storage-engine/src/public-api.ts","../../../projects/storage-engine/src/zs-soft-storage-engine.ts"],"sourcesContent":["import { Observable } from 'rxjs';\n\nimport { inject, Injectable } from '@angular/core';\nimport {\n StorageDeleteOptions,\n StorageEngine,\n StorageFile,\n StorageListOptions,\n StorageListResult,\n StorageUploadOptions,\n} from '@zs-soft/core-api';\n\n@Injectable()\nexport class Storage {\n private readonly engine = inject<StorageEngine>(StorageEngine);\n\n upload(path: string, file: File | Blob, options?: StorageUploadOptions): Observable<StorageFile> {\n return this.engine.upload(path, file, options);\n }\n\n download(path: string): Observable<Blob> {\n return this.engine.download(path);\n }\n\n getDownloadUrl(path: string): Observable<string> {\n return this.engine.getDownloadUrl(path);\n }\n\n getMetadata(path: string): Observable<StorageFile> {\n return this.engine.getMetadata(path);\n }\n\n list(path: string, options?: StorageListOptions): Observable<StorageListResult> {\n return this.engine.list(path, options);\n }\n\n delete(path: string, options?: StorageDeleteOptions): Observable<void> {\n return this.engine.delete(path, options);\n }\n\n exists(path: string): Observable<boolean> {\n return this.engine.exists(path);\n }\n\n copy(sourcePath: string, destinationPath: string): Observable<StorageFile> {\n return this.engine.copy(sourcePath, destinationPath);\n }\n\n move(sourcePath: string, destinationPath: string): Observable<StorageFile> {\n return this.engine.move(sourcePath, destinationPath);\n }\n\n /**\n * Generate a safe file path with timestamp and random suffix\n */\n generatePath(folder: string, fileName: string): string {\n const timestamp = Date.now();\n const randomSuffix = Math.random().toString(36).substring(2, 8);\n const sanitizedName = fileName.replace(/[^a-zA-Z0-9.-]/g, '_');\n return `${folder}/${timestamp}_${randomSuffix}_${sanitizedName}`;\n }\n\n /**\n * Validate file before upload\n */\n validateFile(file: File, allowedTypes?: string[], maxSizeBytes?: number): boolean {\n if (allowedTypes && !allowedTypes.includes(file.type)) {\n throw new Error(`File type ${file.type} not allowed. Allowed: ${allowedTypes.join(', ')}`);\n }\n\n if (maxSizeBytes && file.size > maxSizeBytes) {\n throw new Error(`File size ${file.size} exceeds maximum ${maxSizeBytes} bytes`);\n }\n\n return true;\n }\n}\n","/*\n * Public API Surface of storage-engine\n */\n\nexport * from './lib/storage';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;MAaa,OAAO,CAAA;AACD,IAAA,MAAM,GAAG,MAAM,CAAgB,aAAa,CAAC;AAE9D,IAAA,MAAM,CAAC,IAAY,EAAE,IAAiB,EAAE,OAA8B,EAAA;AACpE,QAAA,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC;IAChD;AAEA,IAAA,QAAQ,CAAC,IAAY,EAAA;QACnB,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;IACnC;AAEA,IAAA,cAAc,CAAC,IAAY,EAAA;QACzB,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC;IACzC;AAEA,IAAA,WAAW,CAAC,IAAY,EAAA;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC;IACtC;IAEA,IAAI,CAAC,IAAY,EAAE,OAA4B,EAAA;QAC7C,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC;IACxC;IAEA,MAAM,CAAC,IAAY,EAAE,OAA8B,EAAA;QACjD,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC;IAC1C;AAEA,IAAA,MAAM,CAAC,IAAY,EAAA;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,I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,OAAO,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;2GAAP,OAAO,EAAA,CAAA;;2FAAP,OAAO,EAAA,UAAA,EAAA,CAAA;kBADnB;;;ACZD;;AAEG;;ACFH;;AAEG;;;;"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@zs-soft/storage-engine",
3
+ "version": "0.10.0",
4
+ "description": "Abstract storage service for Angular applications",
5
+ "author": "zssz-soft",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/zssz-soft/libraries.git",
10
+ "directory": "projects/storage-engine"
11
+ },
12
+ "homepage": "https://github.com/zssz-soft/libraries/tree/main/projects/storage-engine",
13
+ "bugs": {
14
+ "url": "https://github.com/zssz-soft/libraries/issues"
15
+ },
16
+ "keywords": [
17
+ "angular",
18
+ "storage"
19
+ ],
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "peerDependencies": {
24
+ "@angular/common": "^21.2.0",
25
+ "@angular/core": "^21.2.0",
26
+ "@zs-soft/core-api": "^0.10.0",
27
+ "rxjs": "^7.0.0"
28
+ },
29
+ "dependencies": {
30
+ "tslib": "^2.3.0"
31
+ },
32
+ "sideEffects": false,
33
+ "tags": [
34
+ "type:engine",
35
+ "scope:shared"
36
+ ],
37
+ "module": "fesm2022/zs-soft-storage-engine.mjs",
38
+ "typings": "types/zs-soft-storage-engine.d.ts",
39
+ "exports": {
40
+ "./package.json": {
41
+ "default": "./package.json"
42
+ },
43
+ ".": {
44
+ "types": "./types/zs-soft-storage-engine.d.ts",
45
+ "default": "./fesm2022/zs-soft-storage-engine.mjs"
46
+ }
47
+ }
48
+ }
@@ -0,0 +1,28 @@
1
+ import { Observable } from 'rxjs';
2
+ import { StorageUploadOptions, StorageFile, StorageListOptions, StorageListResult, StorageDeleteOptions } from '@zs-soft/core-api';
3
+ import * as i0 from '@angular/core';
4
+
5
+ declare class Storage {
6
+ private readonly engine;
7
+ upload(path: string, file: File | Blob, options?: StorageUploadOptions): Observable<StorageFile>;
8
+ download(path: string): Observable<Blob>;
9
+ getDownloadUrl(path: string): Observable<string>;
10
+ getMetadata(path: string): Observable<StorageFile>;
11
+ list(path: string, options?: StorageListOptions): Observable<StorageListResult>;
12
+ delete(path: string, options?: StorageDeleteOptions): Observable<void>;
13
+ exists(path: string): Observable<boolean>;
14
+ copy(sourcePath: string, destinationPath: string): Observable<StorageFile>;
15
+ move(sourcePath: string, destinationPath: string): Observable<StorageFile>;
16
+ /**
17
+ * Generate a safe file path with timestamp and random suffix
18
+ */
19
+ generatePath(folder: string, fileName: string): string;
20
+ /**
21
+ * Validate file before upload
22
+ */
23
+ validateFile(file: File, allowedTypes?: string[], maxSizeBytes?: number): boolean;
24
+ static ɵfac: i0.ɵɵFactoryDeclaration<Storage, never>;
25
+ static ɵprov: i0.ɵɵInjectableDeclaration<Storage>;
26
+ }
27
+
28
+ export { Storage };