@stately-cloud/schema
Advanced tools
Comparing version 0.14.0 to 0.15.0
@@ -7,2 +7,3 @@ import { create, toBinary } from "@bufbuild/protobuf"; | ||
import packageJson from "../package.json" with { type: "json" }; | ||
import { buildSourceCodeInfo, extractCommentBindings } from "./comments.js"; | ||
import { SchemaError } from "./errors.js"; | ||
@@ -38,5 +39,5 @@ import { StatelyErrorDetailsSchema } from "./errors/error_details_pb.js"; | ||
process.env.PACKAGE = fileName ? `stately.generated.${fileName}` : "stately.generated"; | ||
process.stderr.write(`Building schema from ${fullInputPath}`); | ||
process.stderr.write(`Building schema from ${inputPath}\n`); | ||
// Use TypeScript to parse the input files. | ||
const program = ts.createProgram([fullInputPath], { | ||
const tsOpts = { | ||
strict: true, | ||
@@ -55,3 +56,4 @@ esModuleInterop: true, | ||
useUnknownInCatchVariables: true, | ||
}); | ||
}; | ||
const program = ts.createProgram([fullInputPath], tsOpts); | ||
// Validate and type check the program | ||
@@ -120,2 +122,12 @@ const allDiagnostics = ts.getPreEmitDiagnostics(program); | ||
} | ||
// Add comment information to the FileDescriptorProto, statically extracted | ||
// from the TypeScript AST. | ||
try { | ||
const commentBindings = extractCommentBindings(program); | ||
fd.sourceCodeInfo = buildSourceCodeInfo(fd, commentBindings); | ||
} | ||
catch (e) { | ||
await respondWithError(e, "SchemaComment", "An error occurred while extracting comments from your schema code."); | ||
return; | ||
} | ||
// Collect and expand all the migrations from the latest version. In the | ||
@@ -122,0 +134,0 @@ // future I suppose we can pass a specific from-version argument. |
@@ -48,1 +48,2 @@ import { SchemaType } from "./types.js"; | ||
}, config?: EnumConfig): SchemaType; | ||
export declare function enumValueName(enumName: string, valueName: string): string; |
@@ -44,4 +44,9 @@ import { create } from "@bufbuild/protobuf"; | ||
} | ||
// Note that enum values are a sibling to the enum parent in the proto | ||
// namespace - they must be globally unique. We follow the | ||
// https://buf.build/docs/lint/rules/#enum_value_prefix rule and prefix all | ||
// enum values with the enum name. This produces some awkward names in | ||
// generated code, which we should fix in our own codegen. | ||
enumValues.push(create(EnumValueDescriptorProtoSchema, { | ||
name: `${name}_${valueName}`, | ||
name: enumValueName(name, valueName), | ||
number: valueNum, | ||
@@ -58,3 +63,3 @@ options: config.deprecatedValues?.includes(valueName) | ||
enumValues.unshift(create(EnumValueDescriptorProtoSchema, { | ||
name: `${name}_UNSPECIFIED`, | ||
name: enumValueName(name, "UNSPECIFIED"), | ||
number: 0, | ||
@@ -76,3 +81,6 @@ })); | ||
} | ||
export function enumValueName(enumName, valueName) { | ||
return `${enumName}_${valueName}`; | ||
} | ||
// TODO: Implement flagsType, which is like an enum but the values are flags in a bitfield | ||
//# sourceMappingURL=enum.js.map |
{ | ||
"name": "@stately-cloud/schema", | ||
"version": "0.14.0", | ||
"version": "0.15.0", | ||
"author": "Stately Cloud <support@stately.cloud> (https://stately.cloud/)", | ||
@@ -5,0 +5,0 @@ "description": "Schema language for StatelyDB", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
287383
69
3663