sdk-aws-lambda 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{domain.operations/askLambdaEndpoint/invoke/genLambdaClient.d.ts → access/sdks/lambda/genLambdaSdk.d.ts} +2 -2
- package/dist/{domain.operations/askLambdaEndpoint/invoke/genLambdaClient.js → access/sdks/lambda/genLambdaSdk.js} +7 -7
- package/dist/access/sdks/lambda/genLambdaSdk.js.map +1 -0
- package/dist/{domain.operations/askLambdaEndpoint/invoke → access/sdks/lambda}/sdkLambdaInvoke.d.ts +6 -2
- package/dist/{domain.operations/askLambdaEndpoint/invoke → access/sdks/lambda}/sdkLambdaInvoke.js +6 -3
- package/dist/access/sdks/lambda/sdkLambdaInvoke.js.map +1 -0
- package/dist/contract/cli/asGenArgs.d.ts +21 -0
- package/dist/contract/cli/asGenArgs.js +69 -0
- package/dist/contract/cli/asGenArgs.js.map +1 -0
- package/dist/contract/cli/gen.d.ts +23 -0
- package/dist/contract/cli/gen.js +72 -0
- package/dist/contract/cli/gen.js.map +1 -0
- package/dist/domain.objects/ContextAwsLambdaCaller.d.ts +25 -0
- package/dist/domain.objects/ContextAwsLambdaCaller.js +3 -0
- package/dist/domain.objects/ContextAwsLambdaCaller.js.map +1 -0
- package/dist/domain.objects/ContextAwsLambdaServer.d.ts +30 -0
- package/dist/domain.objects/ContextAwsLambdaServer.js +3 -0
- package/dist/domain.objects/ContextAwsLambdaServer.js.map +1 -0
- package/dist/domain.objects/DomainObjectCaptured.d.ts +51 -0
- package/dist/domain.objects/DomainObjectCaptured.js +8 -0
- package/dist/domain.objects/DomainObjectCaptured.js.map +1 -0
- package/dist/domain.objects/GeneratedFile.d.ts +18 -0
- package/dist/domain.objects/GeneratedFile.js +8 -0
- package/dist/domain.objects/GeneratedFile.js.map +1 -0
- package/dist/domain.objects/HttpStatusCode.d.ts +2 -2
- package/dist/domain.objects/HttpStatusCode.js +3 -3
- package/dist/domain.objects/LambdaCredentialsAbsentError.d.ts +11 -0
- package/dist/domain.objects/LambdaCredentialsAbsentError.js +16 -0
- package/dist/domain.objects/LambdaCredentialsAbsentError.js.map +1 -0
- package/dist/domain.objects/LambdaDomainObjectNotCapturableError.d.ts +12 -0
- package/dist/domain.objects/LambdaDomainObjectNotCapturableError.js +17 -0
- package/dist/domain.objects/LambdaDomainObjectNotCapturableError.js.map +1 -0
- package/dist/domain.objects/LambdaDomainObjectRefUnbindableError.d.ts +14 -0
- package/dist/domain.objects/LambdaDomainObjectRefUnbindableError.js +19 -0
- package/dist/domain.objects/LambdaDomainObjectRefUnbindableError.js.map +1 -0
- package/dist/domain.objects/LambdaEndpoint.d.ts +35 -0
- package/dist/domain.objects/LambdaEndpoint.js +10 -0
- package/dist/domain.objects/LambdaEndpoint.js.map +1 -0
- package/dist/domain.objects/LambdaEndpointError.d.ts +5 -8
- package/dist/domain.objects/LambdaEndpointError.js.map +1 -1
- package/dist/domain.objects/LambdaEndpointSchema.d.ts +9 -0
- package/dist/domain.objects/LambdaEndpointSchema.js +3 -0
- package/dist/domain.objects/LambdaEndpointSchema.js.map +1 -0
- package/dist/domain.objects/LambdaFunctionNotFoundError.d.ts +10 -0
- package/dist/domain.objects/LambdaFunctionNotFoundError.js +15 -0
- package/dist/domain.objects/LambdaFunctionNotFoundError.js.map +1 -0
- package/dist/domain.objects/LambdaIntrospectionBlockedError.d.ts +10 -0
- package/dist/domain.objects/LambdaIntrospectionBlockedError.js +15 -0
- package/dist/domain.objects/LambdaIntrospectionBlockedError.js.map +1 -0
- package/dist/domain.objects/LambdaIntrospectionNotSupportedError.d.ts +18 -0
- package/dist/domain.objects/LambdaIntrospectionNotSupportedError.js +15 -0
- package/dist/domain.objects/LambdaIntrospectionNotSupportedError.js.map +1 -0
- package/dist/domain.objects/LambdaServiceNotFoundError.d.ts +10 -0
- package/dist/domain.objects/LambdaServiceNotFoundError.js +15 -0
- package/dist/domain.objects/LambdaServiceNotFoundError.js.map +1 -0
- package/dist/domain.operations/asLambdaEndpoint/asLambdaEndpoint.d.ts +20 -0
- package/dist/domain.operations/asLambdaEndpoint/asLambdaEndpoint.js +47 -0
- package/dist/domain.operations/asLambdaEndpoint/asLambdaEndpoint.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.d.ts +2 -12
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.js +13 -22
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.js.map +1 -1
- package/dist/domain.operations/askLambdaEndpoint/cache/asCachedExecutor.d.ts +2 -2
- package/dist/domain.operations/askLambdaEndpoint/cache/asCachedExecutor.js.map +1 -1
- package/dist/domain.operations/askLambdaEndpoint/cache/getAskLambdaCacheKey.d.ts +3 -4
- package/dist/domain.operations/askLambdaEndpoint/cache/getAskLambdaCacheKey.js +17 -5
- package/dist/domain.operations/askLambdaEndpoint/cache/getAskLambdaCacheKey.js.map +1 -1
- package/dist/domain.operations/askLambdaEndpoint/error/getStatusCodeHint.d.ts +1 -1
- package/dist/domain.operations/askLambdaEndpoint/error/getStatusCodeHint.js +3 -3
- package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.d.ts +13 -8
- package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.js +20 -19
- package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.js.map +1 -1
- package/dist/domain.operations/askLambdaEndpoint/serde/asUnprefixedErrorMessage.d.ts +13 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asUnprefixedErrorMessage.js +26 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asUnprefixedErrorMessage.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getParsedResponse.d.ts +2 -2
- package/dist/domain.operations/askLambdaEndpoint/serde/getParsedResponse.js +15 -14
- package/dist/domain.operations/askLambdaEndpoint/serde/getParsedResponse.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.d.ts +15 -8
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js +16 -9
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getCorsOrigin.d.ts +3 -3
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getCorsOrigin.js +5 -5
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getIsV2ApiGatewayEvent.d.ts +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getIsV2ApiGatewayEvent.js +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.js +88 -63
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.d.ts +7 -9
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.js +14 -11
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.js +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.d.ts +22 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.getJsonSchemaFromZod.d.ts +7 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.getJsonSchemaFromZod.js +13 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.getJsonSchemaFromZod.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.isIntrospectionPayload.d.ts +5 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.isIntrospectionPayload.js +16 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.isIntrospectionPayload.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.js +53 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.js +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.d.ts +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/getValidationError.d.ts +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/getValidationError.js +12 -4
- package/dist/domain.operations/genLambdaEndpoint/middleware/getValidationError.js.map +1 -1
- package/dist/domain.operations/genServiceSdk/asServiceSymbols/asServiceSymbols.d.ts +16 -0
- package/dist/domain.operations/genServiceSdk/asServiceSymbols/asServiceSymbols.js +36 -0
- package/dist/domain.operations/genServiceSdk/asServiceSymbols/asServiceSymbols.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.file/asBarrelFileSource.d.ts +10 -0
- package/dist/domain.operations/genServiceSdk/gen.file/asBarrelFileSource.js +18 -0
- package/dist/domain.operations/genServiceSdk/gen.file/asBarrelFileSource.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.file/asMechanismsFileSource.d.ts +14 -0
- package/dist/domain.operations/genServiceSdk/gen.file/asMechanismsFileSource.js +44 -0
- package/dist/domain.operations/genServiceSdk/gen.file/asMechanismsFileSource.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.file/asResourcesFileSource.d.ts +11 -0
- package/dist/domain.operations/genServiceSdk/gen.file/asResourcesFileSource.js +42 -0
- package/dist/domain.operations/genServiceSdk/gen.file/asResourcesFileSource.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.file/banner.d.ts +9 -0
- package/dist/domain.operations/genServiceSdk/gen.file/banner.js +16 -0
- package/dist/domain.operations/genServiceSdk/gen.file/banner.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.file/formatTypescript.d.ts +20 -0
- package/dist/domain.operations/genServiceSdk/gen.file/formatTypescript.js +44 -0
- package/dist/domain.operations/genServiceSdk/gen.file/formatTypescript.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.file/setGeneratedFilesBatch.d.ts +13 -0
- package/dist/domain.operations/genServiceSdk/gen.file/setGeneratedFilesBatch.js +49 -0
- package/dist/domain.operations/genServiceSdk/gen.file/setGeneratedFilesBatch.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.mechanism/asMechanismFnSource.d.ts +16 -0
- package/dist/domain.operations/genServiceSdk/gen.mechanism/asMechanismFnSource.js +39 -0
- package/dist/domain.operations/genServiceSdk/gen.mechanism/asMechanismFnSource.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.mechanism/getTypescriptFromJsonSchema.d.ts +35 -0
- package/dist/domain.operations/genServiceSdk/gen.mechanism/getTypescriptFromJsonSchema.js +189 -0
- package/dist/domain.operations/genServiceSdk/gen.mechanism/getTypescriptFromJsonSchema.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/asDomainObjectPragma.d.ts +15 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/asDomainObjectPragma.js +37 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/asDomainObjectPragma.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/asResourceClassSource.d.ts +26 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/asResourceClassSource.js +106 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/asResourceClassSource.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/assertAllDomainObjectRefsBind.d.ts +15 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/assertAllDomainObjectRefsBind.js +51 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/assertAllDomainObjectRefsBind.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/getAllDomainObjectsFromContracts.d.ts +14 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/getAllDomainObjectsFromContracts.js +68 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/getAllDomainObjectsFromContracts.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/genServiceSdk.d.ts +20 -0
- package/dist/domain.operations/genServiceSdk/genServiceSdk.js +88 -0
- package/dist/domain.operations/genServiceSdk/genServiceSdk.js.map +1 -0
- package/dist/domain.operations/getAllLambdaContracts/getAllLambdaContracts.d.ts +33 -0
- package/dist/domain.operations/getAllLambdaContracts/getAllLambdaContracts.js +134 -0
- package/dist/domain.operations/getAllLambdaContracts/getAllLambdaContracts.js.map +1 -0
- package/dist/domain.operations/getAllLambdaContracts/lambdaContract/asContractRecord.d.ts +6 -0
- package/dist/domain.operations/getAllLambdaContracts/lambdaContract/asContractRecord.js +12 -0
- package/dist/domain.operations/getAllLambdaContracts/lambdaContract/asContractRecord.js.map +1 -0
- package/dist/domain.operations/getAllLambdaContracts/lambdaFunction/getAllLambdaFunctionsByPrefix.d.ts +15 -0
- package/dist/domain.operations/getAllLambdaContracts/lambdaFunction/getAllLambdaFunctionsByPrefix.js +44 -0
- package/dist/domain.operations/getAllLambdaContracts/lambdaFunction/getAllLambdaFunctionsByPrefix.js.map +1 -0
- package/dist/domain.operations/getAllLambdaContracts/lambdaFunction/sdkLambdaGetAllFunctions.d.ts +16 -0
- package/dist/domain.operations/getAllLambdaContracts/lambdaFunction/sdkLambdaGetAllFunctions.js +26 -0
- package/dist/domain.operations/getAllLambdaContracts/lambdaFunction/sdkLambdaGetAllFunctions.js.map +1 -0
- package/dist/domain.operations/getOneLambdaContract/asLambdaEndpointSchema.d.ts +16 -0
- package/dist/domain.operations/getOneLambdaContract/asLambdaEndpointSchema.js +76 -0
- package/dist/domain.operations/getOneLambdaContract/asLambdaEndpointSchema.js.map +1 -0
- package/dist/domain.operations/getOneLambdaContract/getOneLambdaContract.d.ts +32 -0
- package/dist/domain.operations/getOneLambdaContract/getOneLambdaContract.js +112 -0
- package/dist/domain.operations/getOneLambdaContract/getOneLambdaContract.js.map +1 -0
- package/dist/index.d.ts +19 -1
- package/dist/index.js +35 -2
- package/dist/index.js.map +1 -1
- package/package.json +19 -14
- package/readme.md +64 -4
- package/dist/domain.operations/askLambdaEndpoint/context/getAccessFromContext.d.ts +0 -11
- package/dist/domain.operations/askLambdaEndpoint/context/getAccessFromContext.js +0 -21
- package/dist/domain.operations/askLambdaEndpoint/context/getAccessFromContext.js.map +0 -1
- package/dist/domain.operations/askLambdaEndpoint/invoke/genLambdaClient.js.map +0 -1
- package/dist/domain.operations/askLambdaEndpoint/invoke/sdkLambdaInvoke.js.map +0 -1
- package/dist/domain.operations/askLambdaEndpoint/serde/getLambdaFunctionName.d.ts +0 -9
- package/dist/domain.operations/askLambdaEndpoint/serde/getLambdaFunctionName.js +0 -12
- package/dist/domain.operations/askLambdaEndpoint/serde/getLambdaFunctionName.js.map +0 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllDomainObjectsFromContracts = void 0;
|
|
4
|
+
const LambdaDomainObjectNotCapturableError_1 = require("../../../domain.objects/LambdaDomainObjectNotCapturableError");
|
|
5
|
+
const asDomainObjectPragma_1 = require("./asDomainObjectPragma");
|
|
6
|
+
/**
|
|
7
|
+
* .what = collect every domain-object captured across a service's contracts,
|
|
8
|
+
* de-duplicated by name
|
|
9
|
+
* .why = the resources file declares each captured dobj once; a dobj referenced
|
|
10
|
+
* by many endpoints must yield a single declaration (uc.2 dedupe)
|
|
11
|
+
*
|
|
12
|
+
* .throws LambdaDomainObjectNotCapturableError — a pragma-tagged node whose shape
|
|
13
|
+
* cannot be reconstructed (no object properties) (uc.9)
|
|
14
|
+
*/
|
|
15
|
+
const getAllDomainObjectsFromContracts = (input) => {
|
|
16
|
+
// collect every dobj contract from every endpoint's input + output schemas
|
|
17
|
+
const captured = new Map();
|
|
18
|
+
// walk each endpoint's input and output schema trees
|
|
19
|
+
for (const schema of Object.values(input.contracts)) {
|
|
20
|
+
collectFromNode({ node: schema.input, captured });
|
|
21
|
+
collectFromNode({ node: schema.output, captured });
|
|
22
|
+
}
|
|
23
|
+
// return the de-duplicated contracts in stable (name-sorted) order
|
|
24
|
+
return [...captured.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
25
|
+
};
|
|
26
|
+
exports.getAllDomainObjectsFromContracts = getAllDomainObjectsFromContracts;
|
|
27
|
+
/**
|
|
28
|
+
* .what = recursively walk a json-schema node, collect every `x-domain-object`
|
|
29
|
+
* .why = a dobj can appear at any depth (properties, items, $defs, anyOf, etc.)
|
|
30
|
+
*/
|
|
31
|
+
const collectFromNode = (input) => {
|
|
32
|
+
const { node, captured } = input;
|
|
33
|
+
// skip non-object nodes (leaves like strings/booleans/numbers)
|
|
34
|
+
if (typeof node !== 'object' || node === null)
|
|
35
|
+
return;
|
|
36
|
+
// capture this node if it carries a domain-object pragma
|
|
37
|
+
const contract = (0, asDomainObjectPragma_1.asDomainObjectPragma)({ node: node });
|
|
38
|
+
if (contract) {
|
|
39
|
+
// fail loud if the pragma names a dobj with no reconstructable shape (uc.9)
|
|
40
|
+
if (!getIsCapturableShape(node))
|
|
41
|
+
throw new LambdaDomainObjectNotCapturableError_1.LambdaDomainObjectNotCapturableError(`domain-object '${contract.name}' cannot be captured: its object schema declares no properties to reconstruct`, {
|
|
42
|
+
name: contract.name,
|
|
43
|
+
hint: 'ensure the domain-object schema declares its properties (an empty object schema cannot be captured)',
|
|
44
|
+
});
|
|
45
|
+
// keep the first capture; a repeat of the same name is a de-dup no-op
|
|
46
|
+
if (!captured.has(contract.name))
|
|
47
|
+
captured.set(contract.name, contract);
|
|
48
|
+
}
|
|
49
|
+
// recurse into every child value (arrays + nested objects)
|
|
50
|
+
for (const value of Object.values(node)) {
|
|
51
|
+
if (Array.isArray(value))
|
|
52
|
+
for (const item of value)
|
|
53
|
+
collectFromNode({ node: item, captured });
|
|
54
|
+
else
|
|
55
|
+
collectFromNode({ node: value, captured });
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* .what = decide whether a schema node has an object shape we can reconstruct
|
|
60
|
+
* .why = a dobj resource needs properties to emit; a pragma without them is uncapturable
|
|
61
|
+
*/
|
|
62
|
+
const getIsCapturableShape = (node) => {
|
|
63
|
+
const properties = node.properties;
|
|
64
|
+
return (typeof properties === 'object' &&
|
|
65
|
+
properties !== null &&
|
|
66
|
+
Object.keys(properties).length > 0);
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=getAllDomainObjectsFromContracts.js.map
|
package/dist/domain.operations/genServiceSdk/gen.resource/getAllDomainObjectsFromContracts.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAllDomainObjectsFromContracts.js","sourceRoot":"","sources":["../../../../src/domain.operations/genServiceSdk/gen.resource/getAllDomainObjectsFromContracts.ts"],"names":[],"mappings":";;;AAGA,uHAAoH;AAEpH,iEAA8D;AAE9D;;;;;;;;GAQG;AACI,MAAM,gCAAgC,GAAG,CAAC,KAEhD,EAA0B,EAAE;IAC3B,2EAA2E;IAC3E,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAgC,CAAC;IAEzD,qDAAqD;IACrD,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;QACpD,eAAe,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QAClD,eAAe,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,EAA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E,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;;YACjE,eAAe,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;IAClD,CAAC;AACH,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAW,EAAE;IACrD,MAAM,UAAU,GAAI,IAAiC,CAAC,UAAU,CAAC;IACjE,OAAO,CACL,OAAO,UAAU,KAAK,QAAQ;QAC9B,UAAU,KAAK,IAAI;QACnB,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,CACnC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ContextAwsLambdaCaller } from '../../domain.objects/ContextAwsLambdaCaller';
|
|
2
|
+
import type { GeneratedFile } from '../../domain.objects/GeneratedFile';
|
|
3
|
+
/**
|
|
4
|
+
* .what = generate a per-service sdk from live lambda contract introspection
|
|
5
|
+
* .why = the whole codegen: discover a service's contracts, capture its
|
|
6
|
+
* domain-objects, and emit the three files (barrel + mechanisms +
|
|
7
|
+
* resources) atomically into the target dir (uc.1, uc.2)
|
|
8
|
+
*
|
|
9
|
+
* .all-or-none = all file content is assembled in memory first; only after every
|
|
10
|
+
* transform succeeds is it written, via one atomic batch call — so any
|
|
11
|
+
* discovery/capture/fs error leaves zero files written (uc.5/6/8/9)
|
|
12
|
+
*/
|
|
13
|
+
export declare const genServiceSdk: (input: {
|
|
14
|
+
which: {
|
|
15
|
+
service: string;
|
|
16
|
+
};
|
|
17
|
+
into: string;
|
|
18
|
+
}, context: ContextAwsLambdaCaller) => Promise<{
|
|
19
|
+
files: GeneratedFile[];
|
|
20
|
+
}>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.genServiceSdk = void 0;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const getAllLambdaContracts_1 = require("../getAllLambdaContracts/getAllLambdaContracts");
|
|
6
|
+
const asServiceSymbols_1 = require("./asServiceSymbols/asServiceSymbols");
|
|
7
|
+
const asBarrelFileSource_1 = require("./gen.file/asBarrelFileSource");
|
|
8
|
+
const asMechanismsFileSource_1 = require("./gen.file/asMechanismsFileSource");
|
|
9
|
+
const asResourcesFileSource_1 = require("./gen.file/asResourcesFileSource");
|
|
10
|
+
const formatTypescript_1 = require("./gen.file/formatTypescript");
|
|
11
|
+
const setGeneratedFilesBatch_1 = require("./gen.file/setGeneratedFilesBatch");
|
|
12
|
+
const assertAllDomainObjectRefsBind_1 = require("./gen.resource/assertAllDomainObjectRefsBind");
|
|
13
|
+
const getAllDomainObjectsFromContracts_1 = require("./gen.resource/getAllDomainObjectsFromContracts");
|
|
14
|
+
/**
|
|
15
|
+
* .what = generate a per-service sdk from live lambda contract introspection
|
|
16
|
+
* .why = the whole codegen: discover a service's contracts, capture its
|
|
17
|
+
* domain-objects, and emit the three files (barrel + mechanisms +
|
|
18
|
+
* resources) atomically into the target dir (uc.1, uc.2)
|
|
19
|
+
*
|
|
20
|
+
* .all-or-none = all file content is assembled in memory first; only after every
|
|
21
|
+
* transform succeeds is it written, via one atomic batch call — so any
|
|
22
|
+
* discovery/capture/fs error leaves zero files written (uc.5/6/8/9)
|
|
23
|
+
*/
|
|
24
|
+
const genServiceSdk = async (input, context) => {
|
|
25
|
+
// discover the service's endpoint contracts (prep-gated by the spine)
|
|
26
|
+
const contracts = await (0, getAllLambdaContracts_1.getAllLambdaContracts)({ which: { service: input.which.service } }, context);
|
|
27
|
+
// derive the codegen symbols (object name + dobj prefix)
|
|
28
|
+
const symbols = (0, asServiceSymbols_1.asServiceSymbols)({ service: input.which.service });
|
|
29
|
+
// capture every domain-object referenced across the contracts (de-duped)
|
|
30
|
+
const dobjs = (0, getAllDomainObjectsFromContracts_1.getAllDomainObjectsFromContracts)({ contracts });
|
|
31
|
+
// fail loud if any dobj REFERENCE (by key) names a dobj captured by no endpoint —
|
|
32
|
+
// its `typeof Svc<Prefix><Name>` resource would not exist (all-or-none, exit 2)
|
|
33
|
+
(0, assertAllDomainObjectRefsBind_1.assertAllDomainObjectRefsBind)({
|
|
34
|
+
contracts,
|
|
35
|
+
capturedNames: new Set(dobjs.map((dobj) => dobj.name)),
|
|
36
|
+
});
|
|
37
|
+
// build the ref map: each dobj name → its prefixed resource name
|
|
38
|
+
const dobjRefs = Object.fromEntries(dobjs.map((dobj) => [dobj.name, `${symbols.prefix}${dobj.name}`]));
|
|
39
|
+
const resourceNames = dobjs.map((dobj) => `${symbols.prefix}${dobj.name}`);
|
|
40
|
+
// the module specifiers the generated files use to import each other
|
|
41
|
+
const resourcesModule = `./${symbols.object}.resources`;
|
|
42
|
+
const mechanismsModule = `./${symbols.object}.mechanisms`;
|
|
43
|
+
// assemble the three file texts in memory
|
|
44
|
+
const resourcesText = (0, asResourcesFileSource_1.asResourcesFileSource)({
|
|
45
|
+
dobjs,
|
|
46
|
+
prefix: symbols.prefix,
|
|
47
|
+
dobjRefs,
|
|
48
|
+
});
|
|
49
|
+
const mechanismsText = (0, asMechanismsFileSource_1.asMechanismsFileSource)({
|
|
50
|
+
service: input.which.service,
|
|
51
|
+
object: symbols.object,
|
|
52
|
+
resourcesModule,
|
|
53
|
+
resourceNames,
|
|
54
|
+
contracts,
|
|
55
|
+
dobjRefs,
|
|
56
|
+
});
|
|
57
|
+
const barrelText = (0, asBarrelFileSource_1.asBarrelFileSource)({
|
|
58
|
+
object: symbols.object,
|
|
59
|
+
mechanismsModule,
|
|
60
|
+
resourcesModule,
|
|
61
|
+
});
|
|
62
|
+
// pair each text with its target path
|
|
63
|
+
const drafts = [
|
|
64
|
+
{ path: (0, node_path_1.join)(input.into, `${symbols.object}.ts`), content: barrelText },
|
|
65
|
+
{
|
|
66
|
+
path: (0, node_path_1.join)(input.into, `${symbols.object}.mechanisms.ts`),
|
|
67
|
+
content: mechanismsText,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
path: (0, node_path_1.join)(input.into, `${symbols.object}.resources.ts`),
|
|
71
|
+
content: resourcesText,
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
// format each file's text through biome (its real target path drives which
|
|
75
|
+
// biome config applies) — clean, drop-in output, not our own whitespace
|
|
76
|
+
const files = await Promise.all(drafts.map(async (draft) => ({
|
|
77
|
+
path: draft.path,
|
|
78
|
+
content: await (0, formatTypescript_1.formatTypescript)({
|
|
79
|
+
content: draft.content,
|
|
80
|
+
path: draft.path,
|
|
81
|
+
}),
|
|
82
|
+
})));
|
|
83
|
+
// write all files atomically (all-or-none)
|
|
84
|
+
await (0, setGeneratedFilesBatch_1.setGeneratedFilesBatch)({ files });
|
|
85
|
+
return { files };
|
|
86
|
+
};
|
|
87
|
+
exports.genServiceSdk = genServiceSdk;
|
|
88
|
+
//# sourceMappingURL=genServiceSdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genServiceSdk.js","sourceRoot":"","sources":["../../../src/domain.operations/genServiceSdk/genServiceSdk.ts"],"names":[],"mappings":";;;AAAA,yCAAiC;AAGjC,0FAAuF;AACvF,0EAAuE;AACvE,sEAAmE;AACnE,8EAA2E;AAC3E,4EAAyE;AACzE,kEAA+D;AAC/D,8EAA2E;AAC3E,gGAA6F;AAC7F,sGAAmG;AAEnG;;;;;;;;;GASG;AACI,MAAM,aAAa,GAAG,KAAK,EAChC,KAGC,EACD,OAA+B,EACM,EAAE;IACvC,sEAAsE;IACtE,MAAM,SAAS,GAAG,MAAM,IAAA,6CAAqB,EAC3C,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,EAC3C,OAAO,CACR,CAAC;IAEF,yDAAyD;IACzD,MAAM,OAAO,GAAG,IAAA,mCAAgB,EAAC,EAAE,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAA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;QAChB,eAAe;KAChB,CAAC,CAAC;IAEH,sCAAsC;IACtC,MAAM,MAAM,GAAoB;QAC9B,EAAE,IAAI,EAAE,IAAA,gBAAI,EAAC,KAAK,CAAC,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE;QACvE;YACE,IAAI,EAAE,IAAA,gBAAI,EAAC,KAAK,CAAC,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,gBAAgB,CAAC;YACzD,OAAO,EAAE,cAAc;SACxB;QACD;YACE,IAAI,EAAE,IAAA,gBAAI,EAAC,KAAK,CAAC,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,eAAe,CAAC;YACxD,OAAO,EAAE,aAAa;SACvB;KACF,CAAC;IAEF,2EAA2E;IAC3E,wEAAwE;IACxE,MAAM,KAAK,GAAoB,MAAM,OAAO,CAAC,GAAG,CAC9C,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QAC3B,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,MAAM,IAAA,mCAAgB,EAAC;YAC9B,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,IAAI,EAAE,KAAK,CAAC,IAAI;SACjB,CAAC;KACH,CAAC,CAAC,CACJ,CAAC;IAEF,2CAA2C;IAC3C,MAAM,IAAA,+CAAsB,EAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAExC,OAAO,EAAE,KAAK,EAAE,CAAC;AACnB,CAAC,CAAC;AArFW,QAAA,aAAa,iBAqFxB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ContextAwsLambdaCaller } from '../../domain.objects/ContextAwsLambdaCaller';
|
|
2
|
+
import type { LambdaEndpointSchema } from '../../domain.objects/LambdaEndpointSchema';
|
|
3
|
+
/**
|
|
4
|
+
* .what = get all lambda contracts for a service
|
|
5
|
+
* .why = enables runtime schema discovery for sdk generation
|
|
6
|
+
*
|
|
7
|
+
* behavior:
|
|
8
|
+
* - lists all lambda endpoints by service+access prefix
|
|
9
|
+
* - introspects each via getOneLambdaContract
|
|
10
|
+
* - all-or-none: if any endpoint does not support introspection, the whole
|
|
11
|
+
* batch fails loud (a partial contract set would generate a broken sdk)
|
|
12
|
+
* - returns as record keyed by bare function name (endpoint.function)
|
|
13
|
+
*
|
|
14
|
+
* .throws LambdaServiceNotFoundError — no endpoints found for service
|
|
15
|
+
* .throws LambdaIntrospectionBlockedError — introspection blocked in prod/test
|
|
16
|
+
* .throws LambdaIntrospectionNotSupportedError — an endpoint in the service does
|
|
17
|
+
* not support introspection (named in the error); the batch is all-or-none
|
|
18
|
+
*/
|
|
19
|
+
export declare const getAllLambdaContracts: (input: {
|
|
20
|
+
which: {
|
|
21
|
+
service: string;
|
|
22
|
+
};
|
|
23
|
+
}, context: ContextAwsLambdaCaller) => Promise<Record<string, LambdaEndpointSchema>>;
|
|
24
|
+
/**
|
|
25
|
+
* .what = input type for getAllLambdaContracts
|
|
26
|
+
* .why = exported for sdk consumers
|
|
27
|
+
*/
|
|
28
|
+
export type GetAllLambdaContractsInput = Parameters<typeof getAllLambdaContracts>[0];
|
|
29
|
+
/**
|
|
30
|
+
* .what = context type for getAllLambdaContracts
|
|
31
|
+
* .why = exported for sdk consumers
|
|
32
|
+
*/
|
|
33
|
+
export type GetAllLambdaContractsContext = Parameters<typeof getAllLambdaContracts>[1];
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getAllLambdaContracts = void 0;
|
|
27
|
+
const LambdaCredentialsAbsentError_1 = require("../../domain.objects/LambdaCredentialsAbsentError");
|
|
28
|
+
const LambdaIntrospectionBlockedError_1 = require("../../domain.objects/LambdaIntrospectionBlockedError");
|
|
29
|
+
const LambdaServiceNotFoundError_1 = require("../../domain.objects/LambdaServiceNotFoundError");
|
|
30
|
+
const asLambdaEndpoint_1 = require("../asLambdaEndpoint/asLambdaEndpoint");
|
|
31
|
+
const getOneLambdaContract_1 = require("../getOneLambdaContract/getOneLambdaContract");
|
|
32
|
+
const asContractRecord_1 = require("./lambdaContract/asContractRecord");
|
|
33
|
+
const getAllLambdaFunctionsByPrefix_1 = require("./lambdaFunction/getAllLambdaFunctionsByPrefix");
|
|
34
|
+
/**
|
|
35
|
+
* .what = get all lambda contracts for a service
|
|
36
|
+
* .why = enables runtime schema discovery for sdk generation
|
|
37
|
+
*
|
|
38
|
+
* behavior:
|
|
39
|
+
* - lists all lambda endpoints by service+access prefix
|
|
40
|
+
* - introspects each via getOneLambdaContract
|
|
41
|
+
* - all-or-none: if any endpoint does not support introspection, the whole
|
|
42
|
+
* batch fails loud (a partial contract set would generate a broken sdk)
|
|
43
|
+
* - returns as record keyed by bare function name (endpoint.function)
|
|
44
|
+
*
|
|
45
|
+
* .throws LambdaServiceNotFoundError — no endpoints found for service
|
|
46
|
+
* .throws LambdaIntrospectionBlockedError — introspection blocked in prod/test
|
|
47
|
+
* .throws LambdaIntrospectionNotSupportedError — an endpoint in the service does
|
|
48
|
+
* not support introspection (named in the error); the batch is all-or-none
|
|
49
|
+
*/
|
|
50
|
+
const getAllLambdaContracts = async (input, context) => {
|
|
51
|
+
// fail fast if introspection is blocked: only prep exposes schemas
|
|
52
|
+
// (gate up front so no request is made and no schema can leak)
|
|
53
|
+
if (context.env.access !== 'prep') {
|
|
54
|
+
throw new LambdaIntrospectionBlockedError_1.LambdaIntrospectionBlockedError(`introspection is only available in prep environment, got: ${context.env.access}`, {
|
|
55
|
+
service: input.which.service,
|
|
56
|
+
access: context.env.access,
|
|
57
|
+
hint: 're-run with --env prep',
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
// build prefix from service + access
|
|
61
|
+
const prefix = `${input.which.service}-${context.env.access}-`;
|
|
62
|
+
// get or create LambdaClient (genLambdaSdk always returns valid client)
|
|
63
|
+
const sdkLambda = context.aws?.lambda?.sdk ??
|
|
64
|
+
(await Promise.resolve().then(() => __importStar(require('../../access/sdks/lambda/genLambdaSdk'))).then((m) => m.genLambdaSdk({ env: { region: context.env.region } })));
|
|
65
|
+
// discover endpoint slugs by prefix. a creds failure surfaces on this first aws
|
|
66
|
+
// call — map it to a caller-must-fix LambdaCredentialsAbsentError (with an unlock
|
|
67
|
+
// hint), not a raw aws CredentialsProviderError
|
|
68
|
+
const slugs = await (0, getAllLambdaFunctionsByPrefix_1.getAllLambdaFunctionsByPrefix)({ prefix }, { sdkLambda }).catch((error) => throwIfCredentialsError({
|
|
69
|
+
error,
|
|
70
|
+
service: input.which.service,
|
|
71
|
+
access: context.env.access,
|
|
72
|
+
}));
|
|
73
|
+
// throw if no endpoints found
|
|
74
|
+
if (slugs.length === 0) {
|
|
75
|
+
throw new LambdaServiceNotFoundError_1.LambdaServiceNotFoundError(`no lambda functions found for service: ${input.which.service}`, {
|
|
76
|
+
service: input.which.service,
|
|
77
|
+
prefix,
|
|
78
|
+
hint: 'check the --for service name and verify it is deployed to the prep environment',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
// log the discovered endpoints for observability
|
|
82
|
+
context.log.debug('getAllLambdaContracts.discovered', {
|
|
83
|
+
service: input.which.service,
|
|
84
|
+
count: slugs.length,
|
|
85
|
+
});
|
|
86
|
+
// reuse the resolved sdk so getOneLambdaContract does not rebuild it per call
|
|
87
|
+
const contextWithSdk = { ...context, aws: { lambda: { sdk: sdkLambda } } };
|
|
88
|
+
// introspect each endpoint in parallel via getOneLambdaContract (build on getOne)
|
|
89
|
+
// all-or-none: an unsupported endpoint rejects here and aborts the batch
|
|
90
|
+
const entries = await Promise.all(slugs.map(async (slug) => {
|
|
91
|
+
const endpoint = (0, asLambdaEndpoint_1.asLambdaEndpoint)({ slug });
|
|
92
|
+
const schema = await (0, getOneLambdaContract_1.getOneLambdaContract)({
|
|
93
|
+
which: {
|
|
94
|
+
service: endpoint.service,
|
|
95
|
+
function: endpoint.function,
|
|
96
|
+
},
|
|
97
|
+
}, contextWithSdk);
|
|
98
|
+
return [endpoint.function, schema];
|
|
99
|
+
}));
|
|
100
|
+
// assemble record keyed by bare function name
|
|
101
|
+
return (0, asContractRecord_1.asContractRecord)(entries);
|
|
102
|
+
};
|
|
103
|
+
exports.getAllLambdaContracts = getAllLambdaContracts;
|
|
104
|
+
/**
|
|
105
|
+
* .what = decide whether an error is an aws sdk credentials failure
|
|
106
|
+
* .why = a creds failure is caller-must-fix (unlock + retry), not a malfunction —
|
|
107
|
+
* the discovery boundary maps it to a hinted LambdaCredentialsAbsentError
|
|
108
|
+
*/
|
|
109
|
+
const getIsCredentialsError = (error) => {
|
|
110
|
+
if (!(error instanceof Error))
|
|
111
|
+
return false;
|
|
112
|
+
const name = error.name.toLowerCase();
|
|
113
|
+
const message = error.message.toLowerCase();
|
|
114
|
+
return (name.includes('credential') ||
|
|
115
|
+
message.includes('credential') ||
|
|
116
|
+
(message.includes('security token') && message.includes('expired')));
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* .what = map an aws credentials failure to a hinted LambdaCredentialsAbsentError
|
|
120
|
+
* .why = surface a creds failure with an unlock hint (caller-must-fix) rather than a
|
|
121
|
+
* raw aws error; any non-creds error rethrows unchanged. returns `never` — it
|
|
122
|
+
* always throws — so the caller keeps a non-null slug list.
|
|
123
|
+
*/
|
|
124
|
+
const throwIfCredentialsError = (input) => {
|
|
125
|
+
if (!getIsCredentialsError(input.error))
|
|
126
|
+
throw input.error;
|
|
127
|
+
throw new LambdaCredentialsAbsentError_1.LambdaCredentialsAbsentError('aws credentials are absent or expired; cannot introspect', {
|
|
128
|
+
service: input.service,
|
|
129
|
+
access: input.access,
|
|
130
|
+
hint: 'unlock prep creds (e.g. `rhx keyrack unlock --owner ehmpath --env prep`), then re-run',
|
|
131
|
+
cause: input.error instanceof Error ? input.error : undefined,
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=getAllLambdaContracts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAllLambdaContracts.js","sourceRoot":"","sources":["../../../src/domain.operations/getAllLambdaContracts/getAllLambdaContracts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,oGAAiG;AAEjG,0GAAuG;AACvG,gGAA6F;AAC7F,2EAAwE;AACxE,uFAAoF;AACpF,wEAAqE;AACrE,kGAA+F;AAE/F;;;;;;;;;;;;;;;GAeG;AACI,MAAM,qBAAqB,GAAG,KAAK,EACxC,KAIC,EACD,OAA+B,EACgB,EAAE;IACjD,mEAAmE;IACnE,+DAA+D;IAC/D,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,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IAC5C,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;QAC3B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;QAC9B,CAAC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CACpE,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,uBAAuB,GAAG,CAAC,KAIhC,EAAS,EAAE;IACV,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,KAAK,CAAC;QAAE,MAAM,KAAK,CAAC,KAAK,CAAC;IAC3D,MAAM,IAAI,2DAA4B,CACpC,0DAA0D,EAC1D;QACE,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,IAAI,EAAE,uFAAuF;QAC7F,KAAK,EAAE,KAAK,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;KAC9D,CACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { LambdaEndpointSchema } from '../../../domain.objects/LambdaEndpointSchema';
|
|
2
|
+
/**
|
|
3
|
+
* .what = transform array of [functionName, schema] tuples to Record
|
|
4
|
+
* .why = enables keyed lookup of contracts by function name
|
|
5
|
+
*/
|
|
6
|
+
export declare const asContractRecord: (contracts: Array<[string, LambdaEndpointSchema]>) => Record<string, LambdaEndpointSchema>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asContractRecord = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = transform array of [functionName, schema] tuples to Record
|
|
6
|
+
* .why = enables keyed lookup of contracts by function name
|
|
7
|
+
*/
|
|
8
|
+
const asContractRecord = (contracts) => {
|
|
9
|
+
return Object.fromEntries(contracts);
|
|
10
|
+
};
|
|
11
|
+
exports.asContractRecord = asContractRecord;
|
|
12
|
+
//# sourceMappingURL=asContractRecord.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asContractRecord.js","sourceRoot":"","sources":["../../../../src/domain.operations/getAllLambdaContracts/lambdaContract/asContractRecord.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACI,MAAM,gBAAgB,GAAG,CAC9B,SAAgD,EACV,EAAE;IACxC,OAAO,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;AACvC,CAAC,CAAC;AAJW,QAAA,gBAAgB,oBAI3B"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LambdaClient } from '@aws-sdk/client-lambda';
|
|
2
|
+
/**
|
|
3
|
+
* .what = get all lambda endpoint slugs that match a prefix
|
|
4
|
+
* .why = enables discovery of lambda endpoints for contract introspection
|
|
5
|
+
*
|
|
6
|
+
* behavior:
|
|
7
|
+
* - paginates through all functions in the aws account
|
|
8
|
+
* - filters by prefix
|
|
9
|
+
* - returns slugs (aws function names, not full ARNs)
|
|
10
|
+
*/
|
|
11
|
+
export declare const getAllLambdaFunctionsByPrefix: (input: {
|
|
12
|
+
prefix: string;
|
|
13
|
+
}, context: {
|
|
14
|
+
sdkLambda: LambdaClient;
|
|
15
|
+
}) => Promise<string[]>;
|
package/dist/domain.operations/getAllLambdaContracts/lambdaFunction/getAllLambdaFunctionsByPrefix.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllLambdaFunctionsByPrefix = void 0;
|
|
4
|
+
const sdkLambdaGetAllFunctions_1 = require("./sdkLambdaGetAllFunctions");
|
|
5
|
+
/**
|
|
6
|
+
* .what = filter slugs by prefix
|
|
7
|
+
* .why = extract transformation from orchestrator for clear grain separation
|
|
8
|
+
*/
|
|
9
|
+
const getMatchedSlugs = (input) => {
|
|
10
|
+
return input.slugs.filter((slug) => slug.startsWith(input.prefix));
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* .what = recursively fetch pages of functions and collect matched slugs
|
|
14
|
+
* .why = avoids mutation via push, enables functional pagination
|
|
15
|
+
*/
|
|
16
|
+
const collectPagesRecursive = async (input, context) => {
|
|
17
|
+
// fetch page from communicator
|
|
18
|
+
const page = await (0, sdkLambdaGetAllFunctions_1.sdkLambdaGetAllFunctions)({ marker: input.marker }, { sdkLambda: context.sdkLambda });
|
|
19
|
+
// filter by prefix via transformer
|
|
20
|
+
const matched = getMatchedSlugs({
|
|
21
|
+
slugs: page.slugs,
|
|
22
|
+
prefix: input.prefix,
|
|
23
|
+
});
|
|
24
|
+
// combine collected with this page
|
|
25
|
+
const nextCollected = [...input.collected, ...matched];
|
|
26
|
+
// recurse if more pages, otherwise return
|
|
27
|
+
if (!page.nextMarker)
|
|
28
|
+
return nextCollected;
|
|
29
|
+
return collectPagesRecursive({ ...input, marker: page.nextMarker, collected: nextCollected }, context);
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* .what = get all lambda endpoint slugs that match a prefix
|
|
33
|
+
* .why = enables discovery of lambda endpoints for contract introspection
|
|
34
|
+
*
|
|
35
|
+
* behavior:
|
|
36
|
+
* - paginates through all functions in the aws account
|
|
37
|
+
* - filters by prefix
|
|
38
|
+
* - returns slugs (aws function names, not full ARNs)
|
|
39
|
+
*/
|
|
40
|
+
const getAllLambdaFunctionsByPrefix = async (input, context) => {
|
|
41
|
+
return collectPagesRecursive({ prefix: input.prefix, marker: undefined, collected: [] }, context);
|
|
42
|
+
};
|
|
43
|
+
exports.getAllLambdaFunctionsByPrefix = getAllLambdaFunctionsByPrefix;
|
|
44
|
+
//# sourceMappingURL=getAllLambdaFunctionsByPrefix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAllLambdaFunctionsByPrefix.js","sourceRoot":"","sources":["../../../../src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E,EAC1D,OAAO,CACR,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,6BAA6B,iCAYxC"}
|
package/dist/domain.operations/getAllLambdaContracts/lambdaFunction/sdkLambdaGetAllFunctions.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type LambdaClient } from '@aws-sdk/client-lambda';
|
|
2
|
+
/**
|
|
3
|
+
* .what = list lambda function slugs via aws sdk
|
|
4
|
+
* .why = communicator encapsulates raw aws sdk i/o at boundary
|
|
5
|
+
*
|
|
6
|
+
* .note = aws function names ARE endpoint slugs; sdkLambda (the client
|
|
7
|
+
* dependency) is injected via context
|
|
8
|
+
*/
|
|
9
|
+
export declare const sdkLambdaGetAllFunctions: (input: {
|
|
10
|
+
marker?: string;
|
|
11
|
+
}, context: {
|
|
12
|
+
sdkLambda: LambdaClient;
|
|
13
|
+
}) => Promise<{
|
|
14
|
+
slugs: string[];
|
|
15
|
+
nextMarker: string | undefined;
|
|
16
|
+
}>;
|
package/dist/domain.operations/getAllLambdaContracts/lambdaFunction/sdkLambdaGetAllFunctions.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sdkLambdaGetAllFunctions = void 0;
|
|
4
|
+
const client_lambda_1 = require("@aws-sdk/client-lambda");
|
|
5
|
+
/**
|
|
6
|
+
* .what = list lambda function slugs via aws sdk
|
|
7
|
+
* .why = communicator encapsulates raw aws sdk i/o at boundary
|
|
8
|
+
*
|
|
9
|
+
* .note = aws function names ARE endpoint slugs; sdkLambda (the client
|
|
10
|
+
* dependency) is injected via context
|
|
11
|
+
*/
|
|
12
|
+
const sdkLambdaGetAllFunctions = async (input, context) => {
|
|
13
|
+
const result = await context.sdkLambda.send(new client_lambda_1.ListFunctionsCommand({
|
|
14
|
+
Marker: input.marker,
|
|
15
|
+
MaxItems: 50,
|
|
16
|
+
}));
|
|
17
|
+
const slugs = (result.Functions ?? [])
|
|
18
|
+
.map((fn) => fn.FunctionName)
|
|
19
|
+
.filter((name) => name !== undefined);
|
|
20
|
+
return {
|
|
21
|
+
slugs,
|
|
22
|
+
nextMarker: result.NextMarker,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
exports.sdkLambdaGetAllFunctions = sdkLambdaGetAllFunctions;
|
|
26
|
+
//# sourceMappingURL=sdkLambdaGetAllFunctions.js.map
|
package/dist/domain.operations/getAllLambdaContracts/lambdaFunction/sdkLambdaGetAllFunctions.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdkLambdaGetAllFunctions.js","sourceRoot":"","sources":["../../../../src/domain.operations/getAllLambdaContracts/lambdaFunction/sdkLambdaGetAllFunctions.ts"],"names":[],"mappings":";;;AAAA,0DAGgC;AAEhC;;;;;;GAMG;AACI,MAAM,wBAAwB,GAAG,KAAK,EAC3C,KAEC,EACD,OAEC,EAIA,EAAE;IACH,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,IAAI,CACzC,IAAI,oCAAoB,CAAC;QACvB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,QAAQ,EAAE,EAAE;KACb,CAAC,CACH,CAAC;IAEF,MAAM,KAAK,GAAG,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC;SACnC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,YAAY,CAAC;SAC5B,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IAExD,OAAO;QACL,KAAK;QACL,UAAU,EAAE,MAAM,CAAC,UAAU;KAC9B,CAAC;AACJ,CAAC,CAAC;AA1BW,QAAA,wBAAwB,4BA0BnC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { LambdaEndpoint } from '../../domain.objects/LambdaEndpoint';
|
|
2
|
+
import type { LambdaEndpointSchema } from '../../domain.objects/LambdaEndpointSchema';
|
|
3
|
+
/**
|
|
4
|
+
* .what = cast a lambda response payload into a LambdaEndpointSchema
|
|
5
|
+
* .why = a payload either is a contract or the lambda does not support
|
|
6
|
+
* introspection; there is no partial state, so this cast throws rather
|
|
7
|
+
* than yield null
|
|
8
|
+
*
|
|
9
|
+
* .throws LambdaIntrospectionNotSupportedError (reason: non-schema-payload)
|
|
10
|
+
* - payload is malformed json
|
|
11
|
+
* - payload is not a json-schema envelope (lacks input/output schema shape)
|
|
12
|
+
*/
|
|
13
|
+
export declare const asLambdaEndpointSchema: (input: {
|
|
14
|
+
payload: Uint8Array;
|
|
15
|
+
endpoint: LambdaEndpoint;
|
|
16
|
+
}) => LambdaEndpointSchema;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asLambdaEndpointSchema = void 0;
|
|
4
|
+
const LambdaIntrospectionNotSupportedError_1 = require("../../domain.objects/LambdaIntrospectionNotSupportedError");
|
|
5
|
+
/**
|
|
6
|
+
* .what = cast a lambda response payload into a LambdaEndpointSchema
|
|
7
|
+
* .why = a payload either is a contract or the lambda does not support
|
|
8
|
+
* introspection; there is no partial state, so this cast throws rather
|
|
9
|
+
* than yield null
|
|
10
|
+
*
|
|
11
|
+
* .throws LambdaIntrospectionNotSupportedError (reason: non-schema-payload)
|
|
12
|
+
* - payload is malformed json
|
|
13
|
+
* - payload is not a json-schema envelope (lacks input/output schema shape)
|
|
14
|
+
*/
|
|
15
|
+
const asLambdaEndpointSchema = (input) => {
|
|
16
|
+
// decode payload bytes to string
|
|
17
|
+
const payloadStr = Buffer.from(input.payload).toString('utf-8');
|
|
18
|
+
// parse json; malformed json means the lambda is not introspectable
|
|
19
|
+
let parsed;
|
|
20
|
+
try {
|
|
21
|
+
parsed = JSON.parse(payloadStr);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
// allowlist: only SyntaxError (malformed json) maps to not-supported
|
|
25
|
+
if (!(error instanceof SyntaxError))
|
|
26
|
+
throw error;
|
|
27
|
+
throw new LambdaIntrospectionNotSupportedError_1.LambdaIntrospectionNotSupportedError(`lambda does not support introspection (non-schema-payload): ${input.endpoint.slug}`, {
|
|
28
|
+
endpoint: input.endpoint,
|
|
29
|
+
reason: 'non-schema-payload',
|
|
30
|
+
cause: error,
|
|
31
|
+
hint: 'ensure handler uses genLambdaEndpoint with zod schemas and env config',
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
// require a schema envelope: an object that carries input AND output schemas
|
|
35
|
+
const envelope = parsed;
|
|
36
|
+
const isSchemaEnvelope = typeof parsed === 'object' &&
|
|
37
|
+
parsed !== null &&
|
|
38
|
+
getIsJsonSchemaShape(envelope?.input) &&
|
|
39
|
+
getIsJsonSchemaShape(envelope?.output);
|
|
40
|
+
if (!isSchemaEnvelope) {
|
|
41
|
+
throw new LambdaIntrospectionNotSupportedError_1.LambdaIntrospectionNotSupportedError(`lambda does not support introspection (non-schema-payload): ${input.endpoint.slug}`, {
|
|
42
|
+
endpoint: input.endpoint,
|
|
43
|
+
reason: 'non-schema-payload',
|
|
44
|
+
hint: 'ensure handler uses genLambdaEndpoint with zod schemas and env config',
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return parsed;
|
|
48
|
+
};
|
|
49
|
+
exports.asLambdaEndpointSchema = asLambdaEndpointSchema;
|
|
50
|
+
/**
|
|
51
|
+
* .what = checks if a value looks like a json-schema object
|
|
52
|
+
* .why = distinguishes a real introspection schema from a business output that
|
|
53
|
+
* coincidentally has input/output keys
|
|
54
|
+
*
|
|
55
|
+
* note: json schemas are objects that carry at least one structural marker
|
|
56
|
+
* (type, properties, $ref, enum, anyOf/oneOf/allOf, items, const, $schema)
|
|
57
|
+
*/
|
|
58
|
+
const getIsJsonSchemaShape = (value) => {
|
|
59
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
const markers = [
|
|
63
|
+
'type',
|
|
64
|
+
'properties',
|
|
65
|
+
'$ref',
|
|
66
|
+
'$schema',
|
|
67
|
+
'enum',
|
|
68
|
+
'const',
|
|
69
|
+
'anyOf',
|
|
70
|
+
'oneOf',
|
|
71
|
+
'allOf',
|
|
72
|
+
'items',
|
|
73
|
+
];
|
|
74
|
+
return markers.some((marker) => marker in value);
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=asLambdaEndpointSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asLambdaEndpointSchema.js","sourceRoot":"","sources":["../../../src/domain.operations/getOneLambdaContract/asLambdaEndpointSchema.ts"],"names":[],"mappings":";;;AAEA,oHAAiH;AAEjH;;;;;;;;;GASG;AACI,MAAM,sBAAsB,GAAG,CAAC,KAGtC,EAAwB,EAAE;IACzB,iCAAiC;IACjC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAEhE,oEAAoE;IACpE,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,qEAAqE;QACrE,IAAI,CAAC,CAAC,KAAK,YAAY,WAAW,CAAC;YAAE,MAAM,KAAK,CAAC;QACjD,MAAM,IAAI,2EAAoC,CAC5C,+DAA+D,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,EACpF;YACE,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,MAAM,EAAE,oBAAoB;YAC5B,KAAK,EAAE,KAAK;YACZ,IAAI,EAAE,uEAAuE;SAC9E,CACF,CAAC;IACJ,CAAC;IAED,6EAA6E;IAC7E,MAAM,QAAQ,GAAG,MAAsD,CAAC;IACxE,MAAM,gBAAgB,GACpB,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACf,oBAAoB,CAAC,QAAQ,EAAE,KAAK,CAAC;QACrC,oBAAoB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACzC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,2EAAoC,CAC5C,+DAA+D,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,EACpF;YACE,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,MAAM,EAAE,oBAAoB;YAC5B,IAAI,EAAE,uEAAuE;SAC9E,CACF,CAAC;IACJ,CAAC;IAED,OAAO,MAA8B,CAAC;AACxC,CAAC,CAAC;AA5CW,QAAA,sBAAsB,0BA4CjC;AAEF;;;;;;;GAOG;AACH,MAAM,oBAAoB,GAAG,CAAC,KAAc,EAAW,EAAE;IACvD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACxE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,OAAO,GAAG;QACd,MAAM;QACN,YAAY;QACZ,MAAM;QACN,SAAS;QACT,MAAM;QACN,OAAO;QACP,OAAO;QACP,OAAO;QACP,OAAO;QACP,OAAO;KACR,CAAC;IACF,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC;AACnD,CAAC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ContextAwsLambdaCaller } from '../../domain.objects/ContextAwsLambdaCaller';
|
|
2
|
+
import type { LambdaEndpoint } from '../../domain.objects/LambdaEndpoint';
|
|
3
|
+
import type { LambdaEndpointSchema } from '../../domain.objects/LambdaEndpointSchema';
|
|
4
|
+
/**
|
|
5
|
+
* .what = get the contract schema from a lambda endpoint
|
|
6
|
+
* .why = enables runtime schema discovery for sdk generation
|
|
7
|
+
*
|
|
8
|
+
* .throws LambdaFunctionNotFoundError — endpoint does not exist
|
|
9
|
+
* .throws LambdaIntrospectionBlockedError — introspection blocked in prod/test
|
|
10
|
+
* .throws LambdaIntrospectionNotSupportedError — endpoint does not support introspection
|
|
11
|
+
*/
|
|
12
|
+
export declare const getOneLambdaContract: (input: {
|
|
13
|
+
which: {
|
|
14
|
+
service: string;
|
|
15
|
+
function: string;
|
|
16
|
+
};
|
|
17
|
+
}, context: ContextAwsLambdaCaller) => Promise<LambdaEndpointSchema>;
|
|
18
|
+
/**
|
|
19
|
+
* .what = input type for getOneLambdaContract
|
|
20
|
+
* .why = exported for sdk consumers
|
|
21
|
+
*/
|
|
22
|
+
export type GetOneLambdaContractInput = Parameters<typeof getOneLambdaContract>[0];
|
|
23
|
+
/**
|
|
24
|
+
* .what = context type for getOneLambdaContract
|
|
25
|
+
* .why = exported for sdk consumers
|
|
26
|
+
*/
|
|
27
|
+
export type GetOneLambdaContractContext = Parameters<typeof getOneLambdaContract>[1];
|
|
28
|
+
/**
|
|
29
|
+
* .what = re-export LambdaEndpoint type for convenience
|
|
30
|
+
* .why = callers of getOneLambdaContract operate on endpoints
|
|
31
|
+
*/
|
|
32
|
+
export type { LambdaEndpoint };
|