Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
"packages/stats/*"
],
"catalog": {
"@effect/opentelemetry": "4.0.1",
"@effect/platform-node": "4.0.1",
"@effect/platform-node-shared": "4.0.1",
"@effect/sql-sqlite-bun": "4.0.1",
"@effect/opentelemetry": "4.0.6",
"@effect/platform-node": "4.0.6",
"@effect/platform-node-shared": "4.0.6",
"@effect/sql-sqlite-bun": "4.0.6",
"@npmcli/arborist": "9.4.0",
"@types/bun": "1.4.3",
"@types/cross-spawn": "6.0.6",
Expand Down Expand Up @@ -77,7 +77,7 @@
"dompurify": "3.4.17",
"drizzle-kit": "1.0.0-rc.5-ab785fc",
"drizzle-orm": "1.0.0-rc.5-169397b",
"effect": "4.0.1",
"effect": "4.0.6",
"fast-check": "4.9.0",
"cross-spawn": "7.0.6",
"hono": "4.10.7",
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/promise/generated/types.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions packages/codemode/src/tool-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ const docTags = (schema: JsonSchema): Array<string> => {
}
if (typeof schema.format === "string") tags.push(`@format ${schema.format}`)
if (schema.type === "integer") tags.push("@integer")
if (typeof schema.minimum === "number") tags.push(`@minimum ${schema.minimum}`)
if (typeof schema.maximum === "number") tags.push(`@maximum ${schema.maximum}`)
const integer = schema.type === "integer"
if (typeof schema.minimum === "number" && !(integer && schema.minimum === Number.MIN_SAFE_INTEGER))
tags.push(`@minimum ${schema.minimum}`)
if (typeof schema.maximum === "number" && !(integer && schema.maximum === Number.MAX_SAFE_INTEGER))
tags.push(`@maximum ${schema.maximum}`)
if (typeof schema.exclusiveMinimum === "number") tags.push(`@exclusiveMinimum ${schema.exclusiveMinimum}`)
if (typeof schema.exclusiveMaximum === "number") tags.push(`@exclusiveMaximum ${schema.exclusiveMaximum}`)
if (typeof schema.multipleOf === "number") tags.push(`@multipleOf ${schema.multipleOf}`)
Expand Down Expand Up @@ -154,7 +157,10 @@ const renderSchema = (
}
if (schema.const !== undefined) return renderLiteral(schema.const)
if (schema.enum) return schema.enum.map(renderLiteral).join(" | ")
const alternatives = schema.anyOf ?? schema.oneOf
const listed = schema.anyOf ?? schema.oneOf
const alternatives = listed?.some((item) => item.type === "number")
? listed.filter((item) => !effectNumberSentinel(item))
: listed
if (alternatives) {
if (
alternatives.some((item) => item.type === "number") &&
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/database/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const makeClient = <
acquirer,
compiler: Statement.makeCompilerSqlite(options.transformQueryNames),
transactionAcquirer,
driver: "sqlite",
spanAttributes: [
...(options.spanAttributes ? Object.entries(options.spanAttributes) : []),
["db.system.name", "sqlite"],
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/database/sqlite.workerd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ const make = (options: Config) =>
compiler,
transactionAcquirer,
transactionService: WorkerdTransaction,
driver: "sqlite-do",
spanAttributes: [
...(options.spanAttributes ? Object.entries(options.spanAttributes) : []),
[ATTR_DB_SYSTEM_NAME, "sqlite"],
Expand Down
16 changes: 15 additions & 1 deletion packages/core/src/tool/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,21 @@ const flattenAllOf = (value: unknown): unknown => {
if (Array.isArray(value)) return value.map(flattenAllOf)
if (typeof value !== "object" || value === null) return value

const schema = Object.fromEntries(Object.entries(value).map(([key, item]) => [key, flattenAllOf(item)]))
// Effect adds the safe-integer range to every Schema.Int. Drop it so tool schemas don't change and
// bust prompt caches.
const integer = "type" in value && value.type === "integer"
const schema = Object.fromEntries(
Object.entries(value)
.filter(
([key, item]) =>
!integer ||
!(
(key === "minimum" && item === Number.MIN_SAFE_INTEGER) ||
(key === "maximum" && item === Number.MAX_SAFE_INTEGER)
),
)
.map(([key, item]) => [key, flattenAllOf(item)]),
)
if (!Array.isArray(schema.allOf) || !schema.allOf.every(isRecord) || !canFlattenAllOf(schema.allOf, schema))
return schema
const { allOf, ...rest } = schema
Expand Down
1 change: 1 addition & 0 deletions packages/core/test/database-migration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const parkedClient = (arrived: Deferred.Deferred<void>, gate: Deferred.Deferred<
executeRaw: (query, params) => park(query, connection.executeRaw(query, params)),
}),
compiler: Statement.makeCompilerSqlite(),
driver: client.driver,
spanAttributes: [],
})
}),
Expand Down
19 changes: 14 additions & 5 deletions packages/httpapi-codegen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ type PromiseInputField =
| (InputField & { readonly optional: boolean })
| { readonly name: string; readonly source: "wildcard"; readonly optional: false }

const resolveHttpApiStatus = SchemaAST.resolveAt<number>("httpApiStatus")
const resolveHttpApiStatus = (ast: SchemaAST.AST) =>
SchemaAST.resolveAt<number>("httpApiStatus")(ast) ??
(ast.checks === undefined ? ast.context?.annotations?.httpApiStatus : undefined)
const resolveHttpApiEncoding = SchemaAST.resolveAt<HttpApiSchema.Encoding>("~httpApiEncoding")
const Manifest = Schema.fromJsonString(Schema.Array(Schema.String))
const manifestName = ".httpapi-codegen.json"
Expand Down Expand Up @@ -1454,7 +1456,10 @@ function sameChecks(left: SchemaAST.Checks | undefined, right: SchemaAST.Checks
}

function sameContext(left: SchemaAST.Context | undefined, right: SchemaAST.Context | undefined) {
return left?.isOptional === right?.isOptional && left?.isMutable === right?.isMutable
return (
(left?.isOptional ?? false) === (right?.isOptional ?? false) &&
(left?.isMutable ?? false) === (right?.isMutable ?? false)
)
}

export function write(
Expand Down Expand Up @@ -1738,7 +1743,9 @@ function isDataEnvelope(schema: Schema.Top) {
)
}

function isStreamSchema(schema: Schema.Top): schema is HttpApiSchema.StreamSchema {
function isStreamSchema(
schema: Schema.Top,
): schema is Exclude<HttpApiSchema.StreamSchema, HttpApiSchema.StreamNdjson<Schema.Top>> {
return "_tag" in schema && (schema._tag === "StreamSse" || schema._tag === "StreamUint8Array")
}

Expand Down Expand Up @@ -1841,7 +1848,7 @@ function renderGroup(group: Group) {
const inputDeclaration =
operation.operation.inputMode === "none"
? ""
: `${opaquePayload ? `type ${prefix}Request = Parameters<RawGroup[${JSON.stringify(endpoint.identifier)}]>[0]\n` : ""}type ${prefix}Input = { ${inputType} }\n`
: `${opaquePayload ? `type ${prefix}Request = Parameters<RawGroup[${JSON.stringify(endpoint.identifier)}]>[0] & { readonly responseMode?: "decoded-only" }\n` : ""}type ${prefix}Input = { ${inputType} }\n`
adapters.push(
`${inputDeclaration}const ${prefix}DeclaredError = ${declaredSchema}\nconst map${prefix}Error = (error: unknown) => HttpClientError.isHttpClientError(error) || Schema.isSchemaError(error) || Sse.Retry.is(error) ? new ClientError({ cause: error }) : Schema.is(${prefix}DeclaredError)(error) ? error : new ClientError({ cause: error })\nconst ${prefix} = (raw: RawGroup) => (${argument}) => ${operation.operation.success === "stream" ? `Stream.unwrap(${rawCall}.pipe(Effect.mapError(map${prefix}Error), Effect.map((stream) => stream.pipe(Stream.mapError(map${prefix}Error)))))` : mapped}`,
)
Expand Down Expand Up @@ -1922,7 +1929,9 @@ function renderSchemas(slots: ReadonlyArray<Slot>) {
]
const document = SchemaRepresentation.toCodeDocument(
SchemaRepresentation.toRepresentations(
codegenAsts(expanded.map((slot) => slot.schema.ast)) as [SchemaAST.AST, ...Array<SchemaAST.AST>],
codegenAsts(
expanded.map((slot) => slot.schema.annotate({ httpApiStatus: resolveHttpApiStatus(slot.schema.ast) }).ast),
) as [SchemaAST.AST, ...Array<SchemaAST.AST>],
),
)
const artifacts = document.artifacts.flatMap((artifact) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/httpapi-codegen/test/generated/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const mapEndpointInterruptError = (error: unknown) =>
const EndpointInterrupt = (raw: RawGroup) => (input: EndpointInterruptInput) =>
raw["interrupt"]({ params: { sessionID: input["sessionID"] } }).pipe(Effect.mapError(mapEndpointInterruptError))

type EndpointConfigureRequest = Parameters<RawGroup["configure"]>[0]
type EndpointConfigureRequest = Parameters<RawGroup["configure"]>[0] & { readonly responseMode?: "decoded-only" }
type EndpointConfigureInput = {
readonly sessionID: (typeof EndpointConfigureParams.Type)["sessionID"]
readonly dryRun?: (typeof EndpointConfigureQuery.Type)["dryRun"]
Expand Down
2 changes: 1 addition & 1 deletion packages/httpapi-codegen/test/write.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe("HttpApiCodegen.write", () => {
mtime: Option.none(),
atime: Option.none(),
birthtime: Option.none(),
dev: 0,
dev: 0n,
ino: Option.none(),
mode: 0,
nlink: Option.none(),
Expand Down
Loading
Loading