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,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setGeneratedFilesBatch = void 0;
|
|
4
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
5
|
+
const promises_1 = require("node:fs/promises");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
/**
|
|
8
|
+
* .what = write a batch of generated files atomically (all-or-none on disk)
|
|
9
|
+
* .why = three sequential single-file writes could leave a partial sdk if the fs
|
|
10
|
+
* fails on file 2 of 3; this stages all to temp names, then renames each
|
|
11
|
+
* into place — on any failure it removes the temp files and throws, so the
|
|
12
|
+
* target directory is never left with a partial set (uc.1 all-or-none)
|
|
13
|
+
*
|
|
14
|
+
* .throws MalfunctionError — a filesystem write/rename failed; temps are cleaned
|
|
15
|
+
*/
|
|
16
|
+
const setGeneratedFilesBatch = async (input) => {
|
|
17
|
+
// pair each target path with an adjacent temp path
|
|
18
|
+
const staged = input.files.map((file) => ({
|
|
19
|
+
finalPath: file.path,
|
|
20
|
+
tempPath: `${file.path}.tmp-${process.pid}-${Date.now()}`,
|
|
21
|
+
content: file.content,
|
|
22
|
+
}));
|
|
23
|
+
try {
|
|
24
|
+
// write every file to its temp path first (parent dirs made as needed)
|
|
25
|
+
for (const item of staged) {
|
|
26
|
+
await (0, promises_1.mkdir)((0, node_path_1.dirname)(item.finalPath), { recursive: true });
|
|
27
|
+
await (0, promises_1.writeFile)(item.tempPath, item.content, 'utf-8');
|
|
28
|
+
}
|
|
29
|
+
// commit: rename each temp into its final place
|
|
30
|
+
for (const item of staged) {
|
|
31
|
+
await (0, promises_1.rename)(item.tempPath, item.finalPath);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
// cleanup: attempt to remove every temp file, then fail loud with the
|
|
36
|
+
// original cause. allSettled (not a per-item catch) is deliberate — the
|
|
37
|
+
// primary fs error is what must surface; a secondary cleanup failure must
|
|
38
|
+
// neither mask it nor abort the other cleanups. `rm({ force: true })` is
|
|
39
|
+
// already a no-op for an absent temp, so the only settle-rejections here
|
|
40
|
+
// are genuine unlink faults, which are subordinate to the thrown cause.
|
|
41
|
+
await Promise.allSettled(staged.map((item) => (0, promises_1.rm)(item.tempPath, { force: true })));
|
|
42
|
+
throw new helpful_errors_1.MalfunctionError('failed to write generated files', {
|
|
43
|
+
cause: error instanceof Error ? error : new Error(String(error)),
|
|
44
|
+
paths: input.files.map((f) => f.path),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
exports.setGeneratedFilesBatch = setGeneratedFilesBatch;
|
|
49
|
+
//# sourceMappingURL=setGeneratedFilesBatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setGeneratedFilesBatch.js","sourceRoot":"","sources":["../../../../src/domain.operations/genServiceSdk/gen.file/setGeneratedFilesBatch.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAElD,+CAAgE;AAChE,yCAAoC;AAGpC;;;;;;;;GAQG;AACI,MAAM,sBAAsB,GAAG,KAAK,EAAE,KAE5C,EAAiB,EAAE;IAClB,mDAAmD;IACnD,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACxC,SAAS,EAAE,IAAI,CAAC,IAAI;QACpB,QAAQ,EAAE,GAAG,IAAI,CAAC,IAAI,QAAQ,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE;QACzD,OAAO,EAAE,IAAI,CAAC,OAAO;KACtB,CAAC,CAAC,CAAC;IAEJ,IAAI,CAAC;QACH,uEAAuE;QACvE,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;YAC1B,MAAM,IAAA,gBAAK,EAAC,IAAA,mBAAO,EAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC1D,MAAM,IAAA,oBAAS,EAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxD,CAAC;QAED,gDAAgD;QAChD,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;YAC1B,MAAM,IAAA,iBAAM,EAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,sEAAsE;QACtE,wEAAwE;QACxE,0EAA0E;QAC1E,yEAAyE;QACzE,yEAAyE;QACzE,wEAAwE;QACxE,MAAM,OAAO,CAAC,UAAU,CACtB,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,aAAE,EAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CACzD,CAAC;QACF,MAAM,IAAI,iCAAgB,CAAC,iCAAiC,EAAE;YAC5D,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAChE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;SACtC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC;AApCW,QAAA,sBAAsB,0BAoCjC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { LambdaEndpointSchema } from '../../../domain.objects/LambdaEndpointSchema';
|
|
2
|
+
/**
|
|
3
|
+
* .what = emit one mechanism fn: a typed `(event, context)` wrapper around
|
|
4
|
+
* `askLambdaEndpoint` for a single endpoint
|
|
5
|
+
* .why = the mechanisms file exposes one fn per discovered endpoint (uc.1); each
|
|
6
|
+
* is a thin, typed call into the endpoint by its service+function
|
|
7
|
+
*
|
|
8
|
+
* .note = `event` is the repo's ubiqlang lambda-payload input; the wrapper keeps
|
|
9
|
+
* the caller's `context` ambient (env.access lives there)
|
|
10
|
+
*/
|
|
11
|
+
export declare const asMechanismFnSource: (input: {
|
|
12
|
+
service: string;
|
|
13
|
+
function: string;
|
|
14
|
+
schema: LambdaEndpointSchema;
|
|
15
|
+
dobjRefs: Record<string, string>;
|
|
16
|
+
}) => string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asMechanismFnSource = void 0;
|
|
4
|
+
const getTypescriptFromJsonSchema_1 = require("./getTypescriptFromJsonSchema");
|
|
5
|
+
/**
|
|
6
|
+
* .what = emit one mechanism fn: a typed `(event, context)` wrapper around
|
|
7
|
+
* `askLambdaEndpoint` for a single endpoint
|
|
8
|
+
* .why = the mechanisms file exposes one fn per discovered endpoint (uc.1); each
|
|
9
|
+
* is a thin, typed call into the endpoint by its service+function
|
|
10
|
+
*
|
|
11
|
+
* .note = `event` is the repo's ubiqlang lambda-payload input; the wrapper keeps
|
|
12
|
+
* the caller's `context` ambient (env.access lives there)
|
|
13
|
+
*/
|
|
14
|
+
const asMechanismFnSource = (input) => {
|
|
15
|
+
// the typed shapes for this endpoint's event (input) and result (output)
|
|
16
|
+
const eventType = (0, getTypescriptFromJsonSchema_1.getTypescriptFromJsonSchema)({
|
|
17
|
+
schema: input.schema.input,
|
|
18
|
+
dobjRefs: input.dobjRefs,
|
|
19
|
+
});
|
|
20
|
+
const resultType = (0, getTypescriptFromJsonSchema_1.getTypescriptFromJsonSchema)({
|
|
21
|
+
schema: input.schema.output,
|
|
22
|
+
dobjRefs: input.dobjRefs,
|
|
23
|
+
});
|
|
24
|
+
// the fn: passes which + event to askLambdaEndpoint, threads context through.
|
|
25
|
+
// the explicit <event, result> generics make the call self-evident — a reader
|
|
26
|
+
// sees the contract at the call site, not only via the outer annotation
|
|
27
|
+
return [
|
|
28
|
+
` ${input.function}: (`,
|
|
29
|
+
` event: ${eventType},`,
|
|
30
|
+
` context: ContextAwsLambdaCaller,`,
|
|
31
|
+
` ): Promise<${resultType}> =>`,
|
|
32
|
+
` askLambdaEndpoint<${eventType}, ${resultType}>(`,
|
|
33
|
+
` { which: { service: ${JSON.stringify(input.service)}, function: ${JSON.stringify(input.function)} }, event },`,
|
|
34
|
+
` context,`,
|
|
35
|
+
` ),`,
|
|
36
|
+
].join('\n');
|
|
37
|
+
};
|
|
38
|
+
exports.asMechanismFnSource = asMechanismFnSource;
|
|
39
|
+
//# sourceMappingURL=asMechanismFnSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asMechanismFnSource.js","sourceRoot":"","sources":["../../../../src/domain.operations/genServiceSdk/gen.mechanism/asMechanismFnSource.ts"],"names":[],"mappings":";;;AACA,+EAA4E;AAE5E;;;;;;;;GAQG;AACI,MAAM,mBAAmB,GAAG,CAAC,KAKnC,EAAU,EAAE;IACX,yEAAyE;IACzE,MAAM,SAAS,GAAG,IAAA,yDAA2B,EAAC;QAC5C,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK;QAC1B,QAAQ,EAAE,KAAK,CAAC,QAAQ;KACzB,CAAC,CAAC;IACH,MAAM,UAAU,GAAG,IAAA,yDAA2B,EAAC;QAC7C,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM;QAC3B,QAAQ,EAAE,KAAK,CAAC,QAAQ;KACzB,CAAC,CAAC;IAEH,8EAA8E;IAC9E,8EAA8E;IAC9E,wEAAwE;IACxE,OAAO;QACL,KAAK,KAAK,CAAC,QAAQ,KAAK;QACxB,cAAc,SAAS,GAAG;QAC1B,sCAAsC;QACtC,gBAAgB,UAAU,MAAM;QAChC,yBAAyB,SAAS,KAAK,UAAU,IAAI;QACrD,6BAA6B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,cAAc;QACrH,gBAAgB;QAChB,QAAQ;KACT,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC,CAAC;AA7BW,QAAA,mBAAmB,uBA6B9B"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { JSONSchema } from 'zod/v4/core/json-schema';
|
|
2
|
+
/**
|
|
3
|
+
* .what = compile a json-schema into a TypeScript type literal string
|
|
4
|
+
* .why = the codegen needs typed shapes for mechanism args/returns + resource
|
|
5
|
+
* interfaces; a bespoke emitter (vs an external tool) keeps output fully
|
|
6
|
+
* deterministic for snapshots and avoids a heavy dep + esm/jest friction
|
|
7
|
+
*
|
|
8
|
+
* .note = these schemas come from zod via `z.toJSONSchema`, so the shapes are a
|
|
9
|
+
* known, bounded subset (object/array/string/number/boolean/enum/const/
|
|
10
|
+
* anyOf/allOf/$ref-free). unknown shapes surface as `unknown`.
|
|
11
|
+
*
|
|
12
|
+
* .dobjRefs = map of `x-domain-object` name → the prefixed resource name; when a
|
|
13
|
+
* sub-node carries a captured dobj pragma, its type becomes that
|
|
14
|
+
* prefixed name (a reference) instead of an inline shape
|
|
15
|
+
*
|
|
16
|
+
* .asRootShape = when true, the ROOT node renders its own shape even if it carries
|
|
17
|
+
* a dobj pragma (so a resource can render its own interface body);
|
|
18
|
+
* nested pragma nodes still become refs. default false — so a
|
|
19
|
+
* top-level dobj (e.g. a mechanism's `job` field) becomes a ref.
|
|
20
|
+
*/
|
|
21
|
+
export declare const getTypescriptFromJsonSchema: (input: {
|
|
22
|
+
schema: JSONSchema;
|
|
23
|
+
dobjRefs?: Record<string, string>;
|
|
24
|
+
asRootShape?: boolean;
|
|
25
|
+
}) => string;
|
|
26
|
+
/**
|
|
27
|
+
* .what = the set of domain-objects ref generics (`Ref` / `RefByPrimary` /
|
|
28
|
+
* `RefByUnique`) a schema tree uses, for the resources-file import line
|
|
29
|
+
* .why = a resources file that references dobjs must import exactly the ref generics
|
|
30
|
+
* it emits — no more (no unused import), no less
|
|
31
|
+
*/
|
|
32
|
+
export declare const getRefGenericsUsed: (input: {
|
|
33
|
+
schema: JSONSchema;
|
|
34
|
+
dobjRefs: Record<string, string>;
|
|
35
|
+
}) => string[];
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRefGenericsUsed = exports.getTypescriptFromJsonSchema = void 0;
|
|
4
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
5
|
+
/**
|
|
6
|
+
* .what = compile a json-schema into a TypeScript type literal string
|
|
7
|
+
* .why = the codegen needs typed shapes for mechanism args/returns + resource
|
|
8
|
+
* interfaces; a bespoke emitter (vs an external tool) keeps output fully
|
|
9
|
+
* deterministic for snapshots and avoids a heavy dep + esm/jest friction
|
|
10
|
+
*
|
|
11
|
+
* .note = these schemas come from zod via `z.toJSONSchema`, so the shapes are a
|
|
12
|
+
* known, bounded subset (object/array/string/number/boolean/enum/const/
|
|
13
|
+
* anyOf/allOf/$ref-free). unknown shapes surface as `unknown`.
|
|
14
|
+
*
|
|
15
|
+
* .dobjRefs = map of `x-domain-object` name → the prefixed resource name; when a
|
|
16
|
+
* sub-node carries a captured dobj pragma, its type becomes that
|
|
17
|
+
* prefixed name (a reference) instead of an inline shape
|
|
18
|
+
*
|
|
19
|
+
* .asRootShape = when true, the ROOT node renders its own shape even if it carries
|
|
20
|
+
* a dobj pragma (so a resource can render its own interface body);
|
|
21
|
+
* nested pragma nodes still become refs. default false — so a
|
|
22
|
+
* top-level dobj (e.g. a mechanism's `job` field) becomes a ref.
|
|
23
|
+
*/
|
|
24
|
+
const getTypescriptFromJsonSchema = (input) => asType(input.schema, input.dobjRefs ?? {}, input.asRootShape ?? false);
|
|
25
|
+
exports.getTypescriptFromJsonSchema = getTypescriptFromJsonSchema;
|
|
26
|
+
/**
|
|
27
|
+
* .what = render one json-schema node as a TS type literal
|
|
28
|
+
* .why = recursive core of the emitter
|
|
29
|
+
*/
|
|
30
|
+
const asType = (node, dobjRefs, skipRootPragma = false) => {
|
|
31
|
+
// a node tagged as a domain-object REFERENCE becomes a typed Ref against the
|
|
32
|
+
// referenced dobj's prefixed resource name (e.g. RefByPrimary<typeof SvcSurfSeaturtle>)
|
|
33
|
+
const refType = asRefType(node, dobjRefs);
|
|
34
|
+
if (refType)
|
|
35
|
+
return refType;
|
|
36
|
+
// a node tagged as a captured dobj becomes a reference to its prefixed name —
|
|
37
|
+
// unless this is the root shape render (a resource emits its own interface)
|
|
38
|
+
const pragma = node['x-domain-object'];
|
|
39
|
+
if (!skipRootPragma && pragma && dobjRefs[pragma.name])
|
|
40
|
+
return dobjRefs[pragma.name];
|
|
41
|
+
// const → literal type
|
|
42
|
+
if ('const' in node)
|
|
43
|
+
return asLiteral(node.const);
|
|
44
|
+
// enum → union of literals
|
|
45
|
+
const enumValues = node.enum;
|
|
46
|
+
if (enumValues)
|
|
47
|
+
return enumValues.map(asLiteral).join(' | ');
|
|
48
|
+
// anyOf / oneOf → union
|
|
49
|
+
const anyOf = node.anyOf ??
|
|
50
|
+
node.oneOf;
|
|
51
|
+
if (anyOf)
|
|
52
|
+
return anyOf.map((m) => asType(m, dobjRefs)).join(' | ');
|
|
53
|
+
// allOf → intersection
|
|
54
|
+
const allOf = node.allOf;
|
|
55
|
+
if (allOf)
|
|
56
|
+
return allOf.map((m) => asType(m, dobjRefs)).join(' & ');
|
|
57
|
+
// by json-schema `type`
|
|
58
|
+
const type = node.type;
|
|
59
|
+
if (type === 'string')
|
|
60
|
+
return 'string';
|
|
61
|
+
if (type === 'number' || type === 'integer')
|
|
62
|
+
return 'number';
|
|
63
|
+
if (type === 'boolean')
|
|
64
|
+
return 'boolean';
|
|
65
|
+
if (type === 'null')
|
|
66
|
+
return 'null';
|
|
67
|
+
if (type === 'array')
|
|
68
|
+
return asArray(node, dobjRefs);
|
|
69
|
+
if (type === 'object')
|
|
70
|
+
return asObject(node, dobjRefs);
|
|
71
|
+
// no recognizable shape → unknown (surfaces upstream schema looseness)
|
|
72
|
+
return 'unknown';
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* .what = render an object node as `{ key: type; ... }`
|
|
76
|
+
* .why = objects are the dominant shape; honor `required` for optionality
|
|
77
|
+
*/
|
|
78
|
+
const asObject = (node, dobjRefs) => {
|
|
79
|
+
const properties = node
|
|
80
|
+
.properties;
|
|
81
|
+
if (!properties || Object.keys(properties).length === 0)
|
|
82
|
+
return 'unknown';
|
|
83
|
+
const required = new Set(node.required ?? []);
|
|
84
|
+
const members = Object.entries(properties).map(([key, propSchema]) => {
|
|
85
|
+
const optional = required.has(key) ? '' : '?';
|
|
86
|
+
return `${asKey(key)}${optional}: ${asType(propSchema, dobjRefs)};`;
|
|
87
|
+
});
|
|
88
|
+
return `{ ${members.join(' ')} }`;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* .what = render an array node as `type[]`
|
|
92
|
+
* .why = items may be a single schema or absent (→ unknown[]); emit the idiomatic
|
|
93
|
+
* `T[]` form, consistent with the absent-items branch (not a mixed
|
|
94
|
+
* `Array<T>` vs `unknown[]` style)
|
|
95
|
+
* .note = union/intersection item types are parenthesized so `A | B` renders as
|
|
96
|
+
* `(A | B)[]`, not the ambiguous `A | B[]`
|
|
97
|
+
*/
|
|
98
|
+
const asArray = (node, dobjRefs) => {
|
|
99
|
+
const items = node.items;
|
|
100
|
+
if (!items)
|
|
101
|
+
return 'unknown[]';
|
|
102
|
+
const itemType = asType(items, dobjRefs);
|
|
103
|
+
const needsParens = /\s[|&]\s/.test(itemType);
|
|
104
|
+
return needsParens ? `(${itemType})[]` : `${itemType}[]`;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* .what = render a literal value as a TS literal type
|
|
108
|
+
*/
|
|
109
|
+
const asLiteral = (value) => {
|
|
110
|
+
if (typeof value === 'string')
|
|
111
|
+
return JSON.stringify(value);
|
|
112
|
+
if (typeof value === 'number' || typeof value === 'boolean')
|
|
113
|
+
return String(value);
|
|
114
|
+
if (value === null)
|
|
115
|
+
return 'null';
|
|
116
|
+
throw new helpful_errors_1.UnexpectedCodePathError('cannot render literal type for value', {
|
|
117
|
+
value,
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* .what = the domain-objects ref generic (`Ref` / `RefByPrimary` / `RefByUnique`) a
|
|
122
|
+
* given `by` maps to
|
|
123
|
+
* .why = the `x-domain-object-ref` pragma's `by` says which key(s) the reference
|
|
124
|
+
* carries; each maps to its domain-objects type
|
|
125
|
+
*/
|
|
126
|
+
const REF_GENERIC_BY = {
|
|
127
|
+
primary: 'RefByPrimary',
|
|
128
|
+
unique: 'RefByUnique',
|
|
129
|
+
ref: 'Ref',
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* .what = read the `x-domain-object-ref` pragma off a schema node (the reference
|
|
133
|
+
* pragma stamped by `X.contract.ref(by)` in domain-objects@0.33.0)
|
|
134
|
+
* .why = a reference field carries only the referenced dobj (`of`) + which key (`by`)
|
|
135
|
+
*/
|
|
136
|
+
const asRefPragma = (node) => node['x-domain-object-ref'];
|
|
137
|
+
/**
|
|
138
|
+
* .what = render a node tagged with `x-domain-object-ref` as a typed Ref, or null
|
|
139
|
+
* when the node carries no ref pragma (or the referenced dobj is unbound)
|
|
140
|
+
* .why = a reference field emits `RefByPrimary<typeof SvcSurfSeaturtle>` (etc)
|
|
141
|
+
* instead of an inline key-shape, so the generated sdk keeps the reference
|
|
142
|
+
* relationship + is typed against the prefixed resource
|
|
143
|
+
* .note = the referenced dobj MUST be captured in full (present in dobjRefs) so the
|
|
144
|
+
* `typeof <prefixed>` binds; an unbound ref returns null here and the caller
|
|
145
|
+
* falls back to the plain inline shape (the bind-or-fail check lives upstream)
|
|
146
|
+
*/
|
|
147
|
+
const asRefType = (node, dobjRefs) => {
|
|
148
|
+
const ref = asRefPragma(node);
|
|
149
|
+
if (!ref)
|
|
150
|
+
return null;
|
|
151
|
+
const prefixed = dobjRefs[ref.of];
|
|
152
|
+
if (!prefixed)
|
|
153
|
+
return null;
|
|
154
|
+
return `${REF_GENERIC_BY[ref.by]}<typeof ${prefixed}>`;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* .what = the set of domain-objects ref generics (`Ref` / `RefByPrimary` /
|
|
158
|
+
* `RefByUnique`) a schema tree uses, for the resources-file import line
|
|
159
|
+
* .why = a resources file that references dobjs must import exactly the ref generics
|
|
160
|
+
* it emits — no more (no unused import), no less
|
|
161
|
+
*/
|
|
162
|
+
const getRefGenericsUsed = (input) => {
|
|
163
|
+
const used = new Set();
|
|
164
|
+
collectRefGenerics(input.schema, input.dobjRefs, used);
|
|
165
|
+
return [...used].sort();
|
|
166
|
+
};
|
|
167
|
+
exports.getRefGenericsUsed = getRefGenericsUsed;
|
|
168
|
+
/**
|
|
169
|
+
* .what = recursively collect the ref generics used across a schema tree
|
|
170
|
+
*/
|
|
171
|
+
const collectRefGenerics = (node, dobjRefs, used) => {
|
|
172
|
+
if (typeof node !== 'object' || node === null)
|
|
173
|
+
return;
|
|
174
|
+
const ref = asRefPragma(node);
|
|
175
|
+
if (ref && dobjRefs[ref.of])
|
|
176
|
+
used.add(REF_GENERIC_BY[ref.by]);
|
|
177
|
+
for (const value of Object.values(node)) {
|
|
178
|
+
if (Array.isArray(value))
|
|
179
|
+
for (const item of value)
|
|
180
|
+
collectRefGenerics(item, dobjRefs, used);
|
|
181
|
+
else
|
|
182
|
+
collectRefGenerics(value, dobjRefs, used);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* .what = render a property key, quoted when it is not a valid identifier
|
|
187
|
+
*/
|
|
188
|
+
const asKey = (key) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : JSON.stringify(key);
|
|
189
|
+
//# sourceMappingURL=getTypescriptFromJsonSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTypescriptFromJsonSchema.js","sourceRoot":"","sources":["../../../../src/domain.operations/genServiceSdk/gen.mechanism/getTypescriptFromJsonSchema.ts"],"names":[],"mappings":";;;AACA,mDAAyD;AAGzD;;;;;;;;;;;;;;;;;;GAkBG;AACI,MAAM,2BAA2B,GAAG,CAAC,KAI3C,EAAU,EAAE,CACX,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,IAAI,EAAE,EAAE,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,CAAC;AAL5D,QAAA,2BAA2B,+BAKiC;AAEzE;;;GAGG;AACH,MAAM,MAAM,GAAG,CACb,IAAgB,EAChB,QAAgC,EAChC,cAAc,GAAG,KAAK,EACd,EAAE;IACV,6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,MAAM,KAAK,GAAG,CAAC,GAAW,EAAU,EAAE,CACpC,4BAA4B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { JSONSchema } from 'zod/v4/core/json-schema';
|
|
2
|
+
import type { DomainObjectCaptured } from '../../../domain.objects/DomainObjectCaptured';
|
|
3
|
+
/**
|
|
4
|
+
* .what = read the `x-domain-object` pragma off one json-schema node → a
|
|
5
|
+
* DomainObjectCaptured, or null when the node carries no pragma
|
|
6
|
+
* .why = a captured node identifies a domain-object only if its schema was built
|
|
7
|
+
* from `SomeDobj.contract`; a plain shape has no pragma and stays a plain type
|
|
8
|
+
*
|
|
9
|
+
* .kind = domain-objects@0.33.0 stamps the true `kind` on the pragma (via getKind).
|
|
10
|
+
* read it directly; fall back to the legacy `primary`-non-empty heuristic
|
|
11
|
+
* only for a pre-0.33 producer whose pragma omits `kind` (cross-version safe)
|
|
12
|
+
*/
|
|
13
|
+
export declare const asDomainObjectPragma: (input: {
|
|
14
|
+
node: JSONSchema;
|
|
15
|
+
}) => DomainObjectCaptured | null;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asDomainObjectPragma = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = read the `x-domain-object` pragma off one json-schema node → a
|
|
6
|
+
* DomainObjectCaptured, or null when the node carries no pragma
|
|
7
|
+
* .why = a captured node identifies a domain-object only if its schema was built
|
|
8
|
+
* from `SomeDobj.contract`; a plain shape has no pragma and stays a plain type
|
|
9
|
+
*
|
|
10
|
+
* .kind = domain-objects@0.33.0 stamps the true `kind` on the pragma (via getKind).
|
|
11
|
+
* read it directly; fall back to the legacy `primary`-non-empty heuristic
|
|
12
|
+
* only for a pre-0.33 producer whose pragma omits `kind` (cross-version safe)
|
|
13
|
+
*/
|
|
14
|
+
const asDomainObjectPragma = (input) => {
|
|
15
|
+
// read the pragma keyword off the node (absent → not a domain-object)
|
|
16
|
+
const pragma = input.node['x-domain-object'];
|
|
17
|
+
if (!pragma)
|
|
18
|
+
return null;
|
|
19
|
+
// default the omitted key-fields (getContract omits them when absent)
|
|
20
|
+
const primary = pragma.primary ?? [];
|
|
21
|
+
const unique = pragma.unique ?? [];
|
|
22
|
+
const alias = pragma.alias ?? null;
|
|
23
|
+
const nested = pragma.nested ?? {};
|
|
24
|
+
// read the stamped kind; fall back to the heuristic for a pre-0.33 pragma
|
|
25
|
+
const kind = pragma.kind ?? (primary.length > 0 ? 'entity' : 'literal');
|
|
26
|
+
return {
|
|
27
|
+
name: pragma.name,
|
|
28
|
+
kind,
|
|
29
|
+
primary,
|
|
30
|
+
unique,
|
|
31
|
+
alias,
|
|
32
|
+
nested,
|
|
33
|
+
shape: input.node,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
exports.asDomainObjectPragma = asDomainObjectPragma;
|
|
37
|
+
//# sourceMappingURL=asDomainObjectPragma.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asDomainObjectPragma.js","sourceRoot":"","sources":["../../../../src/domain.operations/genServiceSdk/gen.resource/asDomainObjectPragma.ts"],"names":[],"mappings":";;;AAKA;;;;;;;;;GASG;AACI,MAAM,oBAAoB,GAAG,CAAC,KAEpC,EAA+B,EAAE;IAChC,sEAAsE;IACtE,MAAM,MAAM,GAAI,KAAK,CAAC,IAAmD,CACvE,iBAAiB,CAClB,CAAC;IACF,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAEzB,sEAAsE;IACtE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC;IACrC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;IACnC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC;IACnC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;IAEnC,0EAA0E;IAC1E,MAAM,IAAI,GACR,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAE7D,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,IAAI;QACJ,OAAO;QACP,MAAM;QACN,KAAK;QACL,MAAM;QACN,KAAK,EAAE,KAAK,CAAC,IAAI;KACM,CAAC;AAC5B,CAAC,CAAC;AA5BW,QAAA,oBAAoB,wBA4B/B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { DomainObjectKind } from 'domain-objects';
|
|
2
|
+
import type { DomainObjectCaptured } from '../../../domain.objects/DomainObjectCaptured';
|
|
3
|
+
/**
|
|
4
|
+
* .what = the domain-objects base class each `kind` maps to
|
|
5
|
+
* .why = the pragma stamps the true `kind`; the resource extends the base class it
|
|
6
|
+
* names (entity→DomainEntity, literal→DomainLiteral, event→DomainEvent,
|
|
7
|
+
* object→a plain DomainObject)
|
|
8
|
+
*/
|
|
9
|
+
export declare const BASE_CLASS_BY_KIND: Record<DomainObjectKind, string>;
|
|
10
|
+
/**
|
|
11
|
+
* .what = emit the TS source for one captured domain-object: its prefixed
|
|
12
|
+
* interface + prefixed class with primary/unique/alias/nested (no schema)
|
|
13
|
+
* .why = the resources file declares each upstream dobj so the consumer gets a
|
|
14
|
+
* real DomainEntity/DomainLiteral (etc), not a bare type (uc.2)
|
|
15
|
+
*
|
|
16
|
+
* .rules
|
|
17
|
+
* - class name = `prefix + name` (the TS class name from the pragma; NOT alias)
|
|
18
|
+
* - base class = the domain-objects class the pragma's `kind` maps to
|
|
19
|
+
* - nested type names are prefixed via the same formula
|
|
20
|
+
* - no `static schema` — consumers do not re-validate
|
|
21
|
+
*/
|
|
22
|
+
export declare const asResourceClassSource: (input: {
|
|
23
|
+
dobj: DomainObjectCaptured;
|
|
24
|
+
prefix: string;
|
|
25
|
+
dobjRefs: Record<string, string>;
|
|
26
|
+
}) => string;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asResourceClassSource = exports.BASE_CLASS_BY_KIND = void 0;
|
|
4
|
+
const getTypescriptFromJsonSchema_1 = require("../gen.mechanism/getTypescriptFromJsonSchema");
|
|
5
|
+
/**
|
|
6
|
+
* .what = the domain-objects base class each `kind` maps to
|
|
7
|
+
* .why = the pragma stamps the true `kind`; the resource extends the base class it
|
|
8
|
+
* names (entity→DomainEntity, literal→DomainLiteral, event→DomainEvent,
|
|
9
|
+
* object→a plain DomainObject)
|
|
10
|
+
*/
|
|
11
|
+
exports.BASE_CLASS_BY_KIND = {
|
|
12
|
+
entity: 'DomainEntity',
|
|
13
|
+
literal: 'DomainLiteral',
|
|
14
|
+
event: 'DomainEvent',
|
|
15
|
+
object: 'DomainObject',
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* .what = emit the TS source for one captured domain-object: its prefixed
|
|
19
|
+
* interface + prefixed class with primary/unique/alias/nested (no schema)
|
|
20
|
+
* .why = the resources file declares each upstream dobj so the consumer gets a
|
|
21
|
+
* real DomainEntity/DomainLiteral (etc), not a bare type (uc.2)
|
|
22
|
+
*
|
|
23
|
+
* .rules
|
|
24
|
+
* - class name = `prefix + name` (the TS class name from the pragma; NOT alias)
|
|
25
|
+
* - base class = the domain-objects class the pragma's `kind` maps to
|
|
26
|
+
* - nested type names are prefixed via the same formula
|
|
27
|
+
* - no `static schema` — consumers do not re-validate
|
|
28
|
+
*/
|
|
29
|
+
const asResourceClassSource = (input) => {
|
|
30
|
+
const { dobj, prefix } = input;
|
|
31
|
+
// the emitted symbol name for this dobj (e.g. SvcJobsJob)
|
|
32
|
+
const symbol = `${prefix}${dobj.name}`;
|
|
33
|
+
// the interface shape, with nested dobj-tagged props referenced by prefixed
|
|
34
|
+
// name; asRootShape renders THIS dobj's own shape (not a self-ref)
|
|
35
|
+
const shape = (0, getTypescriptFromJsonSchema_1.getTypescriptFromJsonSchema)({
|
|
36
|
+
schema: dobj.shape,
|
|
37
|
+
dobjRefs: input.dobjRefs,
|
|
38
|
+
asRootShape: true,
|
|
39
|
+
});
|
|
40
|
+
// the base class the dobj's kind maps to
|
|
41
|
+
const base = exports.BASE_CLASS_BY_KIND[dobj.kind];
|
|
42
|
+
// the static key + metadata lines (omit those with no content)
|
|
43
|
+
const statics = [
|
|
44
|
+
asStaticArray('primary', dobj.primary),
|
|
45
|
+
asStaticArray('unique', dobj.unique),
|
|
46
|
+
asStaticAlias(dobj.alias),
|
|
47
|
+
asStaticNested(dobj.nested, prefix),
|
|
48
|
+
].filter((line) => line !== null);
|
|
49
|
+
const interfaceLine = `export interface ${symbol} ${shape}`;
|
|
50
|
+
const classBody = statics.length > 0 ? `\n ${statics.join('\n ')}\n` : '';
|
|
51
|
+
const classLine = `export class ${symbol} extends ${base}<${symbol}> implements ${symbol} {${classBody}}`;
|
|
52
|
+
// a blank line between the interface + class halves makes each dobj's two-part
|
|
53
|
+
// structure obvious at a glance (biome preserves the gap)
|
|
54
|
+
return `${interfaceLine}\n\n${classLine}`;
|
|
55
|
+
};
|
|
56
|
+
exports.asResourceClassSource = asResourceClassSource;
|
|
57
|
+
/**
|
|
58
|
+
* .what = render a `public static primary = [...] as const;` line, or null if empty
|
|
59
|
+
*/
|
|
60
|
+
const asStaticArray = (name, values) => {
|
|
61
|
+
if (values.length === 0)
|
|
62
|
+
return null;
|
|
63
|
+
const items = values.map((v) => JSON.stringify(v)).join(', ');
|
|
64
|
+
return `public static ${name} = [${items}] as const;`;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* .what = render a `public static alias = ...;` line, or null if absent
|
|
68
|
+
* .why = the alias is a string ('surfboard') or an object ({ singular, plural });
|
|
69
|
+
* render it as a TS literal — NOT `JSON.stringify` (which emits cramped raw
|
|
70
|
+
* json `{"singular":"job"}` with quoted keys, a codegen blemish)
|
|
71
|
+
*/
|
|
72
|
+
const asStaticAlias = (alias) => {
|
|
73
|
+
if (alias === null)
|
|
74
|
+
return null;
|
|
75
|
+
return `public static alias = ${asAliasLiteral(alias)};`;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* .what = render an alias value as a clean TS literal
|
|
79
|
+
* .why = a string alias becomes a string literal; an object alias becomes an
|
|
80
|
+
* object literal with unquoted keys + spaces (`{ singular: "job" }`)
|
|
81
|
+
*/
|
|
82
|
+
const asAliasLiteral = (alias) => {
|
|
83
|
+
if (typeof alias === 'string')
|
|
84
|
+
return JSON.stringify(alias);
|
|
85
|
+
const members = Object.entries(alias).map(([key, value]) => `${key}: ${JSON.stringify(value)}`);
|
|
86
|
+
return `{ ${members.join(', ')} }`;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* .what = render a `public static nested = { key: PrefixedType, ... };` line
|
|
90
|
+
* .why = each nested type name gets the service prefix, so it points at the
|
|
91
|
+
* prefixed resource declaration; an array value (polymorphic) emits an
|
|
92
|
+
* array of prefixed names
|
|
93
|
+
*/
|
|
94
|
+
const asStaticNested = (nested, prefix) => {
|
|
95
|
+
const entries = Object.entries(nested);
|
|
96
|
+
if (entries.length === 0)
|
|
97
|
+
return null;
|
|
98
|
+
const members = entries.map(([key, typeName]) => {
|
|
99
|
+
const value = Array.isArray(typeName)
|
|
100
|
+
? `[${typeName.map((n) => `${prefix}${n}`).join(', ')}]`
|
|
101
|
+
: `${prefix}${typeName}`;
|
|
102
|
+
return `${key}: ${value}`;
|
|
103
|
+
});
|
|
104
|
+
return `public static nested = { ${members.join(', ')} };`;
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=asResourceClassSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asResourceClassSource.js","sourceRo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AC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACrC,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,cAAc,GAAG,CACrB,MAAsC,EACtC,MAAc,EACC,EAAE;IACjB,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACvC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEtC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,EAAE;QAC9C,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;YACnC,CAAC,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;YACxD,CAAC,CAAC,GAAG,MAAM,GAAG,QAAQ,EAAE,CAAC;QAC3B,OAAO,GAAG,GAAG,KAAK,KAAK,EAAE,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,OAAO,4BAA4B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;AAC7D,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LambdaEndpointSchema } from '../../../domain.objects/LambdaEndpointSchema';
|
|
2
|
+
/**
|
|
3
|
+
* .what = verify every `x-domain-object-ref` across a service's contracts names a
|
|
4
|
+
* dobj that is captured in full (present in `capturedNames`)
|
|
5
|
+
* .why = a reference emits `RefByPrimary<typeof Svc<Prefix><Name>>`; that prefixed
|
|
6
|
+
* resource must be declared, else the generated sdk will not compile. an
|
|
7
|
+
* unbound ref means the referenced dobj is surfaced by no endpoint whole —
|
|
8
|
+
* fail loud so the caller surfaces it (all-or-none, exit 2)
|
|
9
|
+
*
|
|
10
|
+
* .throws LambdaDomainObjectRefUnbindableError — names the unbound ref + its dobj
|
|
11
|
+
*/
|
|
12
|
+
export declare const assertAllDomainObjectRefsBind: (input: {
|
|
13
|
+
contracts: Record<string, LambdaEndpointSchema>;
|
|
14
|
+
capturedNames: Set<string>;
|
|
15
|
+
}) => void;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertAllDomainObjectRefsBind = void 0;
|
|
4
|
+
const LambdaDomainObjectRefUnbindableError_1 = require("../../../domain.objects/LambdaDomainObjectRefUnbindableError");
|
|
5
|
+
/**
|
|
6
|
+
* .what = verify every `x-domain-object-ref` across a service's contracts names a
|
|
7
|
+
* dobj that is captured in full (present in `capturedNames`)
|
|
8
|
+
* .why = a reference emits `RefByPrimary<typeof Svc<Prefix><Name>>`; that prefixed
|
|
9
|
+
* resource must be declared, else the generated sdk will not compile. an
|
|
10
|
+
* unbound ref means the referenced dobj is surfaced by no endpoint whole —
|
|
11
|
+
* fail loud so the caller surfaces it (all-or-none, exit 2)
|
|
12
|
+
*
|
|
13
|
+
* .throws LambdaDomainObjectRefUnbindableError — names the unbound ref + its dobj
|
|
14
|
+
*/
|
|
15
|
+
const assertAllDomainObjectRefsBind = (input) => {
|
|
16
|
+
const referencedNames = new Set();
|
|
17
|
+
// walk each endpoint's input + output schema trees for ref-pragma names
|
|
18
|
+
for (const schema of Object.values(input.contracts)) {
|
|
19
|
+
collectRefNames({ node: schema.input, into: referencedNames });
|
|
20
|
+
collectRefNames({ node: schema.output, into: referencedNames });
|
|
21
|
+
}
|
|
22
|
+
// every referenced name must be captured in full; else the ref cannot bind
|
|
23
|
+
const unbound = [...referencedNames]
|
|
24
|
+
.filter((name) => !input.capturedNames.has(name))
|
|
25
|
+
.sort();
|
|
26
|
+
if (unbound.length > 0)
|
|
27
|
+
throw new LambdaDomainObjectRefUnbindableError_1.LambdaDomainObjectRefUnbindableError(`domain-object reference(s) cannot bind: ${unbound.join(', ')} — referenced by key but captured by no endpoint`, {
|
|
28
|
+
unbound,
|
|
29
|
+
hint: 'surface each referenced domain-object in full on some endpoint of this service (return it whole via `.contract`) so the codegen can declare its resource',
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
exports.assertAllDomainObjectRefsBind = assertAllDomainObjectRefsBind;
|
|
33
|
+
/**
|
|
34
|
+
* .what = recursively read every `x-domain-object-ref` name in a schema tree
|
|
35
|
+
*/
|
|
36
|
+
const collectRefNames = (input) => {
|
|
37
|
+
const { node, into } = input;
|
|
38
|
+
if (typeof node !== 'object' || node === null)
|
|
39
|
+
return;
|
|
40
|
+
const ref = node['x-domain-object-ref'];
|
|
41
|
+
if (ref?.of)
|
|
42
|
+
into.add(ref.of);
|
|
43
|
+
for (const value of Object.values(node)) {
|
|
44
|
+
if (Array.isArray(value))
|
|
45
|
+
for (const item of value)
|
|
46
|
+
collectRefNames({ node: item, into });
|
|
47
|
+
else
|
|
48
|
+
collectRefNames({ node: value, into });
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=assertAllDomainObjectRefsBind.js.map
|
package/dist/domain.operations/genServiceSdk/gen.resource/assertAllDomainObjectRefsBind.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertAllDomainObjectRefsBind.js","sourceRoot":"","sources":["../../../../src/domain.operations/genServiceSdk/gen.resource/assertAllDomainObjectRefsBind.ts"],"names":[],"mappings":";;;AAEA,uHAAoH;AAGpH;;;;;;;;;GASG;AACI,MAAM,6BAA6B,GAAG,CAAC,KAG7C,EAAQ,EAAE;IACT,MAAM,eAAe,GAAG,IAAI,GAAG,EAAU,CAAC;IAE1C,wEAAwE;IACxE,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;QACpD,eAAe,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,CAA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CAAC"}
|
package/dist/domain.operations/genServiceSdk/gen.resource/getAllDomainObjectsFromContracts.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DomainObjectCaptured } from '../../../domain.objects/DomainObjectCaptured';
|
|
2
|
+
import type { LambdaEndpointSchema } from '../../../domain.objects/LambdaEndpointSchema';
|
|
3
|
+
/**
|
|
4
|
+
* .what = collect every domain-object captured across a service's contracts,
|
|
5
|
+
* de-duplicated by name
|
|
6
|
+
* .why = the resources file declares each captured dobj once; a dobj referenced
|
|
7
|
+
* by many endpoints must yield a single declaration (uc.2 dedupe)
|
|
8
|
+
*
|
|
9
|
+
* .throws LambdaDomainObjectNotCapturableError — a pragma-tagged node whose shape
|
|
10
|
+
* cannot be reconstructed (no object properties) (uc.9)
|
|
11
|
+
*/
|
|
12
|
+
export declare const getAllDomainObjectsFromContracts: (input: {
|
|
13
|
+
contracts: Record<string, LambdaEndpointSchema>;
|
|
14
|
+
}) => DomainObjectCaptured[];
|