@typespec/http-server-js 0.58.0-alpha.13-dev.8 → 0.58.0-alpha.13-dev.10
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 -1
- package/README.md +13 -0
- package/build-helpers.ts +22 -9
- package/dist/generated-defs/helpers/index.d.ts.map +1 -1
- package/dist/generated-defs/helpers/index.js +1 -0
- package/dist/generated-defs/helpers/index.js.map +1 -1
- package/dist/generated-defs/helpers/temporal/index.d.ts +4 -0
- package/dist/generated-defs/helpers/temporal/index.d.ts.map +1 -0
- package/dist/generated-defs/helpers/temporal/index.js +19 -0
- package/dist/generated-defs/helpers/temporal/index.js.map +1 -0
- package/dist/generated-defs/helpers/temporal/native.d.ts +4 -0
- package/dist/generated-defs/helpers/temporal/native.d.ts.map +1 -0
- package/dist/generated-defs/helpers/temporal/native.js +125 -0
- package/dist/generated-defs/helpers/temporal/native.js.map +1 -0
- package/dist/generated-defs/helpers/temporal/polyfill.d.ts +4 -0
- package/dist/generated-defs/helpers/temporal/polyfill.d.ts.map +1 -0
- package/dist/generated-defs/helpers/temporal/polyfill.js +124 -0
- package/dist/generated-defs/helpers/temporal/polyfill.js.map +1 -0
- package/dist/generated-defs/package.json.d.ts.map +1 -1
- package/dist/generated-defs/package.json.js +1 -0
- package/dist/generated-defs/package.json.js.map +1 -1
- package/dist/src/common/declaration.js +1 -1
- package/dist/src/common/declaration.js.map +1 -1
- package/dist/src/common/scalar.d.ts +1 -1
- package/dist/src/common/scalar.d.ts.map +1 -1
- package/dist/src/common/scalar.js +341 -49
- package/dist/src/common/scalar.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 +3 -9
- package/dist/src/common/serialization/index.js.map +1 -1
- package/dist/src/common/serialization/json.d.ts +2 -0
- package/dist/src/common/serialization/json.d.ts.map +1 -1
- package/dist/src/common/serialization/json.js +10 -19
- package/dist/src/common/serialization/json.js.map +1 -1
- package/dist/src/helpers/temporal/native.d.ts +40 -0
- package/dist/src/helpers/temporal/native.d.ts.map +1 -0
- package/dist/src/helpers/temporal/native.js +81 -0
- package/dist/src/helpers/temporal/native.js.map +1 -0
- package/dist/src/helpers/temporal/polyfill.d.ts +41 -0
- package/dist/src/helpers/temporal/polyfill.d.ts.map +1 -0
- package/dist/src/helpers/temporal/polyfill.js +80 -0
- package/dist/src/helpers/temporal/polyfill.js.map +1 -0
- package/dist/src/http/server/index.d.ts.map +1 -1
- package/dist/src/http/server/index.js +4 -1
- package/dist/src/http/server/index.js.map +1 -1
- package/dist/src/lib.d.ts +9 -0
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +7 -0
- package/dist/src/lib.js.map +1 -1
- package/dist/src/scripts/scaffold/data-mocks.d.ts.map +1 -1
- package/dist/src/scripts/scaffold/data-mocks.js +91 -32
- package/dist/src/scripts/scaffold/data-mocks.js.map +1 -1
- package/generated-defs/helpers/index.ts +1 -0
- package/generated-defs/helpers/temporal/index.ts +25 -0
- package/generated-defs/helpers/temporal/native.ts +132 -0
- package/generated-defs/helpers/temporal/polyfill.ts +131 -0
- package/generated-defs/package.json.ts +1 -0
- package/package.json +6 -5
- package/src/common/declaration.ts +1 -1
- package/src/common/scalar.ts +390 -62
- package/src/common/serialization/index.ts +4 -13
- package/src/common/serialization/json.ts +22 -25
- package/src/helpers/temporal/native.ts +104 -0
- package/src/helpers/temporal/polyfill.ts +103 -0
- package/src/http/server/index.ts +6 -1
- package/src/lib.ts +17 -0
- package/src/scripts/scaffold/data-mocks.ts +97 -32
- package/temp/tsconfig.tsbuildinfo +1 -1
- package/test/scalar.test.ts +547 -97
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { isErrorType, isVoidType, } from "@typespec/compiler";
|
|
2
2
|
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
3
3
|
import { isUnspeakable, parseCase } from "../../util/case.js";
|
|
4
|
-
import { module as dateTimeHelper } from "../../../generated-defs/helpers/datetime.js";
|
|
5
4
|
import { KEYWORDS } from "../../util/keywords.js";
|
|
5
|
+
import { getFullyQualifiedTypeName } from "../../util/name.js";
|
|
6
|
+
import { module as dateTimeHelper } from "../../../generated-defs/helpers/datetime.js";
|
|
6
7
|
/**
|
|
7
8
|
* Generates a mock value for a TypeSpec Model.
|
|
8
9
|
* Handles arrays and records as special cases.
|
|
@@ -12,14 +13,15 @@ import { KEYWORDS } from "../../util/keywords.js";
|
|
|
12
13
|
* @throws Error if a property cannot be mocked
|
|
13
14
|
*/
|
|
14
15
|
function mockModel(ctx, module, type) {
|
|
15
|
-
|
|
16
|
+
const tk = $(ctx.program);
|
|
17
|
+
if (tk.array.is(type)) {
|
|
16
18
|
return mockArray(ctx, module, type);
|
|
17
19
|
}
|
|
18
|
-
if (
|
|
20
|
+
if (tk.record.is(type)) {
|
|
19
21
|
return mockRecord(ctx, module, type);
|
|
20
22
|
}
|
|
21
23
|
const mock = [];
|
|
22
|
-
const properties =
|
|
24
|
+
const properties = tk.model.getProperties(type, { includeExtended: true });
|
|
23
25
|
// If no properties exist, return an empty object
|
|
24
26
|
if (properties.size === 0) {
|
|
25
27
|
return "{}";
|
|
@@ -50,7 +52,8 @@ function mockModel(ctx, module, type) {
|
|
|
50
52
|
* @returns A JavaScript string representation of the mock array
|
|
51
53
|
*/
|
|
52
54
|
function mockArray(ctx, module, type) {
|
|
53
|
-
const
|
|
55
|
+
const tk = $(ctx.program);
|
|
56
|
+
const elementType = tk.array.getElementType(type);
|
|
54
57
|
const mockedType = mockType(ctx, module, elementType);
|
|
55
58
|
// If we can't mock the element type, return an empty array
|
|
56
59
|
if (mockedType === undefined) {
|
|
@@ -65,7 +68,8 @@ function mockArray(ctx, module, type) {
|
|
|
65
68
|
* @returns A JavaScript string representation of the mock record
|
|
66
69
|
*/
|
|
67
70
|
function mockRecord(ctx, module, type) {
|
|
68
|
-
const
|
|
71
|
+
const tk = $(ctx.program);
|
|
72
|
+
const elementType = tk.record.getElementType(type);
|
|
69
73
|
const mockedType = mockType(ctx, module, elementType);
|
|
70
74
|
if (mockedType === undefined) {
|
|
71
75
|
return "{}";
|
|
@@ -100,19 +104,20 @@ function mockLiteral(type) {
|
|
|
100
104
|
* @returns A JavaScript string representation of the mock data, or undefined if the type cannot be mocked
|
|
101
105
|
*/
|
|
102
106
|
export function mockType(ctx, module, type) {
|
|
103
|
-
|
|
107
|
+
const tk = $(ctx.program);
|
|
108
|
+
if (tk.model.is(type)) {
|
|
104
109
|
return mockModel(ctx, module, type);
|
|
105
110
|
}
|
|
106
|
-
if (
|
|
111
|
+
if (tk.literal.is(type)) {
|
|
107
112
|
return mockLiteral(type);
|
|
108
113
|
}
|
|
109
|
-
if (
|
|
114
|
+
if (tk.modelProperty.is(type)) {
|
|
110
115
|
return mockModelProperty(ctx, module, type);
|
|
111
116
|
}
|
|
112
|
-
if (
|
|
117
|
+
if (tk.scalar.is(type)) {
|
|
113
118
|
return mockScalar(ctx, module, type);
|
|
114
119
|
}
|
|
115
|
-
if (
|
|
120
|
+
if (tk.union.is(type)) {
|
|
116
121
|
return mockUnion(ctx, module, type);
|
|
117
122
|
}
|
|
118
123
|
if (isVoidType(type)) {
|
|
@@ -143,17 +148,19 @@ function mockUnion(ctx, module, union) {
|
|
|
143
148
|
* @returns A JavaScript string representation of a suitable mock value for the scalar type
|
|
144
149
|
*/
|
|
145
150
|
function mockScalar(ctx, module, scalar) {
|
|
146
|
-
|
|
151
|
+
const tk = $(ctx.program);
|
|
152
|
+
const dateTimeMode = ctx.options.datetime ?? "temporal-polyfill";
|
|
153
|
+
if (tk.scalar.isBoolean(scalar) || tk.scalar.extendsBoolean(scalar)) {
|
|
147
154
|
return JSON.stringify(true);
|
|
148
155
|
}
|
|
149
|
-
if (
|
|
150
|
-
if (
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
156
|
+
if (tk.scalar.isNumeric(scalar) || tk.scalar.extendsNumeric(scalar)) {
|
|
157
|
+
if (tk.scalar.extendsSafeint(scalar) ||
|
|
158
|
+
tk.scalar.extendsInt32(scalar) ||
|
|
159
|
+
tk.scalar.extendsUint32(scalar) ||
|
|
160
|
+
tk.scalar.extendsFloat64(scalar)) {
|
|
154
161
|
return "42";
|
|
155
162
|
}
|
|
156
|
-
else if (
|
|
163
|
+
else if (tk.scalar.extendsInteger(scalar)) {
|
|
157
164
|
return "42n";
|
|
158
165
|
}
|
|
159
166
|
else {
|
|
@@ -161,32 +168,84 @@ function mockScalar(ctx, module, scalar) {
|
|
|
161
168
|
return "new Decimal(42)";
|
|
162
169
|
}
|
|
163
170
|
}
|
|
164
|
-
if (
|
|
165
|
-
|
|
171
|
+
if (tk.scalar.isUtcDateTime(scalar)) {
|
|
172
|
+
if (dateTimeMode === "date-duration") {
|
|
173
|
+
return "new Date()";
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
if (dateTimeMode === "temporal-polyfill") {
|
|
177
|
+
module.imports.push({
|
|
178
|
+
from: "temporal-polyfill",
|
|
179
|
+
binder: ["Temporal"],
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
// Current instant
|
|
183
|
+
return "Temporal.Now.instant()";
|
|
184
|
+
}
|
|
166
185
|
}
|
|
167
|
-
if (
|
|
186
|
+
if (tk.scalar.isOffsetDateTime(scalar) ||
|
|
187
|
+
tk.scalar.isPlainDate(scalar) ||
|
|
188
|
+
tk.scalar.isPlainTime(scalar)) {
|
|
189
|
+
if (dateTimeMode === "date-duration") {
|
|
190
|
+
return "new Date()";
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
if (dateTimeMode === "temporal-polyfill") {
|
|
194
|
+
module.imports.push({
|
|
195
|
+
from: "temporal-polyfill",
|
|
196
|
+
binder: ["Temporal"],
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
// Current instant
|
|
200
|
+
switch (scalar.name) {
|
|
201
|
+
case "offsetDateTime":
|
|
202
|
+
return "Temporal.Now.zonedDateTimeISO()";
|
|
203
|
+
case "plainDate":
|
|
204
|
+
return "Temporal.Now.zonedDateTimeISO().toPlainDate()";
|
|
205
|
+
case "plainTime":
|
|
206
|
+
return "Temporal.Now.zonedDateTimeISO().toPlainTime()";
|
|
207
|
+
default:
|
|
208
|
+
throw new Error("Unexpected scalar type: " + scalar.name);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (getFullyQualifiedTypeName(scalar) === "TypeSpec.unixTimestamp32") {
|
|
213
|
+
return "Math.floor(new Date().getTime() / 1000)";
|
|
214
|
+
}
|
|
215
|
+
if (tk.scalar.isBytes(scalar) || tk.scalar.extendsBytes(scalar)) {
|
|
168
216
|
return "new Uint8Array()";
|
|
169
217
|
}
|
|
170
|
-
if (
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
218
|
+
if (tk.scalar.isDuration(scalar) || tk.scalar.extendsDuration(scalar)) {
|
|
219
|
+
if (dateTimeMode === "date-duration") {
|
|
220
|
+
module.imports.push({
|
|
221
|
+
from: dateTimeHelper,
|
|
222
|
+
binder: ["Duration"],
|
|
223
|
+
});
|
|
224
|
+
return 'Duration.parseISO8601("P1Y2M3DT4H5M6S")';
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
if (dateTimeMode === "temporal-polyfill") {
|
|
228
|
+
module.imports.push({
|
|
229
|
+
from: "temporal-polyfill",
|
|
230
|
+
binder: ["Temporal"],
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
return `Temporal.Duration.from({ years: 1, months: 2, days: 3, hours: 4, minutes: 5, seconds: 6 })`;
|
|
234
|
+
}
|
|
176
235
|
}
|
|
177
|
-
if (
|
|
236
|
+
if (tk.scalar.isOffsetDateTime(scalar) || tk.scalar.extendsOffsetDateTime(scalar)) {
|
|
178
237
|
return JSON.stringify("2022-01-01T00:00:00Z");
|
|
179
238
|
}
|
|
180
|
-
if (
|
|
239
|
+
if (tk.scalar.isPlainDate(scalar) || tk.scalar.extendsPlainDate(scalar)) {
|
|
181
240
|
return JSON.stringify("2022-01-01");
|
|
182
241
|
}
|
|
183
|
-
if (
|
|
242
|
+
if (tk.scalar.isPlainTime(scalar) || tk.scalar.extendsPlainTime(scalar)) {
|
|
184
243
|
return JSON.stringify("00:00:00");
|
|
185
244
|
}
|
|
186
|
-
if (
|
|
245
|
+
if (tk.scalar.isUrl(scalar) || tk.scalar.extendsUrl(scalar)) {
|
|
187
246
|
return JSON.stringify("https://example.com");
|
|
188
247
|
}
|
|
189
|
-
if (
|
|
248
|
+
if (tk.scalar.isString(scalar) || tk.scalar.extendsString(scalar)) {
|
|
190
249
|
return JSON.stringify("mock-string");
|
|
191
250
|
}
|
|
192
251
|
return undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-mocks.js","sourceRoot":"","sources":["../../../../src/scripts/scaffold/data-mocks.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,UAAU,GAOX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,CAAC,EAAE,MAAM,yCAAyC,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"data-mocks.js","sourceRoot":"","sources":["../../../../src/scripts/scaffold/data-mocks.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,UAAU,GAOX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,CAAC,EAAE,MAAM,yCAAyC,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAEvF;;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AI,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;IAChD,CAAC;IAED,IAAI,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;QACxE,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;QACxE,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IACpC,CAAC;IAED,IAAI,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5D,OAAO,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC;IAC/C,CAAC;IAED,IAAI,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;QAClE,OAAO,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -16,6 +16,7 @@ export async function createModule(parent: Module): Promise<Module> {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
// Child modules
|
|
19
|
+
await import("./temporal/index.js").then((m) => m.createModule(module));
|
|
19
20
|
await import("./datetime.js").then((m) => m.createModule(module));
|
|
20
21
|
await import("./header.js").then((m) => m.createModule(module));
|
|
21
22
|
await import("./http.js").then((m) => m.createModule(module));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
|
|
4
|
+
import { Module } from "../../../src/ctx.js";
|
|
5
|
+
|
|
6
|
+
export let module: Module = undefined as any;
|
|
7
|
+
|
|
8
|
+
export async function createModule(parent: Module): Promise<Module> {
|
|
9
|
+
if (module) return module;
|
|
10
|
+
|
|
11
|
+
module = {
|
|
12
|
+
name: "temporal",
|
|
13
|
+
cursor: parent.cursor.enter("temporal"),
|
|
14
|
+
imports: [],
|
|
15
|
+
declarations: [],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Child modules
|
|
19
|
+
await import("./native.js").then((m) => m.createModule(module));
|
|
20
|
+
await import("./polyfill.js").then((m) => m.createModule(module));
|
|
21
|
+
|
|
22
|
+
parent.declarations.push(module);
|
|
23
|
+
|
|
24
|
+
return module;
|
|
25
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
|
|
4
|
+
import { Module } from "../../../src/ctx.js";
|
|
5
|
+
|
|
6
|
+
export let module: Module = undefined as any;
|
|
7
|
+
|
|
8
|
+
// prettier-ignore
|
|
9
|
+
const lines = [
|
|
10
|
+
"// Copyright (c) Microsoft Corporation",
|
|
11
|
+
"// Licensed under the MIT license.",
|
|
12
|
+
"",
|
|
13
|
+
"// Due to the lack of generally-available global type definitions for Temporal, we use `any` throughout this module.",
|
|
14
|
+
"// When global.d.ts eventually has definitions for Temporal, we can unify this module with `polyfill.ts`.",
|
|
15
|
+
"",
|
|
16
|
+
"/**",
|
|
17
|
+
" * Parses an HTTP date string (e.g. `Wed, 21 Oct 2015 07:28:00 GMT`) into a `Temporal.Instant`.",
|
|
18
|
+
" * The date string must be in the format specified by RFC 7231.",
|
|
19
|
+
" *",
|
|
20
|
+
" * @param httpDate - The HTTP date string to parse.",
|
|
21
|
+
" * @throws {RangeError} If the date string is invalid or cannot be parsed.",
|
|
22
|
+
" * @returns The parsed `Temporal.Instant`.",
|
|
23
|
+
" */",
|
|
24
|
+
"export function parseHttpDate(httpDate: string): any {",
|
|
25
|
+
" const timestamp = globalThis.Date.parse(httpDate);",
|
|
26
|
+
"",
|
|
27
|
+
" if (isNaN(timestamp)) {",
|
|
28
|
+
" throw new RangeError(`Invalid HTTP date: ${httpDate}`);",
|
|
29
|
+
" }",
|
|
30
|
+
"",
|
|
31
|
+
" return (globalThis as any).Temporal.Instant.fromEpochMilliseconds(timestamp);",
|
|
32
|
+
"}",
|
|
33
|
+
"",
|
|
34
|
+
"/**",
|
|
35
|
+
" * Formats a `Temporal.Instant` into an HTTP date string (e.g. `Wed, 21 Oct 2015 07:28:00 GMT`).",
|
|
36
|
+
" * The date string is formatted according to RFC 7231.",
|
|
37
|
+
" *",
|
|
38
|
+
" * @param instant - The `Temporal.Instant` to format.",
|
|
39
|
+
" * @returns The formatted HTTP date string.",
|
|
40
|
+
" */",
|
|
41
|
+
"export function formatHttpDate(instant: any) {",
|
|
42
|
+
" const date = new Date(instant.epochMilliseconds);",
|
|
43
|
+
" return date.toUTCString();",
|
|
44
|
+
"}",
|
|
45
|
+
"",
|
|
46
|
+
"/**",
|
|
47
|
+
" * Converts a `Temporal.Duration` to a number of seconds.",
|
|
48
|
+
" * This method will throw an Error if the duration contains any years, months, weeks, or days, as those require a reference",
|
|
49
|
+
" * point to calculate the total number of seconds.",
|
|
50
|
+
" *",
|
|
51
|
+
" * WARNING: If the total number of seconds is larger than the maximum safe integer in JavaScript, this method will",
|
|
52
|
+
" * lose precision. @see durationTotalSecondsBigInt for a BigInt alternative.",
|
|
53
|
+
" *",
|
|
54
|
+
" * @param duration - the duration to calculate the total number of seconds for",
|
|
55
|
+
" * @returns the total number of seconds in the duration",
|
|
56
|
+
" */",
|
|
57
|
+
"export function durationTotalSeconds(duration: any): number {",
|
|
58
|
+
" if (",
|
|
59
|
+
" duration.years !== 0 ||",
|
|
60
|
+
" duration.months !== 0 ||",
|
|
61
|
+
" duration.weeks !== 0 ||",
|
|
62
|
+
" duration.days !== 0",
|
|
63
|
+
" ) {",
|
|
64
|
+
" throw new Error(",
|
|
65
|
+
" \"Cannot calculate total seconds for a duration with years, months, weeks, or days.\",",
|
|
66
|
+
" );",
|
|
67
|
+
" }",
|
|
68
|
+
"",
|
|
69
|
+
" return (",
|
|
70
|
+
" duration.seconds +",
|
|
71
|
+
" duration.minutes * 60 +",
|
|
72
|
+
" duration.hours * 60 * 60 +",
|
|
73
|
+
" duration.days * 24 * 60 * 60",
|
|
74
|
+
" );",
|
|
75
|
+
"}",
|
|
76
|
+
"",
|
|
77
|
+
"/**",
|
|
78
|
+
" * Gets the total number of seconds in a duration.",
|
|
79
|
+
" *",
|
|
80
|
+
" * This method will throw an Error if the duration contains any years, months, weeks, or days, as those require a reference",
|
|
81
|
+
" * point to calculate the total number of seconds. It will also throw an error if any of the components are not integers.",
|
|
82
|
+
" *",
|
|
83
|
+
" * @param duration - the duration to calculate the total number of seconds for",
|
|
84
|
+
" * @returns the total number of seconds in the duration",
|
|
85
|
+
" */",
|
|
86
|
+
"export function durationTotalSecondsBigInt(duration: any): bigint {",
|
|
87
|
+
" if (",
|
|
88
|
+
" duration.years !== 0 ||",
|
|
89
|
+
" duration.months !== 0 ||",
|
|
90
|
+
" duration.weeks !== 0 ||",
|
|
91
|
+
" duration.days !== 0",
|
|
92
|
+
" ) {",
|
|
93
|
+
" throw new Error(",
|
|
94
|
+
" \"Cannot calculate total seconds for a duration with years, months, weeks, or days.\",",
|
|
95
|
+
" );",
|
|
96
|
+
" }",
|
|
97
|
+
"",
|
|
98
|
+
" if (",
|
|
99
|
+
" !Number.isInteger(duration.seconds) ||",
|
|
100
|
+
" !Number.isInteger(duration.minutes) ||",
|
|
101
|
+
" !Number.isInteger(duration.hours) ||",
|
|
102
|
+
" !Number.isInteger(duration.days)",
|
|
103
|
+
" ) {",
|
|
104
|
+
" throw new Error(\"Duration components must be integers.\");",
|
|
105
|
+
" }",
|
|
106
|
+
"",
|
|
107
|
+
" return (",
|
|
108
|
+
" BigInt(duration.seconds) +",
|
|
109
|
+
" BigInt(duration.minutes) * 60n +",
|
|
110
|
+
" BigInt(duration.hours) * 60n * 60n +",
|
|
111
|
+
" BigInt(duration.days) * 24n * 60n * 60n",
|
|
112
|
+
" );",
|
|
113
|
+
"}",
|
|
114
|
+
"",
|
|
115
|
+
];
|
|
116
|
+
|
|
117
|
+
export async function createModule(parent: Module): Promise<Module> {
|
|
118
|
+
if (module) return module;
|
|
119
|
+
|
|
120
|
+
module = {
|
|
121
|
+
name: "native",
|
|
122
|
+
cursor: parent.cursor.enter("native"),
|
|
123
|
+
imports: [],
|
|
124
|
+
declarations: [],
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
module.declarations.push(lines);
|
|
128
|
+
|
|
129
|
+
parent.declarations.push(module);
|
|
130
|
+
|
|
131
|
+
return module;
|
|
132
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
|
|
4
|
+
import { Module } from "../../../src/ctx.js";
|
|
5
|
+
|
|
6
|
+
export let module: Module = undefined as any;
|
|
7
|
+
|
|
8
|
+
// prettier-ignore
|
|
9
|
+
const lines = [
|
|
10
|
+
"// Copyright (c) Microsoft Corporation",
|
|
11
|
+
"// Licensed under the MIT license.",
|
|
12
|
+
"",
|
|
13
|
+
"import { Temporal } from \"temporal-polyfill\";",
|
|
14
|
+
"",
|
|
15
|
+
"/**",
|
|
16
|
+
" * Parses an HTTP date string (e.g. `Wed, 21 Oct 2015 07:28:00 GMT`) into a `Temporal.Instant`.",
|
|
17
|
+
" * The date string must be in the format specified by RFC 7231.",
|
|
18
|
+
" *",
|
|
19
|
+
" * @param httpDate - The HTTP date string to parse.",
|
|
20
|
+
" * @throws {RangeError} If the date string is invalid or cannot be parsed.",
|
|
21
|
+
" * @returns The parsed `Temporal.Instant`.",
|
|
22
|
+
" */",
|
|
23
|
+
"export function parseHttpDate(httpDate: string): Temporal.Instant {",
|
|
24
|
+
" const timestamp = globalThis.Date.parse(httpDate);",
|
|
25
|
+
"",
|
|
26
|
+
" if (isNaN(timestamp)) {",
|
|
27
|
+
" throw new RangeError(`Invalid HTTP date: ${httpDate}`);",
|
|
28
|
+
" }",
|
|
29
|
+
"",
|
|
30
|
+
" return Temporal.Instant.fromEpochMilliseconds(timestamp);",
|
|
31
|
+
"}",
|
|
32
|
+
"",
|
|
33
|
+
"/**",
|
|
34
|
+
" * Formats a `Temporal.Instant` into an HTTP date string (e.g. `Wed, 21 Oct 2015 07:28:00 GMT`).",
|
|
35
|
+
" * The date string is formatted according to RFC 7231.",
|
|
36
|
+
" *",
|
|
37
|
+
" * @param instant - The `Temporal.Instant` to format.",
|
|
38
|
+
" * @returns The formatted HTTP date string.",
|
|
39
|
+
" */",
|
|
40
|
+
"export function formatHttpDate(instant: Temporal.Instant) {",
|
|
41
|
+
" const date = new Date(instant.epochMilliseconds);",
|
|
42
|
+
" return date.toUTCString();",
|
|
43
|
+
"}",
|
|
44
|
+
"",
|
|
45
|
+
"/**",
|
|
46
|
+
" * Converts a `Temporal.Duration` to a number of seconds.",
|
|
47
|
+
" * This method will throw an Error if the duration contains any years, months, weeks, or days, as those require a reference",
|
|
48
|
+
" * point to calculate the total number of seconds.",
|
|
49
|
+
" *",
|
|
50
|
+
" * WARNING: If the total number of seconds is larger than the maximum safe integer in JavaScript, this method will",
|
|
51
|
+
" * lose precision. @see durationTotalSecondsBigInt for a BigInt alternative.",
|
|
52
|
+
" *",
|
|
53
|
+
" * @param duration - the duration to calculate the total number of seconds for",
|
|
54
|
+
" * @returns the total number of seconds in the duration",
|
|
55
|
+
" */",
|
|
56
|
+
"export function durationTotalSeconds(duration: Temporal.Duration): number {",
|
|
57
|
+
" if (",
|
|
58
|
+
" duration.years !== 0 ||",
|
|
59
|
+
" duration.months !== 0 ||",
|
|
60
|
+
" duration.weeks !== 0 ||",
|
|
61
|
+
" duration.days !== 0",
|
|
62
|
+
" ) {",
|
|
63
|
+
" throw new Error(",
|
|
64
|
+
" \"Cannot calculate total seconds for a duration with years, months, weeks, or days.\",",
|
|
65
|
+
" );",
|
|
66
|
+
" }",
|
|
67
|
+
"",
|
|
68
|
+
" return (",
|
|
69
|
+
" duration.seconds +",
|
|
70
|
+
" duration.minutes * 60 +",
|
|
71
|
+
" duration.hours * 60 * 60 +",
|
|
72
|
+
" duration.days * 24 * 60 * 60",
|
|
73
|
+
" );",
|
|
74
|
+
"}",
|
|
75
|
+
"",
|
|
76
|
+
"/**",
|
|
77
|
+
" * Gets the total number of seconds in a duration.",
|
|
78
|
+
" *",
|
|
79
|
+
" * This method will throw an Error if the duration contains any years, months, weeks, or days, as those require a reference",
|
|
80
|
+
" * point to calculate the total number of seconds. It will also throw an error if any of the components are not integers.",
|
|
81
|
+
" *",
|
|
82
|
+
" * @param duration - the duration to calculate the total number of seconds for",
|
|
83
|
+
" * @returns the total number of seconds in the duration",
|
|
84
|
+
" */",
|
|
85
|
+
"export function durationTotalSecondsBigInt(duration: Temporal.Duration): bigint {",
|
|
86
|
+
" if (",
|
|
87
|
+
" duration.years !== 0 ||",
|
|
88
|
+
" duration.months !== 0 ||",
|
|
89
|
+
" duration.weeks !== 0 ||",
|
|
90
|
+
" duration.days !== 0",
|
|
91
|
+
" ) {",
|
|
92
|
+
" throw new Error(",
|
|
93
|
+
" \"Cannot calculate total seconds for a duration with years, months, weeks, or days.\",",
|
|
94
|
+
" );",
|
|
95
|
+
" }",
|
|
96
|
+
"",
|
|
97
|
+
" if (",
|
|
98
|
+
" !Number.isInteger(duration.seconds) ||",
|
|
99
|
+
" !Number.isInteger(duration.minutes) ||",
|
|
100
|
+
" !Number.isInteger(duration.hours) ||",
|
|
101
|
+
" !Number.isInteger(duration.days)",
|
|
102
|
+
" ) {",
|
|
103
|
+
" throw new Error(\"Duration components must be integers.\");",
|
|
104
|
+
" }",
|
|
105
|
+
"",
|
|
106
|
+
" return (",
|
|
107
|
+
" BigInt(duration.seconds) +",
|
|
108
|
+
" BigInt(duration.minutes) * 60n +",
|
|
109
|
+
" BigInt(duration.hours) * 60n * 60n +",
|
|
110
|
+
" BigInt(duration.days) * 24n * 60n * 60n",
|
|
111
|
+
" );",
|
|
112
|
+
"}",
|
|
113
|
+
"",
|
|
114
|
+
];
|
|
115
|
+
|
|
116
|
+
export async function createModule(parent: Module): Promise<Module> {
|
|
117
|
+
if (module) return module;
|
|
118
|
+
|
|
119
|
+
module = {
|
|
120
|
+
name: "polyfill",
|
|
121
|
+
cursor: parent.cursor.enter("polyfill"),
|
|
122
|
+
imports: [],
|
|
123
|
+
declarations: [],
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
module.declarations.push(lines);
|
|
127
|
+
|
|
128
|
+
parent.declarations.push(module);
|
|
129
|
+
|
|
130
|
+
return module;
|
|
131
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/http-server-js",
|
|
3
|
-
"version": "0.58.0-alpha.13-dev.
|
|
3
|
+
"version": "0.58.0-alpha.13-dev.10",
|
|
4
4
|
"author": "Microsoft Corporation",
|
|
5
5
|
"description": "TypeSpec HTTP server code generator for JavaScript",
|
|
6
6
|
"homepage": "https://github.com/microsoft/typespec",
|
|
@@ -52,10 +52,11 @@
|
|
|
52
52
|
"@types/swagger-ui-express": "^4.1.8",
|
|
53
53
|
"@typespec/compiler": "^1.0.0-rc.0",
|
|
54
54
|
"@typespec/http": "^1.0.0-rc.0",
|
|
55
|
-
"@typespec/http-specs": "^0.1.0-alpha.
|
|
55
|
+
"@typespec/http-specs": "^0.1.0-alpha.19 || >=0.1.0-alpha.20-dev <0.1.0-alpha.20",
|
|
56
56
|
"@typespec/internal-build-utils": "^0.68.0 || >=0.69.0-dev <0.69.0",
|
|
57
57
|
"@typespec/openapi3": "^1.0.0-rc.0",
|
|
58
|
-
"@typespec/spector": "^0.1.0-alpha.
|
|
58
|
+
"@typespec/spector": "^0.1.0-alpha.12 || >=0.1.0-alpha.13-dev <0.1.0-alpha.13",
|
|
59
|
+
"@typespec/tspd": "^0.68.0 || >=0.69.0-dev <0.69.0",
|
|
59
60
|
"@vitest/coverage-v8": "^3.0.9",
|
|
60
61
|
"@vitest/ui": "^3.0.9",
|
|
61
62
|
"decimal.js": "^10.5.0",
|
|
@@ -69,11 +70,11 @@
|
|
|
69
70
|
"pathe": "^2.0.3",
|
|
70
71
|
"picocolors": "~1.1.1",
|
|
71
72
|
"swagger-ui-express": "^5.0.1",
|
|
73
|
+
"temporal-polyfill": "^0.3.0",
|
|
72
74
|
"tsx": "^4.19.3",
|
|
73
75
|
"typescript": "~5.8.2",
|
|
74
76
|
"vitest": "^3.0.9",
|
|
75
|
-
"yargs": "~17.7.2"
|
|
76
|
-
"@typespec/tspd": "^0.46.0"
|
|
77
|
+
"yargs": "~17.7.2"
|
|
77
78
|
},
|
|
78
79
|
"scripts": {
|
|
79
80
|
"clean": "rimraf ./dist ./temp",
|