@ez4/storage 0.35.0 → 0.36.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 CHANGED
@@ -1,15 +1,113 @@
1
1
  # EZ4: Storage
2
2
 
3
- It uses the power of [reflection](../reflection/) to provide an API which determines how to build and connect storage components.
3
+ It uses the power of [reflection](../../foundation/reflection/) to provide a contract that determines how to build and connect storage components.
4
4
 
5
5
  ## Getting started
6
6
 
7
7
  #### Install
8
8
 
9
9
  ```sh
10
- npm install @ez4/storage -D
10
+ npm install @ez4/storage @ez4/local-storage @ez4/aws-bucket -D
11
11
  ```
12
12
 
13
+ #### Create storage
14
+
15
+ ```ts
16
+ // file: storage.ts
17
+ import type { Environment, Service } from '@ez4/common';
18
+ import type { Bucket } from '@ez4/storage';
19
+
20
+ // MyStorage declaration
21
+ export declare class MyStorage extends Bucket.Service {
22
+ autoExpireDays: 1;
23
+
24
+ events: Bucket.UseEvents<{
25
+ handler: typeof eventHandler;
26
+ }>;
27
+
28
+ variables: {
29
+ myVariable: Environment.Variable<'MY_VARIABLE'>;
30
+ };
31
+
32
+ services: {
33
+ otherService: Environment.Service<OtherService>;
34
+ variables: Environment.ServiceVariables;
35
+ };
36
+ }
37
+
38
+ // MyStorage event handler
39
+ export function eventHandler(request: Bucket.Event, context: Service.Context<MyStorage>): void {
40
+ const { otherService, variables } = context;
41
+
42
+ // Access event contents
43
+ request.eventType;
44
+
45
+ // Access injected services
46
+ otherService.call();
47
+
48
+ // Access injected variables
49
+ variables.myVariable;
50
+ }
51
+ ```
52
+
53
+ > Listening to bucket events is optional, so `events`, `services`, and `variables` can be omitted.
54
+
55
+ #### Use storage
56
+
57
+ ```ts
58
+ // file: handler.ts
59
+ import type { Service } from '@ez4/common';
60
+ import type { MyStorage } from './storage';
61
+
62
+ // Any other handler that has injected MyStorage service
63
+ export async function anyHandler(_request: any, context: Service.Context<DummyService>) {
64
+ const { myStorage } = context;
65
+
66
+ // Write a file
67
+ await myStorage.write('dummy.txt', 'Hello storage');
68
+
69
+ // Read a file
70
+ const content = myStorage.read('dummy.txt');
71
+ }
72
+ ```
73
+
74
+ ## Storage properties
75
+
76
+ #### Service
77
+
78
+ | Name | Type | Description |
79
+ | -------------- | ------------------ | ------------------------------------------------------------ |
80
+ | events | Bucket.UseEvents<> | Entry-point handler for bucket events. |
81
+ | cors | Bucket.UseCors<> | CORS configuration for the bucket. |
82
+ | globalName | string | Overwrite the global bucket name. |
83
+ | localPath | string | Specify a local path to synchronize with the storage. |
84
+ | autoExpireDays | integer | Amount of days an object is stored before its auto-deletion. |
85
+ | variables | object | Environment variables associated to the event handler. |
86
+ | services | object | Injected services associated to handler function. |
87
+
88
+ > Use type helpers for `events`, `cors` properties.
89
+
90
+ #### Events
91
+
92
+ | Name | Type | Description |
93
+ | ------------ | -------- | ---------------------------------------------------- |
94
+ | listener | function | Life-cycle listener function for the event. |
95
+ | handler | function | Entry-point handler function for the event. |
96
+ | path | string | Path associated to the event. |
97
+ | variables | object | Environment variables associated to handler. |
98
+ | logRetention | integer | Log retention (in days) for the handler. |
99
+ | timeout | integer | Maximum execution time (in seconds) for the handler. |
100
+ | memory | integer | Memory available (in megabytes) for the handler. |
101
+
102
+ ## Examples
103
+
104
+ - [Storage manager](../../examples/aws-storage-manager)
105
+
106
+ ## Providers
107
+
108
+ - [Local provider](../../providers/local/local-storage)
109
+ - [AWS provider](../../providers/aws/aws-bucket)
110
+
13
111
  ## License
14
112
 
15
113
  MIT License
@@ -5,11 +5,11 @@ import type { BucketEvent, BucketHandler, BucketListener } from './common';
5
5
  */
6
6
  export interface BucketEvents {
7
7
  /**
8
- * Event listener.
8
+ * Life-cycle listener function for the event.
9
9
  */
10
10
  readonly listener?: BucketListener<BucketEvent>;
11
11
  /**
12
- * Event handler.
12
+ * Entry-point handler function for the event.
13
13
  */
14
14
  readonly handler: BucketHandler<BucketEvent>;
15
15
  /**
@@ -29,7 +29,7 @@ export interface BucketEvents {
29
29
  */
30
30
  readonly timeout?: number;
31
31
  /**
32
- * Amount of memory available for the handler.
32
+ * Amount of memory available (in megabytes) for the handler.
33
33
  */
34
34
  readonly memory?: number;
35
35
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ez4/storage",
3
3
  "description": "EZ4: Components to build storage services",
4
- "version": "0.35.0",
4
+ "version": "0.36.0",
5
5
  "author": "Silas B.",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -46,9 +46,9 @@
46
46
  "live:publish": "npm run build && npm publish --access public"
47
47
  },
48
48
  "dependencies": {
49
- "@ez4/common": "^0.35.0",
50
- "@ez4/project": "^0.35.0",
51
- "@ez4/reflection": "^0.35.0",
52
- "@ez4/utils": "^0.35.0"
49
+ "@ez4/common": "^0.36.0",
50
+ "@ez4/project": "^0.36.0",
51
+ "@ez4/reflection": "^0.36.0",
52
+ "@ez4/utils": "^0.36.0"
53
53
  }
54
54
  }