@prisma/ts-builders 6.6.0-dev.100

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.
Files changed (171) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +5 -0
  3. package/dist/AnyDeclarationBuilder.d.ts +6 -0
  4. package/dist/AnyDeclarationBuilder.js +16 -0
  5. package/dist/AnyDeclarationBuilder.mjs +0 -0
  6. package/dist/ArraySpread.d.ts +8 -0
  7. package/dist/ArraySpread.js +42 -0
  8. package/dist/ArraySpread.mjs +17 -0
  9. package/dist/ArrayType.d.ts +8 -0
  10. package/dist/ArrayType.js +43 -0
  11. package/dist/ArrayType.mjs +18 -0
  12. package/dist/ArrayType.test.d.ts +1 -0
  13. package/dist/ArrayType.test.js +24 -0
  14. package/dist/ArrayType.test.mjs +23 -0
  15. package/dist/BasicBuilder.d.ts +4 -0
  16. package/dist/BasicBuilder.js +16 -0
  17. package/dist/BasicBuilder.mjs +0 -0
  18. package/dist/Class.d.ts +22 -0
  19. package/dist/Class.js +79 -0
  20. package/dist/Class.mjs +54 -0
  21. package/dist/Class.test.d.ts +1 -0
  22. package/dist/Class.test.js +56 -0
  23. package/dist/Class.test.mjs +55 -0
  24. package/dist/ConstDeclaration.d.ts +16 -0
  25. package/dist/ConstDeclaration.js +60 -0
  26. package/dist/ConstDeclaration.mjs +35 -0
  27. package/dist/ConstDeclaration.test.d.ts +1 -0
  28. package/dist/ConstDeclaration.test.js +19 -0
  29. package/dist/ConstDeclaration.test.mjs +18 -0
  30. package/dist/DocComment.d.ts +11 -0
  31. package/dist/DocComment.js +101 -0
  32. package/dist/DocComment.mjs +76 -0
  33. package/dist/DocComment.test.d.ts +1 -0
  34. package/dist/DocComment.test.js +80 -0
  35. package/dist/DocComment.test.mjs +79 -0
  36. package/dist/Export.d.ts +12 -0
  37. package/dist/Export.js +48 -0
  38. package/dist/Export.mjs +23 -0
  39. package/dist/ExportFrom.d.ts +34 -0
  40. package/dist/ExportFrom.js +106 -0
  41. package/dist/ExportFrom.mjs +77 -0
  42. package/dist/ExportFrom.test.d.ts +1 -0
  43. package/dist/ExportFrom.test.js +25 -0
  44. package/dist/ExportFrom.test.mjs +24 -0
  45. package/dist/File.d.ts +15 -0
  46. package/dist/File.js +57 -0
  47. package/dist/File.mjs +32 -0
  48. package/dist/FunctionCall.d.ts +9 -0
  49. package/dist/FunctionCall.js +49 -0
  50. package/dist/FunctionCall.mjs +24 -0
  51. package/dist/FunctionType.d.ts +17 -0
  52. package/dist/FunctionType.js +60 -0
  53. package/dist/FunctionType.mjs +35 -0
  54. package/dist/FunctionType.test.d.ts +1 -0
  55. package/dist/FunctionType.test.js +32 -0
  56. package/dist/FunctionType.test.mjs +31 -0
  57. package/dist/GenericParameter.d.ts +15 -0
  58. package/dist/GenericParameter.js +60 -0
  59. package/dist/GenericParameter.mjs +35 -0
  60. package/dist/GenericParameter.test.d.ts +1 -0
  61. package/dist/GenericParameter.test.js +19 -0
  62. package/dist/GenericParameter.test.mjs +18 -0
  63. package/dist/Import.d.ts +38 -0
  64. package/dist/Import.js +127 -0
  65. package/dist/Import.mjs +98 -0
  66. package/dist/Import.test.d.ts +1 -0
  67. package/dist/Import.test.js +33 -0
  68. package/dist/Import.test.mjs +32 -0
  69. package/dist/Interface.d.ts +22 -0
  70. package/dist/Interface.js +79 -0
  71. package/dist/Interface.mjs +54 -0
  72. package/dist/Interface.test.d.ts +1 -0
  73. package/dist/Interface.test.js +56 -0
  74. package/dist/Interface.test.mjs +55 -0
  75. package/dist/KeyType.d.ts +9 -0
  76. package/dist/KeyType.js +44 -0
  77. package/dist/KeyType.mjs +19 -0
  78. package/dist/KeyType.test.d.ts +1 -0
  79. package/dist/KeyType.test.js +28 -0
  80. package/dist/KeyType.test.mjs +27 -0
  81. package/dist/KeyofType.d.ts +8 -0
  82. package/dist/KeyofType.js +47 -0
  83. package/dist/KeyofType.mjs +22 -0
  84. package/dist/KeyofType.test.d.ts +1 -0
  85. package/dist/KeyofType.test.js +28 -0
  86. package/dist/KeyofType.test.mjs +27 -0
  87. package/dist/Method.d.ts +20 -0
  88. package/dist/Method.js +75 -0
  89. package/dist/Method.mjs +50 -0
  90. package/dist/Method.test.d.ts +1 -0
  91. package/dist/Method.test.js +43 -0
  92. package/dist/Method.test.mjs +42 -0
  93. package/dist/NamedType.d.ts +10 -0
  94. package/dist/NamedType.js +50 -0
  95. package/dist/NamedType.mjs +25 -0
  96. package/dist/NamedType.test.d.ts +1 -0
  97. package/dist/NamedType.test.js +15 -0
  98. package/dist/NamedType.test.mjs +14 -0
  99. package/dist/NamedValue.d.ts +8 -0
  100. package/dist/NamedValue.js +43 -0
  101. package/dist/NamedValue.mjs +18 -0
  102. package/dist/NamespaceDeclaration.d.ts +13 -0
  103. package/dist/NamespaceDeclaration.js +48 -0
  104. package/dist/NamespaceDeclaration.mjs +23 -0
  105. package/dist/ObjectType.d.ts +18 -0
  106. package/dist/ObjectType.js +71 -0
  107. package/dist/ObjectType.mjs +46 -0
  108. package/dist/ObjectType.test.d.ts +1 -0
  109. package/dist/ObjectType.test.js +32 -0
  110. package/dist/ObjectType.test.mjs +31 -0
  111. package/dist/Parameter.d.ts +12 -0
  112. package/dist/Parameter.js +50 -0
  113. package/dist/Parameter.mjs +25 -0
  114. package/dist/Parameter.test.d.ts +1 -0
  115. package/dist/Parameter.test.js +14 -0
  116. package/dist/Parameter.test.mjs +13 -0
  117. package/dist/PrimitiveType.d.ts +18 -0
  118. package/dist/PrimitiveType.js +70 -0
  119. package/dist/PrimitiveType.mjs +35 -0
  120. package/dist/Property.d.ts +18 -0
  121. package/dist/Property.js +75 -0
  122. package/dist/Property.mjs +50 -0
  123. package/dist/Property.test.d.ts +1 -0
  124. package/dist/Property.test.js +37 -0
  125. package/dist/Property.test.mjs +36 -0
  126. package/dist/StringLiteralType.d.ts +15 -0
  127. package/dist/StringLiteralType.js +58 -0
  128. package/dist/StringLiteralType.mjs +32 -0
  129. package/dist/TupleType.d.ts +17 -0
  130. package/dist/TupleType.js +69 -0
  131. package/dist/TupleType.mjs +42 -0
  132. package/dist/TupleType.test.d.ts +1 -0
  133. package/dist/TupleType.test.js +21 -0
  134. package/dist/TupleType.test.mjs +20 -0
  135. package/dist/TypeBuilder.d.ts +11 -0
  136. package/dist/TypeBuilder.js +47 -0
  137. package/dist/TypeBuilder.mjs +23 -0
  138. package/dist/TypeDeclaration.d.ts +17 -0
  139. package/dist/TypeDeclaration.js +62 -0
  140. package/dist/TypeDeclaration.mjs +37 -0
  141. package/dist/TypeDeclaration.test.d.ts +1 -0
  142. package/dist/TypeDeclaration.test.js +28 -0
  143. package/dist/TypeDeclaration.test.mjs +27 -0
  144. package/dist/UnionType.d.ts +13 -0
  145. package/dist/UnionType.js +74 -0
  146. package/dist/UnionType.mjs +49 -0
  147. package/dist/UnionType.test.d.ts +1 -0
  148. package/dist/UnionType.test.js +28 -0
  149. package/dist/UnionType.test.mjs +27 -0
  150. package/dist/ValueBuilder.d.ts +12 -0
  151. package/dist/ValueBuilder.js +46 -0
  152. package/dist/ValueBuilder.mjs +21 -0
  153. package/dist/WellKnownSymbol.d.ts +9 -0
  154. package/dist/WellKnownSymbol.js +43 -0
  155. package/dist/WellKnownSymbol.mjs +17 -0
  156. package/dist/Writer.d.ts +94 -0
  157. package/dist/Writer.js +175 -0
  158. package/dist/Writer.mjs +150 -0
  159. package/dist/Writer.test.d.ts +1 -0
  160. package/dist/Writer.test.js +100 -0
  161. package/dist/Writer.test.mjs +99 -0
  162. package/dist/helpers.d.ts +3 -0
  163. package/dist/helpers.js +31 -0
  164. package/dist/helpers.mjs +7 -0
  165. package/dist/index.d.ts +35 -0
  166. package/dist/index.js +90 -0
  167. package/dist/index.mjs +35 -0
  168. package/dist/stringify.d.ts +7 -0
  169. package/dist/stringify.js +44 -0
  170. package/dist/stringify.mjs +20 -0
  171. package/package.json +41 -0
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var import_vitest = require("vitest");
3
+ var import_GenericParameter = require("./GenericParameter");
4
+ var import_Interface = require("./Interface");
5
+ var import_Method = require("./Method");
6
+ var import_NamedType = require("./NamedType");
7
+ var import_Property = require("./Property");
8
+ var import_stringify = require("./stringify");
9
+ const A = (0, import_NamedType.namedType)("A");
10
+ (0, import_vitest.test)("empty", () => {
11
+ const obj = (0, import_Interface.interfaceDeclaration)("MyInterface");
12
+ (0, import_vitest.expect)((0, import_stringify.stringify)(obj)).toMatchInlineSnapshot(`
13
+ "interface MyInterface {}
14
+ "
15
+ `);
16
+ });
17
+ (0, import_vitest.test)("with property", () => {
18
+ const obj = (0, import_Interface.interfaceDeclaration)("SomeInterface").add((0, import_Property.property)("foo", A));
19
+ (0, import_vitest.expect)((0, import_stringify.stringify)(obj)).toMatchInlineSnapshot(`
20
+ "interface SomeInterface {
21
+ foo: A
22
+ }"
23
+ `);
24
+ });
25
+ (0, import_vitest.test)("with method", () => {
26
+ const obj = (0, import_Interface.interfaceDeclaration)("MyInterface").add((0, import_Method.method)("doThing"));
27
+ (0, import_vitest.expect)((0, import_stringify.stringify)(obj)).toMatchInlineSnapshot(`
28
+ "interface MyInterface {
29
+ doThing(): void
30
+ }"
31
+ `);
32
+ });
33
+ (0, import_vitest.test)("with generic parameter", () => {
34
+ const obj = (0, import_Interface.interfaceDeclaration)("SomeInterface").addGenericParameter((0, import_GenericParameter.genericParameter)("T").extends((0, import_NamedType.namedType)("U"))).add((0, import_Property.property)("foo", A));
35
+ (0, import_vitest.expect)((0, import_stringify.stringify)(obj)).toMatchInlineSnapshot(`
36
+ "interface SomeInterface<T extends U> {
37
+ foo: A
38
+ }"
39
+ `);
40
+ });
41
+ (0, import_vitest.test)("extending the type", () => {
42
+ const obj = (0, import_Interface.interfaceDeclaration)("SomeInterface").extends((0, import_NamedType.namedType)("Foo")).add((0, import_Property.property)("foo", A));
43
+ (0, import_vitest.expect)((0, import_stringify.stringify)(obj)).toMatchInlineSnapshot(`
44
+ "interface SomeInterface extends Foo {
45
+ foo: A
46
+ }"
47
+ `);
48
+ });
49
+ (0, import_vitest.test)("extending multiple types", () => {
50
+ const obj = (0, import_Interface.interfaceDeclaration)("SomeInterface").extends((0, import_NamedType.namedType)("Foo")).extends((0, import_NamedType.namedType)("Bar")).add((0, import_Property.property)("foo", A));
51
+ (0, import_vitest.expect)((0, import_stringify.stringify)(obj)).toMatchInlineSnapshot(`
52
+ "interface SomeInterface extends Foo, Bar {
53
+ foo: A
54
+ }"
55
+ `);
56
+ });
@@ -0,0 +1,55 @@
1
+ import { expect, test } from "vitest";
2
+ import { genericParameter } from "./GenericParameter";
3
+ import { interfaceDeclaration } from "./Interface";
4
+ import { method } from "./Method";
5
+ import { namedType } from "./NamedType";
6
+ import { property } from "./Property";
7
+ import { stringify } from "./stringify";
8
+ const A = namedType("A");
9
+ test("empty", () => {
10
+ const obj = interfaceDeclaration("MyInterface");
11
+ expect(stringify(obj)).toMatchInlineSnapshot(`
12
+ "interface MyInterface {}
13
+ "
14
+ `);
15
+ });
16
+ test("with property", () => {
17
+ const obj = interfaceDeclaration("SomeInterface").add(property("foo", A));
18
+ expect(stringify(obj)).toMatchInlineSnapshot(`
19
+ "interface SomeInterface {
20
+ foo: A
21
+ }"
22
+ `);
23
+ });
24
+ test("with method", () => {
25
+ const obj = interfaceDeclaration("MyInterface").add(method("doThing"));
26
+ expect(stringify(obj)).toMatchInlineSnapshot(`
27
+ "interface MyInterface {
28
+ doThing(): void
29
+ }"
30
+ `);
31
+ });
32
+ test("with generic parameter", () => {
33
+ const obj = interfaceDeclaration("SomeInterface").addGenericParameter(genericParameter("T").extends(namedType("U"))).add(property("foo", A));
34
+ expect(stringify(obj)).toMatchInlineSnapshot(`
35
+ "interface SomeInterface<T extends U> {
36
+ foo: A
37
+ }"
38
+ `);
39
+ });
40
+ test("extending the type", () => {
41
+ const obj = interfaceDeclaration("SomeInterface").extends(namedType("Foo")).add(property("foo", A));
42
+ expect(stringify(obj)).toMatchInlineSnapshot(`
43
+ "interface SomeInterface extends Foo {
44
+ foo: A
45
+ }"
46
+ `);
47
+ });
48
+ test("extending multiple types", () => {
49
+ const obj = interfaceDeclaration("SomeInterface").extends(namedType("Foo")).extends(namedType("Bar")).add(property("foo", A));
50
+ expect(stringify(obj)).toMatchInlineSnapshot(`
51
+ "interface SomeInterface extends Foo, Bar {
52
+ foo: A
53
+ }"
54
+ `);
55
+ });
@@ -0,0 +1,9 @@
1
+ import { TypeBuilder } from './TypeBuilder';
2
+ import { Writer } from './Writer';
3
+ export declare class KeyType extends TypeBuilder {
4
+ baseType: TypeBuilder;
5
+ key: string;
6
+ constructor(baseType: TypeBuilder, key: string);
7
+ write(writer: Writer): void;
8
+ }
9
+ export declare function keyType(baseType: TypeBuilder, key: string): KeyType;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var KeyType_exports = {};
20
+ __export(KeyType_exports, {
21
+ KeyType: () => KeyType,
22
+ keyType: () => keyType
23
+ });
24
+ module.exports = __toCommonJS(KeyType_exports);
25
+ var import_TypeBuilder = require("./TypeBuilder");
26
+ class KeyType extends import_TypeBuilder.TypeBuilder {
27
+ constructor(baseType, key) {
28
+ super();
29
+ this.baseType = baseType;
30
+ this.key = key;
31
+ }
32
+ write(writer) {
33
+ this.baseType.writeIndexed(writer);
34
+ writer.write("[").write(`"${this.key}"`).write("]");
35
+ }
36
+ }
37
+ function keyType(baseType, key) {
38
+ return new KeyType(baseType, key);
39
+ }
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ KeyType,
43
+ keyType
44
+ });
@@ -0,0 +1,19 @@
1
+ import { TypeBuilder } from "./TypeBuilder";
2
+ class KeyType extends TypeBuilder {
3
+ constructor(baseType, key) {
4
+ super();
5
+ this.baseType = baseType;
6
+ this.key = key;
7
+ }
8
+ write(writer) {
9
+ this.baseType.writeIndexed(writer);
10
+ writer.write("[").write(`"${this.key}"`).write("]");
11
+ }
12
+ }
13
+ function keyType(baseType, key) {
14
+ return new KeyType(baseType, key);
15
+ }
16
+ export {
17
+ KeyType,
18
+ keyType
19
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var import_vitest = require("vitest");
3
+ var import_ArrayType = require("./ArrayType");
4
+ var import_FunctionType = require("./FunctionType");
5
+ var import_KeyType = require("./KeyType");
6
+ var import_NamedType = require("./NamedType");
7
+ var import_ObjectType = require("./ObjectType");
8
+ var import_stringify = require("./stringify");
9
+ var import_UnionType = require("./UnionType");
10
+ const A = (0, import_NamedType.namedType)("A");
11
+ const B = (0, import_NamedType.namedType)("B");
12
+ const C = (0, import_NamedType.namedType)("C");
13
+ (0, import_vitest.test)("simple only", () => {
14
+ (0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyType.keyType)(A, "foo"))).toMatchInlineSnapshot(`"A["foo"]"`);
15
+ });
16
+ (0, import_vitest.test)("with object type", () => {
17
+ (0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyType.keyType)((0, import_ObjectType.objectType)(), "toString"))).toMatchInlineSnapshot(`"({})["toString"]"`);
18
+ });
19
+ (0, import_vitest.test)("with array type", () => {
20
+ (0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyType.keyType)((0, import_ArrayType.array)(A), "length"))).toMatchInlineSnapshot(`"A[]["length"]"`);
21
+ });
22
+ (0, import_vitest.test)("with function type", () => {
23
+ (0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyType.keyType)((0, import_FunctionType.functionType)(), "length"))).toMatchInlineSnapshot(`"(() => void)["length"]"`);
24
+ });
25
+ (0, import_vitest.test)("with union type", () => {
26
+ const union = (0, import_UnionType.unionType)(A).addVariant(B).addVariant(C);
27
+ (0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyType.keyType)(union, "foo"))).toMatchInlineSnapshot(`"(A | B | C)["foo"]"`);
28
+ });
@@ -0,0 +1,27 @@
1
+ import { expect, test } from "vitest";
2
+ import { array } from "./ArrayType";
3
+ import { functionType } from "./FunctionType";
4
+ import { keyType } from "./KeyType";
5
+ import { namedType } from "./NamedType";
6
+ import { objectType } from "./ObjectType";
7
+ import { stringify } from "./stringify";
8
+ import { unionType } from "./UnionType";
9
+ const A = namedType("A");
10
+ const B = namedType("B");
11
+ const C = namedType("C");
12
+ test("simple only", () => {
13
+ expect(stringify(keyType(A, "foo"))).toMatchInlineSnapshot(`"A["foo"]"`);
14
+ });
15
+ test("with object type", () => {
16
+ expect(stringify(keyType(objectType(), "toString"))).toMatchInlineSnapshot(`"({})["toString"]"`);
17
+ });
18
+ test("with array type", () => {
19
+ expect(stringify(keyType(array(A), "length"))).toMatchInlineSnapshot(`"A[]["length"]"`);
20
+ });
21
+ test("with function type", () => {
22
+ expect(stringify(keyType(functionType(), "length"))).toMatchInlineSnapshot(`"(() => void)["length"]"`);
23
+ });
24
+ test("with union type", () => {
25
+ const union = unionType(A).addVariant(B).addVariant(C);
26
+ expect(stringify(keyType(union, "foo"))).toMatchInlineSnapshot(`"(A | B | C)["foo"]"`);
27
+ });
@@ -0,0 +1,8 @@
1
+ import { TypeBuilder } from './TypeBuilder';
2
+ import { Writer } from './Writer';
3
+ export declare class KeyofType extends TypeBuilder {
4
+ baseType: TypeBuilder;
5
+ constructor(baseType: TypeBuilder);
6
+ write(writer: Writer): void;
7
+ }
8
+ export declare function keyOfType(baseType: TypeBuilder): KeyofType;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var KeyofType_exports = {};
20
+ __export(KeyofType_exports, {
21
+ KeyofType: () => KeyofType,
22
+ keyOfType: () => keyOfType
23
+ });
24
+ module.exports = __toCommonJS(KeyofType_exports);
25
+ var import_TypeBuilder = require("./TypeBuilder");
26
+ class KeyofType extends import_TypeBuilder.TypeBuilder {
27
+ constructor(baseType) {
28
+ super();
29
+ this.baseType = baseType;
30
+ }
31
+ write(writer) {
32
+ writer.write(`keyof `);
33
+ if (this.baseType.needsParenthesisInKeyof) {
34
+ writer.write("(").write(this.baseType).write(")");
35
+ } else {
36
+ writer.write(this.baseType);
37
+ }
38
+ }
39
+ }
40
+ function keyOfType(baseType) {
41
+ return new KeyofType(baseType);
42
+ }
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ KeyofType,
46
+ keyOfType
47
+ });
@@ -0,0 +1,22 @@
1
+ import { TypeBuilder } from "./TypeBuilder";
2
+ class KeyofType extends TypeBuilder {
3
+ constructor(baseType) {
4
+ super();
5
+ this.baseType = baseType;
6
+ }
7
+ write(writer) {
8
+ writer.write(`keyof `);
9
+ if (this.baseType.needsParenthesisInKeyof) {
10
+ writer.write("(").write(this.baseType).write(")");
11
+ } else {
12
+ writer.write(this.baseType);
13
+ }
14
+ }
15
+ }
16
+ function keyOfType(baseType) {
17
+ return new KeyofType(baseType);
18
+ }
19
+ export {
20
+ KeyofType,
21
+ keyOfType
22
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var import_vitest = require("vitest");
3
+ var import_ArrayType = require("./ArrayType");
4
+ var import_FunctionType = require("./FunctionType");
5
+ var import_KeyofType = require("./KeyofType");
6
+ var import_NamedType = require("./NamedType");
7
+ var import_ObjectType = require("./ObjectType");
8
+ var import_stringify = require("./stringify");
9
+ var import_UnionType = require("./UnionType");
10
+ const A = (0, import_NamedType.namedType)("A");
11
+ const B = (0, import_NamedType.namedType)("B");
12
+ const C = (0, import_NamedType.namedType)("C");
13
+ (0, import_vitest.test)("simple only", () => {
14
+ (0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyofType.keyOfType)(A))).toMatchInlineSnapshot(`"keyof A"`);
15
+ });
16
+ (0, import_vitest.test)("with object type", () => {
17
+ (0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyofType.keyOfType)((0, import_ObjectType.objectType)()))).toMatchInlineSnapshot(`"keyof {}"`);
18
+ });
19
+ (0, import_vitest.test)("with array type", () => {
20
+ (0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyofType.keyOfType)((0, import_ArrayType.array)(A)))).toMatchInlineSnapshot(`"keyof A[]"`);
21
+ });
22
+ (0, import_vitest.test)("with function type", () => {
23
+ (0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyofType.keyOfType)((0, import_FunctionType.functionType)()))).toMatchInlineSnapshot(`"keyof (() => void)"`);
24
+ });
25
+ (0, import_vitest.test)("with union type", () => {
26
+ const union = (0, import_UnionType.unionType)(A).addVariant(B).addVariant(C);
27
+ (0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyofType.keyOfType)(union))).toMatchInlineSnapshot(`"keyof (A | B | C)"`);
28
+ });
@@ -0,0 +1,27 @@
1
+ import { expect, test } from "vitest";
2
+ import { array } from "./ArrayType";
3
+ import { functionType } from "./FunctionType";
4
+ import { keyOfType } from "./KeyofType";
5
+ import { namedType } from "./NamedType";
6
+ import { objectType } from "./ObjectType";
7
+ import { stringify } from "./stringify";
8
+ import { unionType } from "./UnionType";
9
+ const A = namedType("A");
10
+ const B = namedType("B");
11
+ const C = namedType("C");
12
+ test("simple only", () => {
13
+ expect(stringify(keyOfType(A))).toMatchInlineSnapshot(`"keyof A"`);
14
+ });
15
+ test("with object type", () => {
16
+ expect(stringify(keyOfType(objectType()))).toMatchInlineSnapshot(`"keyof {}"`);
17
+ });
18
+ test("with array type", () => {
19
+ expect(stringify(keyOfType(array(A)))).toMatchInlineSnapshot(`"keyof A[]"`);
20
+ });
21
+ test("with function type", () => {
22
+ expect(stringify(keyOfType(functionType()))).toMatchInlineSnapshot(`"keyof (() => void)"`);
23
+ });
24
+ test("with union type", () => {
25
+ const union = unionType(A).addVariant(B).addVariant(C);
26
+ expect(stringify(keyOfType(union))).toMatchInlineSnapshot(`"keyof (A | B | C)"`);
27
+ });
@@ -0,0 +1,20 @@
1
+ import { BasicBuilder } from './BasicBuilder';
2
+ import { DocComment } from './DocComment';
3
+ import { GenericParameter } from './GenericParameter';
4
+ import { Parameter } from './Parameter';
5
+ import { TypeBuilder } from './TypeBuilder';
6
+ import { Writer } from './Writer';
7
+ export declare class Method implements BasicBuilder {
8
+ private name;
9
+ private docComment?;
10
+ private returnType;
11
+ private parameters;
12
+ private genericParameters;
13
+ constructor(name: string);
14
+ setDocComment(docComment: DocComment): this;
15
+ setReturnType(returnType: TypeBuilder): this;
16
+ addParameter(param: Parameter): this;
17
+ addGenericParameter(param: GenericParameter): this;
18
+ write(writer: Writer): void;
19
+ }
20
+ export declare function method(name: string): Method;
package/dist/Method.js ADDED
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var Method_exports = {};
20
+ __export(Method_exports, {
21
+ Method: () => Method,
22
+ method: () => method
23
+ });
24
+ module.exports = __toCommonJS(Method_exports);
25
+ var import_PrimitiveType = require("./PrimitiveType");
26
+ class Method {
27
+ constructor(name) {
28
+ this.name = name;
29
+ }
30
+ docComment;
31
+ returnType = import_PrimitiveType.voidType;
32
+ parameters = [];
33
+ genericParameters = [];
34
+ setDocComment(docComment) {
35
+ this.docComment = docComment;
36
+ return this;
37
+ }
38
+ setReturnType(returnType) {
39
+ this.returnType = returnType;
40
+ return this;
41
+ }
42
+ addParameter(param) {
43
+ this.parameters.push(param);
44
+ return this;
45
+ }
46
+ addGenericParameter(param) {
47
+ this.genericParameters.push(param);
48
+ return this;
49
+ }
50
+ write(writer) {
51
+ if (this.docComment) {
52
+ writer.write(this.docComment);
53
+ }
54
+ writer.write(this.name);
55
+ if (this.genericParameters.length > 0) {
56
+ writer.write("<").writeJoined(", ", this.genericParameters).write(">");
57
+ }
58
+ writer.write("(");
59
+ if (this.parameters.length > 0) {
60
+ writer.writeJoined(", ", this.parameters);
61
+ }
62
+ writer.write(")");
63
+ if (this.name !== "constructor") {
64
+ writer.write(": ").write(this.returnType);
65
+ }
66
+ }
67
+ }
68
+ function method(name) {
69
+ return new Method(name);
70
+ }
71
+ // Annotate the CommonJS export names for ESM import in node:
72
+ 0 && (module.exports = {
73
+ Method,
74
+ method
75
+ });
@@ -0,0 +1,50 @@
1
+ import { voidType } from "./PrimitiveType";
2
+ class Method {
3
+ constructor(name) {
4
+ this.name = name;
5
+ }
6
+ docComment;
7
+ returnType = voidType;
8
+ parameters = [];
9
+ genericParameters = [];
10
+ setDocComment(docComment) {
11
+ this.docComment = docComment;
12
+ return this;
13
+ }
14
+ setReturnType(returnType) {
15
+ this.returnType = returnType;
16
+ return this;
17
+ }
18
+ addParameter(param) {
19
+ this.parameters.push(param);
20
+ return this;
21
+ }
22
+ addGenericParameter(param) {
23
+ this.genericParameters.push(param);
24
+ return this;
25
+ }
26
+ write(writer) {
27
+ if (this.docComment) {
28
+ writer.write(this.docComment);
29
+ }
30
+ writer.write(this.name);
31
+ if (this.genericParameters.length > 0) {
32
+ writer.write("<").writeJoined(", ", this.genericParameters).write(">");
33
+ }
34
+ writer.write("(");
35
+ if (this.parameters.length > 0) {
36
+ writer.writeJoined(", ", this.parameters);
37
+ }
38
+ writer.write(")");
39
+ if (this.name !== "constructor") {
40
+ writer.write(": ").write(this.returnType);
41
+ }
42
+ }
43
+ }
44
+ function method(name) {
45
+ return new Method(name);
46
+ }
47
+ export {
48
+ Method,
49
+ method
50
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var import_vitest = require("vitest");
3
+ var import_DocComment = require("./DocComment");
4
+ var import_GenericParameter = require("./GenericParameter");
5
+ var import_Method = require("./Method");
6
+ var import_NamedType = require("./NamedType");
7
+ var import_Parameter = require("./Parameter");
8
+ var import_stringify = require("./stringify");
9
+ const A = (0, import_NamedType.namedType)("A");
10
+ const B = (0, import_NamedType.namedType)("B");
11
+ (0, import_vitest.test)("name only", () => {
12
+ const m = (0, import_Method.method)("doThings");
13
+ (0, import_vitest.expect)((0, import_stringify.stringify)(m)).toMatchInlineSnapshot(`"doThings(): void"`);
14
+ });
15
+ (0, import_vitest.test)("with return type", () => {
16
+ const m = (0, import_Method.method)("doThings").setReturnType(A);
17
+ (0, import_vitest.expect)((0, import_stringify.stringify)(m)).toMatchInlineSnapshot(`"doThings(): A"`);
18
+ });
19
+ (0, import_vitest.test)("with doc comment", () => {
20
+ const m = (0, import_Method.method)("doThings").setDocComment((0, import_DocComment.docComment)("Does things"));
21
+ (0, import_vitest.expect)((0, import_stringify.stringify)(m)).toMatchInlineSnapshot(`
22
+ "/**
23
+ * Does things
24
+ */
25
+ doThings(): void"
26
+ `);
27
+ });
28
+ (0, import_vitest.test)("with parameter", () => {
29
+ const m = (0, import_Method.method)("doThings").addParameter((0, import_Parameter.parameter)("foo", A));
30
+ (0, import_vitest.expect)((0, import_stringify.stringify)(m)).toMatchInlineSnapshot(`"doThings(foo: A): void"`);
31
+ });
32
+ (0, import_vitest.test)("with multiple parameters", () => {
33
+ const m = (0, import_Method.method)("doThings").addParameter((0, import_Parameter.parameter)("foo", A)).addParameter((0, import_Parameter.parameter)("foo", B));
34
+ (0, import_vitest.expect)((0, import_stringify.stringify)(m)).toMatchInlineSnapshot(`"doThings(foo: A, foo: B): void"`);
35
+ });
36
+ (0, import_vitest.test)("with generic parameter", () => {
37
+ const m = (0, import_Method.method)("doThings").addGenericParameter((0, import_GenericParameter.genericParameter)("T"));
38
+ (0, import_vitest.expect)((0, import_stringify.stringify)(m)).toMatchInlineSnapshot(`"doThings<T>(): void"`);
39
+ });
40
+ (0, import_vitest.test)("with multiple generic parameters", () => {
41
+ const m = (0, import_Method.method)("doThings").addGenericParameter((0, import_GenericParameter.genericParameter)("T")).addGenericParameter((0, import_GenericParameter.genericParameter)("U"));
42
+ (0, import_vitest.expect)((0, import_stringify.stringify)(m)).toMatchInlineSnapshot(`"doThings<T, U>(): void"`);
43
+ });
@@ -0,0 +1,42 @@
1
+ import { expect, test } from "vitest";
2
+ import { docComment } from "./DocComment";
3
+ import { genericParameter } from "./GenericParameter";
4
+ import { method } from "./Method";
5
+ import { namedType } from "./NamedType";
6
+ import { parameter } from "./Parameter";
7
+ import { stringify } from "./stringify";
8
+ const A = namedType("A");
9
+ const B = namedType("B");
10
+ test("name only", () => {
11
+ const m = method("doThings");
12
+ expect(stringify(m)).toMatchInlineSnapshot(`"doThings(): void"`);
13
+ });
14
+ test("with return type", () => {
15
+ const m = method("doThings").setReturnType(A);
16
+ expect(stringify(m)).toMatchInlineSnapshot(`"doThings(): A"`);
17
+ });
18
+ test("with doc comment", () => {
19
+ const m = method("doThings").setDocComment(docComment("Does things"));
20
+ expect(stringify(m)).toMatchInlineSnapshot(`
21
+ "/**
22
+ * Does things
23
+ */
24
+ doThings(): void"
25
+ `);
26
+ });
27
+ test("with parameter", () => {
28
+ const m = method("doThings").addParameter(parameter("foo", A));
29
+ expect(stringify(m)).toMatchInlineSnapshot(`"doThings(foo: A): void"`);
30
+ });
31
+ test("with multiple parameters", () => {
32
+ const m = method("doThings").addParameter(parameter("foo", A)).addParameter(parameter("foo", B));
33
+ expect(stringify(m)).toMatchInlineSnapshot(`"doThings(foo: A, foo: B): void"`);
34
+ });
35
+ test("with generic parameter", () => {
36
+ const m = method("doThings").addGenericParameter(genericParameter("T"));
37
+ expect(stringify(m)).toMatchInlineSnapshot(`"doThings<T>(): void"`);
38
+ });
39
+ test("with multiple generic parameters", () => {
40
+ const m = method("doThings").addGenericParameter(genericParameter("T")).addGenericParameter(genericParameter("U"));
41
+ expect(stringify(m)).toMatchInlineSnapshot(`"doThings<T, U>(): void"`);
42
+ });
@@ -0,0 +1,10 @@
1
+ import { TypeBuilder } from './TypeBuilder';
2
+ import { Writer } from './Writer';
3
+ export declare class NamedType extends TypeBuilder {
4
+ readonly name: string;
5
+ readonly genericArguments: TypeBuilder[];
6
+ constructor(name: string);
7
+ addGenericArgument(type: TypeBuilder): this;
8
+ write(writer: Writer): void;
9
+ }
10
+ export declare function namedType(name: string): NamedType;