@ez4/aws-function 0.37.0 → 0.39.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.
@@ -1,5 +1,6 @@
1
+ import type { ArchitectureType, RuntimeType } from '@ez4/project';
2
+ import type { LinkedVariables } from '@ez4/project/library';
1
3
  import type { Arn, ResourceTags } from '@ez4/aws-common';
2
- import type { FunctionVariables } from '../types/variables';
3
4
  export type CreateRequest = {
4
5
  roleArn: Arn;
5
6
  sourceFile: string;
@@ -7,7 +8,9 @@ export type CreateRequest = {
7
8
  handlerName: string;
8
9
  description?: string;
9
10
  logGroup?: string;
10
- variables?: FunctionVariables;
11
+ variables?: LinkedVariables;
12
+ architecture: ArchitectureType;
13
+ runtime: RuntimeType;
11
14
  timeout?: number;
12
15
  memory?: number;
13
16
  publish?: boolean;
@@ -23,12 +26,14 @@ export type UpdateConfigurationRequest = {
23
26
  handlerName?: string;
24
27
  description?: string;
25
28
  logGroup?: string;
26
- variables?: FunctionVariables;
29
+ variables?: LinkedVariables;
30
+ runtime?: RuntimeType;
27
31
  timeout?: number;
28
32
  memory?: number;
29
33
  debug?: boolean;
30
34
  };
31
35
  export type UpdateSourceCodeRequest = {
36
+ architecture?: ArchitectureType;
32
37
  sourceFile: string;
33
38
  publish?: boolean;
34
39
  };
@@ -1,3 +1,3 @@
1
- import type { FunctionVariables } from '../../types/variables';
2
- export declare const assertVariables: (variables: FunctionVariables) => void;
3
- export declare const protectVariables: (variables: FunctionVariables) => FunctionVariables;
1
+ import type { LinkedVariables } from '@ez4/project/library';
2
+ export declare const assertVariables: (variables: LinkedVariables) => void;
3
+ export declare const protectVariables: (variables: LinkedVariables) => LinkedVariables;
@@ -1,7 +1,6 @@
1
1
  import type { EntryState, StepContext } from '@ez4/stateful';
2
2
  import type { LinkedVariables } from '@ez4/project/library';
3
3
  import type { Arn } from '@ez4/aws-common';
4
- import type { FunctionVariables } from '../types/variables';
5
4
  import type { CreateRequest, ImportOrCreateResponse } from './client';
6
5
  export declare const FunctionServiceName = "AWS:Lambda/Function";
7
6
  export declare const FunctionServiceType = "aws:lambda.function";
@@ -9,14 +8,20 @@ export type GetFunctionFiles = () => [string, string[]];
9
8
  export type GetFunctionVariables = () => Promise<LinkedVariables> | LinkedVariables;
10
9
  export type GetFunctionBundle = (context: StepContext) => Promise<string> | string;
11
10
  export type GetFunctionHash = () => Promise<string | undefined> | string | undefined;
11
+ export type FunctionRelease = {
12
+ tagName?: string;
13
+ variableName?: string;
14
+ version: string;
15
+ };
12
16
  export type FunctionParameters = Omit<CreateRequest, 'roleArn' | 'publish' | 'variables'> & {
13
17
  getFunctionFiles: GetFunctionFiles;
14
18
  getFunctionVariables: GetFunctionVariables;
15
19
  getFunctionBundle: GetFunctionBundle;
16
20
  getFunctionHash: GetFunctionHash;
21
+ release?: FunctionRelease;
17
22
  };
18
23
  export type FunctionResult = ImportOrCreateResponse & {
19
- variables: FunctionVariables;
24
+ variables: LinkedVariables;
20
25
  valuesHash?: string;
21
26
  sourceHash: string;
22
27
  bundleHash: string;
package/dist/main.cjs CHANGED
@@ -1,157 +1,172 @@
1
- "use strict";var Qe=Object.create;var I=Object.defineProperty;var Je=Object.getOwnPropertyDescriptor;var Ke=Object.getOwnPropertyNames;var _e=Object.getPrototypeOf,Xe=Object.prototype.hasOwnProperty;var r=(e,t)=>I(e,"name",{value:t,configurable:!0});var Ye=(e,t)=>{for(var n in t)I(e,n,{get:t[n],enumerable:!0})},K=(e,t,n,o)=>{if(t&&
2
- typeof t=="object"||typeof t=="function")for(let i of Ke(t))!Xe.call(e,i)&&i!==n&&
3
- I(e,i,{get:()=>t[i],enumerable:!(o=Je(t,i))||o.enumerable});return e};var et=(e,t,n)=>(n=e!=null?Qe(_e(e)):{},K(t||!e||!e.__esModule?I(n,"default",{value:e,
4
- enumerable:!0}):n,e)),tt=e=>K(I({},"__esModule",{value:!0}),e);var Lt={};Ye(Lt,{FunctionServiceName:()=>p,FunctionServiceType:()=>f,MappingService:()=>j,
5
- MappingServiceName:()=>S,MappingServiceType:()=>v,PermissionServiceName:()=>C,PermissionServiceType:()=>x,
6
- buildFunctionArn:()=>Vt,createFunction:()=>Et,createMapping:()=>Nt,createPermission:()=>It,
7
- getFunctionArn:()=>dt,getFunctionName:()=>A,getFunctionState:()=>gt,getPermission:()=>Mt,
8
- isFunctionState:()=>k,isMappingState:()=>Ht,registerTriggers:()=>At,tryGetFunctionArn:()=>ge,
9
- tryGetFunctionState:()=>lt});module.exports=tt(Lt);var De=require("@ez4/aws-common"),Ge=require("@ez4/aws-identity"),ze=require("@ez4/aws-logs"),
10
- Be=require("@ez4/project/library");var ue=require("@ez4/aws-common");var y=require("@ez4/aws-common"),b=require("@ez4/utils"),W=require("@ez4/aws-logs"),
11
- $=require("@ez4/aws-identity");var s=require("@aws-sdk/client-lambda"),c=require("@ez4/aws-common");var _=require("@ez4/aws-common"),X=require("@ez4/utils");var p="AWS:Lambda/Function",f="aws:lambda.function";var nt=/[a-z][\w]+/i,rt=r(e=>nt.test(e),"isValidName"),G=r(e=>{for(let t in e)if(!rt(
12
- t))throw new _.InvalidParameterError(p,`${t} is an invalid variable name .`)},"a\
13
- ssertVariables"),M=r(e=>{let t={};for(let n in e)t[n]=(0,X.hashData)(e[n]);return t},
14
- "protectVariables");var Y=et(require("adm-zip"),1),ee=require("node:fs/promises");var te=r(async(e,t)=>{let n=new Y.default,o=await(0,ee.readFile)(e);return n.addFile(
15
- t,o),n.toBufferPromise()},"getZipBuffer");var w=new s.LambdaClient({}),V={minDelay:15,maxWaitTime:1800,maxDelay:60,client:w},
16
- ne=r(async(e,t)=>{c.Logger.logImport(p,e);try{let n=await w.send(new s.GetFunctionCommand(
17
- {FunctionName:e,Qualifier:t})),o=n.Configuration.Version,i=n.Configuration.FunctionArn;
18
- return{functionVersion:o,functionArn:i}}catch(n){if(!(n instanceof s.ResourceNotFoundException))
19
- throw n;return}},"importFunction"),re=r(async e=>{let{functionName:t,variables:n}=e;
20
- c.Logger.logCreate(p,t),n&&G(n);let o=pe(e.handlerName),i=await ae(e.sourceFile),
21
- a=await(0,c.waitCreation)(()=>w.send(new s.CreateFunctionCommand({FunctionName:e.
22
- functionName,Description:e.description,MemorySize:e.memory,Timeout:e.timeout,Role:e.
23
- roleArn,Handler:o,Runtime:"nodejs22.x",PackageType:"Zip",LoggingConfig:{LogGroup:e.
24
- logGroup,ApplicationLogLevel:e.debug?s.ApplicationLogLevel.Debug:s.ApplicationLogLevel.
25
- Warn,SystemLogLevel:s.SystemLogLevel.Warn,LogFormat:s.LogFormat.Json},Code:{ZipFile:i},
26
- Environment:{Variables:n},Tags:{...e.tags,ManagedBy:"EZ4"}})));c.Logger.logWait(
27
- p,t),await(0,s.waitUntilFunctionActive)(V,{FunctionName:t});let u=a.FunctionArn;
28
- return e.publish?{functionVersion:await ie(t),functionArn:u}:{functionArn:u}},"c\
29
- reateFunction"),z=r(async(e,t)=>{c.Logger.logUpdate(p,`${e} source code`);let n=await ae(
30
- t.sourceFile),o=await w.send(new s.UpdateFunctionCodeCommand({FunctionName:e,Publish:t.
31
- publish,ZipFile:n}));c.Logger.logWait(p,e),await(0,s.waitUntilFunctionUpdated)(V,
32
- {FunctionName:e});let i=o.FunctionArn;return t.publish?{functionVersion:await ie(
33
- e),functionArn:i}:{functionArn:i}},"updateSourceCode"),B=r(async(e,t)=>{let{handlerName:n,
34
- variables:o}=t;c.Logger.logUpdate(p,`${e} configuration`),o&&G(o),await w.send(new s.UpdateFunctionConfigurationCommand(
35
- {FunctionName:e,Description:t.description,MemorySize:t.memory,Timeout:t.timeout,
36
- Role:t.roleArn,Runtime:"nodejs22.x",...n&&{Handler:pe(n)},LoggingConfig:{LogGroup:t.
37
- logGroup,ApplicationLogLevel:t.debug?s.ApplicationLogLevel.Debug:s.ApplicationLogLevel.
38
- Warn,SystemLogLevel:s.SystemLogLevel.Warn,LogFormat:s.LogFormat.Json},Environment:{
39
- Variables:o}})),c.Logger.logWait(p,e),await(0,s.waitUntilFunctionUpdated)(V,{FunctionName:e})},
40
- "updateConfiguration"),oe=r(async e=>{c.Logger.logDelete(p,e),await(0,c.waitDeletion)(
41
- async()=>{try{await w.send(new s.DeleteFunctionCommand({FunctionName:e}))}catch(t){
42
- if(!(t instanceof s.ResourceNotFoundException))throw t}})},"deleteFunction"),ie=r(
43
- async e=>{c.Logger.logPublish(p,e);let t=await w.send(new s.PublishVersionCommand(
44
- {FunctionName:e}));c.Logger.logWait(p,e);let n=t.Version;return await(0,s.waitUntilPublishedVersionActive)(
45
- V,{FunctionName:e,Qualifier:n}),n},"publishFunction"),O=r(async(e,t)=>{let n=(0,c.tryParseArn)(
46
- e)?.resourceName??e;c.Logger.logTag(p,n),await w.send(new s.TagResourceCommand({
47
- Resource:e,Tags:{...t,ManagedBy:"EZ4"}}))},"tagFunction"),se=r(async(e,t)=>{let n=(0,c.tryParseArn)(
48
- e)?.resourceName??e;c.Logger.logUntag(p,n),await w.send(new s.UntagResourceCommand(
49
- {Resource:e,TagKeys:t}))},"untagFunction"),ae=r(e=>te(e,"main.mjs"),"getSourceZi\
50
- pFile"),pe=r(e=>`main.${e}`,"getSourceHandlerName");var ce=r(()=>({equals:ot,create:me,replace:st,preview:it,update:at,delete:pt}),"\
51
- getFunctionHandler"),ot=r((e,t)=>!!e.result&&e.result.functionArn===t.result?.functionArn,
52
- "equalsResource"),it=r(async(e,t)=>{let n=e.parameters,o=t.parameters,i=(0,b.deepCompare)(
53
- {...n,connections:e.connections,dependencies:e.dependencies,variables:M(await n.
54
- getFunctionVariables()),sourceHash:await(0,y.getBundleHash)(...n.getFunctionFiles()),
55
- valuesHash:n.getFunctionHash()},{...o,connections:t.connections,dependencies:t.dependencies,
1
+ "use strict";var nt=Object.create;var T=Object.defineProperty;var ot=Object.getOwnPropertyDescriptor;var it=Object.getOwnPropertyNames;var at=Object.getPrototypeOf,st=Object.prototype.hasOwnProperty;var n=(e,t)=>T(e,"name",{value:t,configurable:!0});var pt=(e,t)=>{for(var r in t)T(e,r,{get:t[r],enumerable:!0})},oe=(e,t,r,o)=>{if(t&&
2
+ typeof t=="object"||typeof t=="function")for(let i of it(t))!st.call(e,i)&&i!==r&&
3
+ T(e,i,{get:()=>t[i],enumerable:!(o=ot(t,i))||o.enumerable});return e};var ct=(e,t,r)=>(r=e!=null?nt(at(e)):{},oe(t||!e||!e.__esModule?T(r,"default",{value:e,
4
+ enumerable:!0}):r,e)),mt=e=>oe(T({},"__esModule",{value:!0}),e);var $t={};pt($t,{FunctionArchitecture:()=>ae,FunctionDefaults:()=>rt,FunctionRuntime:()=>ie,
5
+ FunctionServiceName:()=>c,FunctionServiceType:()=>S,MappingService:()=>ee,MappingServiceName:()=>x,
6
+ MappingServiceType:()=>h,PermissionServiceName:()=>C,PermissionServiceType:()=>v,
7
+ buildFunctionArn:()=>Wt,createFunction:()=>Dt,createMapping:()=>Ot,createPermission:()=>qt,
8
+ getFunctionArchitecture:()=>U,getFunctionArn:()=>Pt,getFunctionName:()=>I,getFunctionRuntime:()=>H,
9
+ getFunctionState:()=>bt,getPermission:()=>kt,isFunctionState:()=>X,isMappingState:()=>Bt,
10
+ registerTriggers:()=>Gt,tryGetFunctionArn:()=>he,tryGetFunctionState:()=>ht});module.
11
+ exports=mt($t);var Ze=require("@ez4/aws-common"),Qe=require("@ez4/aws-identity"),_e=require("@ez4/aws-logs"),
12
+ Je=require("@ez4/project/library");var ve=require("@ez4/aws-common");var F=require("@ez4/aws-common"),P=require("@ez4/utils"),_=require("@ez4/aws-logs"),
13
+ J=require("@ez4/aws-identity");var s=require("@aws-sdk/client-lambda"),u=require("@ez4/aws-common");var B=require("@ez4/project");var ie=(r=>(r.Node22="nodejs22.x",r.Node24="nodejs24.x",r))(ie||{});var ut={[B.RuntimeType.Node22]:"nodejs22.x",[B.RuntimeType.Node24]:"nodejs24.x"},
14
+ H=n(e=>ut[e],"getFunctionRuntime");var W=require("@ez4/project");var ae=(r=>(r.Arm="arm64",r.x86="x86_64",r))(ae||{});var lt={[W.ArchitectureType.Arm]:"arm64",[W.ArchitectureType.x86]:"x86_64"},U=n(
15
+ e=>lt[e],"getFunctionArchitecture");var se=require("@ez4/aws-common"),pe=require("@ez4/utils");var c="AWS:Lambda/Function",S="aws:lambda.function";var gt=/[a-z][\w]+/i,dt=n(e=>gt.test(e),"isValidName"),$=n(e=>{for(let t in e)if(!dt(
16
+ t))throw new se.InvalidParameterError(c,`${t} is an invalid variable name .`)},"\
17
+ assertVariables"),E=n(e=>{let t={};for(let r in e)t[r]=(0,pe.hashData)(e[r]);return t},
18
+ "protectVariables");var ce=ct(require("adm-zip"),1),me=require("node:fs/promises");var ue=n(async(e,t)=>{let r=new ce.default,o=await(0,me.readFile)(e);return r.addFile(
19
+ t,o),r.toBufferPromise()},"getZipBuffer");var w=new s.LambdaClient({}),z={minDelay:15,maxWaitTime:1800,maxDelay:60,client:w},
20
+ le=n(async(e,t)=>{u.Logger.logImport(c,e);try{let r=await w.send(new s.GetFunctionCommand(
21
+ {FunctionName:e,Qualifier:t})),o=r.Configuration.Version,i=r.Configuration.FunctionArn;
22
+ return{functionVersion:o,functionArn:i}}catch(r){if(!(r instanceof s.ResourceNotFoundException))
23
+ throw r;return}},"importFunction"),ge=n(async e=>{let{functionName:t,variables:r}=e;
24
+ u.Logger.logCreate(c,t),r&&$(r);let o=Fe(e.handlerName),i=await Se(e.sourceFile),
25
+ {description:a,memory:p,timeout:m,architecture:l,runtime:d,debug:y,roleArn:f,logGroup:b}=e,
26
+ N=await(0,u.waitCreation)(()=>w.send(new s.CreateFunctionCommand({FunctionName:t,
27
+ Description:a,MemorySize:p,Timeout:m,Role:f,Handler:o,Architectures:[U(l)],Runtime:H(
28
+ d),PackageType:"Zip",LoggingConfig:{LogGroup:b,ApplicationLogLevel:y?s.ApplicationLogLevel.
29
+ Debug:s.ApplicationLogLevel.Warn,SystemLogLevel:s.SystemLogLevel.Warn,LogFormat:s.LogFormat.
30
+ Json},Code:{ZipFile:i},Environment:{Variables:r},Tags:{...e.tags,ManagedBy:"EZ4"}})));
31
+ u.Logger.logWait(c,t),await(0,s.waitUntilFunctionActive)(z,{FunctionName:t});let V=N.
32
+ FunctionArn;return e.publish?{functionVersion:await ye(t),functionArn:V}:{functionArn:V}},
33
+ "createFunction"),j=n(async(e,t)=>{u.Logger.logUpdate(c,`${e} source code`);let r=await Se(
34
+ t.sourceFile),{publish:o,architecture:i}=t,a=await w.send(new s.UpdateFunctionCodeCommand(
35
+ {Architectures:i&&[U(i)],FunctionName:e,ZipFile:r,Publish:o}));u.Logger.logWait(
36
+ c,e),await(0,s.waitUntilFunctionUpdated)(z,{FunctionName:e});let p=a.FunctionArn;
37
+ return t.publish?{functionVersion:await ye(e),functionArn:p}:{functionArn:p}},"u\
38
+ pdateSourceCode"),Z=n(async(e,t)=>{let{handlerName:r,variables:o}=t;u.Logger.logUpdate(
39
+ c,`${e} configuration`),o&&$(o);let{description:i,memory:a,timeout:p,runtime:m,debug:l,
40
+ roleArn:d,logGroup:y}=t;await w.send(new s.UpdateFunctionConfigurationCommand({Runtime:m&&
41
+ H(m),FunctionName:e,Description:i,MemorySize:a,Timeout:p,Role:d,...r&&{Handler:Fe(
42
+ r)},LoggingConfig:{LogGroup:y,ApplicationLogLevel:l?s.ApplicationLogLevel.Debug:
43
+ s.ApplicationLogLevel.Warn,SystemLogLevel:s.SystemLogLevel.Warn,LogFormat:s.LogFormat.
44
+ Json},Environment:{Variables:o}})),u.Logger.logWait(c,e),await(0,s.waitUntilFunctionUpdated)(
45
+ z,{FunctionName:e})},"updateConfiguration"),de=n(async e=>{u.Logger.logDelete(c,
46
+ e),await(0,u.waitDeletion)(async()=>{try{await w.send(new s.DeleteFunctionCommand(
47
+ {FunctionName:e}))}catch(t){if(!(t instanceof s.ResourceNotFoundException))throw t}})},
48
+ "deleteFunction"),ye=n(async e=>{u.Logger.logPublish(c,e);let t=await w.send(new s.PublishVersionCommand(
49
+ {FunctionName:e}));u.Logger.logWait(c,e);let r=t.Version;return await(0,s.waitUntilPublishedVersionActive)(
50
+ z,{FunctionName:e,Qualifier:r}),r},"publishFunction"),Q=n(async(e,t)=>{let r=(0,u.tryParseArn)(
51
+ e)?.resourceName??e;u.Logger.logTag(c,r),await w.send(new s.TagResourceCommand({
52
+ Resource:e,Tags:{...t,ManagedBy:"EZ4"}}))},"tagFunction"),fe=n(async(e,t)=>{let r=(0,u.tryParseArn)(
53
+ e)?.resourceName??e;u.Logger.logUntag(c,r),await w.send(new s.UntagResourceCommand(
54
+ {Resource:e,TagKeys:t}))},"untagFunction"),Se=n(e=>ue(e,"main.mjs"),"getSourceZi\
55
+ pFile"),Fe=n(e=>`main.${e}`,"getSourceHandlerName");var xe=n(()=>({equals:yt,create:we,replace:St,preview:ft,update:Ft,delete:xt}),"\
56
+ getFunctionHandler"),yt=n((e,t)=>!!e.result&&e.result.functionArn===t.result?.functionArn,
57
+ "equalsResource"),ft=n(async(e,t)=>{let r=e.parameters,o=t.parameters,i=(0,P.deepCompare)(
58
+ {...r,connections:e.connections,dependencies:e.dependencies,variables:E(await r.
59
+ getFunctionVariables()),sourceHash:await(0,F.getBundleHash)(...r.getFunctionFiles()),
60
+ valuesHash:r.getFunctionHash()},{...o,connections:t.connections,dependencies:t.dependencies,
56
61
  variables:t.result?.variables,sourceHash:t.result?.sourceHash,valuesHash:t.result?.
57
- valuesHash});if(i.counts)return{...i,name:n.functionName}},"previewResource"),st=r(
58
- async(e,t,n)=>{if(t.result)throw new y.ReplaceResourceError(p,e.entryId,t.entryId);
59
- return me(e,n)},"replaceResource"),me=r(async(e,t)=>{let{functionName:n,...o}=e.
60
- parameters,i=(0,W.getLogGroupName)(p,n,t),a=(0,$.getRoleArn)(p,n,t),[u,g,l,F]=await Promise.
61
- all([(0,y.getBundleHash)(...o.getFunctionFiles()),o.getFunctionBundle(t),o.getFunctionHash(),
62
- o.getFunctionVariables()]),d=await ne(n),R=await(0,b.hashFile)(g);if(d)return await B(
63
- n,{...o,variables:F,logGroup:i,roleArn:a}),await z(n,{publish:!1,sourceFile:g}),
64
- await O(d.functionArn,{...o.tags}),{functionArn:d.functionArn,functionVersion:d.
65
- functionVersion,variables:M(F),valuesHash:l,sourceHash:u,bundleHash:R,logGroup:i,
66
- roleArn:a};let H=await re({...o,publish:!0,functionName:n,sourceFile:g,variables:F,
67
- logGroup:i,roleArn:a});return{functionArn:H.functionArn,functionVersion:H.functionVersion,
68
- variables:M(F),valuesHash:l,sourceHash:u,bundleHash:R,logGroup:i,roleArn:a}},"cr\
69
- eateResource"),at=r(async(e,t,n)=>{let{parameters:o,result:i}=e;if(!i)return;let a=o.
70
- functionName,u=await o.getFunctionVariables(),g=t.result?.variables??u,l=(0,$.getRoleArn)(
71
- p,a,n),F=t.result?.roleArn??l,d=(0,W.getLogGroupName)(p,a,n),R=t.result?.logGroup??
72
- d,H={...o,variables:u,roleArn:l,logGroup:d},Ze={...t.parameters,variables:g,roleArn:F,
73
- logGroup:R};await ct(a,H,Ze),await mt(i.functionArn,o,t.parameters);let je=await ut(
74
- a,o,t.result,n);return{...i,...je,variables:M(u),logGroup:d,roleArn:l}},"updateR\
75
- esource"),pt=r(async e=>{let{result:t,parameters:n}=e;t&&await oe(n.functionName)},
76
- "deleteResource"),ct=r(async(e,t,n)=>{!(0,b.deepEqual)(t,n,{exclude:{sourceFile:!0,
77
- functionName:!0,tags:!0}})&&await B(e,t)},"checkConfigurationUpdates"),mt=r(async(e,t,n)=>{
78
- await(0,y.applyTagUpdates)(t.tags,n.tags,o=>O(e,o),o=>se(e,o))},"checkTagUpdates"),
79
- ut=r(async(e,t,n,o)=>{let[i,a]=await Promise.all([(0,y.getBundleHash)(...t.getFunctionFiles()),
80
- t.getFunctionHash()]),u=n?.sourceHash,g=n?.valuesHash;if(i!==u||a!==g||o.force){
81
- let l=await t.getFunctionBundle(o),F=await(0,b.hashFile)(l),d=n?.bundleHash;if(F===
82
- d)return y.Logger.logSkip(p,`${e} source code`),{valuesHash:a,sourceHash:i};let{
83
- functionVersion:R}=await z(e,{publish:!n?.functionVersion,sourceFile:l});return{
84
- valuesHash:a,sourceHash:i,bundleHash:F,...R&&{functionVersion:R}}}},"checkSource\
85
- CodeUpdates");var le=r(()=>{(0,ue.tryRegisterProvider)(f,ce())},"registerFunctionProvider");var xe=require("@ez4/aws-common");var Se=require("@ez4/aws-common");var q=require("@ez4/aws-common");var L=class extends Error{static{r(this,"FunctionNotFoundError")}constructor(t){
86
- super(`Function ${t} wasn't found.`)}};var k=r(e=>e.type===f,"isFunctionState"),lt=r((e,t,n)=>{try{let o=e.getServiceState(
87
- t,n);if(k(o))return o}catch{}},"tryGetFunctionState"),gt=r((e,t,n)=>{let o=e.getServiceState(
88
- t,n);if(!k(o))throw new L(t);return o},"getFunctionState"),A=r((e,t,n)=>{let o=n.
89
- getDependencies(f).at(0)?.parameters;if(!o?.functionName)throw new q.IncompleteResourceError(
90
- e,t,"functionName");return o.functionName},"getFunctionName"),ge=r(e=>e.getDependencies(
91
- f)[0]?.result?.functionArn,"tryGetFunctionArn"),dt=r((e,t,n)=>{let o=ge(n);if(!o)
92
- throw new q.IncompleteResourceError(e,t,"functionArn");return o},"getFunctionArn");var P=require("@aws-sdk/client-lambda"),Z=require("@ez4/aws-common");var C="AWS:Lambda/Permission",x="aws:lambda.permission";var de=new P.LambdaClient({}),fe=r(async e=>{Z.Logger.logCreate(C,e.functionName);
93
- let t=e.statementId??`ID${Date.now()}`;return await de.send(new P.AddPermissionCommand(
62
+ valuesHash},{exclude:{release:!0}});if(i.counts)return{...i,name:r.functionName}},
63
+ "previewResource"),St=n(async(e,t,r)=>{if(t.result)throw new F.ReplaceResourceError(
64
+ c,e.entryId,t.entryId);return we(e,r)},"replaceResource"),we=n(async(e,t)=>{let{
65
+ functionName:r,release:o,...i}=e.parameters,a=(0,_.getLogGroupName)(c,r,t),p=(0,J.getRoleArn)(
66
+ c,r,t),[m,l,d,y]=await Promise.all([(0,F.getBundleHash)(...i.getFunctionFiles()),
67
+ i.getFunctionBundle(t),i.getFunctionHash(),i.getFunctionVariables()]),f=await le(
68
+ r),b=await(0,P.hashFile)(l);if(f)return await j(r,{architecture:i.architecture,publish:!1,
69
+ sourceFile:l}),await Z(r,{...i,logGroup:a,roleArn:p,variables:{...y,...o?.variableName&&
70
+ {[o.variableName]:o.version}}}),await Q(f.functionArn,{...i.tags,...o?.tagName&&
71
+ {[o.tagName]:o.version}}),{functionArn:f.functionArn,functionVersion:f.functionVersion,
72
+ variables:E(y),valuesHash:d,sourceHash:m,bundleHash:b,logGroup:a,roleArn:p};let N=await ge(
73
+ {...i,publish:!0,functionName:r,sourceFile:l,logGroup:a,roleArn:p,variables:{...y,
74
+ ...o?.variableName&&{[o.variableName]:o.version}},tags:{...i.tags,...o?.tagName&&
75
+ {[o.tagName]:o.version}}});return{functionArn:N.functionArn,functionVersion:N.functionVersion,
76
+ variables:E(y),valuesHash:d,sourceHash:m,bundleHash:b,logGroup:a,roleArn:p}},"cr\
77
+ eateResource"),Ft=n(async(e,t,r)=>{let{parameters:o,result:i}=e;if(!i)return;let{
78
+ functionName:a}=o,p=await o.getFunctionVariables(),m=t.result?.variables??p,l=(0,J.getRoleArn)(
79
+ c,a,r),d=t.result?.roleArn??l,y=(0,_.getLogGroupName)(c,a,r),f=t.result?.logGroup??
80
+ y,{isUpdated:b,...N}=await Rt(a,o,t.result,r),V={...o,variables:p,roleArn:l,logGroup:y},
81
+ ne={...t.parameters,variables:m,roleArn:d,logGroup:f};return await wt(a,V,ne,b,r),
82
+ await vt(i.functionArn,o,t.parameters,b),{...i,...N,variables:E(p),logGroup:y,roleArn:l}},
83
+ "updateResource"),xt=n(async e=>{let{result:t,parameters:r}=e;t&&await de(r.functionName)},
84
+ "deleteResource"),wt=n(async(e,t,r,o,i)=>{let{variables:a,...p}=t,m={variables:E(
85
+ a),...p},l=!(0,P.deepEqual)(m,r,{exclude:{sourceFile:!0,functionName:!0,architecture:!0,
86
+ release:!0,tags:!0}}),d=o?t.release:r.release,y=o&&d?.variableName;(l||y||i.force)&&
87
+ await Z(e,{...t,variables:{...t.variables,...d?.variableName&&{[d.variableName]:d.
88
+ version}}})},"checkConfigurationUpdates"),vt=n(async(e,t,r,o)=>{let a=o&&t.release?.
89
+ version!==r.release?.version?t.release:void 0,p={...t.tags,...a?.tagName&&{[a.tagName]:a.
90
+ version}};await(0,F.applyTagUpdates)(p,r.tags,m=>Q(e,m),m=>fe(e,m))},"checkTagUp\
91
+ dates"),Rt=n(async(e,t,r,o)=>{let[i,a]=await Promise.all([(0,F.getBundleHash)(...t.
92
+ getFunctionFiles()),t.getFunctionHash()]),p=r?.sourceHash,m=r?.valuesHash;if(i!==
93
+ p||a!==m||o.force){let l=await t.getFunctionBundle(o),d=await(0,P.hashFile)(l),y=r?.
94
+ bundleHash;if(d===y&&a===m)return F.Logger.logSkip(c,`${e} source code`),{isUpdated:!1,
95
+ valuesHash:a,sourceHash:i};let{functionVersion:f}=await j(e,{architecture:t.architecture,
96
+ publish:!r?.functionVersion,sourceFile:l});return{isUpdated:!0,valuesHash:a,sourceHash:i,
97
+ bundleHash:d,...f&&{functionVersion:f}}}return{isUpdated:!1}},"checkSourceCodeUp\
98
+ dates");var Re=n(()=>{(0,ve.tryRegisterProvider)(S,xe())},"registerFunctionProvider");var Ie=require("@ez4/aws-common");var Ae=require("@ez4/aws-common");var K=require("@ez4/aws-common");var G=class extends Error{static{n(this,"FunctionNotFoundError")}constructor(t){
99
+ super(`Function ${t} wasn't found.`)}};var X=n(e=>e.type===S,"isFunctionState"),ht=n((e,t,r)=>{try{let o=e.getServiceState(
100
+ t,r);if(X(o))return o}catch{}},"tryGetFunctionState"),bt=n((e,t,r)=>{let o=e.getServiceState(
101
+ t,r);if(!X(o))throw new G(t);return o},"getFunctionState"),I=n((e,t,r)=>{let o=r.
102
+ getDependencies(S).at(0)?.parameters;if(!o?.functionName)throw new K.IncompleteResourceError(
103
+ e,t,"functionName");return o.functionName},"getFunctionName"),he=n(e=>e.getDependencies(
104
+ S)[0]?.result?.functionArn,"tryGetFunctionArn"),Pt=n((e,t,r)=>{let o=he(r);if(!o)
105
+ throw new K.IncompleteResourceError(e,t,"functionArn");return o},"getFunctionArn");var R=require("@aws-sdk/client-lambda"),Y=require("@ez4/aws-common");var C="AWS:Lambda/Permission",v="aws:lambda.permission";var be=new R.LambdaClient({}),Pe=n(async e=>{Y.Logger.logCreate(C,e.functionName);
106
+ let t=e.statementId??`ID${Date.now()}`;return await be.send(new R.AddPermissionCommand(
94
107
  {StatementId:t,FunctionName:e.functionName,SourceArn:e.sourceArn,Principal:e.principal,
95
- Action:e.action})),{statementId:t}},"createPermission"),ye=r(async(e,t)=>{Z.Logger.
96
- logDelete(C,e);try{return await de.send(new P.RemovePermissionCommand({FunctionName:e,
97
- StatementId:t})),!0}catch(n){if(!(n instanceof P.ResourceNotFoundException))throw n;
98
- return!1}},"deletePermission");var Fe=r(()=>({equals:ft,create:we,replace:St,preview:yt,update:Ft,delete:wt}),"\
99
- getPermissionHandler"),ft=r((e,t)=>!!e.result&&e.result.functionName===t.result?.
100
- functionName,"equalsResource"),yt=r((e,t)=>{},"previewResource"),St=r(async(e,t,n)=>{
101
- if(t.result)throw new Se.ReplaceResourceError(C,e.entryId,t.entryId);return we(e,
102
- n)},"replaceResource"),we=r(async(e,t)=>{let n=e.parameters,o=A(C,"permission",t),
103
- i=await n.getPermission(t);return{statementId:(await fe({action:"lambda:InvokeFu\
108
+ Action:e.action})),{statementId:t}},"createPermission"),Ce=n(async(e,t)=>{Y.Logger.
109
+ logDelete(C,e);try{return await be.send(new R.RemovePermissionCommand({FunctionName:e,
110
+ StatementId:t})),!0}catch(r){if(!(r instanceof R.ResourceNotFoundException))throw r;
111
+ return!1}},"deletePermission");var Ne=n(()=>({equals:Ct,create:Ee,replace:Nt,preview:At,update:Et,delete:It}),"\
112
+ getPermissionHandler"),Ct=n((e,t)=>!!e.result&&e.result.functionName===t.result?.
113
+ functionName,"equalsResource"),At=n((e,t)=>{},"previewResource"),Nt=n(async(e,t,r)=>{
114
+ if(t.result)throw new Ae.ReplaceResourceError(C,e.entryId,t.entryId);return Ee(e,
115
+ r)},"replaceResource"),Ee=n(async(e,t)=>{let r=e.parameters,o=I(C,"permission",t),
116
+ i=await r.getPermission(t);return{statementId:(await Pe({action:"lambda:InvokeFu\
104
117
  nction",sourceArn:i.sourceArn,principal:i.principal,functionName:o})).statementId,
105
- functionName:o}},"createResource"),Ft=r(async()=>{},"updateResource"),wt=r(async e=>{
106
- let t=e.result;t&&await ye(t.functionName,t.statementId)},"deleteResource");var Pe=r(()=>{(0,xe.tryRegisterProvider)(x,Fe())},"registerPermissionProvider");var Ne=require("@ez4/aws-common");var Ee=require("@ez4/aws-common"),T=require("@ez4/utils");var m=require("@aws-sdk/client-lambda"),h=require("@ez4/aws-common"),Q=require("@ez4/utils");var S="AWS:Lambda/Mapping",v="aws:lambda.mapping",j=(n=>(n.DynamoDB="dynamodb",n.
107
- Queue="sqs",n))(j||{});var N=new m.LambdaClient({}),ve=r(async(e,t)=>{h.Logger.logImport(S,e);let n=await N.
108
- send(new m.ListEventSourceMappingsCommand({FunctionName:e,EventSourceArn:t})),[o]=n.
109
- EventSourceMappings;return o?{eventId:o.UUID}:void 0},"importMapping"),Re=r(async e=>{
110
- let{sourceArn:t,functionName:n}=e;h.Logger.logCreate(S,n);let i=(await N.send(new m.CreateEventSourceMappingCommand(
111
- {FunctionName:n,EventSourceArn:t,...Ae(e)}))).UUID;return await he(i),{eventId:i}},
112
- "createMapping"),be=r(async(e,t)=>{let{functionName:n}=t;h.Logger.logUpdate(S,`${n}\
113
- (${e})`),await N.send(new m.UpdateEventSourceMappingCommand({UUID:e,FunctionName:n,
114
- ...Ae(t)})),await he(e)},"updateMapping"),Ce=r(async e=>{h.Logger.logDelete(S,e);
115
- try{return await N.send(new m.DeleteEventSourceMappingCommand({UUID:e})),!0}catch(t){
116
- if(!(t instanceof m.ResourceNotFoundException))throw t;return!1}},"deleteMapping"),
117
- xt=r(async e=>(await N.send(new m.GetEventSourceMappingCommand({UUID:e}))).State,
118
- "getMappingState"),he=r(async e=>{let t=new Set(["Enabled","Disabled"]);await Q.Wait.
119
- until(async()=>{let n=await xt(e);return t.has(n)?!0:Q.Wait.RetryAttempt})},"wai\
120
- tForReadyState"),Ae=r(e=>{let{sourceArn:t,enabled:n,concurrency:o,batch:i}=e,{service:a}=(0,h.parseArn)(
121
- t);return{Enabled:n,FunctionResponseTypes:[m.FunctionResponseType.ReportBatchItemFailures],
118
+ functionName:o}},"createResource"),Et=n(async()=>{},"updateResource"),It=n(async e=>{
119
+ let t=e.result;t&&await Ce(t.functionName,t.statementId)},"deleteResource");var Me=n(()=>{(0,Ie.tryRegisterProvider)(v,Ne())},"registerPermissionProvider");var ke=require("@ez4/aws-common");var Ge=require("@ez4/aws-common"),D=require("@ez4/utils");var g=require("@aws-sdk/client-lambda"),A=require("@ez4/aws-common"),te=require("@ez4/utils");var x="AWS:Lambda/Mapping",h="aws:lambda.mapping",ee=(r=>(r.DynamoDB="dynamodb",
120
+ r.Queue="sqs",r))(ee||{});var L=new g.LambdaClient({}),Te=n(async(e,t)=>{A.Logger.logImport(x,e);let r=await L.
121
+ send(new g.ListEventSourceMappingsCommand({FunctionName:e,EventSourceArn:t})),[o]=r.
122
+ EventSourceMappings;return o?{eventId:o.UUID}:void 0},"importMapping"),Le=n(async e=>{
123
+ let{sourceArn:t,functionName:r}=e;A.Logger.logCreate(x,r);let i=(await L.send(new g.CreateEventSourceMappingCommand(
124
+ {FunctionName:r,EventSourceArn:t,...ze(e)}))).UUID;return await Ue(i),{eventId:i}},
125
+ "createMapping"),Ve=n(async(e,t)=>{let{functionName:r}=t;A.Logger.logUpdate(x,`${r}\
126
+ (${e})`),await L.send(new g.UpdateEventSourceMappingCommand({UUID:e,FunctionName:r,
127
+ ...ze(t)})),await Ue(e)},"updateMapping"),He=n(async e=>{A.Logger.logDelete(x,e);
128
+ try{return await L.send(new g.DeleteEventSourceMappingCommand({UUID:e})),!0}catch(t){
129
+ if(!(t instanceof g.ResourceNotFoundException))throw t;return!1}},"deleteMapping"),
130
+ Mt=n(async e=>(await L.send(new g.GetEventSourceMappingCommand({UUID:e}))).State,
131
+ "getMappingState"),Ue=n(async e=>{let t=new Set(["Enabled","Disabled"]);await te.Wait.
132
+ until(async()=>{let r=await Mt(e);return t.has(r)?!0:te.Wait.RetryAttempt})},"wa\
133
+ itForReadyState"),ze=n(e=>{let{sourceArn:t,enabled:r,concurrency:o,batch:i}=e,{service:a}=(0,A.parseArn)(
134
+ t);return{Enabled:r,FunctionResponseTypes:[g.FunctionResponseType.ReportBatchItemFailures],
122
135
  MaximumBatchingWindowInSeconds:i?.maxWait,BatchSize:i?.size,...a==="dynamodb"&&{
123
- StartingPosition:m.EventSourcePosition.LATEST},...a==="sqs"&&{ScalingConfig:{MaximumConcurrency:o}}}},
124
- "upsertMappingRequest");var Ie=r(()=>({equals:Pt,create:Me,replace:Rt,preview:vt,update:bt,delete:Ct}),"\
125
- getMappingHandler"),Pt=r((e,t)=>!!e.result&&e.result.eventId===t.result?.eventId,
126
- "equalsResource"),vt=r((e,t)=>{let n={...e.parameters,dependencies:e.dependencies},
127
- o={...t.parameters,dependencies:t.dependencies},i=(0,T.deepCompare)(n,o,{exclude:{
128
- getSourceArn:!0}});if(i.counts)return{...i,name:n.fromService}},"previewResource"),
129
- Rt=r(async(e,t,n)=>{if(t.result)throw new Ee.ReplaceResourceError(S,e.entryId,t.
130
- entryId);return Me(e,n)},"replaceResource"),Me=r(async(e,t)=>{let n=e.parameters,
131
- o=A(S,"mapping",t),i=await n.getSourceArn(t);return{eventId:(await ve(o,i)??await Re(
136
+ StartingPosition:g.EventSourcePosition.LATEST},...a==="sqs"&&{ScalingConfig:{MaximumConcurrency:o}}}},
137
+ "upsertMappingRequest");var De=n(()=>({equals:Tt,create:qe,replace:Vt,preview:Lt,update:Ht,delete:Ut}),"\
138
+ getMappingHandler"),Tt=n((e,t)=>!!e.result&&e.result.eventId===t.result?.eventId,
139
+ "equalsResource"),Lt=n((e,t)=>{let r={...e.parameters,dependencies:e.dependencies},
140
+ o={...t.parameters,dependencies:t.dependencies},i=(0,D.deepCompare)(r,o,{exclude:{
141
+ getSourceArn:!0}});if(i.counts)return{...i,name:r.fromService}},"previewResource"),
142
+ Vt=n(async(e,t,r)=>{if(t.result)throw new Ge.ReplaceResourceError(x,e.entryId,t.
143
+ entryId);return qe(e,r)},"replaceResource"),qe=n(async(e,t)=>{let r=e.parameters,
144
+ o=I(x,"mapping",t),i=await r.getSourceArn(t);return{eventId:(await Te(o,i)??await Le(
132
145
  {...e.parameters,functionName:o,sourceArn:i})).eventId,functionName:o,sourceArn:i}},
133
- "createResource"),bt=r(async(e,t,n)=>{let o=e.result;if(!o)return;let i=o.sourceArn,
134
- a=A(S,"mapping",n),u=t.result?.functionName??o.functionName,g={...e.parameters,functionName:a,
135
- sourceArn:i},l={...t.parameters,functionName:u,sourceArn:i};return await ht(o.eventId,
136
- g,l),{...o,functionName:a}},"updateResource"),Ct=r(async e=>{let t=e.result;t&&await Ce(
137
- t.eventId)},"deleteResource"),ht=r(async(e,t,n)=>{!(0,T.deepEqual)(t,n,{exclude:{
138
- getSourceArn:!0,fromService:!0}})&&await be(e,t)},"checkGeneralUpdates");var He=r(()=>{(0,Ne.tryRegisterProvider)(v,Ie())},"registerMappingProvider");var Ve=r(()=>[{account:"lambda.amazonaws.com"}],"prepareIdentityAccount");var U=require("@ez4/aws-identity"),Te=require("@ez4/project/library");var E=require("@ez4/aws-identity");var Le=r(async e=>{let[t,n]=await Promise.all([(0,E.getRegion)(),(0,E.getAccountId)()]);
139
- return(0,E.createPolicyDocument)([{permissions:["logs:CreateLogStream","logs:Put\
140
- LogEvents"],resourceIds:[`arn:aws:logs:${t}:${n}:log-group:${e}-*:*`]}])},"getPo\
141
- licyDocument");var Ue=r(async e=>{let{state:t,options:n}=e,o=(0,Te.getServiceName)("",n),i=`${o}\
142
- -lambda-policy`;return(0,U.tryGetPolicy)(t,i)??(0,U.createPolicy)(t,{tags:n.tags,
143
- policyDocument:await Le(o),policyName:i})},"prepareExecutionPolicy");var At=r(()=>{(0,De.registerTriggers)(),(0,Ge.registerTriggers)(),(0,ze.registerTriggers)(),
144
- (0,Be.tryCreateTrigger)("@ez4/aws-function",{"deploy:prepareIdentityAccount":Ve,
145
- "deploy:prepareExecutionPolicy":Ue}),le(),Pe(),He()},"registerTriggers");var D=require("@ez4/utils"),Oe=require("@ez4/stateful");var Et=r((e,t,n,o)=>{let i=(0,D.toKebabCase)(o.functionName),a=(0,D.hashData)(f,
146
- t.entryId,i),u=[t.entryId];return n&&u.push(n.entryId),(0,Oe.attachEntry)(e,{type:f,
147
- entryId:a,dependencies:u,parameters:{...o,functionName:i}})},"createFunction");var $e=require("@ez4/stateful"),J=require("@ez4/utils");var We=r(e=>e.type===x,"isPermissionState");var It=r((e,t,n,o)=>{let i=(0,J.hashData)(x,t.entryId,n.entryId);return(0,$e.attachEntry)(
148
- e,{type:x,entryId:i,dependencies:[t.entryId,n.entryId],parameters:o})},"createPe\
149
- rmission"),Mt=r((e,t,n)=>{let o=(0,J.hashData)(x,t.entryId,n.entryId),i=e[o];return i&&
150
- We(i)?i:null},"getPermission");var qe=require("@ez4/utils"),ke=require("@ez4/stateful");var Nt=r((e,t,n,o)=>{let i=(0,qe.hashData)(v,t.entryId,n.entryId);return(0,ke.attachEntry)(
151
- e,{type:v,entryId:i,dependencies:[t.entryId,n.entryId],parameters:o})},"createMa\
152
- pping");var Ht=r(e=>e.type===v,"isMappingState");var Vt=r((e,t,n)=>`arn:aws:lambda:${e}:${t}:function:${n}`,"buildFunctionArn");0&&(module.exports={FunctionServiceName,FunctionServiceType,MappingService,MappingServiceName,
153
- MappingServiceType,PermissionServiceName,PermissionServiceType,buildFunctionArn,
154
- createFunction,createMapping,createPermission,getFunctionArn,getFunctionName,getFunctionState,
146
+ "createResource"),Ht=n(async(e,t,r)=>{let o=e.result;if(!o)return;let i=o.sourceArn,
147
+ a=I(x,"mapping",r),p=t.result?.functionName??o.functionName,m={...e.parameters,functionName:a,
148
+ sourceArn:i},l={...t.parameters,functionName:p,sourceArn:i};return await zt(o.eventId,
149
+ m,l),{...o,functionName:a}},"updateResource"),Ut=n(async e=>{let t=e.result;t&&await He(
150
+ t.eventId)},"deleteResource"),zt=n(async(e,t,r)=>{!(0,D.deepEqual)(t,r,{exclude:{
151
+ getSourceArn:!0,fromService:!0}})&&await Ve(e,t)},"checkGeneralUpdates");var Oe=n(()=>{(0,ke.tryRegisterProvider)(h,De())},"registerMappingProvider");var Be=n(()=>[{account:"lambda.amazonaws.com"}],"prepareIdentityAccount");var q=require("@ez4/aws-identity"),$e=require("@ez4/project/library");var M=require("@ez4/aws-identity");var We=n(async e=>{let[t,r]=await Promise.all([(0,M.getRegion)(),(0,M.getAccountId)()]);
152
+ return(0,M.createPolicyDocument)([{permissions:["logs:CreateLogStream","logs:Put\
153
+ LogEvents"],resourceIds:[`arn:aws:logs:${t}:${r}:log-group:${e}-*:*`]}])},"getPo\
154
+ licyDocument");var je=n(async e=>{let{state:t,options:r}=e,o=(0,$e.getServiceName)("",r),i=`${o}\
155
+ -lambda-policy`;return(0,q.tryGetPolicy)(t,i)??(0,q.createPolicy)(t,{tags:r.tags,
156
+ policyDocument:await We(o),policyName:i})},"prepareExecutionPolicy");var Gt=n(()=>{(0,Ze.registerTriggers)(),(0,Qe.registerTriggers)(),(0,_e.registerTriggers)(),
157
+ (0,Je.tryCreateTrigger)("@ez4/aws-function",{"deploy:prepareIdentityAccount":Be,
158
+ "deploy:prepareExecutionPolicy":je}),Re(),Me(),Oe()},"registerTriggers");var k=require("@ez4/utils"),Ke=require("@ez4/stateful");var Dt=n((e,t,r,o)=>{let i=(0,k.toKebabCase)(o.functionName),a=(0,k.hashData)(S,
159
+ t.entryId,i),p=[t.entryId];return r&&p.push(r.entryId),(0,Ke.attachEntry)(e,{type:S,
160
+ entryId:a,dependencies:p,parameters:{...o,functionName:i}})},"createFunction");var Ye=require("@ez4/stateful"),re=require("@ez4/utils");var Xe=n(e=>e.type===v,"isPermissionState");var qt=n((e,t,r,o)=>{let i=(0,re.hashData)(v,t.entryId,r.entryId);return(0,Ye.attachEntry)(
161
+ e,{type:v,entryId:i,dependencies:[t.entryId,r.entryId],parameters:o})},"createPe\
162
+ rmission"),kt=n((e,t,r)=>{let o=(0,re.hashData)(v,t.entryId,r.entryId),i=e[o];return i&&
163
+ Xe(i)?i:null},"getPermission");var et=require("@ez4/utils"),tt=require("@ez4/stateful");var Ot=n((e,t,r,o)=>{let i=(0,et.hashData)(h,t.entryId,r.entryId);return(0,tt.attachEntry)(
164
+ e,{type:h,entryId:i,dependencies:[t.entryId,r.entryId],parameters:o})},"createMa\
165
+ pping");var Bt=n(e=>e.type===h,"isMappingState");var Wt=n((e,t,r)=>`arn:aws:lambda:${e}:${t}:function:${r}`,"buildFunctionArn");var O=require("@ez4/project"),rt;(a=>(a.LogRetention=90,a.Architecture=O.ArchitectureType.
166
+ x86,a.Runtime=O.RuntimeType.Node24,a.Timeout=90,a.Memory=192))(rt||={});0&&(module.exports={FunctionArchitecture,FunctionDefaults,FunctionRuntime,FunctionServiceName,
167
+ FunctionServiceType,MappingService,MappingServiceName,MappingServiceType,PermissionServiceName,
168
+ PermissionServiceType,buildFunctionArn,createFunction,createMapping,createPermission,
169
+ getFunctionArchitecture,getFunctionArn,getFunctionName,getFunctionRuntime,getFunctionState,
155
170
  getPermission,isFunctionState,isMappingState,registerTriggers,tryGetFunctionArn,
156
171
  tryGetFunctionState});
157
172
  //# sourceMappingURL=main.cjs.map
package/dist/main.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './triggers/register';
2
- export * from './types/variables';
2
+ export * from './types/architecture';
3
+ export * from './types/runtime';
3
4
  export * from './function/service';
4
5
  export * from './function/types';
5
6
  export * from './function/utils';
@@ -9,3 +10,6 @@ export * from './mapping/service';
9
10
  export * from './mapping/types';
10
11
  export * from './mapping/utils';
11
12
  export * from './utils/arn';
13
+ export * from './utils/defaults';
14
+ export * from './utils/architecture';
15
+ export * from './utils/runtime';
package/dist/main.mjs CHANGED
@@ -1,141 +1,155 @@
1
- var he=Object.defineProperty;var r=(e,t)=>he(e,"name",{value:t,configurable:!0});import{registerTriggers as kt}from"@ez4/aws-common";import{registerTriggers as Zt}from"@ez4/aws-identity";
2
- import{registerTriggers as jt}from"@ez4/aws-logs";import{tryCreateTrigger as Qt}from"@ez4/project/library";import{tryRegisterProvider as it}from"@ez4/aws-common";import{applyTagUpdates as Ze,getBundleHash as V,Logger as je,ReplaceResourceError as Qe}from"@ez4/aws-common";
3
- import{deepCompare as Je,deepEqual as Ke,hashFile as j}from"@ez4/utils";import{getLogGroupName as Q}from"@ez4/aws-logs";
4
- import{getRoleArn as J}from"@ez4/aws-identity";import{LambdaClient as Ve,GetFunctionCommand as Le,CreateFunctionCommand as Te,DeleteFunctionCommand as Ue,
5
- UpdateFunctionCodeCommand as De,UpdateFunctionConfigurationCommand as Ge,PublishVersionCommand as ze,
6
- TagResourceCommand as Be,UntagResourceCommand as Oe,waitUntilFunctionActive as We,
7
- waitUntilFunctionUpdated as T,waitUntilPublishedVersionActive as $e,ResourceNotFoundException as U,
8
- ApplicationLogLevel as C,SystemLogLevel as D,LogFormat as G}from"@aws-sdk/client-lambda";
9
- import{Logger as c,tryParseArn as z,waitCreation as qe,waitDeletion as ke}from"@ez4/aws-common";import{InvalidParameterError as Ae}from"@ez4/aws-common";import{hashData as Ee}from"@ez4/utils";var a="AWS:Lambda/Function",d="aws:lambda.function";var Ie=/[a-z][\w]+/i,Me=r(e=>Ie.test(e),"isValidName"),I=r(e=>{for(let t in e)if(!Me(
10
- t))throw new Ae(a,`${t} is an invalid variable name .`)},"assertVariables"),P=r(
11
- e=>{let t={};for(let n in e)t[n]=Ee(e[n]);return t},"protectVariables");import Ne from"adm-zip";import{readFile as He}from"node:fs/promises";var L=r(async(e,t)=>{let n=new Ne,o=await He(e);return n.addFile(t,o),n.toBufferPromise()},
12
- "getZipBuffer");var f=new Ve({}),h={minDelay:15,maxWaitTime:1800,maxDelay:60,client:f},B=r(async(e,t)=>{
13
- c.logImport(a,e);try{let n=await f.send(new Le({FunctionName:e,Qualifier:t})),o=n.
14
- Configuration.Version,i=n.Configuration.FunctionArn;return{functionVersion:o,functionArn:i}}catch(n){
15
- if(!(n instanceof U))throw n;return}},"importFunction"),O=r(async e=>{let{functionName:t,
16
- variables:n}=e;c.logCreate(a,t),n&&I(n);let o=Z(e.handlerName),i=await k(e.sourceFile),
17
- s=await qe(()=>f.send(new Te({FunctionName:e.functionName,Description:e.description,
18
- MemorySize:e.memory,Timeout:e.timeout,Role:e.roleArn,Handler:o,Runtime:"nodejs22\
19
- .x",PackageType:"Zip",LoggingConfig:{LogGroup:e.logGroup,ApplicationLogLevel:e.debug?
20
- C.Debug:C.Warn,SystemLogLevel:D.Warn,LogFormat:G.Json},Code:{ZipFile:i},Environment:{
21
- Variables:n},Tags:{...e.tags,ManagedBy:"EZ4"}})));c.logWait(a,t),await We(h,{FunctionName:t});
22
- let p=s.FunctionArn;return e.publish?{functionVersion:await $(t),functionArn:p}:
23
- {functionArn:p}},"createFunction"),M=r(async(e,t)=>{c.logUpdate(a,`${e} source c\
24
- ode`);let n=await k(t.sourceFile),o=await f.send(new De({FunctionName:e,Publish:t.
25
- publish,ZipFile:n}));c.logWait(a,e),await T(h,{FunctionName:e});let i=o.FunctionArn;
26
- return t.publish?{functionVersion:await $(e),functionArn:i}:{functionArn:i}},"up\
27
- dateSourceCode"),N=r(async(e,t)=>{let{handlerName:n,variables:o}=t;c.logUpdate(a,
28
- `${e} configuration`),o&&I(o),await f.send(new Ge({FunctionName:e,Description:t.
29
- description,MemorySize:t.memory,Timeout:t.timeout,Role:t.roleArn,Runtime:"nodejs\
30
- 22.x",...n&&{Handler:Z(n)},LoggingConfig:{LogGroup:t.logGroup,ApplicationLogLevel:t.
31
- debug?C.Debug:C.Warn,SystemLogLevel:D.Warn,LogFormat:G.Json},Environment:{Variables:o}})),
32
- c.logWait(a,e),await T(h,{FunctionName:e})},"updateConfiguration"),W=r(async e=>{
33
- c.logDelete(a,e),await ke(async()=>{try{await f.send(new Ue({FunctionName:e}))}catch(t){
34
- if(!(t instanceof U))throw t}})},"deleteFunction"),$=r(async e=>{c.logPublish(a,
35
- e);let t=await f.send(new ze({FunctionName:e}));c.logWait(a,e);let n=t.Version;return await $e(
36
- h,{FunctionName:e,Qualifier:n}),n},"publishFunction"),H=r(async(e,t)=>{let n=z(e)?.
37
- resourceName??e;c.logTag(a,n),await f.send(new Be({Resource:e,Tags:{...t,ManagedBy:"\
38
- EZ4"}}))},"tagFunction"),q=r(async(e,t)=>{let n=z(e)?.resourceName??e;c.logUntag(
39
- a,n),await f.send(new Oe({Resource:e,TagKeys:t}))},"untagFunction"),k=r(e=>L(e,"\
40
- main.mjs"),"getSourceZipFile"),Z=r(e=>`main.${e}`,"getSourceHandlerName");var K=r(()=>({equals:_e,create:_,replace:Ye,preview:Xe,update:et,delete:tt}),"ge\
41
- tFunctionHandler"),_e=r((e,t)=>!!e.result&&e.result.functionArn===t.result?.functionArn,
42
- "equalsResource"),Xe=r(async(e,t)=>{let n=e.parameters,o=t.parameters,i=Je({...n,
43
- connections:e.connections,dependencies:e.dependencies,variables:P(await n.getFunctionVariables()),
44
- sourceHash:await V(...n.getFunctionFiles()),valuesHash:n.getFunctionHash()},{...o,
1
+ var Me=Object.defineProperty;var n=(e,t)=>Me(e,"name",{value:t,configurable:!0});import{registerTriggers as er}from"@ez4/aws-common";import{registerTriggers as tr}from"@ez4/aws-identity";
2
+ import{registerTriggers as rr}from"@ez4/aws-logs";import{tryCreateTrigger as nr}from"@ez4/project/library";import{tryRegisterProvider as dt}from"@ez4/aws-common";import{applyTagUpdates as tt,getBundleHash as z,Logger as rt,ReplaceResourceError as nt}from"@ez4/aws-common";
3
+ import{deepCompare as ot,deepEqual as it,hashFile as ee}from"@ez4/utils";import{
4
+ getLogGroupName as te}from"@ez4/aws-logs";import{getRoleArn as re}from"@ez4/aws-identity";import{LambdaClient as Oe,GetFunctionCommand as Be,CreateFunctionCommand as We,DeleteFunctionCommand as $e,
5
+ UpdateFunctionCodeCommand as je,UpdateFunctionConfigurationCommand as Ze,PublishVersionCommand as Qe,
6
+ TagResourceCommand as _e,UntagResourceCommand as Je,waitUntilFunctionActive as Ke,
7
+ waitUntilFunctionUpdated as O,waitUntilPublishedVersionActive as Xe,ResourceNotFoundException as B,
8
+ ApplicationLogLevel as A,SystemLogLevel as W,LogFormat as $}from"@aws-sdk/client-lambda";
9
+ import{Logger as g,tryParseArn as j,waitCreation as Ye,waitDeletion as et}from"@ez4/aws-common";import{RuntimeType as D}from"@ez4/project";var Te=(r=>(r.Node22="nodejs22.x",r.Node24="nodejs24.x",r))(Te||{});var Le={[D.Node22]:"nodejs22.x",[D.Node24]:"nodejs24.x"},M=n(e=>Le[e],"getFuncti\
10
+ onRuntime");import{ArchitectureType as q}from"@ez4/project";var Ve=(r=>(r.Arm="arm64",r.x86="x86_64",r))(Ve||{});var He={[q.Arm]:"arm64",[q.x86]:"x86_64"},T=n(e=>He[e],"getFunctionArchitecture");import{InvalidParameterError as Ue}from"@ez4/aws-common";import{hashData as ze}from"@ez4/utils";var p="AWS:Lambda/Function",y="aws:lambda.function";var Ge=/[a-z][\w]+/i,De=n(e=>Ge.test(e),"isValidName"),L=n(e=>{for(let t in e)if(!De(
11
+ t))throw new Ue(p,`${t} is an invalid variable name .`)},"assertVariables"),R=n(
12
+ e=>{let t={};for(let r in e)t[r]=ze(e[r]);return t},"protectVariables");import qe from"adm-zip";import{readFile as ke}from"node:fs/promises";var k=n(async(e,t)=>{let r=new qe,o=await ke(e);return r.addFile(t,o),r.toBufferPromise()},
13
+ "getZipBuffer");var f=new Oe({}),N={minDelay:15,maxWaitTime:1800,maxDelay:60,client:f},Z=n(async(e,t)=>{
14
+ g.logImport(p,e);try{let r=await f.send(new Be({FunctionName:e,Qualifier:t})),o=r.
15
+ Configuration.Version,i=r.Configuration.FunctionArn;return{functionVersion:o,functionArn:i}}catch(r){
16
+ if(!(r instanceof B))throw r;return}},"importFunction"),Q=n(async e=>{let{functionName:t,
17
+ variables:r}=e;g.logCreate(p,t),r&&L(r);let o=Y(e.handlerName),i=await X(e.sourceFile),
18
+ {description:a,memory:s,timeout:c,architecture:m,runtime:u,debug:l,roleArn:d,logGroup:x}=e,
19
+ v=await Ye(()=>f.send(new We({FunctionName:t,Description:a,MemorySize:s,Timeout:c,
20
+ Role:d,Handler:o,Architectures:[T(m)],Runtime:M(u),PackageType:"Zip",LoggingConfig:{
21
+ LogGroup:x,ApplicationLogLevel:l?A.Debug:A.Warn,SystemLogLevel:W.Warn,LogFormat:$.
22
+ Json},Code:{ZipFile:i},Environment:{Variables:r},Tags:{...e.tags,ManagedBy:"EZ4"}})));
23
+ g.logWait(p,t),await Ke(N,{FunctionName:t});let C=v.FunctionArn;return e.publish?
24
+ {functionVersion:await J(t),functionArn:C}:{functionArn:C}},"createFunction"),V=n(
25
+ async(e,t)=>{g.logUpdate(p,`${e} source code`);let r=await X(t.sourceFile),{publish:o,
26
+ architecture:i}=t,a=await f.send(new je({Architectures:i&&[T(i)],FunctionName:e,
27
+ ZipFile:r,Publish:o}));g.logWait(p,e),await O(N,{FunctionName:e});let s=a.FunctionArn;
28
+ return t.publish?{functionVersion:await J(e),functionArn:s}:{functionArn:s}},"up\
29
+ dateSourceCode"),H=n(async(e,t)=>{let{handlerName:r,variables:o}=t;g.logUpdate(p,
30
+ `${e} configuration`),o&&L(o);let{description:i,memory:a,timeout:s,runtime:c,debug:m,
31
+ roleArn:u,logGroup:l}=t;await f.send(new Ze({Runtime:c&&M(c),FunctionName:e,Description:i,
32
+ MemorySize:a,Timeout:s,Role:u,...r&&{Handler:Y(r)},LoggingConfig:{LogGroup:l,ApplicationLogLevel:m?
33
+ A.Debug:A.Warn,SystemLogLevel:W.Warn,LogFormat:$.Json},Environment:{Variables:o}})),
34
+ g.logWait(p,e),await O(N,{FunctionName:e})},"updateConfiguration"),_=n(async e=>{
35
+ g.logDelete(p,e),await et(async()=>{try{await f.send(new $e({FunctionName:e}))}catch(t){
36
+ if(!(t instanceof B))throw t}})},"deleteFunction"),J=n(async e=>{g.logPublish(p,
37
+ e);let t=await f.send(new Qe({FunctionName:e}));g.logWait(p,e);let r=t.Version;return await Xe(
38
+ N,{FunctionName:e,Qualifier:r}),r},"publishFunction"),U=n(async(e,t)=>{let r=j(e)?.
39
+ resourceName??e;g.logTag(p,r),await f.send(new _e({Resource:e,Tags:{...t,ManagedBy:"\
40
+ EZ4"}}))},"tagFunction"),K=n(async(e,t)=>{let r=j(e)?.resourceName??e;g.logUntag(
41
+ p,r),await f.send(new Je({Resource:e,TagKeys:t}))},"untagFunction"),X=n(e=>k(e,"\
42
+ main.mjs"),"getSourceZipFile"),Y=n(e=>`main.${e}`,"getSourceHandlerName");var ne=n(()=>({equals:at,create:oe,replace:pt,preview:st,update:ct,delete:mt}),"\
43
+ getFunctionHandler"),at=n((e,t)=>!!e.result&&e.result.functionArn===t.result?.functionArn,
44
+ "equalsResource"),st=n(async(e,t)=>{let r=e.parameters,o=t.parameters,i=ot({...r,
45
+ connections:e.connections,dependencies:e.dependencies,variables:R(await r.getFunctionVariables()),
46
+ sourceHash:await z(...r.getFunctionFiles()),valuesHash:r.getFunctionHash()},{...o,
45
47
  connections:t.connections,dependencies:t.dependencies,variables:t.result?.variables,
46
- sourceHash:t.result?.sourceHash,valuesHash:t.result?.valuesHash});if(i.counts)return{
47
- ...i,name:n.functionName}},"previewResource"),Ye=r(async(e,t,n)=>{if(t.result)throw new Qe(
48
- a,e.entryId,t.entryId);return _(e,n)},"replaceResource"),_=r(async(e,t)=>{let{functionName:n,
49
- ...o}=e.parameters,i=Q(a,n,t),s=J(a,n,t),[p,u,m,g]=await Promise.all([V(...o.getFunctionFiles()),
50
- o.getFunctionBundle(t),o.getFunctionHash(),o.getFunctionVariables()]),l=await B(
51
- n),F=await j(u);if(l)return await N(n,{...o,variables:g,logGroup:i,roleArn:s}),await M(
52
- n,{publish:!1,sourceFile:u}),await H(l.functionArn,{...o.tags}),{functionArn:l.functionArn,
53
- functionVersion:l.functionVersion,variables:P(g),valuesHash:m,sourceHash:p,bundleHash:F,
54
- logGroup:i,roleArn:s};let b=await O({...o,publish:!0,functionName:n,sourceFile:u,
55
- variables:g,logGroup:i,roleArn:s});return{functionArn:b.functionArn,functionVersion:b.
56
- functionVersion,variables:P(g),valuesHash:m,sourceHash:p,bundleHash:F,logGroup:i,
57
- roleArn:s}},"createResource"),et=r(async(e,t,n)=>{let{parameters:o,result:i}=e;if(!i)
58
- return;let s=o.functionName,p=await o.getFunctionVariables(),u=t.result?.variables??
59
- p,m=J(a,s,n),g=t.result?.roleArn??m,l=Q(a,s,n),F=t.result?.logGroup??l,b={...o,variables:p,
60
- roleArn:m,logGroup:l},be={...t.parameters,variables:u,roleArn:g,logGroup:F};await nt(
61
- s,b,be),await rt(i.functionArn,o,t.parameters);let Ce=await ot(s,o,t.result,n);return{
62
- ...i,...Ce,variables:P(p),logGroup:l,roleArn:m}},"updateResource"),tt=r(async e=>{
63
- let{result:t,parameters:n}=e;t&&await W(n.functionName)},"deleteResource"),nt=r(
64
- async(e,t,n)=>{!Ke(t,n,{exclude:{sourceFile:!0,functionName:!0,tags:!0}})&&await N(
65
- e,t)},"checkConfigurationUpdates"),rt=r(async(e,t,n)=>{await Ze(t.tags,n.tags,o=>H(
66
- e,o),o=>q(e,o))},"checkTagUpdates"),ot=r(async(e,t,n,o)=>{let[i,s]=await Promise.
67
- all([V(...t.getFunctionFiles()),t.getFunctionHash()]),p=n?.sourceHash,u=n?.valuesHash;
68
- if(i!==p||s!==u||o.force){let m=await t.getFunctionBundle(o),g=await j(m),l=n?.bundleHash;
69
- if(g===l)return je.logSkip(a,`${e} source code`),{valuesHash:s,sourceHash:i};let{
70
- functionVersion:F}=await M(e,{publish:!n?.functionVersion,sourceFile:m});return{
71
- valuesHash:s,sourceHash:i,bundleHash:g,...F&&{functionVersion:F}}}},"checkSource\
72
- CodeUpdates");var X=r(()=>{it(d,K())},"registerFunctionProvider");import{tryRegisterProvider as St}from"@ez4/aws-common";import{ReplaceResourceError as ut}from"@ez4/aws-common";import{IncompleteResourceError as Y}from"@ez4/aws-common";var A=class extends Error{static{r(this,"FunctionNotFoundError")}constructor(t){
73
- super(`Function ${t} wasn't found.`)}};var ee=r(e=>e.type===d,"isFunctionState"),zn=r((e,t,n)=>{try{let o=e.getServiceState(
74
- t,n);if(ee(o))return o}catch{}},"tryGetFunctionState"),Bn=r((e,t,n)=>{let o=e.getServiceState(
75
- t,n);if(!ee(o))throw new A(t);return o},"getFunctionState"),v=r((e,t,n)=>{let o=n.
76
- getDependencies(d).at(0)?.parameters;if(!o?.functionName)throw new Y(e,t,"functi\
77
- onName");return o.functionName},"getFunctionName"),st=r(e=>e.getDependencies(d)[0]?.
78
- result?.functionArn,"tryGetFunctionArn"),On=r((e,t,n)=>{let o=st(n);if(!o)throw new Y(
79
- e,t,"functionArn");return o},"getFunctionArn");import{LambdaClient as at,AddPermissionCommand as pt,RemovePermissionCommand as ct,
80
- ResourceNotFoundException as mt}from"@aws-sdk/client-lambda";import{Logger as te}from"@ez4/aws-common";var x="AWS:Lambda/Permission",S="aws:lambda.permission";var ne=new at({}),re=r(async e=>{te.logCreate(x,e.functionName);let t=e.statementId??
81
- `ID${Date.now()}`;return await ne.send(new pt({StatementId:t,FunctionName:e.functionName,
48
+ sourceHash:t.result?.sourceHash,valuesHash:t.result?.valuesHash},{exclude:{release:!0}});
49
+ if(i.counts)return{...i,name:r.functionName}},"previewResource"),pt=n(async(e,t,r)=>{
50
+ if(t.result)throw new nt(p,e.entryId,t.entryId);return oe(e,r)},"replaceResource"),
51
+ oe=n(async(e,t)=>{let{functionName:r,release:o,...i}=e.parameters,a=te(p,r,t),s=re(
52
+ p,r,t),[c,m,u,l]=await Promise.all([z(...i.getFunctionFiles()),i.getFunctionBundle(
53
+ t),i.getFunctionHash(),i.getFunctionVariables()]),d=await Z(r),x=await ee(m);if(d)
54
+ return await V(r,{architecture:i.architecture,publish:!1,sourceFile:m}),await H(
55
+ r,{...i,logGroup:a,roleArn:s,variables:{...l,...o?.variableName&&{[o.variableName]:o.
56
+ version}}}),await U(d.functionArn,{...i.tags,...o?.tagName&&{[o.tagName]:o.version}}),
57
+ {functionArn:d.functionArn,functionVersion:d.functionVersion,variables:R(l),valuesHash:u,
58
+ sourceHash:c,bundleHash:x,logGroup:a,roleArn:s};let v=await Q({...i,publish:!0,functionName:r,
59
+ sourceFile:m,logGroup:a,roleArn:s,variables:{...l,...o?.variableName&&{[o.variableName]:o.
60
+ version}},tags:{...i.tags,...o?.tagName&&{[o.tagName]:o.version}}});return{functionArn:v.
61
+ functionArn,functionVersion:v.functionVersion,variables:R(l),valuesHash:u,sourceHash:c,
62
+ bundleHash:x,logGroup:a,roleArn:s}},"createResource"),ct=n(async(e,t,r)=>{let{parameters:o,
63
+ result:i}=e;if(!i)return;let{functionName:a}=o,s=await o.getFunctionVariables(),
64
+ c=t.result?.variables??s,m=re(p,a,r),u=t.result?.roleArn??m,l=te(p,a,r),d=t.result?.
65
+ logGroup??l,{isUpdated:x,...v}=await gt(a,o,t.result,r),C={...o,variables:s,roleArn:m,
66
+ logGroup:l},G={...t.parameters,variables:c,roleArn:u,logGroup:d};return await ut(
67
+ a,C,G,x,r),await lt(i.functionArn,o,t.parameters,x),{...i,...v,variables:R(s),logGroup:l,
68
+ roleArn:m}},"updateResource"),mt=n(async e=>{let{result:t,parameters:r}=e;t&&await _(
69
+ r.functionName)},"deleteResource"),ut=n(async(e,t,r,o,i)=>{let{variables:a,...s}=t,
70
+ c={variables:R(a),...s},m=!it(c,r,{exclude:{sourceFile:!0,functionName:!0,architecture:!0,
71
+ release:!0,tags:!0}}),u=o?t.release:r.release,l=o&&u?.variableName;(m||l||i.force)&&
72
+ await H(e,{...t,variables:{...t.variables,...u?.variableName&&{[u.variableName]:u.
73
+ version}}})},"checkConfigurationUpdates"),lt=n(async(e,t,r,o)=>{let a=o&&t.release?.
74
+ version!==r.release?.version?t.release:void 0,s={...t.tags,...a?.tagName&&{[a.tagName]:a.
75
+ version}};await tt(s,r.tags,c=>U(e,c),c=>K(e,c))},"checkTagUpdates"),gt=n(async(e,t,r,o)=>{
76
+ let[i,a]=await Promise.all([z(...t.getFunctionFiles()),t.getFunctionHash()]),s=r?.
77
+ sourceHash,c=r?.valuesHash;if(i!==s||a!==c||o.force){let m=await t.getFunctionBundle(
78
+ o),u=await ee(m),l=r?.bundleHash;if(u===l&&a===c)return rt.logSkip(p,`${e} sourc\
79
+ e code`),{isUpdated:!1,valuesHash:a,sourceHash:i};let{functionVersion:d}=await V(
80
+ e,{architecture:t.architecture,publish:!r?.functionVersion,sourceFile:m});return{
81
+ isUpdated:!0,valuesHash:a,sourceHash:i,bundleHash:u,...d&&{functionVersion:d}}}return{
82
+ isUpdated:!1}},"checkSourceCodeUpdates");var ie=n(()=>{dt(y,ne())},"registerFunctionProvider");import{tryRegisterProvider as Ct}from"@ez4/aws-common";import{ReplaceResourceError as wt}from"@ez4/aws-common";import{IncompleteResourceError as ae}from"@ez4/aws-common";var E=class extends Error{static{n(this,"FunctionNotFoundError")}constructor(t){
83
+ super(`Function ${t} wasn't found.`)}};var se=n(e=>e.type===y,"isFunctionState"),sn=n((e,t,r)=>{try{let o=e.getServiceState(
84
+ t,r);if(se(o))return o}catch{}},"tryGetFunctionState"),pn=n((e,t,r)=>{let o=e.getServiceState(
85
+ t,r);if(!se(o))throw new E(t);return o},"getFunctionState"),b=n((e,t,r)=>{let o=r.
86
+ getDependencies(y).at(0)?.parameters;if(!o?.functionName)throw new ae(e,t,"funct\
87
+ ionName");return o.functionName},"getFunctionName"),yt=n(e=>e.getDependencies(y)[0]?.
88
+ result?.functionArn,"tryGetFunctionArn"),cn=n((e,t,r)=>{let o=yt(r);if(!o)throw new ae(
89
+ e,t,"functionArn");return o},"getFunctionArn");import{LambdaClient as ft,AddPermissionCommand as St,RemovePermissionCommand as Ft,
90
+ ResourceNotFoundException as xt}from"@aws-sdk/client-lambda";import{Logger as pe}from"@ez4/aws-common";var h="AWS:Lambda/Permission",F="aws:lambda.permission";var ce=new ft({}),me=n(async e=>{pe.logCreate(h,e.functionName);let t=e.statementId??
91
+ `ID${Date.now()}`;return await ce.send(new St({StatementId:t,FunctionName:e.functionName,
82
92
  SourceArn:e.sourceArn,Principal:e.principal,Action:e.action})),{statementId:t}},
83
- "createPermission"),oe=r(async(e,t)=>{te.logDelete(x,e);try{return await ne.send(
84
- new ct({FunctionName:e,StatementId:t})),!0}catch(n){if(!(n instanceof mt))throw n;
85
- return!1}},"deletePermission");var ie=r(()=>({equals:lt,create:se,replace:dt,preview:gt,update:ft,delete:yt}),"\
86
- getPermissionHandler"),lt=r((e,t)=>!!e.result&&e.result.functionName===t.result?.
87
- functionName,"equalsResource"),gt=r((e,t)=>{},"previewResource"),dt=r(async(e,t,n)=>{
88
- if(t.result)throw new ut(x,e.entryId,t.entryId);return se(e,n)},"replaceResource"),
89
- se=r(async(e,t)=>{let n=e.parameters,o=v(x,"permission",t),i=await n.getPermission(
90
- t);return{statementId:(await re({action:"lambda:InvokeFunction",sourceArn:i.sourceArn,
93
+ "createPermission"),ue=n(async(e,t)=>{pe.logDelete(h,e);try{return await ce.send(
94
+ new Ft({FunctionName:e,StatementId:t})),!0}catch(r){if(!(r instanceof xt))throw r;
95
+ return!1}},"deletePermission");var le=n(()=>({equals:vt,create:ge,replace:ht,preview:Rt,update:bt,delete:Pt}),"\
96
+ getPermissionHandler"),vt=n((e,t)=>!!e.result&&e.result.functionName===t.result?.
97
+ functionName,"equalsResource"),Rt=n((e,t)=>{},"previewResource"),ht=n(async(e,t,r)=>{
98
+ if(t.result)throw new wt(h,e.entryId,t.entryId);return ge(e,r)},"replaceResource"),
99
+ ge=n(async(e,t)=>{let r=e.parameters,o=b(h,"permission",t),i=await r.getPermission(
100
+ t);return{statementId:(await me({action:"lambda:InvokeFunction",sourceArn:i.sourceArn,
91
101
  principal:i.principal,functionName:o})).statementId,functionName:o}},"createReso\
92
- urce"),ft=r(async()=>{},"updateResource"),yt=r(async e=>{let t=e.result;t&&await oe(
93
- t.functionName,t.statementId)},"deleteResource");var ae=r(()=>{St(S,ie())},"registerPermissionProvider");import{tryRegisterProvider as Gt}from"@ez4/aws-common";import{ReplaceResourceError as It}from"@ez4/aws-common";import{deepCompare as Mt,
94
- deepEqual as Nt}from"@ez4/utils";import{LambdaClient as Ft,GetEventSourceMappingCommand as wt,CreateEventSourceMappingCommand as xt,
95
- UpdateEventSourceMappingCommand as Pt,DeleteEventSourceMappingCommand as vt,ListEventSourceMappingsCommand as Rt,
96
- FunctionResponseType as bt,EventSourcePosition as Ct,ResourceNotFoundException as ht}from"@aws-sdk/client-lambda";
97
- import{Logger as E,parseArn as At}from"@ez4/aws-common";import{Wait as ce}from"@ez4/utils";var y="AWS:Lambda/Mapping",w="aws:lambda.mapping",pe=(n=>(n.DynamoDB="dynamodb",
98
- n.Queue="sqs",n))(pe||{});var R=new Ft({}),me=r(async(e,t)=>{E.logImport(y,e);let n=await R.send(new Rt({FunctionName:e,
99
- EventSourceArn:t})),[o]=n.EventSourceMappings;return o?{eventId:o.UUID}:void 0},
100
- "importMapping"),ue=r(async e=>{let{sourceArn:t,functionName:n}=e;E.logCreate(y,
101
- n);let i=(await R.send(new xt({FunctionName:n,EventSourceArn:t,...fe(e)}))).UUID;
102
- return await de(i),{eventId:i}},"createMapping"),le=r(async(e,t)=>{let{functionName:n}=t;
103
- E.logUpdate(y,`${n} (${e})`),await R.send(new Pt({UUID:e,FunctionName:n,...fe(t)})),
104
- await de(e)},"updateMapping"),ge=r(async e=>{E.logDelete(y,e);try{return await R.
105
- send(new vt({UUID:e})),!0}catch(t){if(!(t instanceof ht))throw t;return!1}},"del\
106
- eteMapping"),Et=r(async e=>(await R.send(new wt({UUID:e}))).State,"getMappingSta\
107
- te"),de=r(async e=>{let t=new Set(["Enabled","Disabled"]);await ce.until(async()=>{
108
- let n=await Et(e);return t.has(n)?!0:ce.RetryAttempt})},"waitForReadyState"),fe=r(
109
- e=>{let{sourceArn:t,enabled:n,concurrency:o,batch:i}=e,{service:s}=At(t);return{
110
- Enabled:n,FunctionResponseTypes:[bt.ReportBatchItemFailures],MaximumBatchingWindowInSeconds:i?.
111
- maxWait,BatchSize:i?.size,...s==="dynamodb"&&{StartingPosition:Ct.LATEST},...s===
112
- "sqs"&&{ScalingConfig:{MaximumConcurrency:o}}}},"upsertMappingRequest");var ye=r(()=>({equals:Ht,create:Se,replace:Lt,preview:Vt,update:Tt,delete:Ut}),"\
113
- getMappingHandler"),Ht=r((e,t)=>!!e.result&&e.result.eventId===t.result?.eventId,
114
- "equalsResource"),Vt=r((e,t)=>{let n={...e.parameters,dependencies:e.dependencies},
115
- o={...t.parameters,dependencies:t.dependencies},i=Mt(n,o,{exclude:{getSourceArn:!0}});
116
- if(i.counts)return{...i,name:n.fromService}},"previewResource"),Lt=r(async(e,t,n)=>{
117
- if(t.result)throw new It(y,e.entryId,t.entryId);return Se(e,n)},"replaceResource"),
118
- Se=r(async(e,t)=>{let n=e.parameters,o=v(y,"mapping",t),i=await n.getSourceArn(t);
119
- return{eventId:(await me(o,i)??await ue({...e.parameters,functionName:o,sourceArn:i})).
120
- eventId,functionName:o,sourceArn:i}},"createResource"),Tt=r(async(e,t,n)=>{let o=e.
121
- result;if(!o)return;let i=o.sourceArn,s=v(y,"mapping",n),p=t.result?.functionName??
122
- o.functionName,u={...e.parameters,functionName:s,sourceArn:i},m={...t.parameters,
123
- functionName:p,sourceArn:i};return await Dt(o.eventId,u,m),{...o,functionName:s}},
124
- "updateResource"),Ut=r(async e=>{let t=e.result;t&&await ge(t.eventId)},"deleteR\
125
- esource"),Dt=r(async(e,t,n)=>{!Nt(t,n,{exclude:{getSourceArn:!0,fromService:!0}})&&
126
- await le(e,t)},"checkGeneralUpdates");var Fe=r(()=>{Gt(w,ye())},"registerMappingProvider");var we=r(()=>[{account:"lambda.amazonaws.com"}],"prepareIdentityAccount");import{createPolicy as Wt,tryGetPolicy as $t}from"@ez4/aws-identity";import{getServiceName as qt}from"@ez4/project/library";import{getAccountId as zt,getRegion as Bt,createPolicyDocument as Ot}from"@ez4/aws-identity";var xe=r(async e=>{let[t,n]=await Promise.all([Bt(),zt()]);return Ot([{permissions:[
127
- "logs:CreateLogStream","logs:PutLogEvents"],resourceIds:[`arn:aws:logs:${t}:${n}\
128
- :log-group:${e}-*:*`]}])},"getPolicyDocument");var Pe=r(async e=>{let{state:t,options:n}=e,o=qt("",n),i=`${o}-lambda-policy`;return $t(
129
- t,i)??Wt(t,{tags:n.tags,policyDocument:await xe(o),policyName:i})},"prepareExecu\
130
- tionPolicy");var kr=r(()=>{kt(),Zt(),jt(),Qt("@ez4/aws-function",{"deploy:prepareIdentityAcco\
131
- unt":we,"deploy:prepareExecutionPolicy":Pe}),X(),ae(),Fe()},"registerTriggers");import{toKebabCase as Jt,hashData as Kt}from"@ez4/utils";import{attachEntry as _t}from"@ez4/stateful";var _r=r((e,t,n,o)=>{let i=Jt(o.functionName),s=Kt(d,t.entryId,i),p=[t.entryId];
132
- return n&&p.push(n.entryId),_t(e,{type:d,entryId:s,dependencies:p,parameters:{...o,
133
- functionName:i}})},"createFunction");import{attachEntry as Xt}from"@ez4/stateful";import{hashData as Re}from"@ez4/utils";var ve=r(e=>e.type===S,"isPermissionState");var ao=r((e,t,n,o)=>{let i=Re(S,t.entryId,n.entryId);return Xt(e,{type:S,entryId:i,
134
- dependencies:[t.entryId,n.entryId],parameters:o})},"createPermission"),po=r((e,t,n)=>{
135
- let o=Re(S,t.entryId,n.entryId),i=e[o];return i&&ve(i)?i:null},"getPermission");import{hashData as Yt}from"@ez4/utils";import{attachEntry as en}from"@ez4/stateful";var fo=r((e,t,n,o)=>{let i=Yt(w,t.entryId,n.entryId);return en(e,{type:w,entryId:i,
136
- dependencies:[t.entryId,n.entryId],parameters:o})},"createMapping");var wo=r(e=>e.type===w,"isMappingState");var vo=r((e,t,n)=>`arn:aws:lambda:${e}:${t}:function:${n}`,"buildFunctionArn");export{a as FunctionServiceName,d as FunctionServiceType,pe as MappingService,y as MappingServiceName,
137
- w as MappingServiceType,x as PermissionServiceName,S as PermissionServiceType,vo as buildFunctionArn,
138
- _r as createFunction,fo as createMapping,ao as createPermission,On as getFunctionArn,
139
- v as getFunctionName,Bn as getFunctionState,po as getPermission,ee as isFunctionState,
140
- wo as isMappingState,kr as registerTriggers,st as tryGetFunctionArn,zn as tryGetFunctionState};
102
+ urce"),bt=n(async()=>{},"updateResource"),Pt=n(async e=>{let t=e.result;t&&await ue(
103
+ t.functionName,t.statementId)},"deleteResource");var de=n(()=>{Ct(F,le())},"registerPermissionProvider");import{tryRegisterProvider as Zt}from"@ez4/aws-common";import{ReplaceResourceError as Gt}from"@ez4/aws-common";import{deepCompare as Dt,
104
+ deepEqual as qt}from"@ez4/utils";import{LambdaClient as At,GetEventSourceMappingCommand as Nt,CreateEventSourceMappingCommand as Et,
105
+ UpdateEventSourceMappingCommand as It,DeleteEventSourceMappingCommand as Mt,ListEventSourceMappingsCommand as Tt,
106
+ FunctionResponseType as Lt,EventSourcePosition as Vt,ResourceNotFoundException as Ht}from"@aws-sdk/client-lambda";
107
+ import{Logger as I,parseArn as Ut}from"@ez4/aws-common";import{Wait as fe}from"@ez4/utils";var S="AWS:Lambda/Mapping",w="aws:lambda.mapping",ye=(r=>(r.DynamoDB="dynamodb",
108
+ r.Queue="sqs",r))(ye||{});var P=new At({}),Se=n(async(e,t)=>{I.logImport(S,e);let r=await P.send(new Tt({FunctionName:e,
109
+ EventSourceArn:t})),[o]=r.EventSourceMappings;return o?{eventId:o.UUID}:void 0},
110
+ "importMapping"),Fe=n(async e=>{let{sourceArn:t,functionName:r}=e;I.logCreate(S,
111
+ r);let i=(await P.send(new Et({FunctionName:r,EventSourceArn:t,...Re(e)}))).UUID;
112
+ return await ve(i),{eventId:i}},"createMapping"),xe=n(async(e,t)=>{let{functionName:r}=t;
113
+ I.logUpdate(S,`${r} (${e})`),await P.send(new It({UUID:e,FunctionName:r,...Re(t)})),
114
+ await ve(e)},"updateMapping"),we=n(async e=>{I.logDelete(S,e);try{return await P.
115
+ send(new Mt({UUID:e})),!0}catch(t){if(!(t instanceof Ht))throw t;return!1}},"del\
116
+ eteMapping"),zt=n(async e=>(await P.send(new Nt({UUID:e}))).State,"getMappingSta\
117
+ te"),ve=n(async e=>{let t=new Set(["Enabled","Disabled"]);await fe.until(async()=>{
118
+ let r=await zt(e);return t.has(r)?!0:fe.RetryAttempt})},"waitForReadyState"),Re=n(
119
+ e=>{let{sourceArn:t,enabled:r,concurrency:o,batch:i}=e,{service:a}=Ut(t);return{
120
+ Enabled:r,FunctionResponseTypes:[Lt.ReportBatchItemFailures],MaximumBatchingWindowInSeconds:i?.
121
+ maxWait,BatchSize:i?.size,...a==="dynamodb"&&{StartingPosition:Vt.LATEST},...a===
122
+ "sqs"&&{ScalingConfig:{MaximumConcurrency:o}}}},"upsertMappingRequest");var he=n(()=>({equals:kt,create:be,replace:Bt,preview:Ot,update:Wt,delete:$t}),"\
123
+ getMappingHandler"),kt=n((e,t)=>!!e.result&&e.result.eventId===t.result?.eventId,
124
+ "equalsResource"),Ot=n((e,t)=>{let r={...e.parameters,dependencies:e.dependencies},
125
+ o={...t.parameters,dependencies:t.dependencies},i=Dt(r,o,{exclude:{getSourceArn:!0}});
126
+ if(i.counts)return{...i,name:r.fromService}},"previewResource"),Bt=n(async(e,t,r)=>{
127
+ if(t.result)throw new Gt(S,e.entryId,t.entryId);return be(e,r)},"replaceResource"),
128
+ be=n(async(e,t)=>{let r=e.parameters,o=b(S,"mapping",t),i=await r.getSourceArn(t);
129
+ return{eventId:(await Se(o,i)??await Fe({...e.parameters,functionName:o,sourceArn:i})).
130
+ eventId,functionName:o,sourceArn:i}},"createResource"),Wt=n(async(e,t,r)=>{let o=e.
131
+ result;if(!o)return;let i=o.sourceArn,a=b(S,"mapping",r),s=t.result?.functionName??
132
+ o.functionName,c={...e.parameters,functionName:a,sourceArn:i},m={...t.parameters,
133
+ functionName:s,sourceArn:i};return await jt(o.eventId,c,m),{...o,functionName:a}},
134
+ "updateResource"),$t=n(async e=>{let t=e.result;t&&await we(t.eventId)},"deleteR\
135
+ esource"),jt=n(async(e,t,r)=>{!qt(t,r,{exclude:{getSourceArn:!0,fromService:!0}})&&
136
+ await xe(e,t)},"checkGeneralUpdates");var Pe=n(()=>{Zt(w,he())},"registerMappingProvider");var Ce=n(()=>[{account:"lambda.amazonaws.com"}],"prepareIdentityAccount");import{createPolicy as Kt,tryGetPolicy as Xt}from"@ez4/aws-identity";import{getServiceName as Yt}from"@ez4/project/library";import{getAccountId as Qt,getRegion as _t,createPolicyDocument as Jt}from"@ez4/aws-identity";var Ae=n(async e=>{let[t,r]=await Promise.all([_t(),Qt()]);return Jt([{permissions:[
137
+ "logs:CreateLogStream","logs:PutLogEvents"],resourceIds:[`arn:aws:logs:${t}:${r}\
138
+ :log-group:${e}-*:*`]}])},"getPolicyDocument");var Ne=n(async e=>{let{state:t,options:r}=e,o=Yt("",r),i=`${o}-lambda-policy`;return Xt(
139
+ t,i)??Kt(t,{tags:r.tags,policyDocument:await Ae(o),policyName:i})},"prepareExecu\
140
+ tionPolicy");var go=n(()=>{er(),tr(),rr(),nr("@ez4/aws-function",{"deploy:prepareIdentityAcco\
141
+ unt":Ce,"deploy:prepareExecutionPolicy":Ne}),ie(),de(),Pe()},"registerTriggers");import{toKebabCase as or,hashData as ir}from"@ez4/utils";import{attachEntry as ar}from"@ez4/stateful";var wo=n((e,t,r,o)=>{let i=or(o.functionName),a=ir(y,t.entryId,i),s=[t.entryId];
142
+ return r&&s.push(r.entryId),ar(e,{type:y,entryId:a,dependencies:s,parameters:{...o,
143
+ functionName:i}})},"createFunction");import{attachEntry as sr}from"@ez4/stateful";import{hashData as Ie}from"@ez4/utils";var Ee=n(e=>e.type===F,"isPermissionState");var Io=n((e,t,r,o)=>{let i=Ie(F,t.entryId,r.entryId);return sr(e,{type:F,entryId:i,
144
+ dependencies:[t.entryId,r.entryId],parameters:o})},"createPermission"),Mo=n((e,t,r)=>{
145
+ let o=Ie(F,t.entryId,r.entryId),i=e[o];return i&&Ee(i)?i:null},"getPermission");import{hashData as pr}from"@ez4/utils";import{attachEntry as cr}from"@ez4/stateful";var zo=n((e,t,r,o)=>{let i=pr(w,t.entryId,r.entryId);return cr(e,{type:w,entryId:i,
146
+ dependencies:[t.entryId,r.entryId],parameters:o})},"createMapping");var ko=n(e=>e.type===w,"isMappingState");var Wo=n((e,t,r)=>`arn:aws:lambda:${e}:${t}:function:${r}`,"buildFunctionArn");import{ArchitectureType as mr,RuntimeType as ur}from"@ez4/project";var lr;(a=>(a.
147
+ LogRetention=90,a.Architecture=mr.x86,a.Runtime=ur.Node24,a.Timeout=90,a.Memory=
148
+ 192))(lr||={});export{Ve as FunctionArchitecture,lr as FunctionDefaults,Te as FunctionRuntime,p as FunctionServiceName,
149
+ y as FunctionServiceType,ye as MappingService,S as MappingServiceName,w as MappingServiceType,
150
+ h as PermissionServiceName,F as PermissionServiceType,Wo as buildFunctionArn,wo as createFunction,
151
+ zo as createMapping,Io as createPermission,T as getFunctionArchitecture,cn as getFunctionArn,
152
+ b as getFunctionName,M as getFunctionRuntime,pn as getFunctionState,Mo as getPermission,
153
+ se as isFunctionState,ko as isMappingState,go as registerTriggers,yt as tryGetFunctionArn,
154
+ sn as tryGetFunctionState};
141
155
  //# sourceMappingURL=main.mjs.map
@@ -0,0 +1,4 @@
1
+ export declare const enum FunctionArchitecture {
2
+ Arm = "arm64",
3
+ x86 = "x86_64"
4
+ }
@@ -0,0 +1,4 @@
1
+ export declare const enum FunctionRuntime {
2
+ Node22 = "nodejs22.x",
3
+ Node24 = "nodejs24.x"
4
+ }
@@ -0,0 +1,3 @@
1
+ import { ArchitectureType } from '@ez4/project';
2
+ import { FunctionArchitecture } from '../types/architecture';
3
+ export declare const getFunctionArchitecture: (architecture: ArchitectureType) => FunctionArchitecture;
@@ -0,0 +1,23 @@
1
+ import { ArchitectureType, RuntimeType } from '@ez4/project';
2
+ export declare namespace FunctionDefaults {
3
+ /**
4
+ * Default log retention in days.
5
+ */
6
+ const LogRetention = 15;
7
+ /**
8
+ * Default function architecture.
9
+ */
10
+ const Architecture = ArchitectureType.x86;
11
+ /**
12
+ * Default function runtime.
13
+ */
14
+ const Runtime = RuntimeType.Node24;
15
+ /**
16
+ * Default function timeout.
17
+ */
18
+ const Timeout = 90;
19
+ /**
20
+ * Default function memory.
21
+ */
22
+ const Memory = 192;
23
+ }
@@ -0,0 +1,3 @@
1
+ import { RuntimeType } from '@ez4/project';
2
+ import { FunctionRuntime } from '../types/runtime';
3
+ export declare const getFunctionRuntime: (runtime: RuntimeType) => FunctionRuntime;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ez4/aws-function",
3
3
  "description": "EZ4: Self-managed AWS lambda function provider",
4
- "version": "0.37.0",
4
+ "version": "0.39.0",
5
5
  "author": "Silas B.",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -42,13 +42,14 @@
42
42
  "live:publish": "npm run build && npm publish --access public"
43
43
  },
44
44
  "dependencies": {
45
- "@aws-sdk/client-lambda": "^3.913.0",
46
- "@ez4/aws-common": "^0.37.0",
47
- "@ez4/aws-identity": "^0.37.0",
48
- "@ez4/aws-logs": "^0.37.0",
49
- "@ez4/project": "^0.37.0",
50
- "@ez4/stateful": "^0.37.0",
51
- "@ez4/utils": "^0.37.0",
45
+ "@aws-sdk/client-lambda": "^3.958.0",
46
+ "@ez4/aws-common": "^0.39.0",
47
+ "@ez4/aws-identity": "^0.39.0",
48
+ "@ez4/aws-logs": "^0.39.0",
49
+ "@ez4/project": "^0.39.0",
50
+ "@ez4/common": "^0.39.0",
51
+ "@ez4/stateful": "^0.39.0",
52
+ "@ez4/utils": "^0.39.0",
52
53
  "@types/adm-zip": "^0.5.5",
53
54
  "adm-zip": "^0.5.14"
54
55
  }
@@ -1,3 +0,0 @@
1
- export type FunctionVariables = {
2
- [name: string]: string;
3
- };