@typespec/http-server-js 0.58.0-alpha.13-dev.0 → 0.58.0-alpha.13-dev.3
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/.testignore +0 -6
- package/dist/src/common/enum.d.ts.map +1 -1
- package/dist/src/common/enum.js +2 -1
- package/dist/src/common/enum.js.map +1 -1
- package/dist/src/common/model.js +2 -2
- package/dist/src/common/model.js.map +1 -1
- package/dist/src/common/reference.d.ts.map +1 -1
- package/dist/src/common/reference.js +21 -1
- package/dist/src/common/reference.js.map +1 -1
- package/dist/src/common/serialization/index.d.ts +2 -2
- package/dist/src/common/serialization/index.d.ts.map +1 -1
- package/dist/src/common/serialization/index.js +5 -1
- package/dist/src/common/serialization/index.js.map +1 -1
- package/dist/src/common/serialization/json.d.ts.map +1 -1
- package/dist/src/common/serialization/json.js +20 -6
- package/dist/src/common/serialization/json.js.map +1 -1
- package/dist/src/http/server/router.js +4 -4
- package/dist/src/http/server/router.js.map +1 -1
- package/package.json +2 -2
- package/src/common/enum.ts +2 -1
- package/src/common/model.ts +2 -2
- package/src/common/reference.ts +19 -1
- package/src/common/serialization/index.ts +9 -3
- package/src/common/serialization/json.ts +25 -8
- package/src/http/server/router.ts +4 -4
- package/temp/tsconfig.tsbuildinfo +1 -1
|
@@ -28,7 +28,12 @@ import { keywordSafe } from "../../util/keywords.js";
|
|
|
28
28
|
import { getFullyQualifiedTypeName } from "../../util/name.js";
|
|
29
29
|
import { emitTypeReference, escapeUnsafeChars } from "../reference.js";
|
|
30
30
|
import { Encoder, JS_SCALAR_UNKNOWN, JsScalar, getJsScalar } from "../scalar.js";
|
|
31
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
SerializableType,
|
|
33
|
+
SerializationContext,
|
|
34
|
+
isSerializableType,
|
|
35
|
+
requireSerialization,
|
|
36
|
+
} from "./index.js";
|
|
32
37
|
|
|
33
38
|
/**
|
|
34
39
|
* Memoization cache for requiresJsonSerialization.
|
|
@@ -84,6 +89,8 @@ export function requiresJsonSerialization(
|
|
|
84
89
|
case "ModelProperty":
|
|
85
90
|
requiresSerialization = requiresJsonSerialization(ctx, module, type.type);
|
|
86
91
|
break;
|
|
92
|
+
case "Enum":
|
|
93
|
+
requiresSerialization = false;
|
|
87
94
|
}
|
|
88
95
|
|
|
89
96
|
_REQUIRES_JSON_SERIALIZATION.set(type, requiresSerialization);
|
|
@@ -114,12 +121,7 @@ function isHttpMetadata(ctx: JsContext, property: ModelProperty): boolean {
|
|
|
114
121
|
}
|
|
115
122
|
|
|
116
123
|
function isSerializable(type: Type): type is SerializableType | ModelProperty {
|
|
117
|
-
return (
|
|
118
|
-
type.kind === "Model" ||
|
|
119
|
-
type.kind === "Scalar" ||
|
|
120
|
-
type.kind === "Union" ||
|
|
121
|
-
type.kind === "ModelProperty"
|
|
122
|
-
);
|
|
124
|
+
return type.kind === "ModelProperty" || isSerializableType(type);
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
export function* emitJsonSerialization(
|
|
@@ -211,6 +213,14 @@ function* emitToJson(
|
|
|
211
213
|
|
|
212
214
|
return;
|
|
213
215
|
}
|
|
216
|
+
case "Enum": {
|
|
217
|
+
yield `return input;`;
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
default: {
|
|
221
|
+
void (type satisfies never);
|
|
222
|
+
throw new UnimplementedError(`emitToJson: ${(type as Type).kind}`);
|
|
223
|
+
}
|
|
214
224
|
}
|
|
215
225
|
}
|
|
216
226
|
|
|
@@ -300,7 +310,6 @@ function transposeExpressionToJson(
|
|
|
300
310
|
case "Boolean":
|
|
301
311
|
return literalToExpr(type);
|
|
302
312
|
case "Interface":
|
|
303
|
-
case "Enum":
|
|
304
313
|
case "EnumMember":
|
|
305
314
|
case "TemplateParameter":
|
|
306
315
|
case "Namespace":
|
|
@@ -444,6 +453,14 @@ function* emitFromJson(
|
|
|
444
453
|
|
|
445
454
|
return;
|
|
446
455
|
}
|
|
456
|
+
case "Enum": {
|
|
457
|
+
yield `return input;`;
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
default: {
|
|
461
|
+
void (type satisfies never);
|
|
462
|
+
throw new UnimplementedError(`emitFromJson: ${(type as Type).kind}`);
|
|
463
|
+
}
|
|
447
464
|
}
|
|
448
465
|
}
|
|
449
466
|
|
|
@@ -134,12 +134,12 @@ function* emitRouterDefinition(
|
|
|
134
134
|
yield `export function create${routerName}(`;
|
|
135
135
|
|
|
136
136
|
for (const [param] of backends.values()) {
|
|
137
|
-
yield ` ${param.camelCase}: ${param.pascalCase},`;
|
|
137
|
+
yield ` ${keywordSafe(param.camelCase)}: ${param.pascalCase},`;
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
yield ` options: RouterOptions<{`;
|
|
141
141
|
for (const [param] of backends.values()) {
|
|
142
|
-
yield ` ${param.camelCase}: ${param.pascalCase}<HttpContext>,`;
|
|
142
|
+
yield ` ${keywordSafe(param.camelCase)}: ${param.pascalCase}<HttpContext>,`;
|
|
143
143
|
}
|
|
144
144
|
yield ` }> = {}`;
|
|
145
145
|
yield `): ${routerName} {`;
|
|
@@ -328,7 +328,7 @@ function* emitRouteOperationDispatch(
|
|
|
328
328
|
backend.snakeCase + "_" + parseCase(operation.operation.name).snakeCase,
|
|
329
329
|
);
|
|
330
330
|
|
|
331
|
-
const backendMemberName = backend.camelCase;
|
|
331
|
+
const backendMemberName = keywordSafe(backend.camelCase);
|
|
332
332
|
|
|
333
333
|
const parameters =
|
|
334
334
|
operation.parameters.length > 0
|
|
@@ -408,7 +408,7 @@ function* emitRouteOperationDispatchMultiple(
|
|
|
408
408
|
backend.snakeCase + "_" + parseCase(operation.operation.name).snakeCase,
|
|
409
409
|
);
|
|
410
410
|
|
|
411
|
-
const backendMemberName = backend.camelCase;
|
|
411
|
+
const backendMemberName = keywordSafe(backend.camelCase);
|
|
412
412
|
|
|
413
413
|
const parameters =
|
|
414
414
|
operation.parameters.length > 0
|