@aws-blocks/core 0.1.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/LICENSE +174 -0
- package/dist/api.d.ts +147 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +10 -0
- package/dist/api.test.d.ts +2 -0
- package/dist/api.test.d.ts.map +1 -0
- package/dist/api.test.js +19 -0
- package/dist/bb-utils.d.ts +11 -0
- package/dist/bb-utils.d.ts.map +1 -0
- package/dist/bb-utils.js +12 -0
- package/dist/builtin-routes.d.ts +6 -0
- package/dist/builtin-routes.d.ts.map +1 -0
- package/dist/builtin-routes.js +57 -0
- package/dist/cdk/__fixtures__/factory-backend.d.ts +3 -0
- package/dist/cdk/__fixtures__/factory-backend.d.ts.map +1 -0
- package/dist/cdk/__fixtures__/factory-backend.js +6 -0
- package/dist/cdk/__fixtures__/fullid-construct-backend.d.ts +2 -0
- package/dist/cdk/__fixtures__/fullid-construct-backend.d.ts.map +1 -0
- package/dist/cdk/__fixtures__/fullid-construct-backend.js +37 -0
- package/dist/cdk/__fixtures__/handler.d.ts +5 -0
- package/dist/cdk/__fixtures__/handler.d.ts.map +1 -0
- package/dist/cdk/__fixtures__/handler.js +3 -0
- package/dist/cdk/__fixtures__/side-effect-backend.d.ts +2 -0
- package/dist/cdk/__fixtures__/side-effect-backend.d.ts.map +1 -0
- package/dist/cdk/__fixtures__/side-effect-backend.js +5 -0
- package/dist/cdk/blocks-backend.d.ts +68 -0
- package/dist/cdk/blocks-backend.d.ts.map +1 -0
- package/dist/cdk/blocks-backend.js +214 -0
- package/dist/cdk/blocks-backend.test.d.ts +2 -0
- package/dist/cdk/blocks-backend.test.d.ts.map +1 -0
- package/dist/cdk/blocks-backend.test.js +151 -0
- package/dist/cdk/blocks-stack.test.d.ts +2 -0
- package/dist/cdk/blocks-stack.test.d.ts.map +1 -0
- package/dist/cdk/blocks-stack.test.js +78 -0
- package/dist/cdk/config-registry.d.ts +26 -0
- package/dist/cdk/config-registry.d.ts.map +1 -0
- package/dist/cdk/config-registry.js +80 -0
- package/dist/cdk/index.d.ts +35 -0
- package/dist/cdk/index.d.ts.map +1 -0
- package/dist/cdk/index.js +90 -0
- package/dist/cdk/mixins.d.ts +28 -0
- package/dist/cdk/mixins.d.ts.map +1 -0
- package/dist/cdk/mixins.js +37 -0
- package/dist/cdk/mixins.test.d.ts +2 -0
- package/dist/cdk/mixins.test.d.ts.map +1 -0
- package/dist/cdk/mixins.test.js +108 -0
- package/dist/cdk/node-version.d.ts +14 -0
- package/dist/cdk/node-version.d.ts.map +1 -0
- package/dist/cdk/node-version.js +15 -0
- package/dist/cdk/stack-metadata.d.ts +12 -0
- package/dist/cdk/stack-metadata.d.ts.map +1 -0
- package/dist/cdk/stack-metadata.js +22 -0
- package/dist/cdk/stack-metadata.test.d.ts +2 -0
- package/dist/cdk/stack-metadata.test.d.ts.map +1 -0
- package/dist/cdk/stack-metadata.test.js +56 -0
- package/dist/cdk/synth-guard.d.ts +14 -0
- package/dist/cdk/synth-guard.d.ts.map +1 -0
- package/dist/cdk/synth-guard.js +20 -0
- package/dist/cdk/synth-guard.test.d.ts +2 -0
- package/dist/cdk/synth-guard.test.d.ts.map +1 -0
- package/dist/cdk/synth-guard.test.js +15 -0
- package/dist/client/index.d.ts +97 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +238 -0
- package/dist/client/index.test.d.ts +2 -0
- package/dist/client/index.test.d.ts.map +1 -0
- package/dist/client/index.test.js +113 -0
- package/dist/common/config.d.ts +45 -0
- package/dist/common/config.d.ts.map +1 -0
- package/dist/common/config.js +154 -0
- package/dist/common/config.test.d.ts +2 -0
- package/dist/common/config.test.d.ts.map +1 -0
- package/dist/common/config.test.js +173 -0
- package/dist/common/constants.d.ts +11 -0
- package/dist/common/constants.d.ts.map +1 -0
- package/dist/common/constants.js +12 -0
- package/dist/common/crypto.d.ts +6 -0
- package/dist/common/crypto.d.ts.map +1 -0
- package/dist/common/crypto.js +14 -0
- package/dist/common/index.d.ts +220 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +180 -0
- package/dist/common/index.test.d.ts +2 -0
- package/dist/common/index.test.d.ts.map +1 -0
- package/dist/common/index.test.js +195 -0
- package/dist/common/mock-data.d.ts +40 -0
- package/dist/common/mock-data.d.ts.map +1 -0
- package/dist/common/mock-data.js +39 -0
- package/dist/common/official-bb-names.generated.d.ts +7 -0
- package/dist/common/official-bb-names.generated.d.ts.map +1 -0
- package/dist/common/official-bb-names.generated.js +28 -0
- package/dist/common/sdk-registry.d.ts +136 -0
- package/dist/common/sdk-registry.d.ts.map +1 -0
- package/dist/common/sdk-registry.js +125 -0
- package/dist/constants.d.ts +27 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +28 -0
- package/dist/cors.d.ts +39 -0
- package/dist/cors.d.ts.map +1 -0
- package/dist/cors.js +85 -0
- package/dist/cors.test.d.ts +2 -0
- package/dist/cors.test.d.ts.map +1 -0
- package/dist/cors.test.js +241 -0
- package/dist/db-naming.d.ts +21 -0
- package/dist/db-naming.d.ts.map +1 -0
- package/dist/db-naming.js +38 -0
- package/dist/db-naming.test.d.ts +2 -0
- package/dist/db-naming.test.d.ts.map +1 -0
- package/dist/db-naming.test.js +29 -0
- package/dist/errors.d.ts +67 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +69 -0
- package/dist/hosting.d.ts +258 -0
- package/dist/hosting.d.ts.map +1 -0
- package/dist/hosting.js +340 -0
- package/dist/hosting.test.d.ts +2 -0
- package/dist/hosting.test.d.ts.map +1 -0
- package/dist/hosting.test.js +1077 -0
- package/dist/index.cdk.d.ts +13 -0
- package/dist/index.cdk.d.ts.map +1 -0
- package/dist/index.cdk.js +13 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/lambda-handler.d.ts +131 -0
- package/dist/lambda-handler.d.ts.map +1 -0
- package/dist/lambda-handler.js +610 -0
- package/dist/lambda-handler.test.d.ts +2 -0
- package/dist/lambda-handler.test.d.ts.map +1 -0
- package/dist/lambda-handler.test.js +835 -0
- package/dist/pipeline/index.d.ts +4 -0
- package/dist/pipeline/index.d.ts.map +1 -0
- package/dist/pipeline/index.js +3 -0
- package/dist/pipeline/pipeline-construct.d.ts +130 -0
- package/dist/pipeline/pipeline-construct.d.ts.map +1 -0
- package/dist/pipeline/pipeline-construct.js +484 -0
- package/dist/pipeline/pipeline.test.d.ts +2 -0
- package/dist/pipeline/pipeline.test.d.ts.map +1 -0
- package/dist/pipeline/pipeline.test.js +1231 -0
- package/dist/pipeline/types.d.ts +351 -0
- package/dist/pipeline/types.d.ts.map +1 -0
- package/dist/pipeline/types.js +3 -0
- package/dist/raw-route.cdk.d.ts +47 -0
- package/dist/raw-route.cdk.d.ts.map +1 -0
- package/dist/raw-route.cdk.js +51 -0
- package/dist/raw-route.d.ts +119 -0
- package/dist/raw-route.d.ts.map +1 -0
- package/dist/raw-route.js +239 -0
- package/dist/raw-route.mock.d.ts +47 -0
- package/dist/raw-route.mock.d.ts.map +1 -0
- package/dist/raw-route.mock.js +51 -0
- package/dist/raw-route.test.d.ts +2 -0
- package/dist/raw-route.test.d.ts.map +1 -0
- package/dist/raw-route.test.js +597 -0
- package/dist/redact.d.ts +51 -0
- package/dist/redact.d.ts.map +1 -0
- package/dist/redact.js +134 -0
- package/dist/redact.test.d.ts +2 -0
- package/dist/redact.test.d.ts.map +1 -0
- package/dist/redact.test.js +199 -0
- package/dist/rpc.d.ts +54 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +127 -0
- package/dist/rpc.test.d.ts +2 -0
- package/dist/rpc.test.d.ts.map +1 -0
- package/dist/rpc.test.js +60 -0
- package/dist/scripts/cdk-telemetry-env.d.ts +13 -0
- package/dist/scripts/cdk-telemetry-env.d.ts.map +1 -0
- package/dist/scripts/cdk-telemetry-env.js +21 -0
- package/dist/scripts/cdk-telemetry-env.test.d.ts +2 -0
- package/dist/scripts/cdk-telemetry-env.test.d.ts.map +1 -0
- package/dist/scripts/cdk-telemetry-env.test.js +56 -0
- package/dist/scripts/cleanup.d.ts +3 -0
- package/dist/scripts/cleanup.d.ts.map +1 -0
- package/dist/scripts/cleanup.js +35 -0
- package/dist/scripts/console.d.ts +6 -0
- package/dist/scripts/console.d.ts.map +1 -0
- package/dist/scripts/console.js +25 -0
- package/dist/scripts/deploy.d.ts +6 -0
- package/dist/scripts/deploy.d.ts.map +1 -0
- package/dist/scripts/deploy.js +82 -0
- package/dist/scripts/destroy.d.ts +6 -0
- package/dist/scripts/destroy.d.ts.map +1 -0
- package/dist/scripts/destroy.js +30 -0
- package/dist/scripts/dev-server-cors.test.d.ts +2 -0
- package/dist/scripts/dev-server-cors.test.d.ts.map +1 -0
- package/dist/scripts/dev-server-cors.test.js +23 -0
- package/dist/scripts/dev-server-telemetry.test.d.ts +2 -0
- package/dist/scripts/dev-server-telemetry.test.d.ts.map +1 -0
- package/dist/scripts/dev-server-telemetry.test.js +113 -0
- package/dist/scripts/dev-server.d.ts +21 -0
- package/dist/scripts/dev-server.d.ts.map +1 -0
- package/dist/scripts/dev-server.js +456 -0
- package/dist/scripts/ensure-secrets.d.ts +31 -0
- package/dist/scripts/ensure-secrets.d.ts.map +1 -0
- package/dist/scripts/ensure-secrets.js +100 -0
- package/dist/scripts/ensure-secrets.test.d.ts +2 -0
- package/dist/scripts/ensure-secrets.test.d.ts.map +1 -0
- package/dist/scripts/ensure-secrets.test.js +44 -0
- package/dist/scripts/external-migrations-step.d.ts +62 -0
- package/dist/scripts/external-migrations-step.d.ts.map +1 -0
- package/dist/scripts/external-migrations-step.js +243 -0
- package/dist/scripts/external-migrations-step.test.d.ts +2 -0
- package/dist/scripts/external-migrations-step.test.d.ts.map +1 -0
- package/dist/scripts/external-migrations-step.test.js +47 -0
- package/dist/scripts/extract-ts-types.d.ts +65 -0
- package/dist/scripts/extract-ts-types.d.ts.map +1 -0
- package/dist/scripts/extract-ts-types.js +664 -0
- package/dist/scripts/extract-ts-types.test.d.ts +2 -0
- package/dist/scripts/extract-ts-types.test.d.ts.map +1 -0
- package/dist/scripts/extract-ts-types.test.js +497 -0
- package/dist/scripts/generate-client-worker.d.ts +2 -0
- package/dist/scripts/generate-client-worker.d.ts.map +1 -0
- package/dist/scripts/generate-client-worker.js +13 -0
- package/dist/scripts/generate-client.d.ts +14 -0
- package/dist/scripts/generate-client.d.ts.map +1 -0
- package/dist/scripts/generate-client.js +73 -0
- package/dist/scripts/generate-client.test.d.ts +2 -0
- package/dist/scripts/generate-client.test.d.ts.map +1 -0
- package/dist/scripts/generate-client.test.js +48 -0
- package/dist/scripts/generate-spec-cli.d.ts +3 -0
- package/dist/scripts/generate-spec-cli.d.ts.map +1 -0
- package/dist/scripts/generate-spec-cli.js +77 -0
- package/dist/scripts/generate-spec-cli.test.d.ts +14 -0
- package/dist/scripts/generate-spec-cli.test.d.ts.map +1 -0
- package/dist/scripts/generate-spec-cli.test.js +90 -0
- package/dist/scripts/generate-spec.d.ts +61 -0
- package/dist/scripts/generate-spec.d.ts.map +1 -0
- package/dist/scripts/generate-spec.js +746 -0
- package/dist/scripts/generate-spec.test.d.ts +12 -0
- package/dist/scripts/generate-spec.test.d.ts.map +1 -0
- package/dist/scripts/generate-spec.test.js +88 -0
- package/dist/scripts/index.d.ts +12 -0
- package/dist/scripts/index.d.ts.map +1 -0
- package/dist/scripts/index.js +13 -0
- package/dist/scripts/sandbox.d.ts +11 -0
- package/dist/scripts/sandbox.d.ts.map +1 -0
- package/dist/scripts/sandbox.js +200 -0
- package/dist/scripts/telemetry-cli.d.ts +3 -0
- package/dist/scripts/telemetry-cli.d.ts.map +1 -0
- package/dist/scripts/telemetry-cli.js +8 -0
- package/dist/scripts/telemetry.d.ts +17 -0
- package/dist/scripts/telemetry.d.ts.map +1 -0
- package/dist/scripts/telemetry.js +150 -0
- package/dist/scripts/telemetry.test.d.ts +2 -0
- package/dist/scripts/telemetry.test.d.ts.map +1 -0
- package/dist/scripts/telemetry.test.js +203 -0
- package/dist/scripts/validate-spec.d.ts +22 -0
- package/dist/scripts/validate-spec.d.ts.map +1 -0
- package/dist/scripts/validate-spec.js +159 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +3 -0
- package/dist/server/withAuth.d.ts +142 -0
- package/dist/server/withAuth.d.ts.map +1 -0
- package/dist/server/withAuth.js +261 -0
- package/dist/server/withAuth.test.d.ts +2 -0
- package/dist/server/withAuth.test.d.ts.map +1 -0
- package/dist/server/withAuth.test.js +278 -0
- package/dist/telemetry/client.d.ts +59 -0
- package/dist/telemetry/client.d.ts.map +1 -0
- package/dist/telemetry/client.js +215 -0
- package/dist/telemetry/config-writer.d.ts +16 -0
- package/dist/telemetry/config-writer.d.ts.map +1 -0
- package/dist/telemetry/config-writer.js +36 -0
- package/dist/telemetry/consent-commands.test.d.ts +2 -0
- package/dist/telemetry/consent-commands.test.d.ts.map +1 -0
- package/dist/telemetry/consent-commands.test.js +161 -0
- package/dist/telemetry/consent.d.ts +60 -0
- package/dist/telemetry/consent.d.ts.map +1 -0
- package/dist/telemetry/consent.js +122 -0
- package/dist/telemetry/environment.d.ts +33 -0
- package/dist/telemetry/environment.d.ts.map +1 -0
- package/dist/telemetry/environment.js +87 -0
- package/dist/telemetry/identifiers.d.ts +20 -0
- package/dist/telemetry/identifiers.d.ts.map +1 -0
- package/dist/telemetry/identifiers.js +86 -0
- package/dist/telemetry/index.d.ts +6 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +4 -0
- package/dist/telemetry/telemetry.test.d.ts +2 -0
- package/dist/telemetry/telemetry.test.d.ts.map +1 -0
- package/dist/telemetry/telemetry.test.js +1131 -0
- package/dist/telemetry/trackCommand.d.ts +32 -0
- package/dist/telemetry/trackCommand.d.ts.map +1 -0
- package/dist/telemetry/trackCommand.js +102 -0
- package/dist/telemetry/types.d.ts +92 -0
- package/dist/telemetry/types.d.ts.map +1 -0
- package/dist/telemetry/types.js +1 -0
- package/dist/types.d.ts +24 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/package.json +83 -0
- package/src/api.test.ts +25 -0
- package/src/api.ts +163 -0
- package/src/bb-utils.ts +13 -0
- package/src/builtin-routes.ts +62 -0
- package/src/cdk/__fixtures__/factory-backend.ts +8 -0
- package/src/cdk/__fixtures__/fullid-construct-backend.ts +42 -0
- package/src/cdk/__fixtures__/handler.ts +4 -0
- package/src/cdk/__fixtures__/side-effect-backend.ts +7 -0
- package/src/cdk/blocks-backend.test.ts +207 -0
- package/src/cdk/blocks-backend.ts +249 -0
- package/src/cdk/blocks-stack.test.ts +106 -0
- package/src/cdk/config-registry.ts +106 -0
- package/src/cdk/index.ts +115 -0
- package/src/cdk/mixins.test.ts +129 -0
- package/src/cdk/mixins.ts +41 -0
- package/src/cdk/node-version.ts +17 -0
- package/src/cdk/stack-metadata.test.ts +71 -0
- package/src/cdk/stack-metadata.ts +29 -0
- package/src/cdk/synth-guard.test.ts +21 -0
- package/src/cdk/synth-guard.ts +23 -0
- package/src/client/index.test.ts +118 -0
- package/src/client/index.ts +320 -0
- package/src/common/config.test.ts +236 -0
- package/src/common/config.ts +169 -0
- package/src/common/constants.ts +15 -0
- package/src/common/crypto.ts +15 -0
- package/src/common/index.test.ts +242 -0
- package/src/common/index.ts +335 -0
- package/src/common/mock-data.ts +52 -0
- package/src/common/official-bb-names.generated.ts +29 -0
- package/src/common/sdk-registry.ts +150 -0
- package/src/constants.ts +31 -0
- package/src/cors.test.ts +279 -0
- package/src/cors.ts +91 -0
- package/src/db-naming.test.ts +48 -0
- package/src/db-naming.ts +41 -0
- package/src/errors.ts +72 -0
- package/src/hosting.test.ts +1431 -0
- package/src/hosting.ts +626 -0
- package/src/index.cdk.ts +45 -0
- package/src/index.ts +22 -0
- package/src/lambda-handler.test.ts +1005 -0
- package/src/lambda-handler.ts +706 -0
- package/src/pipeline/index.ts +12 -0
- package/src/pipeline/pipeline-construct.ts +662 -0
- package/src/pipeline/pipeline.test.ts +1565 -0
- package/src/pipeline/types.ts +384 -0
- package/src/raw-route.cdk.ts +56 -0
- package/src/raw-route.mock.ts +56 -0
- package/src/raw-route.test.ts +819 -0
- package/src/raw-route.ts +316 -0
- package/src/redact.test.ts +222 -0
- package/src/redact.ts +143 -0
- package/src/rpc.test.ts +73 -0
- package/src/rpc.ts +174 -0
- package/src/scripts/cdk-telemetry-env.test.ts +75 -0
- package/src/scripts/cdk-telemetry-env.ts +23 -0
- package/src/scripts/cleanup.ts +39 -0
- package/src/scripts/console.ts +34 -0
- package/src/scripts/deploy.ts +106 -0
- package/src/scripts/destroy.ts +42 -0
- package/src/scripts/dev-server-cors.test.ts +28 -0
- package/src/scripts/dev-server-telemetry.test.ts +127 -0
- package/src/scripts/dev-server.ts +515 -0
- package/src/scripts/ensure-secrets.test.ts +50 -0
- package/src/scripts/ensure-secrets.ts +113 -0
- package/src/scripts/external-migrations-step.test.ts +64 -0
- package/src/scripts/external-migrations-step.ts +269 -0
- package/src/scripts/extract-ts-types.test.ts +516 -0
- package/src/scripts/extract-ts-types.ts +773 -0
- package/src/scripts/generate-client-worker.ts +15 -0
- package/src/scripts/generate-client.test.ts +69 -0
- package/src/scripts/generate-client.ts +86 -0
- package/src/scripts/generate-spec-cli.test.ts +106 -0
- package/src/scripts/generate-spec-cli.ts +92 -0
- package/src/scripts/generate-spec.test.ts +99 -0
- package/src/scripts/generate-spec.ts +833 -0
- package/src/scripts/index.ts +21 -0
- package/src/scripts/sandbox.ts +230 -0
- package/src/scripts/telemetry-cli.ts +10 -0
- package/src/scripts/telemetry.test.ts +239 -0
- package/src/scripts/telemetry.ts +173 -0
- package/src/scripts/validate-spec.ts +199 -0
- package/src/server/index.ts +5 -0
- package/src/server/withAuth.test.ts +348 -0
- package/src/server/withAuth.ts +323 -0
- package/src/telemetry/client.ts +226 -0
- package/src/telemetry/config-writer.ts +52 -0
- package/src/telemetry/consent-commands.test.ts +196 -0
- package/src/telemetry/consent.ts +154 -0
- package/src/telemetry/environment.ts +100 -0
- package/src/telemetry/identifiers.ts +94 -0
- package/src/telemetry/index.ts +11 -0
- package/src/telemetry/telemetry.test.ts +1343 -0
- package/src/telemetry/trackCommand.ts +110 -0
- package/src/telemetry/types.ts +92 -0
- package/src/types.ts +33 -0
- package/src/version.ts +2 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Worker script for generating client code.
|
|
6
|
+
* Usage: node [--conditions=aws-runtime] --import tsx generate-client-worker.js <foundationPath> <outputPath>
|
|
7
|
+
*/
|
|
8
|
+
import { generateClientCode } from './generate-client.js';
|
|
9
|
+
import { writeFileSync, mkdirSync } from 'fs';
|
|
10
|
+
import { dirname } from 'path';
|
|
11
|
+
|
|
12
|
+
const [foundationPath, outputPath] = process.argv.slice(2);
|
|
13
|
+
const code = await generateClientCode(foundationPath);
|
|
14
|
+
mkdirSync(dirname(outputPath), { recursive: true });
|
|
15
|
+
writeFileSync(outputPath, code);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { describe, it, beforeEach, afterEach } from 'node:test';
|
|
5
|
+
import assert from 'node:assert';
|
|
6
|
+
import { generateClientCode } from './generate-client.js';
|
|
7
|
+
import { writeFileSync, mkdirSync, rmSync } from 'fs';
|
|
8
|
+
import { join } from 'path';
|
|
9
|
+
import { tmpdir } from 'os';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Regression test: generateClientCode collects middleware from whatever
|
|
13
|
+
* the backend registers via registerClientMiddleware(). In sandbox mode,
|
|
14
|
+
* the backend is imported WITHOUT --conditions=aws-runtime, so it registers
|
|
15
|
+
* mock-middleware instead of aws-middleware. The dev server must NOT call
|
|
16
|
+
* generateClientCode in sandbox mode (sandbox.ts already generated the
|
|
17
|
+
* correct client with the aws-runtime condition).
|
|
18
|
+
*
|
|
19
|
+
* This test verifies the mechanism: middleware specifiers registered during
|
|
20
|
+
* backend import appear as imports in the generated client code.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
describe('generateClientCode — middleware collection', () => {
|
|
24
|
+
let tmpDir: string;
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
tmpDir = join(tmpdir(), `blocks-gen-client-test-${Date.now()}`);
|
|
28
|
+
mkdirSync(tmpDir, { recursive: true });
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
rmSync(tmpDir, { recursive: true, force: true });
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('includes middleware specifiers registered by the backend', async () => {
|
|
36
|
+
// Create a minimal backend that registers a middleware specifier
|
|
37
|
+
const backendPath = join(tmpDir, 'backend.mjs');
|
|
38
|
+
writeFileSync(backendPath, `
|
|
39
|
+
globalThis.__BLOCKS_CLIENT_MIDDLEWARE__?.push('@aws-blocks/bb-realtime/aws-middleware');
|
|
40
|
+
`);
|
|
41
|
+
|
|
42
|
+
const code = await generateClientCode(backendPath);
|
|
43
|
+
assert.ok(
|
|
44
|
+
code.includes("import '@aws-blocks/bb-realtime/aws-middleware'"),
|
|
45
|
+
'Generated client must include aws-middleware when backend registers it',
|
|
46
|
+
);
|
|
47
|
+
assert.ok(
|
|
48
|
+
!code.includes('mock-middleware'),
|
|
49
|
+
'Generated client must NOT include mock-middleware when backend registers aws-middleware',
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('includes mock-middleware when backend registers it (local dev mode)', async () => {
|
|
54
|
+
const backendPath = join(tmpDir, 'backend.mjs');
|
|
55
|
+
writeFileSync(backendPath, `
|
|
56
|
+
globalThis.__BLOCKS_CLIENT_MIDDLEWARE__?.push('@aws-blocks/bb-realtime/mock-middleware');
|
|
57
|
+
`);
|
|
58
|
+
|
|
59
|
+
const code = await generateClientCode(backendPath);
|
|
60
|
+
assert.ok(
|
|
61
|
+
code.includes("import '@aws-blocks/bb-realtime/mock-middleware'"),
|
|
62
|
+
'Generated client must include mock-middleware in local dev mode',
|
|
63
|
+
);
|
|
64
|
+
assert.ok(
|
|
65
|
+
!code.includes('aws-middleware'),
|
|
66
|
+
'Generated client must NOT include aws-middleware in local dev mode',
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
5
|
+
import { dirname } from 'path';
|
|
6
|
+
import { pathToFileURL } from 'url';
|
|
7
|
+
import { API_NAMESPACE_MARKER } from '../api.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Generate browser-safe client code from backend exports.
|
|
11
|
+
*
|
|
12
|
+
* Sets up global collectors (__BLOCKS_CLIENT_MIDDLEWARE__) before importing
|
|
13
|
+
* the backend so that Building Block constructors can register their
|
|
14
|
+
* middleware. After import, reads the collected specifiers and emits
|
|
15
|
+
* import statements + ApiNamespace proxy exports.
|
|
16
|
+
*/
|
|
17
|
+
export async function generateClientCode(foundationPath: string): Promise<string> {
|
|
18
|
+
// Set up global collector if not already present (dev server may have already done this)
|
|
19
|
+
const collectorAlreadyActive = Array.isArray((globalThis as any).__BLOCKS_CLIENT_MIDDLEWARE__);
|
|
20
|
+
if (!collectorAlreadyActive) {
|
|
21
|
+
(globalThis as any).__BLOCKS_CLIENT_MIDDLEWARE__ = [];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const backend = await import(pathToFileURL(foundationPath).href);
|
|
25
|
+
|
|
26
|
+
// Read collected middleware and clean up
|
|
27
|
+
const middleware: string[] = (globalThis as any).__BLOCKS_CLIENT_MIDDLEWARE__;
|
|
28
|
+
delete (globalThis as any).__BLOCKS_CLIENT_MIDDLEWARE__;
|
|
29
|
+
|
|
30
|
+
const imports = new Set<string>();
|
|
31
|
+
const lines: string[] = [];
|
|
32
|
+
const namespaceNames: string[] = [];
|
|
33
|
+
|
|
34
|
+
imports.add(`import { ApiNamespaceClient as __BLOCKS_ApiNamespaceClient__ } from '@aws-blocks/blocks/client';`);
|
|
35
|
+
|
|
36
|
+
for (const specifier of middleware) {
|
|
37
|
+
imports.add(`import '${specifier}';`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Emit ApiNamespace proxy exports
|
|
41
|
+
for (const [name, value] of Object.entries(backend)) {
|
|
42
|
+
if (name.startsWith('_')) continue;
|
|
43
|
+
|
|
44
|
+
const isApiNamespace = typeof (value as any)?.[API_NAMESPACE_MARKER] === 'string';
|
|
45
|
+
if (isApiNamespace) {
|
|
46
|
+
lines.push(`export const ${name} = __BLOCKS_ApiNamespaceClient__('${name}');`);
|
|
47
|
+
namespaceNames.push(name);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Fallback: any exported function/object that isn't a Scope gets a proxy.
|
|
52
|
+
const isScope = typeof (value as any)?.id === 'string' && typeof (value as any)?.fullId === 'string';
|
|
53
|
+
if (isScope) continue;
|
|
54
|
+
|
|
55
|
+
// Fallback: any exported function/object gets an ApiNamespace proxy.
|
|
56
|
+
if ((typeof value === 'function' || typeof value === 'object') && value !== null) {
|
|
57
|
+
lines.push(`export const ${name} = __BLOCKS_ApiNamespaceClient__('${name}');`);
|
|
58
|
+
namespaceNames.push(name);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Emit generateClient — creates new ApiNamespaceClient instances with the given url
|
|
63
|
+
const nsEntries = namespaceNames.map(n => ` ${n}: __BLOCKS_ApiNamespaceClient__('${n}', config),`).join('\n');
|
|
64
|
+
lines.push('');
|
|
65
|
+
lines.push(`export const generateClient = (config) => ({\n${nsEntries}\n});`);
|
|
66
|
+
|
|
67
|
+
const header = [
|
|
68
|
+
'// ============================================================',
|
|
69
|
+
'// AUTO-GENERATED FILE — DO NOT EDIT',
|
|
70
|
+
'//',
|
|
71
|
+
'// This file is generated by the Blocks dev server / build process.',
|
|
72
|
+
'// Any manual changes will be overwritten on the next build.',
|
|
73
|
+
'// ============================================================',
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
return [...header, '', ...imports, '', ...lines].join('\n');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Generate client code and write it to the aws-blocks subpackage.
|
|
81
|
+
*/
|
|
82
|
+
export async function writeClientCode(foundationPath: string, outputPath: string): Promise<void> {
|
|
83
|
+
const code = await generateClientCode(foundationPath);
|
|
84
|
+
mkdirSync(dirname(outputPath), { recursive: true });
|
|
85
|
+
writeFileSync(outputPath, code);
|
|
86
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration test for the `blocks-generate-spec` bin.
|
|
3
|
+
*
|
|
4
|
+
* Verifies:
|
|
5
|
+
* 1. The CLI accepts a `.ts` entry point (regression for the
|
|
6
|
+
* "Unknown file extension .ts" failure that broke fresh scaffolds).
|
|
7
|
+
* 2. The CLI still accepts a `.js` entry point and does not require tsx.
|
|
8
|
+
*
|
|
9
|
+
* Spawns the bin as a child process, the same way an end user (or `npx`) would.
|
|
10
|
+
* The "tsx missing" branch is covered by manual review — it's hard to
|
|
11
|
+
* simulate inside this monorepo where `tsx` is hoisted at the workspace root.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { describe, it } from 'node:test';
|
|
15
|
+
import assert from 'node:assert';
|
|
16
|
+
import { writeFileSync, mkdirSync, rmSync, readFileSync, existsSync, copyFileSync } from 'node:fs';
|
|
17
|
+
import { join, dirname } from 'node:path';
|
|
18
|
+
import { tmpdir } from 'node:os';
|
|
19
|
+
import { fileURLToPath } from 'node:url';
|
|
20
|
+
import { spawnSync } from 'node:child_process';
|
|
21
|
+
|
|
22
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
23
|
+
const cliPath = join(__dirname, 'generate-spec-cli.js');
|
|
24
|
+
|
|
25
|
+
function makeBackend(dir: string, ext: 'ts' | 'js'): string {
|
|
26
|
+
// Copy the marker module next to the foundation so a relative import
|
|
27
|
+
// resolves through both ESM and CJS loaders.
|
|
28
|
+
const distDir = join(__dirname, '..');
|
|
29
|
+
copyFileSync(join(distDir, 'api.js'), join(dir, 'api.js'));
|
|
30
|
+
|
|
31
|
+
const indexPath = join(dir, `index.${ext}`);
|
|
32
|
+
writeFileSync(indexPath, `
|
|
33
|
+
import { ApiNamespace } from './api.js';
|
|
34
|
+
|
|
35
|
+
export const api = new ApiNamespace(null, 'api', (context) => ({
|
|
36
|
+
async ping() { return { ok: true }; },
|
|
37
|
+
async echo(s) { return s; },
|
|
38
|
+
}));
|
|
39
|
+
`);
|
|
40
|
+
// tsconfig that allows JS so the spec emitter's TypeScript pass succeeds
|
|
41
|
+
// regardless of which extension the entry point uses.
|
|
42
|
+
writeFileSync(join(dir, 'tsconfig.json'), JSON.stringify({
|
|
43
|
+
compilerOptions: {
|
|
44
|
+
target: 'ESNext',
|
|
45
|
+
module: 'ESNext',
|
|
46
|
+
moduleResolution: 'bundler',
|
|
47
|
+
allowJs: true,
|
|
48
|
+
esModuleInterop: true,
|
|
49
|
+
skipLibCheck: true,
|
|
50
|
+
},
|
|
51
|
+
}));
|
|
52
|
+
return indexPath;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function runCli(args: string[], env: NodeJS.ProcessEnv = process.env) {
|
|
56
|
+
return spawnSync(process.execPath, [cliPath, ...args], {
|
|
57
|
+
encoding: 'utf-8',
|
|
58
|
+
env,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
describe('blocks-generate-spec CLI', () => {
|
|
63
|
+
it('accepts a TypeScript entry point and emits a valid spec', async () => {
|
|
64
|
+
const dir = join(tmpdir(), `blocks-spec-cli-test-${Date.now()}-ts`);
|
|
65
|
+
mkdirSync(dir, { recursive: true });
|
|
66
|
+
const indexPath = makeBackend(dir, 'ts');
|
|
67
|
+
const outputPath = join(dir, 'blocks.spec.json');
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
const result = runCli([indexPath, outputPath]);
|
|
71
|
+
assert.strictEqual(
|
|
72
|
+
result.status,
|
|
73
|
+
0,
|
|
74
|
+
`CLI exited ${result.status}.\nstdout:\n${result.stdout}\nstderr:\n${result.stderr}`,
|
|
75
|
+
);
|
|
76
|
+
assert.ok(existsSync(outputPath), 'spec file should exist');
|
|
77
|
+
const spec = JSON.parse(readFileSync(outputPath, 'utf-8'));
|
|
78
|
+
const methodNames = (spec.methods as { name: string }[]).map((m) => m.name).sort();
|
|
79
|
+
assert.deepStrictEqual(methodNames, ['api.echo', 'api.ping']);
|
|
80
|
+
} finally {
|
|
81
|
+
rmSync(dir, { recursive: true, force: true });
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('accepts a JavaScript entry point (no tsx needed)', async () => {
|
|
86
|
+
const dir = join(tmpdir(), `blocks-spec-cli-test-${Date.now()}-js`);
|
|
87
|
+
mkdirSync(dir, { recursive: true });
|
|
88
|
+
const indexPath = makeBackend(dir, 'js');
|
|
89
|
+
const outputPath = join(dir, 'blocks.spec.json');
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
const result = runCli([indexPath, outputPath]);
|
|
93
|
+
assert.strictEqual(
|
|
94
|
+
result.status,
|
|
95
|
+
0,
|
|
96
|
+
`CLI exited ${result.status}.\nstdout:\n${result.stdout}\nstderr:\n${result.stderr}`,
|
|
97
|
+
);
|
|
98
|
+
const spec = JSON.parse(readFileSync(outputPath, 'utf-8'));
|
|
99
|
+
const methodNames = (spec.methods as { name: string }[]).map((m) => m.name).sort();
|
|
100
|
+
assert.deepStrictEqual(methodNames, ['api.echo', 'api.ping']);
|
|
101
|
+
} finally {
|
|
102
|
+
rmSync(dir, { recursive: true, force: true });
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* CLI wrapper for `writeSpec()`. Generates `aws-blocks/blocks.spec.json` from a
|
|
7
|
+
* backend entry point. Exposed as the `blocks-generate-spec` bin entry on
|
|
8
|
+
* `@aws-blocks/core`, so any Blocks app can invoke it via
|
|
9
|
+
* `npx blocks-generate-spec`.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* node dist/scripts/generate-spec-cli.js [backendPath] [outputPath]
|
|
13
|
+
*
|
|
14
|
+
* Defaults:
|
|
15
|
+
* backendPath = ./aws-blocks/index.ts
|
|
16
|
+
* outputPath = ./aws-blocks/blocks.spec.json
|
|
17
|
+
*
|
|
18
|
+
* For a TypeScript backend entry, this CLI lazily loads `tsx` and uses
|
|
19
|
+
* its programmatic `tsImport` so no extra build step is needed. JS entries
|
|
20
|
+
* use plain `import()` and don't pull tsx in.
|
|
21
|
+
*
|
|
22
|
+
* The spec emitter loads the TypeScript compiler (~1.5s of cold-start), which
|
|
23
|
+
* is why this lives in its own CLI rather than being wired into `npm run dev`.
|
|
24
|
+
* See docs/native-clients/codegen-design.md § Build pipeline.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { resolve, dirname, join } from 'node:path';
|
|
28
|
+
import { writeSpec, type FoundationLoader } from './generate-spec.js';
|
|
29
|
+
|
|
30
|
+
/** Pick a loader based on the file extension. `.ts` / `.tsx` use tsx; everything else uses Node's native `import()`. */
|
|
31
|
+
async function selectLoader(foundationPath: string): Promise<FoundationLoader | undefined> {
|
|
32
|
+
if (!/\.(ts|tsx|mts|cts)$/i.test(foundationPath)) {
|
|
33
|
+
// JS entry point — let the default `import()` handle it.
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let tsImport: ((specifier: string, parentURL: string) => Promise<unknown>) | undefined;
|
|
38
|
+
try {
|
|
39
|
+
// `tsx/esm/api` is a peer-style helper. We require the consuming app to
|
|
40
|
+
// have it installed (via the template's devDependencies) rather than
|
|
41
|
+
// bundling it into @aws-blocks/core, so the runtime Lambda path stays
|
|
42
|
+
// JS-only. If it's missing, fall through to the helpful error below.
|
|
43
|
+
const mod = await import('tsx/esm/api');
|
|
44
|
+
tsImport = (mod as { tsImport?: typeof tsImport }).tsImport;
|
|
45
|
+
} catch {
|
|
46
|
+
throw new Error(
|
|
47
|
+
[
|
|
48
|
+
`Cannot load TypeScript entry "${foundationPath}" — \`tsx\` is not installed.`,
|
|
49
|
+
`Install it as a devDependency:`,
|
|
50
|
+
` npm install -D tsx`,
|
|
51
|
+
`Or pass a pre-built JavaScript entry instead.`,
|
|
52
|
+
].join('\n'),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!tsImport) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`The installed version of tsx does not export \`tsImport\` from \`tsx/esm/api\`. Upgrade to tsx ≥ 4.7.`,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// `tsImport` needs a `parentURL` so it can resolve relative imports inside
|
|
63
|
+
// the TS file. `import.meta.url` of *this* CLI works because the entry
|
|
64
|
+
// path we pass is absolute — the parentURL only seeds the registry.
|
|
65
|
+
const parentURL = import.meta.url;
|
|
66
|
+
return (fileUrl) => tsImport!(fileUrl, parentURL) as Promise<Record<string, unknown>>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function main() {
|
|
70
|
+
const [, , backendArg, outputArg] = process.argv;
|
|
71
|
+
|
|
72
|
+
const backendPath = resolve(backendArg ?? './aws-blocks/index.ts');
|
|
73
|
+
const outputPath = resolve(
|
|
74
|
+
outputArg ?? join(dirname(backendPath), 'blocks.spec.json')
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
console.log('📝 Generating OpenRPC spec...');
|
|
78
|
+
console.log(' backend:', backendPath);
|
|
79
|
+
console.log(' output: ', outputPath);
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const loader = await selectLoader(backendPath);
|
|
83
|
+
await writeSpec(backendPath, outputPath, loader);
|
|
84
|
+
console.log('✅ OpenRPC spec written to', outputPath);
|
|
85
|
+
} catch (err) {
|
|
86
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
87
|
+
console.error('❌ Spec generation failed:', message);
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
main();
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration test for `generateSpec`. Builds a tiny backend file with one
|
|
3
|
+
* normal method and one `@blocksSkipCodegen`-tagged method, runs the spec
|
|
4
|
+
* emitter, and asserts the tagged method is dropped from the OpenRPC
|
|
5
|
+
* document.
|
|
6
|
+
*
|
|
7
|
+
* Uses a `.js` foundation file so plain `node --test dist/...` can run the
|
|
8
|
+
* test without a TypeScript loader. The TS compiler still parses JSDoc on
|
|
9
|
+
* the `.js` file when `allowJs` is enabled in the synthetic tsconfig.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { describe, it } from 'node:test';
|
|
13
|
+
import assert from 'node:assert';
|
|
14
|
+
import { writeFileSync, mkdirSync, rmSync } from 'fs';
|
|
15
|
+
import { join, dirname } from 'path';
|
|
16
|
+
import { tmpdir } from 'os';
|
|
17
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
18
|
+
import { generateSpec } from './generate-spec.js';
|
|
19
|
+
|
|
20
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
21
|
+
// `import.meta.url` lives in dist/scripts/, so `..` is dist/ and the built
|
|
22
|
+
// `api.js` is next to it. Re-using the real ApiNamespace ensures the marker
|
|
23
|
+
// symbol matches what `generateSpec` discovers.
|
|
24
|
+
const builtApiUrl = pathToFileURL(join(__dirname, '..', 'api.js')).href;
|
|
25
|
+
|
|
26
|
+
function writeTsconfig(dir: string): void {
|
|
27
|
+
writeFileSync(join(dir, 'tsconfig.json'), JSON.stringify({
|
|
28
|
+
compilerOptions: {
|
|
29
|
+
target: 'ESNext',
|
|
30
|
+
module: 'ESNext',
|
|
31
|
+
moduleResolution: 'bundler',
|
|
32
|
+
allowJs: true,
|
|
33
|
+
esModuleInterop: true,
|
|
34
|
+
skipLibCheck: true,
|
|
35
|
+
},
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe('generateSpec — @blocksSkipCodegen', () => {
|
|
40
|
+
it('drops methods carrying @blocksSkipCodegen from the OpenRPC document', async () => {
|
|
41
|
+
const dir = join(tmpdir(), `blocks-spec-test-${Date.now()}-skip`);
|
|
42
|
+
mkdirSync(dir, { recursive: true });
|
|
43
|
+
writeTsconfig(dir);
|
|
44
|
+
|
|
45
|
+
writeFileSync(join(dir, 'index.js'), `
|
|
46
|
+
import { ApiNamespace } from ${JSON.stringify(builtApiUrl)};
|
|
47
|
+
|
|
48
|
+
export const api = new ApiNamespace(null, 'api', (context) => ({
|
|
49
|
+
async normalMethod(name) {
|
|
50
|
+
return { greeting: 'hi ' + name };
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Mock-only helper.
|
|
55
|
+
* @blocksSkipCodegen
|
|
56
|
+
*/
|
|
57
|
+
async getLastCode() {
|
|
58
|
+
return null;
|
|
59
|
+
},
|
|
60
|
+
}));
|
|
61
|
+
`);
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const doc = await generateSpec(join(dir, 'index.js'));
|
|
65
|
+
const methodNames = doc.methods.map((m) => m.name).sort();
|
|
66
|
+
assert.deepStrictEqual(
|
|
67
|
+
methodNames,
|
|
68
|
+
['api.normalMethod'],
|
|
69
|
+
'getLastCode should be omitted; only normalMethod should remain',
|
|
70
|
+
);
|
|
71
|
+
} finally {
|
|
72
|
+
rmSync(dir, { recursive: true, force: true });
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('keeps methods that do not carry the tag', async () => {
|
|
77
|
+
const dir = join(tmpdir(), `blocks-spec-test-${Date.now()}-keep`);
|
|
78
|
+
mkdirSync(dir, { recursive: true });
|
|
79
|
+
writeTsconfig(dir);
|
|
80
|
+
|
|
81
|
+
writeFileSync(join(dir, 'index.js'), `
|
|
82
|
+
import { ApiNamespace } from ${JSON.stringify(builtApiUrl)};
|
|
83
|
+
|
|
84
|
+
export const api = new ApiNamespace(null, 'api', (context) => ({
|
|
85
|
+
/** Plain JSDoc with no special tag. */
|
|
86
|
+
async ping() { return { ok: true }; },
|
|
87
|
+
async echo(s) { return s; },
|
|
88
|
+
}));
|
|
89
|
+
`);
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
const doc = await generateSpec(join(dir, 'index.js'));
|
|
93
|
+
const methodNames = doc.methods.map((m) => m.name).sort();
|
|
94
|
+
assert.deepStrictEqual(methodNames, ['api.echo', 'api.ping']);
|
|
95
|
+
} finally {
|
|
96
|
+
rmSync(dir, { recursive: true, force: true });
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|