@ez4/storage 0.13.0 → 0.15.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,11 @@
1
+ import { IncompleteTypeError, IncorrectTypeError, InvalidTypeError } from '@ez4/common/library';
2
+ export declare class IncompleteEventError extends IncompleteTypeError {
3
+ constructor(properties: string[], fileName?: string);
4
+ }
5
+ export declare class InvalidEventTypeError extends InvalidTypeError {
6
+ constructor(fileName?: string);
7
+ }
8
+ export declare class IncorrectEventTypeError extends IncorrectTypeError {
9
+ eventType: string;
10
+ constructor(eventType: string, fileName?: string);
11
+ }
@@ -0,0 +1,4 @@
1
+ import { IncompleteTypeError } from '@ez4/common/library';
2
+ export declare class IncompleteHandlerError extends IncompleteTypeError {
3
+ constructor(properties: string[], fileName?: string);
4
+ }
package/dist/library.cjs CHANGED
@@ -1,29 +1,55 @@
1
- "use strict";var S=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var R=(e,r)=>{for(var t in r)S(e,t,{get:r[t],enumerable:!0})},N=(e,r,t,s)=>{if(r&&
2
- typeof r=="object"||typeof r=="function")for(let o of A(r))!D.call(e,o)&&o!==t&&
3
- S(e,o,{get:()=>r[o],enumerable:!(s=j(r,o))||s.enumerable});return e};var H=e=>N(S({},"__esModule",{value:!0}),e);var J={};R(J,{IncompleteCorsError:()=>y,IncompleteServiceError:()=>f,IncorrectCorsTypeError:()=>k,
4
- InvalidCorsTypeError:()=>g,ServiceType:()=>d,getBucketCors:()=>T,getBucketServices:()=>b,
5
- isBucketService:()=>V,registerTriggers:()=>G});module.exports=H(J);var O=require("@ez4/common/library"),z=require("@ez4/project/library");var p=require("@ez4/common/library"),I=require("@ez4/reflection"),w=require("@ez4/utils");var d="@ez4/bucket",V=e=>e.type===d;var x=require("@ez4/common/library"),f=class extends x.IncompleteTypeError{constructor(r,t){
6
- super("Incomplete bucket service",r,t)}};var m=require("@ez4/common/library"),v=e=>(0,m.isClassDeclaration)(e)&&(0,m.hasHeritageType)(
7
- e,"Bucket.Service"),B=e=>(0,m.isModelDeclaration)(e)&&(0,m.hasHeritageType)(e,"B\
8
- ucket.Cors");var n=require("@ez4/common/library"),a=require("@ez4/reflection"),h=require("@ez4/utils");var l=require("@ez4/common/library"),y=class extends l.IncompleteTypeError{constructor(r,t){
9
- super("Incomplete bucket CORS",r,t)}},g=class extends l.InvalidTypeError{constructor(r){
10
- super("Invalid bucket CORS type",void 0,"Bucket.Cors",r)}},k=class extends l.IncorrectTypeError{constructor(t,s){
11
- super("Incorrect bucket CORS type",t,"Bucket.Cors",s);this.fallbackType=t}};var T=(e,r,t,s)=>{if(!(0,a.isTypeReference)(e))return M(e,r,s);let o=t[e.path];return o?
12
- M(o,r,s):null},L=e=>!!e.allowOrigins?.length,M=(e,r,t)=>(0,a.isTypeObject)(e)?C(
13
- e,(0,n.getObjectMembers)(e),t):(0,n.isModelDeclaration)(e)?B(e)?C(e,(0,n.getModelMembers)(
14
- e),t):(t.push(new k(e.name,e.file)),null):(t.push(new g(r.file)),null),C=(e,r,t)=>{
15
- let s={},o=new Set(["allowOrigins"]);for(let i of r)if(!(!(0,a.isModelProperty)(
16
- i)||i.inherited))switch(i.name){case"allowOrigins":case"allowMethods":case"allow\
17
- Headers":case"exposeHeaders":{let c=F(i);c.length&&(s[i.name]=c);break}case"maxA\
18
- ge":{let c=(0,n.getPropertyNumber)(i);(0,h.isAnyNumber)(c)&&(s[i.name]=c);break}}
19
- return L(s)?s:(t.push(new y([...o],e.file)),null)},F=e=>{let r=(0,n.getPropertyTuple)(
20
- e)??[],t=[];for(let s of r){let o=(0,n.getLiteralString)(s);o&&t.push(o)}return t};var b=e=>{let r={},t=[];for(let s in e){let o=e[s];if(!v(o)||(0,p.isExternalStatement)(
21
- o))continue;let i={type:d};i.name=o.name;for(let c of(0,p.getModelMembers)(o))if(!(!(0,I.isModelProperty)(
22
- c)||c.inherited))switch(c.name){case"cors":i.cors=T(c.value,o,e,t);break;case"lo\
23
- calPath":{let u=(0,p.getPropertyString)(c);u!=null&&(i[c.name]=u);break}case"aut\
24
- oExpireDays":{let u=(0,p.getPropertyNumber)(c);(0,w.isAnyNumber)(u)&&(i[c.name]=
25
- u);break}}if(!q(i)){t.push(new f([],o.file));continue}if(r[o.name]){t.push(new p.DuplicateServiceError(
26
- o.name,o.file));continue}r[o.name]=i}return{services:r,errors:t}},q=e=>!!e.name;var P=e=>v(e)?e.name:null;var E=!1,G=()=>{E||((0,O.registerTriggers)(),(0,z.createTrigger)("@ez4/bucket",{
27
- "metadata:getServices":b,"metadata:getLinkedService":P}),E=!0)};0&&(module.exports={IncompleteCorsError,IncompleteServiceError,IncorrectCorsTypeError,
28
- InvalidCorsTypeError,ServiceType,getBucketCors,getBucketServices,isBucketService,
1
+ "use strict";var I=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var Z=(e,t)=>{for(var r in t)I(e,r,{get:t[r],enumerable:!0})},$=(e,t,r,n)=>{if(t&&
2
+ typeof t=="object"||typeof t=="function")for(let o of X(t))!Y.call(e,o)&&o!==r&&
3
+ I(e,o,{get:()=>t[o],enumerable:!(n=W(t,o))||n.enumerable});return e};var ee=e=>$(I({},"__esModule",{value:!0}),e);var pe={};Z(pe,{IncompleteCorsError:()=>T,IncompleteEventError:()=>g,IncompleteServiceError:()=>d,
4
+ IncorrectCorsTypeError:()=>E,IncorrectEventTypeError:()=>b,InvalidCorsTypeError:()=>S,
5
+ InvalidEventTypeError:()=>k,ServiceType:()=>x,getBucketCors:()=>P,getBucketEvent:()=>w,
6
+ getBucketServices:()=>j,getEventHandler:()=>C,isBucketService:()=>re,registerTriggers:()=>ce});
7
+ module.exports=ee(pe);var Q=require("@ez4/common/library"),U=require("@ez4/project/library");var p=require("@ez4/common/library"),G=require("@ez4/reflection"),J=require("@ez4/utils");var x="@ez4/bucket",re=e=>e.type===x;var z=require("@ez4/common/library"),d=class extends z.IncompleteTypeError{constructor(t,r){
8
+ super("Incomplete bucket service",t,r)}};var l=require("@ez4/common/library"),M=require("@ez4/reflection"),B=e=>(0,l.isClassDeclaration)(
9
+ e)&&(0,l.hasHeritageType)(e,"Bucket.Service"),O=e=>(0,M.isTypeCallback)(e)||(0,M.isTypeFunction)(
10
+ e),A=e=>(0,l.hasHeritageType)(e,"Bucket.Event"),H=e=>(0,l.hasHeritageType)(e,"Bu\
11
+ cket.Cors");var c=require("@ez4/common/library"),f=require("@ez4/reflection"),V=require("@ez4/utils");var u=require("@ez4/common/library"),g=class extends u.IncompleteTypeError{constructor(t,r){
12
+ super("Incomplete bucket event",t,r)}},k=class extends u.InvalidTypeError{constructor(t){
13
+ super("Invalid bucket event type",void 0,"Bucket.Event",t)}},b=class extends u.IncorrectTypeError{constructor(r,n){
14
+ super("Incorrect bucket event type",r,"Bucket.Event",n);this.eventType=r}};var N=require("@ez4/common/library"),h=class extends N.IncompleteTypeError{constructor(t,r){
15
+ super("Incomplete event handler",t,r)}};var C=(e,t,r)=>{if(!O(e))return null;let n={},o=new Set(["name","file"]);return e.
16
+ description&&(n.description=e.description),(n.name=e.name)&&o.delete("name"),(n.
17
+ file=e.file)&&o.delete("file"),o.size===0&&te(n)?n:(r.push(new h([...o],e.file)),
18
+ null)},te=e=>!!e.name&&!!e.file;var w=(e,t,r,n)=>{if(!(0,f.isTypeReference)(e))return D(e,t,r,n);let o=r[e.path];
19
+ return o?D(o,t,r,n):null},oe=e=>!!e.handler,D=(e,t,r,n)=>(0,f.isTypeObject)(e)?R(
20
+ e,(0,c.getObjectMembers)(e),r,n):(0,c.isModelDeclaration)(e)?A(e)?R(e,(0,c.getModelMembers)(
21
+ e),r,n):(n.push(new b(e.name,e.file)),null):(n.push(new k(t.file)),null),R=(e,t,r,n)=>{
22
+ let o={},s=new Set(["handler"]);for(let i of t)if(!(!(0,f.isModelProperty)(i)||i.
23
+ inherited))switch(i.name){default:n.push(new c.InvalidServicePropertyError(parent.
24
+ name,i.name,e.file));break;case"listener":{let a=(0,c.getServiceListener)(i.value,
25
+ n);a&&(o.listener=a);break}case"handler":o.handler=C(i.value,r,n);break;case"pat\
26
+ h":{let a=(0,c.getPropertyString)(i);a&&(o[i.name]=a);break}case"timeout":case"m\
27
+ emory":{let a=(0,c.getPropertyNumber)(i);(0,V.isAnyNumber)(a)&&(o[i.name]=a);break}case"\
28
+ variables":o.variables=(0,c.getLinkedVariableList)(i,n);break}return oe(o)?o:(n.
29
+ push(new g([...s],e.file)),null)};var m=require("@ez4/common/library"),v=require("@ez4/reflection"),q=require("@ez4/utils");var y=require("@ez4/common/library"),T=class extends y.IncompleteTypeError{constructor(t,r){
30
+ super("Incomplete bucket CORS",t,r)}},S=class extends y.InvalidTypeError{constructor(t){
31
+ super("Invalid bucket CORS type",void 0,"Bucket.Cors",t)}},E=class extends y.IncorrectTypeError{constructor(r,n){
32
+ super("Incorrect bucket CORS type",r,"Bucket.Cors",n);this.fallbackType=r}};var P=(e,t,r,n)=>{if(!(0,v.isTypeReference)(e))return F(e,t,n);let o=r[e.path];return o?
33
+ F(o,t,n):null},ne=e=>!!e.allowOrigins?.length,F=(e,t,r)=>(0,v.isTypeObject)(e)?_(
34
+ e,(0,m.getObjectMembers)(e),r):(0,m.isModelDeclaration)(e)?H(e)?_(e,(0,m.getModelMembers)(
35
+ e),r):(r.push(new E(e.name,e.file)),null):(r.push(new S(t.file)),null),_=(e,t,r)=>{
36
+ let n={},o=new Set(["allowOrigins"]);for(let s of t)if(!(!(0,v.isModelProperty)(
37
+ s)||s.inherited))switch(s.name){default:r.push(new m.InvalidServicePropertyError(
38
+ parent.name,s.name,e.file));break;case"allowOrigins":case"allowMethods":case"all\
39
+ owHeaders":case"exposeHeaders":{let i=ie(s);i.length&&(n[s.name]=i);break}case"m\
40
+ axAge":{let i=(0,m.getPropertyNumber)(s);(0,q.isAnyNumber)(i)&&(n[s.name]=i);break}}
41
+ return ne(n)?n:(r.push(new T([...o],e.file)),null)},ie=e=>{let t=(0,m.getPropertyTuple)(
42
+ e)??[],r=[];for(let n of t){let o=(0,m.getLiteralString)(n);o&&r.push(o)}return r};var j=e=>{let t={},r=[];for(let n in e){let o=e[n];if(!B(o)||(0,p.isExternalStatement)(
43
+ o))continue;let s={type:x};s.name=o.name;for(let i of(0,p.getModelMembers)(o))if(!(!(0,G.isModelProperty)(
44
+ i)||i.inherited))switch(i.name){default:r.push(new p.InvalidServicePropertyError(
45
+ parent.name,i.name,o.file));break;case"localPath":case"globalName":{let a=(0,p.getPropertyString)(
46
+ i);a&&(s[i.name]=a);break}case"autoExpireDays":{let a=(0,p.getPropertyNumber)(i);
47
+ (0,J.isAnyNumber)(a)&&(s.autoExpireDays=a);break}case"events":s.events=w(i.value,
48
+ o,e,r);break;case"cors":s.cors=P(i.value,o,e,r);break;case"variables":s.variables=
49
+ (0,p.getLinkedVariableList)(i,r);break;case"services":s.services=(0,p.getLinkedServiceList)(
50
+ i,e,r);break}if(!se(s)){r.push(new d([],o.file));continue}if(t[o.name]){r.push(new p.DuplicateServiceError(
51
+ o.name,o.file));continue}t[o.name]=s}return{services:t,errors:r}},se=e=>!!e.name;var K=e=>B(e)?e.name:null;var L=!1,ce=()=>{L||((0,Q.registerTriggers)(),(0,U.createTrigger)("@ez4/bucket",
52
+ {"metadata:getServices":j,"metadata:getLinkedService":K}),L=!0)};0&&(module.exports={IncompleteCorsError,IncompleteEventError,IncompleteServiceError,
53
+ IncorrectCorsTypeError,IncorrectEventTypeError,InvalidCorsTypeError,InvalidEventTypeError,
54
+ ServiceType,getBucketCors,getBucketEvent,getBucketServices,getEventHandler,isBucketService,
29
55
  registerTriggers});
package/dist/library.d.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  export * from './triggers/register.js';
2
2
  export * from './metadata/service.js';
3
+ export * from './metadata/event.js';
4
+ export * from './metadata/handler.js';
3
5
  export * from './metadata/cors.js';
4
6
  export * from './errors/service.js';
7
+ export * from './errors/event.js';
5
8
  export * from './errors/cors.js';
6
9
  export * from './types/service.js';
7
- export * from './types/cors.js';
10
+ export * from './types/common.js';
package/dist/library.mjs CHANGED
@@ -1,25 +1,51 @@
1
- import{registerTriggers as W}from"@ez4/common/library";import{createTrigger as X}from"@ez4/project/library";import{DuplicateServiceError as L,isExternalStatement as F,getModelMembers as q,
2
- getPropertyNumber as G,getPropertyString as J}from"@ez4/common/library";import{isModelProperty as K}from"@ez4/reflection";
3
- import{isAnyNumber as Q}from"@ez4/utils";var f="@ez4/bucket",Y=e=>e.type===f;import{IncompleteTypeError as x}from"@ez4/common/library";var p=class extends x{constructor(t,r){
4
- super("Incomplete bucket service",t,r)}};import{hasHeritageType as y,isClassDeclaration as B,isModelDeclaration as M}from"@ez4/common/library";
5
- var m=e=>B(e)&&y(e,"Bucket.Service"),g=e=>M(e)&&y(e,"Bucket.Cors");import{getLiteralString as w,getModelMembers as P,getObjectMembers as E,getPropertyNumber as O,
6
- getPropertyTuple as z,isModelDeclaration as j}from"@ez4/common/library";import{isModelProperty as A,
7
- isTypeObject as D,isTypeReference as R}from"@ez4/reflection";import{isAnyNumber as N}from"@ez4/utils";import{IncompleteTypeError as C,IncorrectTypeError as h,InvalidTypeError as I}from"@ez4/common/library";
8
- var u=class extends C{constructor(t,r){super("Incomplete bucket CORS",t,r)}},l=class extends I{constructor(t){
9
- super("Invalid bucket CORS type",void 0,"Bucket.Cors",t)}},a=class extends h{constructor(r,c){
10
- super("Incorrect bucket CORS type",r,"Bucket.Cors",c);this.fallbackType=r}};var v=(e,t,r,c)=>{if(!R(e))return k(e,t,c);let o=r[e.path];return o?k(o,t,c):null},
11
- H=e=>!!e.allowOrigins?.length,k=(e,t,r)=>D(e)?d(e,E(e),r):j(e)?g(e)?d(e,P(e),r):
12
- (r.push(new a(e.name,e.file)),null):(r.push(new l(t.file)),null),d=(e,t,r)=>{let c={},
13
- o=new Set(["allowOrigins"]);for(let s of t)if(!(!A(s)||s.inherited))switch(s.name){case"\
14
- allowOrigins":case"allowMethods":case"allowHeaders":case"exposeHeaders":{let i=V(
15
- s);i.length&&(c[s.name]=i);break}case"maxAge":{let i=O(s);N(i)&&(c[s.name]=i);break}}
16
- return H(c)?c:(r.push(new u([...o],e.file)),null)},V=e=>{let t=z(e)??[],r=[];for(let c of t){
17
- let o=w(c);o&&r.push(o)}return r};var S=e=>{let t={},r=[];for(let c in e){let o=e[c];if(!m(o)||F(o))continue;let s={
18
- type:f};s.name=o.name;for(let i of q(o))if(!(!K(i)||i.inherited))switch(i.name){case"\
19
- cors":s.cors=v(i.value,o,e,r);break;case"localPath":{let n=J(i);n!=null&&(s[i.name]=
20
- n);break}case"autoExpireDays":{let n=G(i);Q(n)&&(s[i.name]=n);break}}if(!U(s)){r.
21
- push(new p([],o.file));continue}if(t[o.name]){r.push(new L(o.name,o.file));continue}
22
- t[o.name]=s}return{services:t,errors:r}},U=e=>!!e.name;var T=e=>m(e)?e.name:null;var b=!1,Me=()=>{b||(W(),X("@ez4/bucket",{"metadata:getServices":S,"metadata:get\
23
- LinkedService":T}),b=!0)};export{u as IncompleteCorsError,p as IncompleteServiceError,a as IncorrectCorsTypeError,
24
- l as InvalidCorsTypeError,f as ServiceType,v as getBucketCors,S as getBucketServices,
25
- Y as isBucketService,Me as registerTriggers};
1
+ import{registerTriggers as Ie}from"@ez4/common/library";import{createTrigger as Ce}from"@ez4/project/library";import{DuplicateServiceError as de,InvalidServicePropertyError as ge,isExternalStatement as ke,
2
+ getLinkedVariableList as be,getLinkedServiceList as Te,getModelMembers as Se,getPropertyNumber as Ee,
3
+ getPropertyString as xe}from"@ez4/common/library";import{isModelProperty as Me}from"@ez4/reflection";
4
+ import{isAnyNumber as Be}from"@ez4/utils";var g="@ez4/bucket",we=e=>e.type===g;import{IncompleteTypeError as z}from"@ez4/common/library";var p=class extends z{constructor(n,r){
5
+ super("Incomplete bucket service",n,r)}};import{hasHeritageType as k,isClassDeclaration as O}from"@ez4/common/library";import{
6
+ isTypeCallback as A,isTypeFunction as H}from"@ez4/reflection";var a=e=>O(e)&&k(e,
7
+ "Bucket.Service"),b=e=>A(e)||H(e),T=e=>k(e,"Bucket.Event"),S=e=>k(e,"Bucket.Cors");import{InvalidServicePropertyError as _,isModelDeclaration as q,getLinkedVariableList as G,
8
+ getModelMembers as J,getObjectMembers as K,getPropertyNumber as L,getPropertyString as Q,
9
+ getServiceListener as U}from"@ez4/common/library";import{isModelProperty as W,isTypeObject as X,
10
+ isTypeReference as Y}from"@ez4/reflection";import{isAnyNumber as Z}from"@ez4/utils";import{IncompleteTypeError as N,IncorrectTypeError as D,InvalidTypeError as R}from"@ez4/common/library";
11
+ var m=class extends N{constructor(n,r){super("Incomplete bucket event",n,r)}},l=class extends R{constructor(n){
12
+ super("Invalid bucket event type",void 0,"Bucket.Event",n)}},u=class extends D{constructor(r,o){
13
+ super("Incorrect bucket event type",r,"Bucket.Event",o);this.eventType=r}};import{IncompleteTypeError as V}from"@ez4/common/library";var f=class extends V{constructor(n,r){
14
+ super("Incomplete event handler",n,r)}};var E=(e,n,r)=>{if(!b(e))return null;let o={},t=new Set(["name","file"]);return e.
15
+ description&&(o.description=e.description),(o.name=e.name)&&t.delete("name"),(o.
16
+ file=e.file)&&t.delete("file"),t.size===0&&F(o)?o:(r.push(new f([...t],e.file)),
17
+ null)},F=e=>!!e.name&&!!e.file;var B=(e,n,r,o)=>{if(!Y(e))return x(e,n,r,o);let t=r[e.path];return t?x(t,n,r,o):
18
+ null},$=e=>!!e.handler,x=(e,n,r,o)=>X(e)?M(e,K(e),r,o):q(e)?T(e)?M(e,J(e),r,o):(o.
19
+ push(new u(e.name,e.file)),null):(o.push(new l(n.file)),null),M=(e,n,r,o)=>{let t={},
20
+ s=new Set(["handler"]);for(let i of n)if(!(!W(i)||i.inherited))switch(i.name){default:
21
+ o.push(new _(parent.name,i.name,e.file));break;case"listener":{let c=U(i.value,o);
22
+ c&&(t.listener=c);break}case"handler":t.handler=E(i.value,r,o);break;case"path":{
23
+ let c=Q(i);c&&(t[i.name]=c);break}case"timeout":case"memory":{let c=L(i);Z(c)&&(t[i.
24
+ name]=c);break}case"variables":t.variables=G(i,o);break}return $(t)?t:(o.push(new m(
25
+ [...s],e.file)),null)};import{InvalidServicePropertyError as oe,isModelDeclaration as ne,getLiteralString as ie,
26
+ getModelMembers as se,getObjectMembers as ce,getPropertyNumber as pe,getPropertyTuple as ae}from"@ez4/common/library";
27
+ import{isModelProperty as me,isTypeObject as le,isTypeReference as ue}from"@ez4/reflection";
28
+ import{isAnyNumber as fe}from"@ez4/utils";import{IncompleteTypeError as ee,IncorrectTypeError as re,InvalidTypeError as te}from"@ez4/common/library";
29
+ var y=class extends ee{constructor(n,r){super("Incomplete bucket CORS",n,r)}},v=class extends te{constructor(n){
30
+ super("Invalid bucket CORS type",void 0,"Bucket.Cors",n)}},d=class extends re{constructor(r,o){
31
+ super("Incorrect bucket CORS type",r,"Bucket.Cors",o);this.fallbackType=r}};var C=(e,n,r,o)=>{if(!ue(e))return h(e,n,o);let t=r[e.path];return t?h(t,n,o):null},
32
+ ye=e=>!!e.allowOrigins?.length,h=(e,n,r)=>le(e)?I(e,ce(e),r):ne(e)?S(e)?I(e,se(e),
33
+ r):(r.push(new d(e.name,e.file)),null):(r.push(new v(n.file)),null),I=(e,n,r)=>{
34
+ let o={},t=new Set(["allowOrigins"]);for(let s of n)if(!(!me(s)||s.inherited))switch(s.
35
+ name){default:r.push(new oe(parent.name,s.name,e.file));break;case"allowOrigins":case"\
36
+ allowMethods":case"allowHeaders":case"exposeHeaders":{let i=ve(s);i.length&&(o[s.
37
+ name]=i);break}case"maxAge":{let i=pe(s);fe(i)&&(o[s.name]=i);break}}return ye(o)?
38
+ o:(r.push(new y([...t],e.file)),null)},ve=e=>{let n=ae(e)??[],r=[];for(let o of n){
39
+ let t=ie(o);t&&r.push(t)}return r};var w=e=>{let n={},r=[];for(let o in e){let t=e[o];if(!a(t)||ke(t))continue;let s={
40
+ type:g};s.name=t.name;for(let i of Se(t))if(!(!Me(i)||i.inherited))switch(i.name){default:
41
+ r.push(new ge(parent.name,i.name,t.file));break;case"localPath":case"globalName":{
42
+ let c=xe(i);c&&(s[i.name]=c);break}case"autoExpireDays":{let c=Ee(i);Be(c)&&(s.autoExpireDays=
43
+ c);break}case"events":s.events=B(i.value,t,e,r);break;case"cors":s.cors=C(i.value,
44
+ t,e,r);break;case"variables":s.variables=be(i,r);break;case"services":s.services=
45
+ Te(i,e,r);break}if(!he(s)){r.push(new p([],t.file));continue}if(n[t.name]){r.push(
46
+ new de(t.name,t.file));continue}n[t.name]=s}return{services:n,errors:r}},he=e=>!!e.
47
+ name;var P=e=>a(e)?e.name:null;var j=!1,br=()=>{j||(Ie(),Ce("@ez4/bucket",{"metadata:getServices":w,"metadata:g\
48
+ etLinkedService":P}),j=!0)};export{y as IncompleteCorsError,m as IncompleteEventError,p as IncompleteServiceError,
49
+ d as IncorrectCorsTypeError,u as IncorrectEventTypeError,v as InvalidCorsTypeError,
50
+ l as InvalidEventTypeError,g as ServiceType,C as getBucketCors,B as getBucketEvent,
51
+ w as getBucketServices,E as getEventHandler,we as isBucketService,br as registerTriggers};
package/dist/main.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var s=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var n=(r,e)=>{for(var t in e)s(r,t,{get:e[t],enumerable:!0})},l=(r,e,t,c)=>{if(e&&
2
- typeof e=="object"||typeof e=="function")for(let o of m(e))!a.call(r,o)&&o!==t&&
3
- s(r,o,{get:()=>e[o],enumerable:!(c=p(e,o))||c.enumerable});return r};var v=r=>l(s({},"__esModule",{value:!0}),r);var x={};n(x,{Bucket:()=>i});module.exports=v(x);var i;(r=>{})(i||={});0&&(module.exports={Bucket});
1
+ "use strict";var o=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var v=(t,e)=>{for(var r in e)o(t,r,{get:e[r],enumerable:!0})},u=(t,e,r,c)=>{if(e&&
2
+ typeof e=="object"||typeof e=="function")for(let n of m(e))!a.call(t,n)&&n!==r&&
3
+ o(t,n,{get:()=>e[n],enumerable:!(c=p(e,n))||c.enumerable});return t};var l=t=>u(o({},"__esModule",{value:!0}),t);var x={};v(x,{Bucket:()=>s,BucketEventType:()=>i});module.exports=l(x);var i=(r=>(r.Create="create",r.Delete="delete",r))(i||{});var s;(t=>{})(s||={});0&&(module.exports={Bucket,BucketEventType});
package/dist/main.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export * from './services/bucket.js';
1
+ export { BucketEventType } from './services/common.js';
2
+ export * from './services/contract.js';
2
3
  export * from './services/client.js';
package/dist/main.mjs CHANGED
@@ -1 +1 @@
1
- var e;(r=>{})(e||={});export{e as Bucket};
1
+ var t=(e=>(e.Create="create",e.Delete="delete",e))(t||{});var r;(n=>{})(r||={});export{r as Bucket,t as BucketEventType};
@@ -1,5 +1,5 @@
1
1
  import type { AllType, SourceMap, TypeModel, TypeObject } from '@ez4/reflection';
2
- import type { BucketCors } from '../types/cors.js';
2
+ import type { BucketCors } from '../types/common.js';
3
3
  type TypeParent = TypeModel | TypeObject;
4
4
  export declare const getBucketCors: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => BucketCors | null;
5
5
  export {};
@@ -0,0 +1,5 @@
1
+ import type { AllType, SourceMap, TypeModel, TypeObject } from '@ez4/reflection';
2
+ import type { BucketEvent } from '../types/common.js';
3
+ type TypeParent = TypeModel | TypeObject;
4
+ export declare const getBucketEvent: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => BucketEvent | null;
5
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { AllType, SourceMap } from '@ez4/reflection';
2
+ import type { EventHandler } from '../types/common.js';
3
+ export declare const getEventHandler: (type: AllType, _reflection: SourceMap, errorList: Error[]) => EventHandler | null;
@@ -1,3 +1,5 @@
1
- import type { AllType, TypeClass } from '@ez4/reflection';
1
+ import type { AllType, TypeCallback, TypeClass, TypeFunction, TypeModel } from '@ez4/reflection';
2
2
  export declare const isBucketService: (type: AllType) => type is TypeClass;
3
- export declare const isBucketCors: (type: AllType) => boolean;
3
+ export declare const isEventHandler: (type: AllType) => type is TypeCallback | TypeFunction;
4
+ export declare const isBucketEvent: (type: TypeModel) => boolean;
5
+ export declare const isBucketCors: (type: TypeModel) => boolean;
@@ -0,0 +1,72 @@
1
+ import type { Service } from '@ez4/common';
2
+ import type { Bucket } from './contract.js';
3
+ /**
4
+ * Bucket event type.
5
+ */
6
+ export declare const enum BucketEventType {
7
+ Create = "create",
8
+ Delete = "delete"
9
+ }
10
+ /**
11
+ * Bucket event.
12
+ */
13
+ export type BucketEvent = {
14
+ /**
15
+ * Type of event.
16
+ */
17
+ eventType: BucketEventType;
18
+ /**
19
+ * Bucket from the event.
20
+ */
21
+ bucketName: string;
22
+ /**
23
+ * Object key in the bucket.
24
+ */
25
+ objectKey: string;
26
+ /**
27
+ * Size of the created object.
28
+ */
29
+ objectSize?: number;
30
+ };
31
+ /**
32
+ * Bucket CORS configuration.
33
+ */
34
+ export interface BucketCors {
35
+ /**
36
+ * List of allowed origins.
37
+ */
38
+ allowOrigins: string[];
39
+ /**
40
+ * List of allowed methods.
41
+ */
42
+ allowMethods?: string[];
43
+ /**
44
+ * List of allowed headers.
45
+ */
46
+ allowHeaders?: string[];
47
+ /**
48
+ * List of exposed headers.
49
+ */
50
+ exposeHeaders?: string[];
51
+ /**
52
+ * Determines how long the preflight result can be cached.
53
+ */
54
+ maxAge?: number;
55
+ }
56
+ /**
57
+ * Incoming event.
58
+ */
59
+ export type BucketIncoming<T extends BucketEvent> = T & {
60
+ /**
61
+ * Request tracking Id.
62
+ */
63
+ requestId: string;
64
+ };
65
+ /**
66
+ * Message listener.
67
+ */
68
+ export type BucketListener<T extends BucketEvent> = (event: Service.Event<BucketIncoming<T>>, context: Service.Context<Bucket.Service>) => Promise<void> | void;
69
+ /**
70
+ * Event handler.
71
+ */
72
+ export type BucketHandler<T extends BucketEvent> = (request: BucketIncoming<T> | T, context: Service.Context<Bucket.Service>) => Promise<void> | void;
@@ -0,0 +1,77 @@
1
+ import type { LinkedVariables } from '@ez4/project/library';
2
+ import type { Service } from '@ez4/common';
3
+ import type { Client } from './client.js';
4
+ import type { BucketCors, BucketEvent, BucketHandler, BucketIncoming, BucketListener } from './common.js';
5
+ /**
6
+ * Provide all contracts for a self-managed Bucket service.
7
+ */
8
+ export declare namespace Bucket {
9
+ type Cors = BucketCors;
10
+ type Event = BucketEvent;
11
+ type Incoming = BucketIncoming<Event>;
12
+ type Listener = BucketListener<Event>;
13
+ type Handler = BucketHandler<Event>;
14
+ type ServiceEvent = Service.Event<Incoming>;
15
+ /**
16
+ * Bucket events.
17
+ */
18
+ interface Events {
19
+ /**
20
+ * Event listener.
21
+ */
22
+ listener?: Listener;
23
+ /**
24
+ * Event handler.
25
+ */
26
+ handler: Handler;
27
+ /**
28
+ * Path associated to the event.
29
+ */
30
+ path?: string;
31
+ /**
32
+ * Variables associated to the handler.
33
+ */
34
+ variables?: LinkedVariables;
35
+ /**
36
+ * Max execution time (in seconds) for the handler.
37
+ */
38
+ timeout?: number;
39
+ /**
40
+ * Amount of memory available for the handler.
41
+ */
42
+ memory?: number;
43
+ }
44
+ /**
45
+ * Bucket service.
46
+ */
47
+ abstract class Service implements Service.Provider {
48
+ /**
49
+ * Overwrite the global bucket name.
50
+ */
51
+ globalName?: string;
52
+ /**
53
+ * Specify a local path to synchronize with the storage.
54
+ */
55
+ localPath?: string;
56
+ /**
57
+ * Maximum amount of days an object is stored before its auto-deletion.
58
+ */
59
+ autoExpireDays?: number;
60
+ /**
61
+ * Bucket events.
62
+ */
63
+ events?: Events;
64
+ /**
65
+ * CORS configuration.
66
+ */
67
+ cors?: Cors;
68
+ /**
69
+ * Variables associated to all events.
70
+ */
71
+ variables?: LinkedVariables;
72
+ /**
73
+ * Service client.
74
+ */
75
+ client: Client;
76
+ }
77
+ }
@@ -0,0 +1,22 @@
1
+ import type { LinkedVariables } from '@ez4/project/library';
2
+ import type { ServiceListener } from '@ez4/common/library';
3
+ export type BucketCors = {
4
+ allowOrigins: string[];
5
+ allowMethods?: string[];
6
+ exposeHeaders?: string[];
7
+ allowHeaders?: string[];
8
+ maxAge?: number;
9
+ };
10
+ export type EventHandler = {
11
+ name: string;
12
+ file: string;
13
+ description?: string;
14
+ };
15
+ export type BucketEvent = {
16
+ listener?: ServiceListener;
17
+ handler: EventHandler;
18
+ path?: string;
19
+ variables?: LinkedVariables | null;
20
+ timeout?: number;
21
+ memory?: number;
22
+ };
@@ -1,11 +1,13 @@
1
1
  import type { ServiceMetadata } from '@ez4/project/library';
2
- import type { BucketCors } from './cors.js';
2
+ import type { BucketCors, BucketEvent } from './common.js';
3
3
  export declare const ServiceType = "@ez4/bucket";
4
4
  export type BucketService = ServiceMetadata & {
5
5
  type: typeof ServiceType;
6
6
  name: string;
7
7
  localPath?: string;
8
+ globalName?: string;
8
9
  autoExpireDays?: number;
10
+ events?: BucketEvent;
9
11
  cors?: BucketCors;
10
12
  };
11
13
  export declare const isBucketService: (service: ServiceMetadata) => service is BucketService;
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.13.0",
4
+ "version": "0.15.0",
5
5
  "author": "Silas B.",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -42,8 +42,8 @@
42
42
  "live:publish": "npm run test && npm publish --access public"
43
43
  },
44
44
  "dependencies": {
45
- "@ez4/common": "^0.13.0",
46
- "@ez4/project": "^0.13.0",
47
- "@ez4/reflection": "^0.13.0"
45
+ "@ez4/common": "^0.15.0",
46
+ "@ez4/project": "^0.15.0",
47
+ "@ez4/reflection": "^0.15.0"
48
48
  }
49
49
  }