@ez4/storage 0.35.0 → 0.37.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 +100 -2
- package/dist/errors/handler.d.ts +1 -1
- package/dist/library.cjs +53 -54
- package/dist/library.mjs +51 -51
- package/dist/metadata/cors.d.ts +2 -2
- package/dist/metadata/event.d.ts +2 -2
- package/dist/metadata/handler.d.ts +2 -3
- package/dist/metadata/service.d.ts +2 -2
- package/dist/services/events.d.ts +3 -3
- package/dist/types/common.d.ts +2 -7
- package/dist/types/service.d.ts +13 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,15 +1,113 @@
|
|
|
1
1
|
# EZ4: Storage
|
|
2
2
|
|
|
3
|
-
It uses the power of [reflection](
|
|
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
|
package/dist/errors/handler.d.ts
CHANGED
package/dist/library.cjs
CHANGED
|
@@ -1,62 +1,61 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
typeof r=="object"||typeof r=="function")for(let n of
|
|
3
|
-
|
|
4
|
-
IncorrectCorsTypeError:()=>
|
|
5
|
-
InvalidEventTypeError:()=>T,ServiceType:()=>
|
|
6
|
-
|
|
7
|
-
module.exports=
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
e=>(0,u.hasHeritageType)(e,"Bucket.
|
|
1
|
+
"use strict";var B=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var o=(e,r)=>B(e,"name",{value:r,configurable:!0});var $=(e,r)=>{for(var t in r)B(e,t,{get:r[t],enumerable:!0})},ee=(e,r,t,i)=>{if(r&&
|
|
2
|
+
typeof r=="object"||typeof r=="function")for(let n of Z(r))!_.call(e,n)&&n!==t&&
|
|
3
|
+
B(e,n,{get:()=>r[n],enumerable:!(i=Y(r,n))||i.enumerable});return e};var re=e=>ee(B({},"__esModule",{value:!0}),e);var pe={};$(pe,{IncompleteCorsError:()=>x,IncompleteEventError:()=>k,IncompleteServiceError:()=>g,
|
|
4
|
+
IncorrectCorsTypeError:()=>E,IncorrectEventTypeError:()=>b,InvalidCorsTypeError:()=>S,
|
|
5
|
+
InvalidEventTypeError:()=>T,ServiceType:()=>I,createBucketService:()=>w,getBucketCors:()=>R,
|
|
6
|
+
getBucketEvent:()=>O,getBucketServices:()=>z,getEventHandler:()=>P,isBucketService:()=>te,
|
|
7
|
+
registerTriggers:()=>ce});module.exports=re(pe);var U=require("@ez4/common/library"),X=require("@ez4/project/library");var a=require("@ez4/common/library"),K=require("@ez4/reflection"),L=require("@ez4/utils");var A=require("@ez4/project/library");var I="@ez4/bucket",te=o(e=>e.type===I,"isBucketService"),w=o(e=>({...(0,A.createServiceMetadata)(
|
|
8
|
+
I,e),variables:{},services:{}}),"createBucketService");var j=require("@ez4/common/library");var g=class extends j.IncompleteTypeError{static{o(this,"IncompleteServiceError")}constructor(r,t){
|
|
9
|
+
super("Incomplete bucket service",r,t)}};var u=require("@ez4/common/library"),M=require("@ez4/reflection");var h=o(e=>(0,u.isClassDeclaration)(e)&&(0,u.hasHeritageType)(e,"Bucket.Service"),
|
|
10
|
+
"isBucketService"),D=o(e=>(0,M.isTypeCallback)(e)||(0,M.isTypeFunction)(e),"isEv\
|
|
11
|
+
entHandler"),H=o(e=>(0,u.hasHeritageType)(e,"Bucket.Event"),"isBucketEvent"),F=o(
|
|
12
|
+
e=>(0,u.hasHeritageType)(e,"Bucket.Cors"),"isBucketCors");var c=require("@ez4/common/library"),d=require("@ez4/reflection");var f=require("@ez4/common/library");var k=class extends f.IncompleteTypeError{static{o(this,"IncompleteEventError")}constructor(r,t){
|
|
12
13
|
super("Incomplete bucket event",r,t)}},T=class extends f.InvalidTypeError{static{
|
|
13
14
|
o(this,"InvalidEventTypeError")}constructor(r){super("Invalid bucket event type",
|
|
14
15
|
void 0,"Bucket.Event",r)}},b=class extends f.IncorrectTypeError{constructor(t,i){
|
|
15
16
|
super("Incorrect bucket event type",t,"Bucket.Event",i);this.eventType=t}static{
|
|
16
|
-
o(this,"IncorrectEventTypeError")}};var
|
|
17
|
-
super("Incomplete event handler",r
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
t,i)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
c))return c;n.push(new k([...p],e.file))},"getTypeFromMembers");var a=require("@ez4/common/library"),v=require("@ez4/reflection");var y=require("@ez4/common/library");var S=class extends y.IncompleteTypeError{static{o(this,"IncompleteCorsError")}constructor(r,t){
|
|
32
|
-
super("Incomplete bucket CORS",r,t)}},x=class extends y.InvalidTypeError{static{
|
|
17
|
+
o(this,"IncorrectEventTypeError")}};var V=require("@ez4/common/library");var N=require("@ez4/common/library");var C=class extends N.IncompleteTypeError{static{o(this,"IncompleteHandlerError")}constructor(r){
|
|
18
|
+
super("Incomplete event handler",[],r)}};var P=o((e,r)=>{if(!D(e))return;let t=(0,V.getFunctionSignature)(e);return t||r.
|
|
19
|
+
push(new C(e.file)),t},"getEventHandler");var O=o((e,r,t,i)=>{if(!(0,d.isTypeReference)(e))return q(e,r,i);let n=(0,c.getReferenceType)(
|
|
20
|
+
e,t);if(n)return q(n,r,i)},"getBucketEvent"),oe=o(e=>!!e.handler,"isValidEvent"),
|
|
21
|
+
q=o((e,r,t)=>{if((0,d.isTypeObject)(e))return W(e,r,(0,c.getObjectMembers)(e),t);
|
|
22
|
+
if(!(0,c.isModelDeclaration)(e)){t.push(new T(r.file));return}if(!H(e)){t.push(new b(
|
|
23
|
+
e.name,e.file));return}return W(e,r,(0,c.getModelMembers)(e),t)},"getTypeEvent"),
|
|
24
|
+
W=o((e,r,t,i)=>{let n={},m=new Set(["handler"]);for(let s of t)if(!(!(0,d.isModelProperty)(
|
|
25
|
+
s)||s.inherited))switch(s.name){default:i.push(new c.InvalidServicePropertyError(
|
|
26
|
+
r.name,s.name,e.file));break;case"path":n.path=(0,c.getPropertyString)(s);break;case"\
|
|
27
|
+
listener":n.listener=(0,c.getServiceListener)(s.value,i);break;case"handler":n.handler=
|
|
28
|
+
P(s.value,i);break;case"memory":case"logRetention":case"timeout":n[s.name]=(0,c.getPropertyNumber)(
|
|
29
|
+
s);break;case"variables":n.variables=(0,c.getLinkedVariableList)(s,i);break}if(oe(
|
|
30
|
+
n))return n;i.push(new k([...m],e.file))},"getTypeFromMembers");var p=require("@ez4/common/library"),v=require("@ez4/reflection");var y=require("@ez4/common/library");var x=class extends y.IncompleteTypeError{static{o(this,"IncompleteCorsError")}constructor(r,t){
|
|
31
|
+
super("Incomplete bucket CORS",r,t)}},S=class extends y.InvalidTypeError{static{
|
|
33
32
|
o(this,"InvalidCorsTypeError")}constructor(r){super("Invalid bucket CORS type",void 0,
|
|
34
|
-
"Bucket.Cors",r)}},
|
|
33
|
+
"Bucket.Cors",r)}},E=class extends y.IncorrectTypeError{constructor(t,i){super("\
|
|
35
34
|
Incorrect bucket CORS type",t,"Bucket.Cors",i);this.fallbackType=t}static{o(this,
|
|
36
|
-
"IncorrectCorsTypeError")}};var
|
|
37
|
-
e,t);if(n)return
|
|
38
|
-
ValidCors"),
|
|
39
|
-
e),t);if(!(0,
|
|
40
|
-
push(new
|
|
41
|
-
TypeCors"),
|
|
42
|
-
|
|
43
|
-
r.name,
|
|
44
|
-
ders":case"exposeHeaders":n[
|
|
45
|
-
|
|
46
|
-
e=>{let r=(0,
|
|
47
|
-
i);n&&t.push(n)}return t},"getStringValues");var
|
|
48
|
-
n))continue;let
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
name]=(0,
|
|
52
|
-
|
|
53
|
-
n,e,t);break;case"variables":
|
|
54
|
-
services":
|
|
55
|
-
[],
|
|
56
|
-
r[n.name]=
|
|
57
|
-
|
|
58
|
-
tadata:getServices":
|
|
35
|
+
"IncorrectCorsTypeError")}};var R=o((e,r,t,i)=>{if(!(0,v.isTypeReference)(e))return G(e,r,i);let n=(0,p.getReferenceType)(
|
|
36
|
+
e,t);if(n)return G(n,r,i)},"getBucketCors"),ne=o(e=>!!e.allowOrigins?.length,"is\
|
|
37
|
+
ValidCors"),G=o((e,r,t)=>{if((0,v.isTypeObject)(e))return J(e,r,(0,p.getObjectMembers)(
|
|
38
|
+
e),t);if(!(0,p.isModelDeclaration)(e)){t.push(new S(r.file));return}if(!F(e)){t.
|
|
39
|
+
push(new E(e.name,e.file));return}return J(e,r,(0,p.getModelMembers)(e),t)},"get\
|
|
40
|
+
TypeCors"),J=o((e,r,t,i)=>{let n={},m=new Set(["allowOrigins"]);for(let s of t)if(!(!(0,v.isModelProperty)(
|
|
41
|
+
s)||s.inherited))switch(s.name){default:i.push(new p.InvalidServicePropertyError(
|
|
42
|
+
r.name,s.name,e.file));break;case"allowOrigins":case"allowMethods":case"allowHea\
|
|
43
|
+
ders":case"exposeHeaders":n[s.name]=ie(s);break;case"maxAge":n.maxAge=(0,p.getPropertyNumber)(
|
|
44
|
+
s);break}if(ne(n))return n;i.push(new x([...m],e.file))},"getTypeFromMembers"),ie=o(
|
|
45
|
+
e=>{let r=(0,p.getPropertyTuple)(e)??[],t=[];for(let i of r){let n=(0,p.getLiteralString)(
|
|
46
|
+
i);n&&t.push(n)}return t},"getStringValues");var z=o(e=>{let r={},t=[];for(let i in e){let n=e[i];if(!h(n)||(0,a.isExternalDeclaration)(
|
|
47
|
+
n))continue;let m=w(n.name),s=n.file;for(let l of(0,a.getModelMembers)(n))if(!(!(0,K.isModelProperty)(
|
|
48
|
+
l)||l.inherited))switch(l.name){default:t.push(new a.InvalidServicePropertyError(
|
|
49
|
+
m.name,l.name,s));break;case"client":break;case"localPath":case"globalName":m[l.
|
|
50
|
+
name]=(0,a.getPropertyString)(l);break;case"autoExpireDays":m.autoExpireDays=(0,a.getPropertyNumber)(
|
|
51
|
+
l);break;case"events":m.events=O(l.value,n,e,t);break;case"cors":m.cors=R(l.value,
|
|
52
|
+
n,e,t);break;case"variables":m.variables=(0,a.getLinkedVariableList)(l,t);break;case"\
|
|
53
|
+
services":m.services=(0,a.getLinkedServiceList)(l,e,t);break}if(!se(m)){t.push(new g(
|
|
54
|
+
[],s));continue}if(r[n.name]){t.push(new a.DuplicateServiceError(n.name,s));continue}
|
|
55
|
+
r[n.name]=m}return{services:r,errors:t}},"getBucketServices"),se=o(e=>(0,L.isObjectWith)(
|
|
56
|
+
e,["variables","services"]),"isCompleteService");var Q=o(e=>h(e)?e.name:null,"getLinkedService");var ce=o(()=>{(0,U.registerTriggers)(),(0,X.tryCreateTrigger)("@ez4/bucket",{"me\
|
|
57
|
+
tadata:getServices":z,"metadata:getLinkedService":Q})},"registerTriggers");0&&(module.exports={IncompleteCorsError,IncompleteEventError,IncompleteServiceError,
|
|
59
58
|
IncorrectCorsTypeError,IncorrectEventTypeError,InvalidCorsTypeError,InvalidEventTypeError,
|
|
60
|
-
ServiceType,getBucketCors,getBucketEvent,getBucketServices,getEventHandler,
|
|
61
|
-
registerTriggers});
|
|
59
|
+
ServiceType,createBucketService,getBucketCors,getBucketEvent,getBucketServices,getEventHandler,
|
|
60
|
+
isBucketService,registerTriggers});
|
|
62
61
|
//# sourceMappingURL=library.cjs.map
|
package/dist/library.mjs
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
var
|
|
2
|
-
getLinkedVariableList as
|
|
3
|
-
getPropertyString as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
var z=Object.defineProperty;var o=(e,t)=>z(e,"name",{value:t,configurable:!0});import{registerTriggers as Pe}from"@ez4/common/library";import{tryCreateTrigger as Oe}from"@ez4/project/library";import{DuplicateServiceError as Te,InvalidServicePropertyError as be,isExternalDeclaration as xe,
|
|
2
|
+
getLinkedVariableList as Se,getLinkedServiceList as Ee,getModelMembers as Be,getPropertyNumber as Me,
|
|
3
|
+
getPropertyString as he}from"@ez4/common/library";import{isModelProperty as Ce}from"@ez4/reflection";
|
|
4
|
+
import{isObjectWith as Ie}from"@ez4/utils";import{createServiceMetadata as A}from"@ez4/project/library";var T="@ez4/bucket",Ae=o(e=>e.type===T,"isBucketService"),b=o(e=>({...A(T,e),variables:{},
|
|
5
|
+
services:{}}),"createBucketService");import{IncompleteTypeError as j}from"@ez4/common/library";var a=class extends j{static{o(this,"IncompleteServiceError")}constructor(t,r){super(
|
|
6
|
+
"Incomplete bucket service",t,r)}};import{hasHeritageType as k,isClassDeclaration as D}from"@ez4/common/library";import{
|
|
7
|
+
isTypeCallback as H,isTypeFunction as F}from"@ez4/reflection";var m=o(e=>D(e)&&k(e,"Bucket.Service"),"isBucketService"),x=o(e=>H(e)||F(e),"isE\
|
|
8
|
+
ventHandler"),S=o(e=>k(e,"Bucket.Event"),"isBucketEvent"),E=o(e=>k(e,"Bucket.Cor\
|
|
9
|
+
s"),"isBucketCors");import{InvalidServicePropertyError as J,isModelDeclaration as K,getLinkedVariableList as L,
|
|
10
|
+
getModelMembers as Q,getObjectMembers as U,getPropertyNumber as X,getPropertyString as Y,
|
|
11
|
+
getServiceListener as Z,getReferenceType as _}from"@ez4/common/library";import{isModelProperty as $,
|
|
12
|
+
isTypeObject as ee,isTypeReference as re}from"@ez4/reflection";import{IncompleteTypeError as N,IncorrectTypeError as V,InvalidTypeError as q}from"@ez4/common/library";var l=class extends N{static{o(this,"IncompleteEventError")}constructor(t,r){super(
|
|
13
|
+
"Incomplete bucket event",t,r)}},u=class extends q{static{o(this,"InvalidEventTy\
|
|
12
14
|
peError")}constructor(t){super("Invalid bucket event type",void 0,"Bucket.Event",
|
|
13
15
|
t)}},f=class extends V{constructor(r,i){super("Incorrect bucket event type",r,"B\
|
|
14
|
-
ucket.Event",i);this.eventType=r}static{o(this,"IncorrectEventTypeError")}};import{IncompleteTypeError as
|
|
15
|
-
"Incomplete event handler",t
|
|
16
|
-
|
|
17
|
-
(
|
|
18
|
-
e
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
getReferenceType as le}from"@ez4/common/library";import{isModelProperty as ue,isTypeObject as fe,
|
|
30
|
-
isTypeReference as de}from"@ez4/reflection";import{IncompleteTypeError as re,IncorrectTypeError as te,InvalidTypeError as oe}from"@ez4/common/library";var y=class extends re{static{o(this,"IncompleteCorsError")}constructor(t,r){super(
|
|
31
|
-
"Incomplete bucket CORS",t,r)}},v=class extends oe{static{o(this,"InvalidCorsTyp\
|
|
16
|
+
ucket.Event",i);this.eventType=r}static{o(this,"IncorrectEventTypeError")}};import{getFunctionSignature as G}from"@ez4/common/library";import{IncompleteTypeError as W}from"@ez4/common/library";var d=class extends W{static{o(this,"IncompleteHandlerError")}constructor(t){super(
|
|
17
|
+
"Incomplete event handler",[],t)}};var B=o((e,t)=>{if(!x(e))return;let r=G(e);return r||t.push(new d(e.file)),r},"g\
|
|
18
|
+
etEventHandler");var C=o((e,t,r,i)=>{if(!re(e))return M(e,t,i);let n=_(e,r);if(n)return M(n,t,i)},
|
|
19
|
+
"getBucketEvent"),te=o(e=>!!e.handler,"isValidEvent"),M=o((e,t,r)=>{if(ee(e))return h(
|
|
20
|
+
e,t,U(e),r);if(!K(e)){r.push(new u(t.file));return}if(!S(e)){r.push(new f(e.name,
|
|
21
|
+
e.file));return}return h(e,t,Q(e),r)},"getTypeEvent"),h=o((e,t,r,i)=>{let n={},c=new Set(
|
|
22
|
+
["handler"]);for(let s of r)if(!(!$(s)||s.inherited))switch(s.name){default:i.push(
|
|
23
|
+
new J(t.name,s.name,e.file));break;case"path":n.path=Y(s);break;case"listener":n.
|
|
24
|
+
listener=Z(s.value,i);break;case"handler":n.handler=B(s.value,i);break;case"memo\
|
|
25
|
+
ry":case"logRetention":case"timeout":n[s.name]=X(s);break;case"variables":n.variables=
|
|
26
|
+
L(s,i);break}if(te(n))return n;i.push(new l([...c],e.file))},"getTypeFromMembers");import{InvalidServicePropertyError as se,isModelDeclaration as ce,getLiteralString as pe,
|
|
27
|
+
getModelMembers as ae,getObjectMembers as me,getPropertyNumber as le,getPropertyTuple as ue,
|
|
28
|
+
getReferenceType as fe}from"@ez4/common/library";import{isModelProperty as de,isTypeObject as ye,
|
|
29
|
+
isTypeReference as ve}from"@ez4/reflection";import{IncompleteTypeError as oe,IncorrectTypeError as ne,InvalidTypeError as ie}from"@ez4/common/library";var y=class extends oe{static{o(this,"IncompleteCorsError")}constructor(t,r){super(
|
|
30
|
+
"Incomplete bucket CORS",t,r)}},v=class extends ie{static{o(this,"InvalidCorsTyp\
|
|
32
31
|
eError")}constructor(t){super("Invalid bucket CORS type",void 0,"Bucket.Cors",t)}},
|
|
33
|
-
g=class extends
|
|
34
|
-
.Cors",i);this.fallbackType=r}static{o(this,"IncorrectCorsTypeError")}};var
|
|
35
|
-
"getBucketCors"),
|
|
36
|
-
e))return
|
|
37
|
-
new g(e.name,e.file));return}return
|
|
38
|
-
let n={},c=new Set(["allowOrigins"]);for(let
|
|
39
|
-
name){default:i.push(new
|
|
40
|
-
allowMethods":case"allowHeaders":case"exposeHeaders":n[
|
|
41
|
-
maxAge":n.maxAge=
|
|
42
|
-
tTypeFromMembers"),
|
|
43
|
-
r.push(n)}return r},"getStringValues");var
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
dService":
|
|
32
|
+
g=class extends ne{constructor(r,i){super("Incorrect bucket CORS type",r,"Bucket\
|
|
33
|
+
.Cors",i);this.fallbackType=r}static{o(this,"IncorrectCorsTypeError")}};var P=o((e,t,r,i)=>{if(!ve(e))return I(e,t,i);let n=fe(e,r);if(n)return I(n,t,i)},
|
|
34
|
+
"getBucketCors"),ge=o(e=>!!e.allowOrigins?.length,"isValidCors"),I=o((e,t,r)=>{if(ye(
|
|
35
|
+
e))return w(e,t,me(e),r);if(!ce(e)){r.push(new v(t.file));return}if(!E(e)){r.push(
|
|
36
|
+
new g(e.name,e.file));return}return w(e,t,ae(e),r)},"getTypeCors"),w=o((e,t,r,i)=>{
|
|
37
|
+
let n={},c=new Set(["allowOrigins"]);for(let s of r)if(!(!de(s)||s.inherited))switch(s.
|
|
38
|
+
name){default:i.push(new se(t.name,s.name,e.file));break;case"allowOrigins":case"\
|
|
39
|
+
allowMethods":case"allowHeaders":case"exposeHeaders":n[s.name]=ke(s);break;case"\
|
|
40
|
+
maxAge":n.maxAge=le(s);break}if(ge(n))return n;i.push(new y([...c],e.file))},"ge\
|
|
41
|
+
tTypeFromMembers"),ke=o(e=>{let t=ue(e)??[],r=[];for(let i of t){let n=pe(i);n&&
|
|
42
|
+
r.push(n)}return r},"getStringValues");var O=o(e=>{let t={},r=[];for(let i in e){let n=e[i];if(!m(n)||xe(n))continue;let c=b(
|
|
43
|
+
n.name),s=n.file;for(let p of Be(n))if(!(!Ce(p)||p.inherited))switch(p.name){default:
|
|
44
|
+
r.push(new be(c.name,p.name,s));break;case"client":break;case"localPath":case"gl\
|
|
45
|
+
obalName":c[p.name]=he(p);break;case"autoExpireDays":c.autoExpireDays=Me(p);break;case"\
|
|
46
|
+
events":c.events=C(p.value,n,e,r);break;case"cors":c.cors=P(p.value,n,e,r);break;case"\
|
|
47
|
+
variables":c.variables=Se(p,r);break;case"services":c.services=Ee(p,e,r);break}if(!we(
|
|
48
|
+
c)){r.push(new a([],s));continue}if(t[n.name]){r.push(new Te(n.name,s));continue}
|
|
49
|
+
t[n.name]=c}return{services:t,errors:r}},"getBucketServices"),we=o(e=>Ie(e,["var\
|
|
50
|
+
iables","services"]),"isCompleteService");var R=o(e=>m(e)?e.name:null,"getLinkedService");var Ar=o(()=>{Pe(),Oe("@ez4/bucket",{"metadata:getServices":O,"metadata:getLinke\
|
|
51
|
+
dService":R})},"registerTriggers");export{y as IncompleteCorsError,l as IncompleteEventError,a as IncompleteServiceError,
|
|
53
52
|
g as IncorrectCorsTypeError,f as IncorrectEventTypeError,v as InvalidCorsTypeError,
|
|
54
|
-
u as InvalidEventTypeError,
|
|
55
|
-
|
|
53
|
+
u as InvalidEventTypeError,T as ServiceType,b as createBucketService,P as getBucketCors,
|
|
54
|
+
C as getBucketEvent,O as getBucketServices,B as getEventHandler,Ae as isBucketService,
|
|
55
|
+
Ar as registerTriggers};
|
|
56
56
|
//# sourceMappingURL=library.mjs.map
|
package/dist/metadata/cors.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { AllType,
|
|
1
|
+
import type { AllType, ReflectionTypes, TypeModel } from '@ez4/reflection';
|
|
2
2
|
import type { BucketCors } from '../types/common';
|
|
3
|
-
export declare const getBucketCors: (type: AllType, parent: TypeModel, reflection:
|
|
3
|
+
export declare const getBucketCors: (type: AllType, parent: TypeModel, reflection: ReflectionTypes, errorList: Error[]) => BucketCors | undefined;
|
package/dist/metadata/event.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { AllType,
|
|
1
|
+
import type { AllType, ReflectionTypes, TypeModel } from '@ez4/reflection';
|
|
2
2
|
import type { BucketEvent } from '../types/common';
|
|
3
|
-
export declare const getBucketEvent: (type: AllType, parent: TypeModel, reflection:
|
|
3
|
+
export declare const getBucketEvent: (type: AllType, parent: TypeModel, reflection: ReflectionTypes, errorList: Error[]) => BucketEvent | undefined;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { AllType
|
|
2
|
-
|
|
3
|
-
export declare const getEventHandler: (type: AllType, _reflection: SourceMap, errorList: Error[]) => EventHandler | undefined;
|
|
1
|
+
import type { AllType } from '@ez4/reflection';
|
|
2
|
+
export declare const getEventHandler: (type: AllType, errorList: Error[]) => import("@ez4/common/library").FunctionSignature | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ReflectionTypes } from '@ez4/reflection';
|
|
2
2
|
import type { BucketService } from '../types/service';
|
|
3
|
-
export declare const getBucketServices: (reflection:
|
|
3
|
+
export declare const getBucketServices: (reflection: ReflectionTypes) => {
|
|
4
4
|
services: Record<string, BucketService>;
|
|
5
5
|
errors: Error[];
|
|
6
6
|
};
|
|
@@ -5,11 +5,11 @@ import type { BucketEvent, BucketHandler, BucketListener } from './common';
|
|
|
5
5
|
*/
|
|
6
6
|
export interface BucketEvents {
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Life-cycle listener function for the event.
|
|
9
9
|
*/
|
|
10
10
|
readonly listener?: BucketListener<BucketEvent>;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
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/dist/types/common.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { FunctionSignature, ServiceListener } from '@ez4/common/library';
|
|
1
2
|
import type { LinkedVariables } from '@ez4/project/library';
|
|
2
|
-
import type { ServiceListener } from '@ez4/common/library';
|
|
3
3
|
export type BucketCors = {
|
|
4
4
|
allowOrigins: string[];
|
|
5
5
|
allowMethods?: string[];
|
|
@@ -7,12 +7,7 @@ export type BucketCors = {
|
|
|
7
7
|
allowHeaders?: string[];
|
|
8
8
|
maxAge?: number;
|
|
9
9
|
};
|
|
10
|
-
export type EventHandler =
|
|
11
|
-
file: string;
|
|
12
|
-
module?: string;
|
|
13
|
-
name: string;
|
|
14
|
-
description?: string;
|
|
15
|
-
};
|
|
10
|
+
export type EventHandler = FunctionSignature;
|
|
16
11
|
export type BucketEvent = {
|
|
17
12
|
path?: string;
|
|
18
13
|
listener?: ServiceListener;
|
package/dist/types/service.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ServiceMetadata } from '@ez4/project/library';
|
|
2
2
|
import type { BucketCors, BucketEvent } from './common';
|
|
3
3
|
export declare const ServiceType = "@ez4/bucket";
|
|
4
|
-
export type BucketService = ServiceMetadata & {
|
|
4
|
+
export type BucketService = Omit<ServiceMetadata, 'variables' | 'services'> & Required<Pick<ServiceMetadata, 'variables' | 'services'>> & {
|
|
5
5
|
type: typeof ServiceType;
|
|
6
6
|
name: string;
|
|
7
7
|
localPath?: string;
|
|
@@ -11,3 +11,15 @@ export type BucketService = ServiceMetadata & {
|
|
|
11
11
|
cors?: BucketCors;
|
|
12
12
|
};
|
|
13
13
|
export declare const isBucketService: (service: ServiceMetadata) => service is BucketService;
|
|
14
|
+
export declare const createBucketService: (name: string) => {
|
|
15
|
+
variables: {};
|
|
16
|
+
services: {};
|
|
17
|
+
type: "@ez4/bucket";
|
|
18
|
+
name: string;
|
|
19
|
+
context: Record<string, import("@ez4/project/library").LinkedContext>;
|
|
20
|
+
localPath?: string | null | undefined;
|
|
21
|
+
globalName?: string | null | undefined;
|
|
22
|
+
autoExpireDays?: number | null | undefined;
|
|
23
|
+
events?: BucketEvent | null | undefined;
|
|
24
|
+
cors?: BucketCors | null | undefined;
|
|
25
|
+
};
|
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.
|
|
4
|
+
"version": "0.37.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.
|
|
50
|
-
"@ez4/project": "^0.
|
|
51
|
-
"@ez4/reflection": "^0.
|
|
52
|
-
"@ez4/utils": "^0.
|
|
49
|
+
"@ez4/common": "^0.37.0",
|
|
50
|
+
"@ez4/project": "^0.37.0",
|
|
51
|
+
"@ez4/reflection": "^0.37.0",
|
|
52
|
+
"@ez4/utils": "^0.37.0"
|
|
53
53
|
}
|
|
54
54
|
}
|