typespec-typescript-emitter 1.2.0 → 2.0.1
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/.husky/pre-commit +2 -1
- package/.prettierignore +2 -1
- package/CHANGELOG.md +19 -24
- package/CODE_OF_CONDUCT.md +128 -0
- package/README.md +362 -219
- package/dist/src/emit_routedTypemap.d.ts +4 -0
- package/dist/src/emit_routedTypemap.js +83 -0
- package/dist/src/emit_routedTypemap.js.map +1 -0
- package/dist/src/emit_routes.d.ts +3 -2
- package/dist/src/emit_routes.js +73 -47
- package/dist/src/emit_routes.js.map +1 -1
- package/dist/src/emit_types.d.ts +3 -9
- package/dist/src/emit_types.js +109 -74
- package/dist/src/emit_types.js.map +1 -1
- package/dist/src/emitter.d.ts +2 -6
- package/dist/src/emitter.js +18 -76
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/helpers/appendableString.d.ts +15 -0
- package/dist/src/helpers/appendableString.js +41 -0
- package/dist/src/helpers/appendableString.js.map +1 -0
- package/dist/src/helpers/arrays.d.ts +3 -0
- package/dist/src/helpers/arrays.js +23 -0
- package/dist/src/helpers/arrays.js.map +1 -0
- package/dist/src/{helper_autogenerateWarning.d.ts → helpers/autogenerateWarning.d.ts} +1 -1
- package/dist/src/{helper_autogenerateWarning.js → helpers/autogenerateWarning.js} +1 -2
- package/dist/src/helpers/autogenerateWarning.js.map +1 -0
- package/dist/src/helpers/buildTypeMap.d.ts +12 -0
- package/dist/src/helpers/buildTypeMap.js +44 -0
- package/dist/src/helpers/buildTypeMap.js.map +1 -0
- package/dist/src/helpers/diagnostics.d.ts +4 -0
- package/dist/src/helpers/diagnostics.js +15 -0
- package/dist/src/helpers/diagnostics.js.map +1 -0
- package/dist/src/helpers/getImports.d.ts +2 -0
- package/dist/src/helpers/getImports.js +3 -0
- package/dist/src/helpers/getImports.js.map +1 -0
- package/dist/src/helpers/namespaces.d.ts +4 -0
- package/dist/src/helpers/namespaces.js +14 -0
- package/dist/src/helpers/namespaces.js.map +1 -0
- package/dist/src/helpers/visibilityHelperFile.d.ts +4 -0
- package/dist/src/helpers/visibilityHelperFile.js +57 -0
- package/dist/src/helpers/visibilityHelperFile.js.map +1 -0
- package/dist/src/lib.d.ts +4 -1
- package/dist/src/lib.js +14 -3
- package/dist/src/lib.js.map +1 -1
- package/dist/src/parseOptions.d.ts +8 -0
- package/dist/src/parseOptions.js +26 -0
- package/dist/src/parseOptions.js.map +1 -0
- package/dist/src/resolve/Resolvable.d.ts +32 -0
- package/dist/src/resolve/Resolvable.js +180 -0
- package/dist/src/resolve/Resolvable.js.map +1 -0
- package/dist/src/resolve/Resolvable_helpers.d.ts +42 -0
- package/dist/src/resolve/Resolvable_helpers.js +19 -0
- package/dist/src/resolve/Resolvable_helpers.js.map +1 -0
- package/dist/src/resolve/operationTypemap.d.ts +21 -0
- package/dist/src/resolve/operationTypemap.js +138 -0
- package/dist/src/resolve/operationTypemap.js.map +1 -0
- package/dist/src/resolve/types/Enum.d.ts +21 -0
- package/dist/src/resolve/types/Enum.js +61 -0
- package/dist/src/resolve/types/Enum.js.map +1 -0
- package/dist/src/resolve/types/Model.Indexed.d.ts +12 -0
- package/dist/src/resolve/types/Model.Indexed.js +69 -0
- package/dist/src/resolve/types/Model.Indexed.js.map +1 -0
- package/dist/src/resolve/types/Model.Shaped.d.ts +17 -0
- package/dist/src/resolve/types/Model.Shaped.js +210 -0
- package/dist/src/resolve/types/Model.Shaped.js.map +1 -0
- package/dist/src/resolve/types/Scalar.d.ts +9 -0
- package/dist/src/resolve/types/Scalar.js +109 -0
- package/dist/src/resolve/types/Scalar.js.map +1 -0
- package/dist/src/resolve/types/Simple.d.ts +11 -0
- package/dist/src/resolve/types/Simple.js +49 -0
- package/dist/src/resolve/types/Simple.js.map +1 -0
- package/dist/src/resolve/types/Tuple.d.ts +9 -0
- package/dist/src/resolve/types/Tuple.js +38 -0
- package/dist/src/resolve/types/Tuple.js.map +1 -0
- package/dist/src/resolve/types/Union.d.ts +9 -0
- package/dist/src/resolve/types/Union.js +36 -0
- package/dist/src/resolve/types/Union.js.map +1 -0
- package/eslint.config.js +12 -4
- package/package.json +2 -2
- package/src/emit_routedTypemap.ts +128 -0
- package/src/emit_routes.ts +108 -61
- package/src/emit_types.ts +137 -92
- package/src/emitter.ts +19 -107
- package/src/helpers/appendableString.ts +52 -0
- package/src/helpers/arrays.ts +21 -0
- package/src/{helper_autogenerateWarning.ts → helpers/autogenerateWarning.ts} +0 -1
- package/src/helpers/buildTypeMap.ts +72 -0
- package/src/helpers/diagnostics.ts +19 -0
- package/src/helpers/getImports.ts +9 -0
- package/src/helpers/namespaces.ts +18 -0
- package/src/helpers/visibilityHelperFile.ts +63 -0
- package/src/lib.ts +25 -4
- package/src/parseOptions.ts +26 -0
- package/src/resolve/Resolvable.ts +267 -0
- package/src/resolve/Resolvable_helpers.ts +65 -0
- package/src/resolve/operationTypemap.ts +212 -0
- package/src/resolve/types/Enum.ts +92 -0
- package/src/resolve/types/Model.Indexed.ts +113 -0
- package/src/resolve/types/Model.Shaped.ts +291 -0
- package/src/resolve/types/Scalar.ts +140 -0
- package/src/resolve/types/Simple.ts +88 -0
- package/src/resolve/types/Tuple.ts +56 -0
- package/src/resolve/types/Union.ts +52 -0
- package/test/helpers/integrationTest-novis.tsp +51 -0
- package/test/helpers/integrationTest.tsp +53 -0
- package/test/helpers/largeModel.tsp +40 -0
- package/test/{runner.ts → helpers/runner.ts} +1 -1
- package/test/helpers/ts.ts +11 -0
- package/test/helpers/wrapper.ts +144 -0
- package/test/routes/routes.target.ts +35 -0
- package/test/routes/routes.test.ts +22 -0
- package/test/typeguards/combined.test.ts +78 -0
- package/test/typeguards/enum.test.ts +10 -0
- package/test/typeguards/model.indexed.test.ts +68 -0
- package/test/typeguards/model.shaped.test.ts +38 -0
- package/test/typeguards/scalar.test.ts +62 -0
- package/test/typeguards/simple.test.ts +35 -0
- package/test/typeguards/tuple.test.ts +34 -0
- package/test/typeguards/union.test.ts +29 -0
- package/test/typemap/typemap-novis.target.ts +38 -0
- package/test/typemap/typemap.target.ts +39 -0
- package/test/typemap/typemap.test.ts +48 -0
- package/test/types/combined.test.ts +71 -0
- package/test/types/enum.test.ts +57 -0
- package/test/types/model.indexed.test.ts +46 -0
- package/test/types/model.shaped.test.ts +23 -0
- package/test/types/scalar.test.ts +53 -0
- package/test/types/simple.test.ts +20 -0
- package/test/types/tuple.test.ts +29 -0
- package/test/types/union.test.ts +20 -0
- package/tsconfig.json +1 -0
- package/dist/src/emit_mapped_types.d.ts +0 -2
- package/dist/src/emit_mapped_types.js +0 -124
- package/dist/src/emit_mapped_types.js.map +0 -1
- package/dist/src/emit_types_resolve.d.ts +0 -22
- package/dist/src/emit_types_resolve.js +0 -217
- package/dist/src/emit_types_resolve.js.map +0 -1
- package/dist/src/emit_types_typeguards.d.ts +0 -17
- package/dist/src/emit_types_typeguards.js +0 -121
- package/dist/src/emit_types_typeguards.js.map +0 -1
- package/dist/src/helper_autogenerateWarning.js.map +0 -1
- package/src/emit_mapped_types.ts +0 -155
- package/src/emit_types_resolve.ts +0 -280
- package/src/emit_types_typeguards.ts +0 -178
- package/test/main.test.ts +0 -83
- package/test/out/.gitkeep +0 -0
- package/test/targets/enum.routed-types.ts +0 -59
- package/test/targets/enum.routes.ts +0 -29
- package/test/targets/enum.target.ts +0 -39
- package/test/targets/enum.tsp +0 -36
- package/test/targets/pr8.routed-types.ts +0 -131
- package/test/targets/pr8.routes.ts +0 -30
- package/test/targets/pr8.target.ts +0 -97
- package/test/targets/pr8.tsp +0 -62
- package/test/targets/simple-routes.routed-types.ts +0 -64
- package/test/targets/simple-routes.routes.ts +0 -29
- package/test/targets/simple-routes.target.ts +0 -21
- package/test/targets/simple-routes.tsp +0 -23
- package/test/targets/union.routed-types.ts +0 -59
- package/test/targets/union.routes.ts +0 -23
- package/test/targets/union.target.ts +0 -59
- package/test/targets/union.tsp +0 -38
- package/test/targets/visibility.routed-types.ts +0 -81
- package/test/targets/visibility.routes.ts +0 -38
- package/test/targets/visibility.target.ts +0 -36
- package/test/targets/visibility.tsp +0 -49
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Type } from "@typespec/compiler";
|
|
2
|
+
import { Resolver } from "../../src/resolve/Resolvable_helpers";
|
|
3
|
+
import { expectResolution } from "../helpers/wrapper";
|
|
4
|
+
|
|
5
|
+
type Value = string;
|
|
6
|
+
type Target = string;
|
|
7
|
+
|
|
8
|
+
const tests: [Type["kind"], Value, Target][] = [
|
|
9
|
+
["Boolean", "true", "undefined === true"],
|
|
10
|
+
["Boolean", "false", "undefined === false"],
|
|
11
|
+
// ["Intrinsic", ["never", "unknown", "void", "null"]],
|
|
12
|
+
["Intrinsic", "never", "false"],
|
|
13
|
+
["Intrinsic", "unknown", "true"],
|
|
14
|
+
["Intrinsic", "void", "undefined === undefined"],
|
|
15
|
+
["Intrinsic", "null", "undefined === null"],
|
|
16
|
+
["String", `"stringy"`, `undefined === 'stringy'`],
|
|
17
|
+
...[5, 8, 17, 15.55, -4].map(
|
|
18
|
+
(n) =>
|
|
19
|
+
["Number", n.toString(), `undefined === ${n}`] as [
|
|
20
|
+
Type["kind"],
|
|
21
|
+
Value,
|
|
22
|
+
Target,
|
|
23
|
+
],
|
|
24
|
+
),
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
tests.forEach((test) => {
|
|
28
|
+
expectResolution(Resolver.Typeguard, {
|
|
29
|
+
type: test[0],
|
|
30
|
+
desc: `simple: ${test[1]}`,
|
|
31
|
+
source: `alias test = ${test[1]};`,
|
|
32
|
+
target: test[2],
|
|
33
|
+
typescriptTransformer: null,
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Resolver } from "../../src/resolve/Resolvable_helpers";
|
|
2
|
+
import { expectResolution } from "../helpers/wrapper";
|
|
3
|
+
|
|
4
|
+
type Name = string;
|
|
5
|
+
type Source = string;
|
|
6
|
+
type Target = string;
|
|
7
|
+
|
|
8
|
+
const tests: [Name, Source, Target][] = [
|
|
9
|
+
[
|
|
10
|
+
"basic, strings",
|
|
11
|
+
"[string, string]",
|
|
12
|
+
"Array.isArray(undefined) && (typeof undefined[0] === 'string') && (typeof undefined[1] === 'string')",
|
|
13
|
+
],
|
|
14
|
+
[
|
|
15
|
+
"mixed",
|
|
16
|
+
"[string, int32, null, {a: unknown, b: float}]",
|
|
17
|
+
"Array.isArray(undefined) && (typeof undefined[0] === 'string') && (typeof undefined[1] === 'number') && (undefined[2] === null) && (undefined[3]['a'] !== undefined && (true) &&undefined[3]['b'] !== undefined && (typeof undefined[3]['b'] === 'number'))",
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
"unions",
|
|
21
|
+
"[string | float, null | unknown]",
|
|
22
|
+
"Array.isArray(undefined) && ((typeof undefined[0] === 'string') || (typeof undefined[0] === 'number')) && ((undefined[1] === null) || (true))",
|
|
23
|
+
],
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
tests.forEach((test) => {
|
|
27
|
+
expectResolution(Resolver.Typeguard, {
|
|
28
|
+
type: "Tuple",
|
|
29
|
+
desc: test[0],
|
|
30
|
+
source: `alias test = ${test[1]};`,
|
|
31
|
+
target: test[2],
|
|
32
|
+
typescriptTransformer: null,
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Resolver } from "../../src/resolve/Resolvable_helpers";
|
|
2
|
+
import { expectResolution } from "../helpers/wrapper";
|
|
3
|
+
|
|
4
|
+
type Name = string;
|
|
5
|
+
type Source = string;
|
|
6
|
+
type Target = string;
|
|
7
|
+
|
|
8
|
+
const tests: [Name, Source, Target][] = [
|
|
9
|
+
[
|
|
10
|
+
"basic",
|
|
11
|
+
"string | float",
|
|
12
|
+
"(typeof undefined === 'string') || (typeof undefined === 'number')",
|
|
13
|
+
],
|
|
14
|
+
[
|
|
15
|
+
"mixed",
|
|
16
|
+
"[string, int32] | {a: null}",
|
|
17
|
+
"(Array.isArray(undefined) && (typeof undefined[0] === 'string') && (typeof undefined[1] === 'number')) || (undefined['a'] !== undefined && (undefined['a'] === null))",
|
|
18
|
+
],
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
tests.forEach((test) => {
|
|
22
|
+
expectResolution(Resolver.Typeguard, {
|
|
23
|
+
type: "Union",
|
|
24
|
+
desc: test[0],
|
|
25
|
+
source: `alias test = ${test[1]};`,
|
|
26
|
+
target: test[2],
|
|
27
|
+
typescriptTransformer: null,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
// WARN this file may be broken by auto formatting.
|
|
3
|
+
// WARN by default in vscode, save: Ctrl+K , Ctrl+Shift+S
|
|
4
|
+
/*
|
|
5
|
+
* This file is automatically generated by typespec-typescript-emitter.
|
|
6
|
+
*
|
|
7
|
+
* You should not change or manipulate this file, as it will be overwritten.
|
|
8
|
+
* Instead, change the underlying spec.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
import * as test from './test.ts';
|
|
13
|
+
import * as test_inner from './test.inner.ts';
|
|
14
|
+
|
|
15
|
+
export type types_test = {
|
|
16
|
+
['/']: {
|
|
17
|
+
['GET']: {
|
|
18
|
+
request: null
|
|
19
|
+
response: {status: 200, body: test.Resource}
|
|
20
|
+
},
|
|
21
|
+
['PUT']: {
|
|
22
|
+
request: test.Resource | test_inner.InnerModel
|
|
23
|
+
response: {status: 200, body: {
|
|
24
|
+
statusCode: 200
|
|
25
|
+
}}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
['/inner']: {
|
|
29
|
+
['DELETE']: {
|
|
30
|
+
request: test_inner.InnerModel | test_inner.InnerModel2
|
|
31
|
+
response: {status: 200, body: {
|
|
32
|
+
statusCode: 200
|
|
33
|
+
}} | {status: 401, body: {
|
|
34
|
+
statusCode: 401
|
|
35
|
+
}}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
// WARN this file may be broken by auto formatting.
|
|
3
|
+
// WARN by default in vscode, save: Ctrl+K , Ctrl+Shift+S
|
|
4
|
+
/*
|
|
5
|
+
* This file is automatically generated by typespec-typescript-emitter.
|
|
6
|
+
*
|
|
7
|
+
* You should not change or manipulate this file, as it will be overwritten.
|
|
8
|
+
* Instead, change the underlying spec.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
import * as test from './test.ts';
|
|
13
|
+
import * as test_inner from './test.inner.ts';
|
|
14
|
+
import {Lifecycle, FilterLifecycle} from './lifecycleVisibility.ts';
|
|
15
|
+
|
|
16
|
+
export type types_test<V extends Lifecycle = Lifecycle.All> = {
|
|
17
|
+
['/']: {
|
|
18
|
+
['GET']: {
|
|
19
|
+
request: null
|
|
20
|
+
response: {status: 200, body: test.Resource<V extends Lifecycle.All ? (Lifecycle.Read) : V>}
|
|
21
|
+
},
|
|
22
|
+
['PUT']: {
|
|
23
|
+
request: test.Resource<V extends Lifecycle.All ? (Lifecycle.Create | Lifecycle.Update) : V> | test_inner.InnerModel<V extends Lifecycle.All ? (Lifecycle.Create | Lifecycle.Update) : V>
|
|
24
|
+
response: {status: 200, body: {
|
|
25
|
+
statusCode: 200
|
|
26
|
+
}}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
['/inner']: {
|
|
30
|
+
['DELETE']: {
|
|
31
|
+
request: test_inner.InnerModel<V extends Lifecycle.All ? (Lifecycle.Delete) : V> | test_inner.InnerModel2
|
|
32
|
+
response: {status: 200, body: {
|
|
33
|
+
statusCode: 200
|
|
34
|
+
}} | {status: 401, body: {
|
|
35
|
+
statusCode: 401
|
|
36
|
+
}}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { readFileSync } from "fs";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { expectEmit } from "../helpers/wrapper";
|
|
4
|
+
|
|
5
|
+
const prepareContents = (s: string): string => {
|
|
6
|
+
let ret = s;
|
|
7
|
+
ret = ret.replaceAll(
|
|
8
|
+
"// WARN this file may be broken by auto formatting.",
|
|
9
|
+
"",
|
|
10
|
+
);
|
|
11
|
+
ret = ret.replaceAll(
|
|
12
|
+
"// WARN by default in vscode, save: Ctrl+K , Ctrl+Shift+S",
|
|
13
|
+
"",
|
|
14
|
+
);
|
|
15
|
+
return `/* eslint-disable */${ret}`;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
expectEmit(
|
|
19
|
+
"routed typemap",
|
|
20
|
+
{
|
|
21
|
+
["main.tsp"]: readFileSync(
|
|
22
|
+
join(__dirname, "..", "helpers", "integrationTest.tsp"),
|
|
23
|
+
"utf8",
|
|
24
|
+
),
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"routedTypemap_test.ts": prepareContents(
|
|
28
|
+
readFileSync(join(__dirname, "typemap.target.ts"), "utf8"),
|
|
29
|
+
),
|
|
30
|
+
},
|
|
31
|
+
{ "enable-routed-typemap": true },
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
expectEmit(
|
|
35
|
+
"routed typemap - no visibility",
|
|
36
|
+
{
|
|
37
|
+
["main.tsp"]: readFileSync(
|
|
38
|
+
join(__dirname, "..", "helpers", "integrationTest-novis.tsp"),
|
|
39
|
+
"utf8",
|
|
40
|
+
),
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"routedTypemap_test.ts": prepareContents(
|
|
44
|
+
readFileSync(join(__dirname, "typemap-novis.target.ts"), "utf8"),
|
|
45
|
+
),
|
|
46
|
+
},
|
|
47
|
+
{ "enable-routed-typemap": true },
|
|
48
|
+
);
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { readFileSync } from "fs";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { Resolver } from "../../src/resolve/Resolvable_helpers";
|
|
4
|
+
import { expectResolution } from "../helpers/wrapper";
|
|
5
|
+
|
|
6
|
+
const input = readFileSync(
|
|
7
|
+
join(__dirname, "..", "helpers", "largeModel.tsp"),
|
|
8
|
+
"utf8",
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
const target = `
|
|
12
|
+
FilterLifecycle<{
|
|
13
|
+
id_onlyRead: number,
|
|
14
|
+
name: string,
|
|
15
|
+
aliasedName?: string,
|
|
16
|
+
date: string,
|
|
17
|
+
time: string,
|
|
18
|
+
created_onlyCreate: number,
|
|
19
|
+
tuple_strIntModel_readQuery: [string, number, {inmodel_union: null | unknown}],
|
|
20
|
+
nested?: {
|
|
21
|
+
availability: boolean
|
|
22
|
+
},
|
|
23
|
+
array: (string)[],
|
|
24
|
+
array_union: (string | number)[],
|
|
25
|
+
record: {[k: string]: string},
|
|
26
|
+
record_union: {[k: string]: string | number},
|
|
27
|
+
nested_deleteQuery: {
|
|
28
|
+
str_onlyQuery: string,
|
|
29
|
+
aliasedModel: {str: string,fl: number,nested: {int: number}},
|
|
30
|
+
modelWithVis: {
|
|
31
|
+
a: 'a',
|
|
32
|
+
seven_onlyDelete: 7
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
nestedInnerVis: {
|
|
36
|
+
unk?: unknown,
|
|
37
|
+
void_onlyUpdate: void
|
|
38
|
+
},
|
|
39
|
+
tupleWithUnion: [string, number | boolean]
|
|
40
|
+
}, {
|
|
41
|
+
'id_onlyRead': {vis: [Lifecycle.Read]},
|
|
42
|
+
'created_onlyCreate': {vis: [Lifecycle.Create]},
|
|
43
|
+
'tuple_strIntModel_readQuery': {vis: [Lifecycle.Read, Lifecycle.Query]},
|
|
44
|
+
'nested_deleteQuery': {
|
|
45
|
+
vis: [Lifecycle.Delete, Lifecycle.Query],
|
|
46
|
+
nested: {
|
|
47
|
+
'str_onlyQuery': {vis: [Lifecycle.Query]},
|
|
48
|
+
'modelWithVis': {
|
|
49
|
+
nested: {
|
|
50
|
+
'seven_onlyDelete': {vis: [Lifecycle.Delete]}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
'nestedInnerVis': {
|
|
56
|
+
nested: {
|
|
57
|
+
'void_onlyUpdate': {vis: [Lifecycle.Update]}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}, V>
|
|
61
|
+
`;
|
|
62
|
+
|
|
63
|
+
expectResolution(Resolver.Type, {
|
|
64
|
+
type: "Model",
|
|
65
|
+
desc: "combined",
|
|
66
|
+
source: input,
|
|
67
|
+
target: target,
|
|
68
|
+
config: {
|
|
69
|
+
"serializable-date-types": true,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { EmitterOptions } from "../../src/lib";
|
|
2
|
+
import { Resolver } from "../../src/resolve/Resolvable_helpers";
|
|
3
|
+
import { expectResolution } from "../helpers/wrapper";
|
|
4
|
+
|
|
5
|
+
type Name = string;
|
|
6
|
+
type Source = string;
|
|
7
|
+
type Target = string;
|
|
8
|
+
|
|
9
|
+
const tests: [Name, Source, Target, Partial<EmitterOptions>][] = [
|
|
10
|
+
[
|
|
11
|
+
"basic, not nominal",
|
|
12
|
+
"enum test {val1, val2}",
|
|
13
|
+
"{val1,val2}",
|
|
14
|
+
{ "string-nominal-enums": false },
|
|
15
|
+
],
|
|
16
|
+
[
|
|
17
|
+
"basic, nominal",
|
|
18
|
+
"enum test {val1, val2}",
|
|
19
|
+
"{val1 = 'val1',val2 = 'val2'}",
|
|
20
|
+
{ "string-nominal-enums": true },
|
|
21
|
+
],
|
|
22
|
+
[
|
|
23
|
+
"shifted, not nominal",
|
|
24
|
+
"enum test {val1: 1, val2: 2}",
|
|
25
|
+
"{val1 = 1,val2 = 2}",
|
|
26
|
+
{ "string-nominal-enums": false },
|
|
27
|
+
],
|
|
28
|
+
[
|
|
29
|
+
"shifted, nominal",
|
|
30
|
+
"enum test {val1: 1, val2: 2}",
|
|
31
|
+
"{val1 = 1,val2 = 2}",
|
|
32
|
+
{ "string-nominal-enums": true },
|
|
33
|
+
],
|
|
34
|
+
[
|
|
35
|
+
"string, not nominal",
|
|
36
|
+
'enum test {val1: "value1", val2: "value2"}',
|
|
37
|
+
"{val1 = 'value1',val2 = 'value2'}",
|
|
38
|
+
{ "string-nominal-enums": false },
|
|
39
|
+
],
|
|
40
|
+
[
|
|
41
|
+
"string, nominal",
|
|
42
|
+
'enum test {val1: "value1", val2: "value2"}',
|
|
43
|
+
"{val1 = 'value1',val2 = 'value2'}",
|
|
44
|
+
{ "string-nominal-enums": true },
|
|
45
|
+
],
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
tests.forEach((test) => {
|
|
49
|
+
expectResolution(Resolver.Type, {
|
|
50
|
+
type: "Enum",
|
|
51
|
+
desc: test[0],
|
|
52
|
+
source: test[1],
|
|
53
|
+
target: test[2],
|
|
54
|
+
config: test[3],
|
|
55
|
+
typescriptTransformer: (tsp) => `enum test ${tsp}`,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Model } from "@typespec/compiler";
|
|
2
|
+
import { Resolver } from "../../src/resolve/Resolvable_helpers";
|
|
3
|
+
import { expectResolution } from "../helpers/wrapper";
|
|
4
|
+
|
|
5
|
+
type Name = string;
|
|
6
|
+
type Source = string;
|
|
7
|
+
type Target = string;
|
|
8
|
+
|
|
9
|
+
const tests: [Name, string, Source, Target][] = [
|
|
10
|
+
["Array", "simple", "string[]", "(string)[]"],
|
|
11
|
+
["Array", "union", "(string | int32)[]", "(string | number)[]"],
|
|
12
|
+
["Array", "tuple", "[string, int32][]", "([string, number])[]"],
|
|
13
|
+
["Array", "model", "{str: string}[]", "({str: string})[]"],
|
|
14
|
+
["Record", "simple", "Record<string>", "{[k: string]: string}"],
|
|
15
|
+
[
|
|
16
|
+
"Record",
|
|
17
|
+
"union",
|
|
18
|
+
"Record<string | int32>",
|
|
19
|
+
"{[k: string]: string | number}",
|
|
20
|
+
],
|
|
21
|
+
[
|
|
22
|
+
"Record",
|
|
23
|
+
"tuple",
|
|
24
|
+
"Record<[string, int32]>",
|
|
25
|
+
"{[k: string]: [string, number]}",
|
|
26
|
+
],
|
|
27
|
+
[
|
|
28
|
+
"Record",
|
|
29
|
+
"model",
|
|
30
|
+
"Record<{str?: string}>",
|
|
31
|
+
"{[k: string]: {str?: string}}",
|
|
32
|
+
],
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
tests.forEach((test) => {
|
|
36
|
+
expectResolution(Resolver.Type, {
|
|
37
|
+
type: "Model",
|
|
38
|
+
desc: `${test[0]}: ${test[1]}`,
|
|
39
|
+
source: `alias test = ${test[2]};`,
|
|
40
|
+
target: test[3],
|
|
41
|
+
test: (t) =>
|
|
42
|
+
(t as Model).name === test[0]
|
|
43
|
+
? true
|
|
44
|
+
: `model name was ${(t as Model).name}`,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Resolver } from "../../src/resolve/Resolvable_helpers";
|
|
2
|
+
import { expectResolution } from "../helpers/wrapper";
|
|
3
|
+
|
|
4
|
+
const tests: [string, string][] = [
|
|
5
|
+
["{s: string}", "{s: string}"],
|
|
6
|
+
["{s?: string}", "{s?: string}"],
|
|
7
|
+
["{m: {s: float | int32}}", "{m: {s: number | number}}"],
|
|
8
|
+
["{a: {s: float}[]}", "{a: ({s: number})[]}"],
|
|
9
|
+
["{a: {s?: float}[]}", "{a: ({s?: number})[]}"],
|
|
10
|
+
[
|
|
11
|
+
"{r: Record<[string, int32]>, a: string[], f: never}",
|
|
12
|
+
"{r: {[k: string]: [string, number]},a: (string)[],f: never}",
|
|
13
|
+
],
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
tests.forEach((test) => {
|
|
17
|
+
expectResolution(Resolver.Type, {
|
|
18
|
+
type: "Model",
|
|
19
|
+
desc: test[0],
|
|
20
|
+
source: `alias test = ${test[0]};`,
|
|
21
|
+
target: test[1],
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Scalar } from "@typespec/compiler";
|
|
2
|
+
import { EmitterOptions } from "../../src/lib";
|
|
3
|
+
import { Resolver } from "../../src/resolve/Resolvable_helpers";
|
|
4
|
+
import { expectResolution } from "../helpers/wrapper";
|
|
5
|
+
|
|
6
|
+
type Name = string;
|
|
7
|
+
type Target = string;
|
|
8
|
+
|
|
9
|
+
const tests: [Name, Target, Partial<EmitterOptions>?][] = [
|
|
10
|
+
["boolean", "boolean"],
|
|
11
|
+
["bytes", "Uint8Array"],
|
|
12
|
+
["duration", "number"],
|
|
13
|
+
["numeric", "number"],
|
|
14
|
+
["plainTime", "string"],
|
|
15
|
+
["string", "string"],
|
|
16
|
+
["url", "string"],
|
|
17
|
+
|
|
18
|
+
// date / time types
|
|
19
|
+
...["offsetDateTime", "plainDate", "utcDateTime"].map(
|
|
20
|
+
(t) =>
|
|
21
|
+
[t, "Date", { "serializable-date-types": false }] as [
|
|
22
|
+
string,
|
|
23
|
+
string,
|
|
24
|
+
any,
|
|
25
|
+
],
|
|
26
|
+
),
|
|
27
|
+
...["offsetDateTime", "plainDate", "utcDateTime"].map(
|
|
28
|
+
(t) =>
|
|
29
|
+
[t, "string", { "serializable-date-types": true }] as [
|
|
30
|
+
string,
|
|
31
|
+
string,
|
|
32
|
+
any,
|
|
33
|
+
],
|
|
34
|
+
),
|
|
35
|
+
["unixTimestamp32", "Date", { "serializable-date-types": false }],
|
|
36
|
+
["unixTimestamp32", "number", { "serializable-date-types": true }],
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
tests.forEach((test) => {
|
|
40
|
+
expectResolution(Resolver.Type, {
|
|
41
|
+
type: "Scalar",
|
|
42
|
+
desc: test[2]
|
|
43
|
+
? `{${Object.entries(test[2]).map((p) => `${p[0]}: ${p[1]}`)}}`
|
|
44
|
+
: undefined,
|
|
45
|
+
source: `alias test = ${test[0]};`,
|
|
46
|
+
target: test[1],
|
|
47
|
+
test: (t) =>
|
|
48
|
+
(t as Scalar).name === test[0]
|
|
49
|
+
? true
|
|
50
|
+
: `scalar name was ${(t as Scalar).name}`,
|
|
51
|
+
config: test[2],
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Type } from "@typespec/compiler";
|
|
2
|
+
import { Resolver } from "../../src/resolve/Resolvable_helpers";
|
|
3
|
+
import { expectResolution } from "../helpers/wrapper";
|
|
4
|
+
|
|
5
|
+
const tests: [Type["kind"], any[]][] = [
|
|
6
|
+
["Boolean", ["true", "false"]],
|
|
7
|
+
["Intrinsic", ["never", "unknown", "void", "null"]],
|
|
8
|
+
["Number", [5, 8, 17, 15.55, -4]],
|
|
9
|
+
["String", [`""`, `"someString"`]],
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
tests.forEach((test) => {
|
|
13
|
+
test[1].forEach((v) =>
|
|
14
|
+
expectResolution(Resolver.Type, {
|
|
15
|
+
type: test[0],
|
|
16
|
+
source: `alias test = ${v};`,
|
|
17
|
+
target: v.toString().replaceAll('"', "'"),
|
|
18
|
+
}),
|
|
19
|
+
);
|
|
20
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Resolver } from "../../src/resolve/Resolvable_helpers";
|
|
2
|
+
import { expectResolution } from "../helpers/wrapper";
|
|
3
|
+
|
|
4
|
+
type Name = string;
|
|
5
|
+
type Source = string;
|
|
6
|
+
type Target = string;
|
|
7
|
+
|
|
8
|
+
const tests: [Name, Source, Target][] = [
|
|
9
|
+
["basic, strings", "[string, string]", "[string, string]"],
|
|
10
|
+
[
|
|
11
|
+
"mixed",
|
|
12
|
+
"[string, int32, null, {a: unknown, b: float}]",
|
|
13
|
+
"[string, number, null, {a: unknown,b: number}]",
|
|
14
|
+
],
|
|
15
|
+
[
|
|
16
|
+
"unions",
|
|
17
|
+
"[string | float, null | unknown]",
|
|
18
|
+
"[string | number, null | unknown]",
|
|
19
|
+
],
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
tests.forEach((test) => {
|
|
23
|
+
expectResolution(Resolver.Type, {
|
|
24
|
+
type: "Tuple",
|
|
25
|
+
desc: test[0],
|
|
26
|
+
source: `alias test = ${test[1]};`,
|
|
27
|
+
target: test[2],
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Resolver } from "../../src/resolve/Resolvable_helpers";
|
|
2
|
+
import { expectResolution } from "../helpers/wrapper";
|
|
3
|
+
|
|
4
|
+
type Name = string;
|
|
5
|
+
type Source = string;
|
|
6
|
+
type Target = string;
|
|
7
|
+
|
|
8
|
+
const tests: [Name, Source, Target][] = [
|
|
9
|
+
["basic", "string | float", "string | number"],
|
|
10
|
+
["mixed", "[string, int32] | {a: null}", "[string, number] | {a: null}"],
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
tests.forEach((test) => {
|
|
14
|
+
expectResolution(Resolver.Type, {
|
|
15
|
+
type: "Union",
|
|
16
|
+
desc: test[0],
|
|
17
|
+
source: `alias test = ${test[1]};`,
|
|
18
|
+
target: test[2],
|
|
19
|
+
});
|
|
20
|
+
});
|
package/tsconfig.json
CHANGED