Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
63 changes: 45 additions & 18 deletions packages/aws/scripts/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BunRuntime, BunServices } from "@effect/platform-bun";
import dedent from "dedent";
import {
Console,
Context,
Data,
Deferred,
Effect,
Expand All @@ -10,12 +11,9 @@ import {
Option,
Ref,
Schema as S,
Context,
} from "effect";
import * as FileSystem from "effect/FileSystem";
import * as Path from "effect/Path";
import * as ChildProcess from "effect/unstable/process/ChildProcess";
import { loadServiceSpecPatch, type ServiceSpec } from "./spec-schema.ts";
import type { RuleSetObject } from "./compile-rules.ts";
import { generateRuleSetCode } from "./compile-rules.ts";
import {
Expand All @@ -24,6 +22,7 @@ import {
SmithyModel,
type ShapeTypeMap,
} from "./model-schema.ts";
import { loadServiceSpecPatch, type ServiceSpec } from "./spec-schema.ts";
//todo(pear): swap out for effect platform path
import path from "pathe";

Expand Down Expand Up @@ -128,7 +127,7 @@ class UnableToTransformShapeToSchema extends Data.TaggedError(
const annotatePureExportConst = (definition: string) =>
definition.replace(
/^export const ([^=]+?)\s*=\s*/m,
"export const $1 = /*@__PURE__*/ /*#__PURE__*/ ",
`export const $1 = ${definition.includes("(") ? "/*@__PURE__*/ " : ""}`,
);

// =============================================================================
Expand Down Expand Up @@ -1552,7 +1551,9 @@ const convertShapeToSchema: (
.map((v) => `"${v}"`)
.join("\n | ");
const typeAlias = `export type ${schemaName} =\n | ${literalUnion}\n | (string & {});`;
const schemaDef = annotatePureExportConst(`export const ${schemaName} = S.String;`);
const schemaDef = annotatePureExportConst(
`export const ${schemaName} = S.String;`,
);
return addAlias(Effect.succeed(`${typeAlias}\n${schemaDef}`), []);
},
),
Expand Down Expand Up @@ -1583,7 +1584,9 @@ const convertShapeToSchema: (
const literals = enumValues.join(", ");
const literalUnion = enumValues.join(" | ");
const typeAlias = `export type ${schemaName} = ${literalUnion};`;
const schemaDef = annotatePureExportConst(`export const ${schemaName} = S.Literals([${literals}]);`);
const schemaDef = annotatePureExportConst(
`export const ${schemaName} = S.Literals([${literals}]);`,
);
return addAlias(Effect.succeed(`${typeAlias}\n${schemaDef}`), []);
},
),
Expand Down Expand Up @@ -1638,8 +1641,12 @@ const convertShapeToSchema: (
);
const typeAlias = `export type ${schemaName} = ${memberTsType}[];`;
const schemaDef = isCyclic
? annotatePureExportConst(`export const ${schemaName} = S.Array(${innerType})${sparsePipe} as any as S.Schema<${schemaName}>;`)
: annotatePureExportConst(`export const ${schemaName} = S.Array(${innerType})${sparsePipe};`);
? annotatePureExportConst(
`export const ${schemaName} = S.Array(${innerType})${sparsePipe} as any as S.Schema<${schemaName}>;`,
)
: annotatePureExportConst(
`export const ${schemaName} = S.Array(${innerType})${sparsePipe};`,
);
return `${typeAlias}\n${schemaDef}`;
}),
),
Expand Down Expand Up @@ -2010,7 +2017,9 @@ const convertShapeToSchema: (
// Generate interface + suspend(struct) pattern
// Trait annotations inside suspend, identifier outside
const interfaceDef = `export interface ${exportedName} { ${interfaceFields} }`;
const schemaDef = annotatePureExportConst(`export const ${exportedName} = S.suspend(() => S.Struct({${schemaFields}})${encodeKeysPipe}${innerPipe})${outerAnnotation} as any as S.Schema<${exportedName}>;`);
const schemaDef = annotatePureExportConst(
`export const ${exportedName} = S.suspend(() => S.Struct({${schemaFields}})${encodeKeysPipe}${innerPipe})${outerAnnotation} as any as S.Schema<${exportedName}>;`,
);

return `${interfaceDef}\n${schemaDef}`;
}),
Expand Down Expand Up @@ -2259,8 +2268,12 @@ const convertShapeToSchema: (
}

const schemaDef = isCyclic
? annotatePureExportConst(`export const ${schemaName} = ${recordExpr} as any as S.Schema<${schemaName}>;`)
: annotatePureExportConst(`export const ${schemaName} = ${recordExpr};`);
? annotatePureExportConst(
`export const ${schemaName} = ${recordExpr} as any as S.Schema<${schemaName}>;`,
)
: annotatePureExportConst(
`export const ${schemaName} = ${recordExpr};`,
);
return `${typeAlias}\n${schemaDef}`;
}),
),
Expand Down Expand Up @@ -2627,7 +2640,9 @@ const generateClient = Effect.fn(function* (
const outerAnnotation = `.annotate({ identifier: "${className}" })`;

const interfaceDef = `export interface ${className} {}`;
const schemaDef = annotatePureExportConst(`export const ${className} = S.suspend(() => S.Struct({})${innerPipe})${outerAnnotation} as any as S.Schema<${className}>;`);
const schemaDef = annotatePureExportConst(
`export const ${className} = S.suspend(() => S.Struct({})${innerPipe})${outerAnnotation} as any as S.Schema<${className}>;`,
);
const definition = `${interfaceDef}\n${schemaDef}`;
yield* Ref.update(sdkFile.schemas, (arr) => [
...arr,
Expand Down Expand Up @@ -2661,7 +2676,9 @@ const generateClient = Effect.fn(function* (
const outerAnnotation = `.annotate({ identifier: "${className}" })`;

const interfaceDef = `export interface ${className} {}`;
const schemaDef = annotatePureExportConst(`export const ${className} = S.suspend(() => S.Struct({})${innerPipe})${outerAnnotation} as any as S.Schema<${className}>;`);
const schemaDef = annotatePureExportConst(
`export const ${className} = S.suspend(() => S.Struct({})${innerPipe})${outerAnnotation} as any as S.Schema<${className}>;`,
);
const definition = `${interfaceDef}\n${schemaDef}`;
yield* Ref.update(sdkFile.schemas, (arr) => [
...arr,
Expand Down Expand Up @@ -2928,7 +2945,7 @@ const generateClient = Effect.fn(function* (
c +
errorTypeAlias +
operationComment +
`export const ${exportedName}: ${typeAnnotation} = /*@__PURE__*/ /*#__PURE__*/ ${apiFn}(() => (${metaObject}));\n`,
`export const ${exportedName}: ${typeAnnotation} = /*@__PURE__*/ ${apiFn}(() => (${metaObject}));\n`,
),
);
}),
Expand Down Expand Up @@ -3264,14 +3281,24 @@ BunRuntime.runMain(
"partition",
"partitions.json",
);
const partitionsExists = yield* fs.exists(partitionsSrc).pipe(Effect.catch(() => Effect.succeed(false)));
const partitionsExists = yield* fs
.exists(partitionsSrc)
.pipe(Effect.catch(() => Effect.succeed(false)));
if (partitionsExists) {
yield* fs.makeDirectory(path.join("src", "rules-engine"), { recursive: true });
const partitionsDest = path.join("src", "rules-engine", "partitions.json");
yield* fs.makeDirectory(path.join("src", "rules-engine"), {
recursive: true,
});
const partitionsDest = path.join(
"src",
"rules-engine",
"partitions.json",
);
yield* fs.copyFile(partitionsSrc, partitionsDest);
yield* Console.log("✅ partitions.json");
} else {
yield* Console.log("⚠️ partitions.json not found (smithy submodule not initialized)");
yield* Console.log(
"⚠️ partitions.json not found (smithy submodule not initialized)",
);
}

const rootModelsPath = path.join(AWS_MODELS_PATH, "models");
Expand Down
Loading