@typespec/http
Advanced tools
Comparing version
@@ -0,7 +1,7 @@ | ||
import { createDiagnostic, reportDiagnostic } from "./lib.js"; | ||
import { createDiagnosticCollector, getDoc, isArrayModelType, reportDeprecated, setTypeSpecNamespace, typespecTypeToJson, validateDecoratorTarget, validateDecoratorUniqueOnNode, } from "@typespec/compiler"; | ||
import { createDiagnostic, createStateSymbol, reportDiagnostic } from "./lib.js"; | ||
import { setRoute, setSharedRoute } from "./route.js"; | ||
import { HttpStateKeys } from "./state.js"; | ||
import { extractParamsFromPath } from "./utils.js"; | ||
export const namespace = "TypeSpec.Http"; | ||
const headerFieldsKey = createStateSymbol("header"); | ||
export function $header(context, entity, headerNameOrOptions) { | ||
@@ -45,6 +45,6 @@ var _a, _b; | ||
} | ||
context.program.stateMap(headerFieldsKey).set(entity, options); | ||
context.program.stateMap(HttpStateKeys.headerFieldsKey).set(entity, options); | ||
} | ||
export function getHeaderFieldOptions(program, entity) { | ||
return program.stateMap(headerFieldsKey).get(entity); | ||
return program.stateMap(HttpStateKeys.headerFieldsKey).get(entity); | ||
} | ||
@@ -56,5 +56,4 @@ export function getHeaderFieldName(program, entity) { | ||
export function isHeader(program, entity) { | ||
return program.stateMap(headerFieldsKey).has(entity); | ||
return program.stateMap(HttpStateKeys.headerFieldsKey).has(entity); | ||
} | ||
const queryFieldsKey = createStateSymbol("query"); | ||
export function $query(context, entity, queryNameOrOptions) { | ||
@@ -89,6 +88,6 @@ var _a, _b; | ||
} | ||
context.program.stateMap(queryFieldsKey).set(entity, options); | ||
context.program.stateMap(HttpStateKeys.queryFieldsKey).set(entity, options); | ||
} | ||
export function getQueryParamOptions(program, entity) { | ||
return program.stateMap(queryFieldsKey).get(entity); | ||
return program.stateMap(HttpStateKeys.queryFieldsKey).get(entity); | ||
} | ||
@@ -100,5 +99,4 @@ export function getQueryParamName(program, entity) { | ||
export function isQueryParam(program, entity) { | ||
return program.stateMap(queryFieldsKey).has(entity); | ||
return program.stateMap(HttpStateKeys.queryFieldsKey).has(entity); | ||
} | ||
const pathFieldsKey = createStateSymbol("path"); | ||
export function $path(context, entity, paramName) { | ||
@@ -109,6 +107,6 @@ const options = { | ||
}; | ||
context.program.stateMap(pathFieldsKey).set(entity, options); | ||
context.program.stateMap(HttpStateKeys.pathFieldsKey).set(entity, options); | ||
} | ||
export function getPathParamOptions(program, entity) { | ||
return program.stateMap(pathFieldsKey).get(entity); | ||
return program.stateMap(HttpStateKeys.pathFieldsKey).get(entity); | ||
} | ||
@@ -120,14 +118,12 @@ export function getPathParamName(program, entity) { | ||
export function isPathParam(program, entity) { | ||
return program.stateMap(pathFieldsKey).has(entity); | ||
return program.stateMap(HttpStateKeys.pathFieldsKey).has(entity); | ||
} | ||
const bodyFieldsKey = createStateSymbol("body"); | ||
export function $body(context, entity) { | ||
context.program.stateSet(bodyFieldsKey).add(entity); | ||
context.program.stateSet(HttpStateKeys.bodyFieldsKey).add(entity); | ||
} | ||
export function isBody(program, entity) { | ||
return program.stateSet(bodyFieldsKey).has(entity); | ||
return program.stateSet(HttpStateKeys.bodyFieldsKey).has(entity); | ||
} | ||
const statusCodeKey = createStateSymbol("statusCode"); | ||
export function $statusCode(context, entity) { | ||
context.program.stateSet(statusCodeKey).add(entity); | ||
context.program.stateSet(HttpStateKeys.statusCodeKey).add(entity); | ||
const codes = []; | ||
@@ -177,3 +173,3 @@ if (entity.type.kind === "String") { | ||
export function setStatusCode(program, entity, codes) { | ||
program.stateMap(statusCodeKey).set(entity, codes); | ||
program.stateMap(HttpStateKeys.statusCodeKey).set(entity, codes); | ||
} | ||
@@ -195,7 +191,7 @@ // Check status code value: 3 digits with first digit in [1-5] | ||
export function isStatusCode(program, entity) { | ||
return program.stateMap(statusCodeKey).has(entity); | ||
return program.stateMap(HttpStateKeys.statusCodeKey).has(entity); | ||
} | ||
export function getStatusCodes(program, entity) { | ||
var _a; | ||
return (_a = program.stateMap(statusCodeKey).get(entity)) !== null && _a !== void 0 ? _a : []; | ||
return (_a = program.stateMap(HttpStateKeys.statusCodeKey).get(entity)) !== null && _a !== void 0 ? _a : []; | ||
} | ||
@@ -247,7 +243,6 @@ // Reference: https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html | ||
} | ||
const operationVerbsKey = createStateSymbol("verbs"); | ||
function setOperationVerb(program, entity, verb) { | ||
if (entity.kind === "Operation") { | ||
if (!program.stateMap(operationVerbsKey).has(entity)) { | ||
program.stateMap(operationVerbsKey).set(entity, verb); | ||
if (!program.stateMap(HttpStateKeys.operationVerbsKey).has(entity)) { | ||
program.stateMap(HttpStateKeys.operationVerbsKey).set(entity, verb); | ||
} | ||
@@ -271,3 +266,3 @@ else { | ||
export function getOperationVerb(program, entity) { | ||
return program.stateMap(operationVerbsKey).get(entity); | ||
return program.stateMap(HttpStateKeys.operationVerbsKey).get(entity); | ||
} | ||
@@ -292,3 +287,2 @@ export function $get(context, entity) { | ||
} | ||
const serversKey = createStateSymbol("servers"); | ||
/** | ||
@@ -316,6 +310,6 @@ * Configure the server url for the service. | ||
} | ||
let servers = context.program.stateMap(serversKey).get(target); | ||
let servers = context.program.stateMap(HttpStateKeys.serversKey).get(target); | ||
if (servers === undefined) { | ||
servers = []; | ||
context.program.stateMap(serversKey).set(target, servers); | ||
context.program.stateMap(HttpStateKeys.serversKey).set(target, servers); | ||
} | ||
@@ -329,3 +323,3 @@ servers.push({ | ||
export function getServers(program, type) { | ||
return program.stateMap(serversKey).get(type); | ||
return program.stateMap(HttpStateKeys.serversKey).get(type); | ||
} | ||
@@ -336,7 +330,7 @@ export function $plainData(context, entity) { | ||
const [headers, bodies, queries, paths, statusCodes] = [ | ||
program.stateMap(headerFieldsKey), | ||
program.stateSet(bodyFieldsKey), | ||
program.stateMap(queryFieldsKey), | ||
program.stateMap(pathFieldsKey), | ||
program.stateMap(statusCodeKey), | ||
program.stateMap(HttpStateKeys.headerFieldsKey), | ||
program.stateSet(HttpStateKeys.bodyFieldsKey), | ||
program.stateMap(HttpStateKeys.queryFieldsKey), | ||
program.stateMap(HttpStateKeys.pathFieldsKey), | ||
program.stateMap(HttpStateKeys.statusCodeKey), | ||
]; | ||
@@ -356,3 +350,2 @@ for (const property of entity.properties.values()) { | ||
setTypeSpecNamespace("Private", $plainData); | ||
const authenticationKey = createStateSymbol("authentication"); | ||
export function $useAuth(context, serviceNamespace, authConfig) { | ||
@@ -367,3 +360,3 @@ const [auth, diagnostics] = extractServiceAuthentication(context.program, authConfig); | ||
export function setAuthentication(program, serviceNamespace, auth) { | ||
program.stateMap(authenticationKey).set(serviceNamespace, auth); | ||
program.stateMap(HttpStateKeys.authenticationKey).set(serviceNamespace, auth); | ||
} | ||
@@ -466,3 +459,3 @@ function extractServiceAuthentication(program, type) { | ||
export function getAuthentication(program, namespace) { | ||
return program.stateMap(authenticationKey).get(namespace); | ||
return program.stateMap(HttpStateKeys.authenticationKey).get(namespace); | ||
} | ||
@@ -507,3 +500,2 @@ /** | ||
} | ||
const includeInapplicableMetadataInPayloadKey = createStateSymbol("includeInapplicableMetadataInPayload"); | ||
/** | ||
@@ -532,3 +524,3 @@ * Specifies if inapplicable metadata should be included in the payload for | ||
} | ||
const state = context.program.stateMap(includeInapplicableMetadataInPayloadKey); | ||
const state = context.program.stateMap(HttpStateKeys.includeInapplicableMetadataInPayloadKey); | ||
state.set(entity, value); | ||
@@ -546,3 +538,3 @@ } | ||
for (e = property; e; e = e.kind === "ModelProperty" ? e.model : e.namespace) { | ||
const value = program.stateMap(includeInapplicableMetadataInPayloadKey).get(e); | ||
const value = program.stateMap(HttpStateKeys.includeInapplicableMetadataInPayloadKey).get(e); | ||
if (value !== undefined) { | ||
@@ -549,0 +541,0 @@ return value; |
@@ -1,2 +0,2 @@ | ||
export declare const namespace = "TypeSpec.Http"; | ||
export { $lib } from "./lib.js"; | ||
export * from "./content-types.js"; | ||
@@ -3,0 +3,0 @@ export * from "./decorators.js"; |
@@ -1,2 +0,2 @@ | ||
export const namespace = "TypeSpec.Http"; | ||
export { $lib } from "./lib.js"; | ||
export * from "./content-types.js"; | ||
@@ -3,0 +3,0 @@ export * from "./decorators.js"; |
@@ -1,309 +0,308 @@ | ||
declare const httpLib: import("@typespec/compiler").TypeSpecLibrary<{ | ||
export declare const $lib: import("@typespec/compiler").TypeSpecLibrary<{ | ||
"http-verb-duplicate": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["entityName"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"http-verb-wrong-type": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["verb", "entityKind"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string, string]>; | ||
}; | ||
"missing-path-param": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["param"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"optional-path-param": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["paramName"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"missing-server-param": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["param"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"duplicate-body": { | ||
readonly default: "Operation has multiple @body parameters declared"; | ||
readonly duplicateUnannotated: "Operation has multiple unannotated parameters. There can only be one representing the body"; | ||
readonly bodyAndUnannotated: "Operation has a @body and an unannotated parameter. There can only be one representing the body"; | ||
default: string; | ||
duplicateUnannotated: string; | ||
bodyAndUnannotated: string; | ||
}; | ||
"duplicate-route-decorator": { | ||
readonly namespace: "@route was defined twice on this namespace and has different values."; | ||
namespace: string; | ||
}; | ||
"operation-param-duplicate-type": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["paramName", "types"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string, string]>; | ||
}; | ||
"duplicate-operation": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["operationName", "verb", "path"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string, string, string]>; | ||
}; | ||
"status-code-invalid": { | ||
readonly default: "statusCode value must be a numeric or string literal or union of numeric or string literals"; | ||
readonly value: "statusCode value must be a three digit code between 100 and 599"; | ||
default: string; | ||
value: string; | ||
}; | ||
"content-type-string": { | ||
readonly default: "contentType parameter must be a string literal or union of string literals"; | ||
default: string; | ||
}; | ||
"content-type-ignored": { | ||
readonly default: "`Content-Type` header ignored because there is no body."; | ||
default: string; | ||
}; | ||
"no-routes": { | ||
readonly default: "Current spec is not exposing any routes. This could be to not having the service namespace marked with @service."; | ||
default: string; | ||
}; | ||
"invalid-type-for-auth": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["kind"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"shared-inconsistency": { | ||
readonly default: "All shared routes must agree on the value of the shared parameter."; | ||
default: string; | ||
}; | ||
"write-visibility-not-supported": { | ||
readonly default: "@visibility(\"write\") is not supported. Use @visibility(\"update\"), @visibility(\"create\") or @visibility(\"create\", \"update\") as appropriate."; | ||
default: string; | ||
}; | ||
"multipart-model": { | ||
readonly default: "Multipart request body must be a model."; | ||
default: string; | ||
}; | ||
"header-format-required": { | ||
readonly default: "A format must be specified for @header when type is an array. e.g. @header({format: \"csv\"})"; | ||
default: string; | ||
}; | ||
"query-format-required": { | ||
readonly default: "A format must be specified for @query when type is an array. e.g. @query({format: \"multi\"})"; | ||
default: string; | ||
}; | ||
}, Record<string, any>>; | ||
declare const reportDiagnostic: <C extends "http-verb-duplicate" | "http-verb-wrong-type" | "missing-path-param" | "optional-path-param" | "missing-server-param" | "duplicate-body" | "duplicate-route-decorator" | "operation-param-duplicate-type" | "duplicate-operation" | "status-code-invalid" | "content-type-string" | "content-type-ignored" | "no-routes" | "invalid-type-for-auth" | "shared-inconsistency" | "write-visibility-not-supported" | "multipart-model" | "header-format-required" | "query-format-required", M extends keyof { | ||
export declare const reportDiagnostic: <C extends "http-verb-duplicate" | "http-verb-wrong-type" | "missing-path-param" | "optional-path-param" | "missing-server-param" | "duplicate-body" | "duplicate-route-decorator" | "operation-param-duplicate-type" | "duplicate-operation" | "status-code-invalid" | "content-type-string" | "content-type-ignored" | "no-routes" | "invalid-type-for-auth" | "shared-inconsistency" | "write-visibility-not-supported" | "multipart-model" | "header-format-required" | "query-format-required", M extends keyof { | ||
"http-verb-duplicate": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["entityName"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"http-verb-wrong-type": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["verb", "entityKind"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string, string]>; | ||
}; | ||
"missing-path-param": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["param"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"optional-path-param": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["paramName"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"missing-server-param": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["param"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"duplicate-body": { | ||
readonly default: "Operation has multiple @body parameters declared"; | ||
readonly duplicateUnannotated: "Operation has multiple unannotated parameters. There can only be one representing the body"; | ||
readonly bodyAndUnannotated: "Operation has a @body and an unannotated parameter. There can only be one representing the body"; | ||
default: string; | ||
duplicateUnannotated: string; | ||
bodyAndUnannotated: string; | ||
}; | ||
"duplicate-route-decorator": { | ||
readonly namespace: "@route was defined twice on this namespace and has different values."; | ||
namespace: string; | ||
}; | ||
"operation-param-duplicate-type": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["paramName", "types"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string, string]>; | ||
}; | ||
"duplicate-operation": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["operationName", "verb", "path"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string, string, string]>; | ||
}; | ||
"status-code-invalid": { | ||
readonly default: "statusCode value must be a numeric or string literal or union of numeric or string literals"; | ||
readonly value: "statusCode value must be a three digit code between 100 and 599"; | ||
default: string; | ||
value: string; | ||
}; | ||
"content-type-string": { | ||
readonly default: "contentType parameter must be a string literal or union of string literals"; | ||
default: string; | ||
}; | ||
"content-type-ignored": { | ||
readonly default: "`Content-Type` header ignored because there is no body."; | ||
default: string; | ||
}; | ||
"no-routes": { | ||
readonly default: "Current spec is not exposing any routes. This could be to not having the service namespace marked with @service."; | ||
default: string; | ||
}; | ||
"invalid-type-for-auth": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["kind"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"shared-inconsistency": { | ||
readonly default: "All shared routes must agree on the value of the shared parameter."; | ||
default: string; | ||
}; | ||
"write-visibility-not-supported": { | ||
readonly default: "@visibility(\"write\") is not supported. Use @visibility(\"update\"), @visibility(\"create\") or @visibility(\"create\", \"update\") as appropriate."; | ||
default: string; | ||
}; | ||
"multipart-model": { | ||
readonly default: "Multipart request body must be a model."; | ||
default: string; | ||
}; | ||
"header-format-required": { | ||
readonly default: "A format must be specified for @header when type is an array. e.g. @header({format: \"csv\"})"; | ||
default: string; | ||
}; | ||
"query-format-required": { | ||
readonly default: "A format must be specified for @query when type is an array. e.g. @query({format: \"multi\"})"; | ||
default: string; | ||
}; | ||
}[C]>(program: import("@typespec/compiler").Program, diag: import("@typespec/compiler").DiagnosticReport<{ | ||
"http-verb-duplicate": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["entityName"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"http-verb-wrong-type": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["verb", "entityKind"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string, string]>; | ||
}; | ||
"missing-path-param": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["param"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"optional-path-param": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["paramName"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"missing-server-param": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["param"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"duplicate-body": { | ||
readonly default: "Operation has multiple @body parameters declared"; | ||
readonly duplicateUnannotated: "Operation has multiple unannotated parameters. There can only be one representing the body"; | ||
readonly bodyAndUnannotated: "Operation has a @body and an unannotated parameter. There can only be one representing the body"; | ||
default: string; | ||
duplicateUnannotated: string; | ||
bodyAndUnannotated: string; | ||
}; | ||
"duplicate-route-decorator": { | ||
readonly namespace: "@route was defined twice on this namespace and has different values."; | ||
namespace: string; | ||
}; | ||
"operation-param-duplicate-type": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["paramName", "types"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string, string]>; | ||
}; | ||
"duplicate-operation": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["operationName", "verb", "path"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string, string, string]>; | ||
}; | ||
"status-code-invalid": { | ||
readonly default: "statusCode value must be a numeric or string literal or union of numeric or string literals"; | ||
readonly value: "statusCode value must be a three digit code between 100 and 599"; | ||
default: string; | ||
value: string; | ||
}; | ||
"content-type-string": { | ||
readonly default: "contentType parameter must be a string literal or union of string literals"; | ||
default: string; | ||
}; | ||
"content-type-ignored": { | ||
readonly default: "`Content-Type` header ignored because there is no body."; | ||
default: string; | ||
}; | ||
"no-routes": { | ||
readonly default: "Current spec is not exposing any routes. This could be to not having the service namespace marked with @service."; | ||
default: string; | ||
}; | ||
"invalid-type-for-auth": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["kind"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"shared-inconsistency": { | ||
readonly default: "All shared routes must agree on the value of the shared parameter."; | ||
default: string; | ||
}; | ||
"write-visibility-not-supported": { | ||
readonly default: "@visibility(\"write\") is not supported. Use @visibility(\"update\"), @visibility(\"create\") or @visibility(\"create\", \"update\") as appropriate."; | ||
default: string; | ||
}; | ||
"multipart-model": { | ||
readonly default: "Multipart request body must be a model."; | ||
default: string; | ||
}; | ||
"header-format-required": { | ||
readonly default: "A format must be specified for @header when type is an array. e.g. @header({format: \"csv\"})"; | ||
default: string; | ||
}; | ||
"query-format-required": { | ||
readonly default: "A format must be specified for @query when type is an array. e.g. @query({format: \"multi\"})"; | ||
default: string; | ||
}; | ||
}, C, M>) => void, createDiagnostic: <C extends "http-verb-duplicate" | "http-verb-wrong-type" | "missing-path-param" | "optional-path-param" | "missing-server-param" | "duplicate-body" | "duplicate-route-decorator" | "operation-param-duplicate-type" | "duplicate-operation" | "status-code-invalid" | "content-type-string" | "content-type-ignored" | "no-routes" | "invalid-type-for-auth" | "shared-inconsistency" | "write-visibility-not-supported" | "multipart-model" | "header-format-required" | "query-format-required", M extends keyof { | ||
"http-verb-duplicate": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["entityName"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"http-verb-wrong-type": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["verb", "entityKind"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string, string]>; | ||
}; | ||
"missing-path-param": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["param"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"optional-path-param": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["paramName"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"missing-server-param": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["param"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"duplicate-body": { | ||
readonly default: "Operation has multiple @body parameters declared"; | ||
readonly duplicateUnannotated: "Operation has multiple unannotated parameters. There can only be one representing the body"; | ||
readonly bodyAndUnannotated: "Operation has a @body and an unannotated parameter. There can only be one representing the body"; | ||
default: string; | ||
duplicateUnannotated: string; | ||
bodyAndUnannotated: string; | ||
}; | ||
"duplicate-route-decorator": { | ||
readonly namespace: "@route was defined twice on this namespace and has different values."; | ||
namespace: string; | ||
}; | ||
"operation-param-duplicate-type": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["paramName", "types"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string, string]>; | ||
}; | ||
"duplicate-operation": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["operationName", "verb", "path"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string, string, string]>; | ||
}; | ||
"status-code-invalid": { | ||
readonly default: "statusCode value must be a numeric or string literal or union of numeric or string literals"; | ||
readonly value: "statusCode value must be a three digit code between 100 and 599"; | ||
default: string; | ||
value: string; | ||
}; | ||
"content-type-string": { | ||
readonly default: "contentType parameter must be a string literal or union of string literals"; | ||
default: string; | ||
}; | ||
"content-type-ignored": { | ||
readonly default: "`Content-Type` header ignored because there is no body."; | ||
default: string; | ||
}; | ||
"no-routes": { | ||
readonly default: "Current spec is not exposing any routes. This could be to not having the service namespace marked with @service."; | ||
default: string; | ||
}; | ||
"invalid-type-for-auth": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["kind"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"shared-inconsistency": { | ||
readonly default: "All shared routes must agree on the value of the shared parameter."; | ||
default: string; | ||
}; | ||
"write-visibility-not-supported": { | ||
readonly default: "@visibility(\"write\") is not supported. Use @visibility(\"update\"), @visibility(\"create\") or @visibility(\"create\", \"update\") as appropriate."; | ||
default: string; | ||
}; | ||
"multipart-model": { | ||
readonly default: "Multipart request body must be a model."; | ||
default: string; | ||
}; | ||
"header-format-required": { | ||
readonly default: "A format must be specified for @header when type is an array. e.g. @header({format: \"csv\"})"; | ||
default: string; | ||
}; | ||
"query-format-required": { | ||
readonly default: "A format must be specified for @query when type is an array. e.g. @query({format: \"multi\"})"; | ||
default: string; | ||
}; | ||
}[C]>(diag: import("@typespec/compiler").DiagnosticReport<{ | ||
"http-verb-duplicate": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["entityName"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"http-verb-wrong-type": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["verb", "entityKind"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string, string]>; | ||
}; | ||
"missing-path-param": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["param"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"optional-path-param": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["paramName"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"missing-server-param": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["param"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"duplicate-body": { | ||
readonly default: "Operation has multiple @body parameters declared"; | ||
readonly duplicateUnannotated: "Operation has multiple unannotated parameters. There can only be one representing the body"; | ||
readonly bodyAndUnannotated: "Operation has a @body and an unannotated parameter. There can only be one representing the body"; | ||
default: string; | ||
duplicateUnannotated: string; | ||
bodyAndUnannotated: string; | ||
}; | ||
"duplicate-route-decorator": { | ||
readonly namespace: "@route was defined twice on this namespace and has different values."; | ||
namespace: string; | ||
}; | ||
"operation-param-duplicate-type": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["paramName", "types"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string, string]>; | ||
}; | ||
"duplicate-operation": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["operationName", "verb", "path"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string, string, string]>; | ||
}; | ||
"status-code-invalid": { | ||
readonly default: "statusCode value must be a numeric or string literal or union of numeric or string literals"; | ||
readonly value: "statusCode value must be a three digit code between 100 and 599"; | ||
default: string; | ||
value: string; | ||
}; | ||
"content-type-string": { | ||
readonly default: "contentType parameter must be a string literal or union of string literals"; | ||
default: string; | ||
}; | ||
"content-type-ignored": { | ||
readonly default: "`Content-Type` header ignored because there is no body."; | ||
default: string; | ||
}; | ||
"no-routes": { | ||
readonly default: "Current spec is not exposing any routes. This could be to not having the service namespace marked with @service."; | ||
default: string; | ||
}; | ||
"invalid-type-for-auth": { | ||
readonly default: import("@typespec/compiler").CallableMessage<["kind"]>; | ||
default: import("@typespec/compiler").CallableMessage<[string]>; | ||
}; | ||
"shared-inconsistency": { | ||
readonly default: "All shared routes must agree on the value of the shared parameter."; | ||
default: string; | ||
}; | ||
"write-visibility-not-supported": { | ||
readonly default: "@visibility(\"write\") is not supported. Use @visibility(\"update\"), @visibility(\"create\") or @visibility(\"create\", \"update\") as appropriate."; | ||
default: string; | ||
}; | ||
"multipart-model": { | ||
readonly default: "Multipart request body must be a model."; | ||
default: string; | ||
}; | ||
"header-format-required": { | ||
readonly default: "A format must be specified for @header when type is an array. e.g. @header({format: \"csv\"})"; | ||
default: string; | ||
}; | ||
"query-format-required": { | ||
readonly default: "A format must be specified for @query when type is an array. e.g. @query({format: \"multi\"})"; | ||
default: string; | ||
}; | ||
}, C, M>) => import("@typespec/compiler").Diagnostic, createStateSymbol: (name: string) => symbol; | ||
export { createDiagnostic, createStateSymbol, httpLib, reportDiagnostic }; | ||
//# sourceMappingURL=lib.d.ts.map |
import { createTypeSpecLibrary, paramMessage } from "@typespec/compiler"; | ||
const libDefinition = { | ||
import { opReferenceContainerRouteRule } from "./rules/op-reference-container-route.js"; | ||
export const $lib = createTypeSpecLibrary({ | ||
name: "@typespec/http", | ||
@@ -123,6 +124,14 @@ diagnostics: { | ||
}, | ||
}; | ||
const httpLib = createTypeSpecLibrary(libDefinition); | ||
const { reportDiagnostic, createDiagnostic, createStateSymbol } = httpLib; | ||
export { createDiagnostic, createStateSymbol, httpLib, reportDiagnostic }; | ||
linter: { | ||
rules: [opReferenceContainerRouteRule], | ||
ruleSets: { | ||
all: { | ||
enable: { | ||
[`@typespec/http/${opReferenceContainerRouteRule.name}`]: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
export const { reportDiagnostic, createDiagnostic, createStateSymbol } = $lib; | ||
//# sourceMappingURL=lib.js.map |
@@ -0,4 +1,5 @@ | ||
import { createDiagnostic, reportDiagnostic } from "./lib.js"; | ||
import { createDiagnosticCollector, validateDecoratorTarget, } from "@typespec/compiler"; | ||
import { createDiagnostic, createStateSymbol, reportDiagnostic } from "./lib.js"; | ||
import { getOperationParameters } from "./parameters.js"; | ||
import { HttpStateKeys } from "./state.js"; | ||
import { extractParamsFromPath } from "./utils.js"; | ||
@@ -69,3 +70,2 @@ // The set of allowed segment separator characters | ||
} | ||
const externalInterfaces = createStateSymbol("externalInterfaces"); | ||
/** | ||
@@ -78,10 +78,9 @@ * @deprecated DO NOT USE. For internal use only as a workaround. | ||
export function includeInterfaceRoutesInNamespace(program, target, sourceInterface) { | ||
let array = program.stateMap(externalInterfaces).get(target); | ||
let array = program.stateMap(HttpStateKeys.externalInterfaces).get(target); | ||
if (array === undefined) { | ||
array = []; | ||
program.stateMap(externalInterfaces).set(target, array); | ||
program.stateMap(HttpStateKeys.externalInterfaces).set(target, array); | ||
} | ||
array.push(sourceInterface); | ||
} | ||
const routeProducerKey = createStateSymbol("routeProducer"); | ||
export function DefaultRouteProducer(program, operation, parentSegments, overloadBase, options) { | ||
@@ -112,8 +111,7 @@ var _a; | ||
export function setRouteProducer(program, operation, routeProducer) { | ||
program.stateMap(routeProducerKey).set(operation, routeProducer); | ||
program.stateMap(HttpStateKeys.routeProducerKey).set(operation, routeProducer); | ||
} | ||
export function getRouteProducer(program, operation) { | ||
return program.stateMap(routeProducerKey).get(operation); | ||
return program.stateMap(HttpStateKeys.routeProducerKey).get(operation); | ||
} | ||
const routesKey = createStateSymbol("routes"); | ||
export function setRoute(context, entity, details) { | ||
@@ -123,3 +121,3 @@ if (!validateDecoratorTarget(context, entity, "@route", ["Namespace", "Interface", "Operation"])) { | ||
} | ||
const state = context.program.stateMap(routesKey); | ||
const state = context.program.stateMap(HttpStateKeys.routesKey); | ||
if (state.has(entity) && entity.kind === "Namespace") { | ||
@@ -142,11 +140,10 @@ const existingPath = state.get(entity); | ||
} | ||
const sharedRoutesKey = createStateSymbol("sharedRoutes"); | ||
export function setSharedRoute(program, operation) { | ||
program.stateMap(sharedRoutesKey).set(operation, true); | ||
program.stateMap(HttpStateKeys.sharedRoutesKey).set(operation, true); | ||
} | ||
export function isSharedRoute(program, operation) { | ||
return program.stateMap(sharedRoutesKey).get(operation) === true; | ||
return program.stateMap(HttpStateKeys.sharedRoutesKey).get(operation) === true; | ||
} | ||
export function getRoutePath(program, entity) { | ||
const path = program.stateMap(routesKey).get(entity); | ||
const path = program.stateMap(HttpStateKeys.routesKey).get(entity); | ||
return path | ||
@@ -159,9 +156,8 @@ ? { | ||
} | ||
const routeOptionsKey = createStateSymbol("routeOptions"); | ||
export function setRouteOptionsForNamespace(program, namespace, options) { | ||
program.stateMap(routeOptionsKey).set(namespace, options); | ||
program.stateMap(HttpStateKeys.routeOptionsKey).set(namespace, options); | ||
} | ||
export function getRouteOptionsForNamespace(program, namespace) { | ||
return program.stateMap(routeOptionsKey).get(namespace); | ||
return program.stateMap(HttpStateKeys.routeOptionsKey).get(namespace); | ||
} | ||
//# sourceMappingURL=route.js.map |
{ | ||
"name": "@typespec/http", | ||
"version": "0.48.0-dev.5", | ||
"version": "0.48.0-dev.6", | ||
"author": "Microsoft Corporation", | ||
@@ -5,0 +5,0 @@ "description": "TypeSpec HTTP protocol binding", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
218623
0.56%66
13.79%2819
3.53%