@typespec/http-server-js 0.58.0-alpha.18-dev.2 → 0.58.0-alpha.18-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/dist/src/common/scalar.d.ts.map +1 -1
- package/dist/src/common/scalar.js +9 -1
- package/dist/src/common/scalar.js.map +1 -1
- package/dist/src/http/server/index.d.ts.map +1 -1
- package/dist/src/http/server/index.js +33 -11
- package/dist/src/http/server/index.js.map +1 -1
- package/dist/src/util/differentiate.d.ts +11 -1
- package/dist/src/util/differentiate.d.ts.map +1 -1
- package/dist/src/util/differentiate.js +17 -1
- package/dist/src/util/differentiate.js.map +1 -1
- package/package.json +1 -1
- package/src/common/scalar.ts +9 -1
- package/src/http/server/index.ts +45 -23
- package/src/util/differentiate.ts +32 -0
- package/temp/tsconfig.tsbuildinfo +1 -1
- package/test/e2e/http/type/array/main.test.e2e.ts +78 -0
- package/test/e2e/http/type/dictionary/main.test.e2e.ts +86 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { afterEach, assert, beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
import { createArrayRouter } from "../../../generated/type/array/src/generated/http/router.js";
|
|
3
|
+
import { startServer, testRouterOptions } from "../../../helpers.js";
|
|
4
|
+
import { runScenario } from "../../../spector.js";
|
|
5
|
+
|
|
6
|
+
import { Temporal } from "temporal-polyfill";
|
|
7
|
+
import { HttpContext } from "../../../../../src/http/index.js";
|
|
8
|
+
|
|
9
|
+
class ArrayImpl<T> {
|
|
10
|
+
#assert: (l: T, r: T) => void;
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
public readonly value: T[],
|
|
14
|
+
assert: (l: T, r: T) => void = (l, r) => l === r,
|
|
15
|
+
) {
|
|
16
|
+
this.#assert = assert;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async get() {
|
|
20
|
+
return this.value;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async put(_: HttpContext, body: T[]) {
|
|
24
|
+
assert.equal(body.length, this.value.length);
|
|
25
|
+
|
|
26
|
+
for (let i = 0; i < body.length; i++) {
|
|
27
|
+
this.#assert(this.value[i], body[i]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe("Type.Array", () => {
|
|
35
|
+
let serverAbortController: AbortController;
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
serverAbortController = new AbortController();
|
|
38
|
+
});
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
serverAbortController.abort();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("passes all scenarios", async () => {
|
|
44
|
+
const router = createArrayRouter(
|
|
45
|
+
new ArrayImpl([1, 2]),
|
|
46
|
+
new ArrayImpl([0x7fffffffffffffffn, -0x7fffffffffffffffn]),
|
|
47
|
+
new ArrayImpl([true, false]),
|
|
48
|
+
new ArrayImpl(["hello", ""]),
|
|
49
|
+
new ArrayImpl([43.125]),
|
|
50
|
+
new ArrayImpl([Temporal.Instant.from("2022-08-26T18:38:00Z")], (l, r) => {
|
|
51
|
+
assert.equal(Temporal.Instant.compare(l, r), 0);
|
|
52
|
+
}),
|
|
53
|
+
new ArrayImpl([Temporal.Duration.from("P123DT22H14M12.011S")], (l, r) => {
|
|
54
|
+
assert.equal(Temporal.Duration.compare(l, r), 0);
|
|
55
|
+
}),
|
|
56
|
+
new ArrayImpl([1, "hello", null]),
|
|
57
|
+
new ArrayImpl([{ property: "hello" }, { property: "world" }], (l, r) => {
|
|
58
|
+
assert.equal(l.property, r.property);
|
|
59
|
+
}),
|
|
60
|
+
new ArrayImpl([1.25, null, 3.0]),
|
|
61
|
+
new ArrayImpl([1, null, 3]),
|
|
62
|
+
new ArrayImpl([true, null, false]),
|
|
63
|
+
new ArrayImpl(["hello", null, "world"]),
|
|
64
|
+
new ArrayImpl([{ property: "hello" }, null, { property: "world" }], (l, r) => {
|
|
65
|
+
if (l === null) {
|
|
66
|
+
assert.equal(r, null);
|
|
67
|
+
} else {
|
|
68
|
+
assert.isNotNull(r);
|
|
69
|
+
assert.equal(l.property, r.property);
|
|
70
|
+
}
|
|
71
|
+
}),
|
|
72
|
+
testRouterOptions,
|
|
73
|
+
);
|
|
74
|
+
const baseUrl = await startServer(router, serverAbortController.signal);
|
|
75
|
+
const { status } = await runScenario("type/array/!(int64value)*/*", baseUrl);
|
|
76
|
+
expect(status).toBe("pass");
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { afterEach, assert, beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
import { createDictionaryRouter } from "../../../generated/type/dictionary/src/generated/http/router.js";
|
|
3
|
+
import { startServer, testRouterOptions } from "../../../helpers.js";
|
|
4
|
+
import { runScenario } from "../../../spector.js";
|
|
5
|
+
|
|
6
|
+
import { Temporal } from "temporal-polyfill";
|
|
7
|
+
import { HttpContext } from "../../../../../src/http/index.js";
|
|
8
|
+
import { InnerModel } from "../../../generated/type/dictionary/src/generated/models/all/type/dictionary.js";
|
|
9
|
+
|
|
10
|
+
class RecordImpl<T> {
|
|
11
|
+
#assert: (l: T, r: T) => void;
|
|
12
|
+
|
|
13
|
+
constructor(
|
|
14
|
+
public readonly value: Record<string, T>,
|
|
15
|
+
assert: (l: T, r: T) => void = (l, r) => l === r,
|
|
16
|
+
) {
|
|
17
|
+
this.#assert = assert;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async get() {
|
|
21
|
+
return this.value;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async put(_: HttpContext, body: Record<string, T>) {
|
|
25
|
+
const props = Object.entries(this.value);
|
|
26
|
+
const bodyProps = Object.entries(body);
|
|
27
|
+
|
|
28
|
+
assert.equal(bodyProps.length, props.length);
|
|
29
|
+
|
|
30
|
+
for (const [k, v] of bodyProps) {
|
|
31
|
+
this.#assert(v, this.value[k]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe("Type.Dictionary", () => {
|
|
39
|
+
let serverAbortController: AbortController;
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
serverAbortController = new AbortController();
|
|
42
|
+
});
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
serverAbortController.abort();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("passes all scenarios", async () => {
|
|
48
|
+
const router = createDictionaryRouter(
|
|
49
|
+
new RecordImpl({ k1: 1, k2: 2 }),
|
|
50
|
+
new RecordImpl({ k1: 0x7fffffffffffffffn, k2: -0x7fffffffffffffffn }),
|
|
51
|
+
new RecordImpl({ k1: true, k2: false }),
|
|
52
|
+
new RecordImpl({ k1: "hello", k2: "" }),
|
|
53
|
+
new RecordImpl({ k1: 43.125 }),
|
|
54
|
+
new RecordImpl({ k1: Temporal.Instant.from("2022-08-26T18:38:00Z") }, (l, r) => {
|
|
55
|
+
assert.equal(Temporal.Instant.compare(l, r), 0);
|
|
56
|
+
}),
|
|
57
|
+
new RecordImpl({ k1: Temporal.Duration.from("P123DT22H14M12.011S") }, (l, r) => {
|
|
58
|
+
assert.equal(Temporal.Duration.compare(l, r), 0);
|
|
59
|
+
}),
|
|
60
|
+
new RecordImpl({ k1: 1, k2: "hello", k3: null }),
|
|
61
|
+
new RecordImpl({ k1: { property: "hello" }, k2: { property: "world" } }, (l, r) => {
|
|
62
|
+
assert.equal(l.property, r.property);
|
|
63
|
+
}),
|
|
64
|
+
new RecordImpl<InnerModel>(
|
|
65
|
+
{
|
|
66
|
+
k1: { property: "hello", children: {} },
|
|
67
|
+
k2: {
|
|
68
|
+
property: "world",
|
|
69
|
+
children: {
|
|
70
|
+
"k2.1": { property: "inner world" },
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
(l, r) => {
|
|
75
|
+
assert.equal(l.property, r.property);
|
|
76
|
+
assert.deepEqual(l.children, r.children);
|
|
77
|
+
},
|
|
78
|
+
),
|
|
79
|
+
new RecordImpl({ k1: 1.25, k2: 0.5, k3: null }),
|
|
80
|
+
testRouterOptions,
|
|
81
|
+
);
|
|
82
|
+
const baseUrl = await startServer(router, serverAbortController.signal);
|
|
83
|
+
const { status } = await runScenario("type/dictionary/!(int64value)*/*", baseUrl);
|
|
84
|
+
expect(status).toBe("pass");
|
|
85
|
+
});
|
|
86
|
+
});
|