@prisma/ts-builders 6.6.0-dev.59

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 (162) 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 +13 -0
  25. package/dist/ConstDeclaration.js +49 -0
  26. package/dist/ConstDeclaration.mjs +24 -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 +32 -0
  40. package/dist/ExportFrom.js +98 -0
  41. package/dist/ExportFrom.mjs +69 -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/FunctionType.d.ts +17 -0
  49. package/dist/FunctionType.js +60 -0
  50. package/dist/FunctionType.mjs +35 -0
  51. package/dist/FunctionType.test.d.ts +1 -0
  52. package/dist/FunctionType.test.js +32 -0
  53. package/dist/FunctionType.test.mjs +31 -0
  54. package/dist/GenericParameter.d.ts +15 -0
  55. package/dist/GenericParameter.js +60 -0
  56. package/dist/GenericParameter.mjs +35 -0
  57. package/dist/GenericParameter.test.d.ts +1 -0
  58. package/dist/GenericParameter.test.js +19 -0
  59. package/dist/GenericParameter.test.mjs +18 -0
  60. package/dist/Import.d.ts +36 -0
  61. package/dist/Import.js +119 -0
  62. package/dist/Import.mjs +90 -0
  63. package/dist/Import.test.d.ts +1 -0
  64. package/dist/Import.test.js +33 -0
  65. package/dist/Import.test.mjs +32 -0
  66. package/dist/Interface.d.ts +22 -0
  67. package/dist/Interface.js +79 -0
  68. package/dist/Interface.mjs +54 -0
  69. package/dist/Interface.test.d.ts +1 -0
  70. package/dist/Interface.test.js +56 -0
  71. package/dist/Interface.test.mjs +55 -0
  72. package/dist/KeyType.d.ts +9 -0
  73. package/dist/KeyType.js +44 -0
  74. package/dist/KeyType.mjs +19 -0
  75. package/dist/KeyType.test.d.ts +1 -0
  76. package/dist/KeyType.test.js +28 -0
  77. package/dist/KeyType.test.mjs +27 -0
  78. package/dist/KeyofType.d.ts +8 -0
  79. package/dist/KeyofType.js +47 -0
  80. package/dist/KeyofType.mjs +22 -0
  81. package/dist/KeyofType.test.d.ts +1 -0
  82. package/dist/KeyofType.test.js +28 -0
  83. package/dist/KeyofType.test.mjs +27 -0
  84. package/dist/Method.d.ts +20 -0
  85. package/dist/Method.js +75 -0
  86. package/dist/Method.mjs +50 -0
  87. package/dist/Method.test.d.ts +1 -0
  88. package/dist/Method.test.js +43 -0
  89. package/dist/Method.test.mjs +42 -0
  90. package/dist/NamedType.d.ts +10 -0
  91. package/dist/NamedType.js +50 -0
  92. package/dist/NamedType.mjs +25 -0
  93. package/dist/NamedType.test.d.ts +1 -0
  94. package/dist/NamedType.test.js +15 -0
  95. package/dist/NamedType.test.mjs +14 -0
  96. package/dist/NamespaceDeclaration.d.ts +13 -0
  97. package/dist/NamespaceDeclaration.js +48 -0
  98. package/dist/NamespaceDeclaration.mjs +23 -0
  99. package/dist/ObjectType.d.ts +18 -0
  100. package/dist/ObjectType.js +71 -0
  101. package/dist/ObjectType.mjs +46 -0
  102. package/dist/ObjectType.test.d.ts +1 -0
  103. package/dist/ObjectType.test.js +32 -0
  104. package/dist/ObjectType.test.mjs +31 -0
  105. package/dist/Parameter.d.ts +12 -0
  106. package/dist/Parameter.js +50 -0
  107. package/dist/Parameter.mjs +25 -0
  108. package/dist/Parameter.test.d.ts +1 -0
  109. package/dist/Parameter.test.js +14 -0
  110. package/dist/Parameter.test.mjs +13 -0
  111. package/dist/PrimitiveType.d.ts +18 -0
  112. package/dist/PrimitiveType.js +70 -0
  113. package/dist/PrimitiveType.mjs +35 -0
  114. package/dist/Property.d.ts +18 -0
  115. package/dist/Property.js +75 -0
  116. package/dist/Property.mjs +50 -0
  117. package/dist/Property.test.d.ts +1 -0
  118. package/dist/Property.test.js +37 -0
  119. package/dist/Property.test.mjs +36 -0
  120. package/dist/StringLiteralType.d.ts +8 -0
  121. package/dist/StringLiteralType.js +42 -0
  122. package/dist/StringLiteralType.mjs +17 -0
  123. package/dist/TupleType.d.ts +17 -0
  124. package/dist/TupleType.js +69 -0
  125. package/dist/TupleType.mjs +42 -0
  126. package/dist/TupleType.test.d.ts +1 -0
  127. package/dist/TupleType.test.js +21 -0
  128. package/dist/TupleType.test.mjs +20 -0
  129. package/dist/TypeBuilder.d.ts +11 -0
  130. package/dist/TypeBuilder.js +47 -0
  131. package/dist/TypeBuilder.mjs +23 -0
  132. package/dist/TypeDeclaration.d.ts +17 -0
  133. package/dist/TypeDeclaration.js +62 -0
  134. package/dist/TypeDeclaration.mjs +37 -0
  135. package/dist/TypeDeclaration.test.d.ts +1 -0
  136. package/dist/TypeDeclaration.test.js +28 -0
  137. package/dist/TypeDeclaration.test.mjs +27 -0
  138. package/dist/UnionType.d.ts +13 -0
  139. package/dist/UnionType.js +74 -0
  140. package/dist/UnionType.mjs +49 -0
  141. package/dist/UnionType.test.d.ts +1 -0
  142. package/dist/UnionType.test.js +28 -0
  143. package/dist/UnionType.test.mjs +27 -0
  144. package/dist/WellKnownSymbol.d.ts +9 -0
  145. package/dist/WellKnownSymbol.js +43 -0
  146. package/dist/WellKnownSymbol.mjs +17 -0
  147. package/dist/Writer.d.ts +94 -0
  148. package/dist/Writer.js +175 -0
  149. package/dist/Writer.mjs +150 -0
  150. package/dist/Writer.test.d.ts +1 -0
  151. package/dist/Writer.test.js +100 -0
  152. package/dist/Writer.test.mjs +99 -0
  153. package/dist/helpers.d.ts +6 -0
  154. package/dist/helpers.js +46 -0
  155. package/dist/helpers.mjs +19 -0
  156. package/dist/index.d.ts +32 -0
  157. package/dist/index.js +84 -0
  158. package/dist/index.mjs +32 -0
  159. package/dist/stringify.d.ts +7 -0
  160. package/dist/stringify.js +44 -0
  161. package/dist/stringify.mjs +20 -0
  162. package/package.json +41 -0
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var import_vitest = require("vitest");
3
+ var import_GenericParameter = require("./GenericParameter");
4
+ var import_NamedType = require("./NamedType");
5
+ var import_stringify = require("./stringify");
6
+ const A = (0, import_NamedType.namedType)("A");
7
+ const B = (0, import_NamedType.namedType)("B");
8
+ (0, import_vitest.test)("name only", () => {
9
+ (0, import_vitest.expect)((0, import_stringify.stringify)((0, import_GenericParameter.genericParameter)("T"))).toMatchInlineSnapshot(`"T"`);
10
+ });
11
+ (0, import_vitest.test)("with extends", () => {
12
+ (0, import_vitest.expect)((0, import_stringify.stringify)((0, import_GenericParameter.genericParameter)("T").extends(A))).toMatchInlineSnapshot(`"T extends A"`);
13
+ });
14
+ (0, import_vitest.test)("with default", () => {
15
+ (0, import_vitest.expect)((0, import_stringify.stringify)((0, import_GenericParameter.genericParameter)("T").default(B))).toMatchInlineSnapshot(`"T = B"`);
16
+ });
17
+ (0, import_vitest.test)("with extends + default", () => {
18
+ (0, import_vitest.expect)((0, import_stringify.stringify)((0, import_GenericParameter.genericParameter)("T").extends(A).default(B))).toMatchInlineSnapshot(`"T extends A = B"`);
19
+ });
@@ -0,0 +1,18 @@
1
+ import { expect, test } from "vitest";
2
+ import { genericParameter } from "./GenericParameter";
3
+ import { namedType } from "./NamedType";
4
+ import { stringify } from "./stringify";
5
+ const A = namedType("A");
6
+ const B = namedType("B");
7
+ test("name only", () => {
8
+ expect(stringify(genericParameter("T"))).toMatchInlineSnapshot(`"T"`);
9
+ });
10
+ test("with extends", () => {
11
+ expect(stringify(genericParameter("T").extends(A))).toMatchInlineSnapshot(`"T extends A"`);
12
+ });
13
+ test("with default", () => {
14
+ expect(stringify(genericParameter("T").default(B))).toMatchInlineSnapshot(`"T = B"`);
15
+ });
16
+ test("with extends + default", () => {
17
+ expect(stringify(genericParameter("T").extends(A).default(B))).toMatchInlineSnapshot(`"T extends A = B"`);
18
+ });
@@ -0,0 +1,36 @@
1
+ import { BasicBuilder } from './BasicBuilder';
2
+ import { Writer } from './Writer';
3
+ export type Import = NamespaceImport | BindingsImport | ModuleImport;
4
+ export declare class NamespaceImport implements BasicBuilder {
5
+ readonly alias: string;
6
+ readonly from: string;
7
+ constructor(alias: string, from: string);
8
+ write(writer: Writer<undefined>): void;
9
+ }
10
+ export declare class BindingsImport implements BasicBuilder {
11
+ readonly from: string;
12
+ private defaultImport;
13
+ private namedImports;
14
+ constructor(from: string);
15
+ default(name: string): this;
16
+ named(namedImport: string | NamedImport): this;
17
+ write(writer: Writer): void;
18
+ private hasNamedImports;
19
+ }
20
+ export declare class NamedImport implements BasicBuilder {
21
+ readonly name: string;
22
+ private alias;
23
+ constructor(name: string);
24
+ as(alias: string): this;
25
+ write(writer: Writer): void;
26
+ }
27
+ export declare class ModuleImport implements BasicBuilder {
28
+ readonly from: string;
29
+ constructor(from: string);
30
+ asNamespace(alias: string): NamespaceImport;
31
+ default(alias: string): BindingsImport;
32
+ named(namedImport: string | NamedImport): BindingsImport;
33
+ write(writer: Writer): void;
34
+ }
35
+ export declare function moduleImport(from: string): ModuleImport;
36
+ export declare function namedImport(name: string): NamedImport;
package/dist/Import.js ADDED
@@ -0,0 +1,119 @@
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 Import_exports = {};
20
+ __export(Import_exports, {
21
+ BindingsImport: () => BindingsImport,
22
+ ModuleImport: () => ModuleImport,
23
+ NamedImport: () => NamedImport,
24
+ NamespaceImport: () => NamespaceImport,
25
+ moduleImport: () => moduleImport,
26
+ namedImport: () => namedImport
27
+ });
28
+ module.exports = __toCommonJS(Import_exports);
29
+ class NamespaceImport {
30
+ constructor(alias, from) {
31
+ this.alias = alias;
32
+ this.from = from;
33
+ }
34
+ write(writer) {
35
+ writer.write("import * as ").write(this.alias).write(` from "${this.from}"`);
36
+ }
37
+ }
38
+ class BindingsImport {
39
+ constructor(from) {
40
+ this.from = from;
41
+ }
42
+ defaultImport;
43
+ namedImports = [];
44
+ default(name) {
45
+ this.defaultImport = name;
46
+ return this;
47
+ }
48
+ named(namedImport2) {
49
+ if (typeof namedImport2 === "string") {
50
+ namedImport2 = new NamedImport(namedImport2);
51
+ }
52
+ this.namedImports.push(namedImport2);
53
+ return this;
54
+ }
55
+ write(writer) {
56
+ writer.write("import ");
57
+ if (this.defaultImport) {
58
+ writer.write(this.defaultImport);
59
+ if (this.hasNamedImports()) {
60
+ writer.write(", ");
61
+ }
62
+ }
63
+ if (this.hasNamedImports()) {
64
+ writer.write("{ ").writeJoined(", ", this.namedImports).write(" }");
65
+ }
66
+ writer.write(` from "${this.from}"`);
67
+ }
68
+ hasNamedImports() {
69
+ return this.namedImports.length > 0;
70
+ }
71
+ }
72
+ class NamedImport {
73
+ constructor(name) {
74
+ this.name = name;
75
+ }
76
+ alias;
77
+ as(alias) {
78
+ this.alias = alias;
79
+ return this;
80
+ }
81
+ write(writer) {
82
+ writer.write(this.name);
83
+ if (this.alias) {
84
+ writer.write(" as ").write(this.alias);
85
+ }
86
+ }
87
+ }
88
+ class ModuleImport {
89
+ constructor(from) {
90
+ this.from = from;
91
+ }
92
+ asNamespace(alias) {
93
+ return new NamespaceImport(alias, this.from);
94
+ }
95
+ default(alias) {
96
+ return new BindingsImport(this.from).default(alias);
97
+ }
98
+ named(namedImport2) {
99
+ return new BindingsImport(this.from).named(namedImport2);
100
+ }
101
+ write(writer) {
102
+ writer.write("import ").write(`"${this.from}"`);
103
+ }
104
+ }
105
+ function moduleImport(from) {
106
+ return new ModuleImport(from);
107
+ }
108
+ function namedImport(name) {
109
+ return new NamedImport(name);
110
+ }
111
+ // Annotate the CommonJS export names for ESM import in node:
112
+ 0 && (module.exports = {
113
+ BindingsImport,
114
+ ModuleImport,
115
+ NamedImport,
116
+ NamespaceImport,
117
+ moduleImport,
118
+ namedImport
119
+ });
@@ -0,0 +1,90 @@
1
+ class NamespaceImport {
2
+ constructor(alias, from) {
3
+ this.alias = alias;
4
+ this.from = from;
5
+ }
6
+ write(writer) {
7
+ writer.write("import * as ").write(this.alias).write(` from "${this.from}"`);
8
+ }
9
+ }
10
+ class BindingsImport {
11
+ constructor(from) {
12
+ this.from = from;
13
+ }
14
+ defaultImport;
15
+ namedImports = [];
16
+ default(name) {
17
+ this.defaultImport = name;
18
+ return this;
19
+ }
20
+ named(namedImport2) {
21
+ if (typeof namedImport2 === "string") {
22
+ namedImport2 = new NamedImport(namedImport2);
23
+ }
24
+ this.namedImports.push(namedImport2);
25
+ return this;
26
+ }
27
+ write(writer) {
28
+ writer.write("import ");
29
+ if (this.defaultImport) {
30
+ writer.write(this.defaultImport);
31
+ if (this.hasNamedImports()) {
32
+ writer.write(", ");
33
+ }
34
+ }
35
+ if (this.hasNamedImports()) {
36
+ writer.write("{ ").writeJoined(", ", this.namedImports).write(" }");
37
+ }
38
+ writer.write(` from "${this.from}"`);
39
+ }
40
+ hasNamedImports() {
41
+ return this.namedImports.length > 0;
42
+ }
43
+ }
44
+ class NamedImport {
45
+ constructor(name) {
46
+ this.name = name;
47
+ }
48
+ alias;
49
+ as(alias) {
50
+ this.alias = alias;
51
+ return this;
52
+ }
53
+ write(writer) {
54
+ writer.write(this.name);
55
+ if (this.alias) {
56
+ writer.write(" as ").write(this.alias);
57
+ }
58
+ }
59
+ }
60
+ class ModuleImport {
61
+ constructor(from) {
62
+ this.from = from;
63
+ }
64
+ asNamespace(alias) {
65
+ return new NamespaceImport(alias, this.from);
66
+ }
67
+ default(alias) {
68
+ return new BindingsImport(this.from).default(alias);
69
+ }
70
+ named(namedImport2) {
71
+ return new BindingsImport(this.from).named(namedImport2);
72
+ }
73
+ write(writer) {
74
+ writer.write("import ").write(`"${this.from}"`);
75
+ }
76
+ }
77
+ function moduleImport(from) {
78
+ return new ModuleImport(from);
79
+ }
80
+ function namedImport(name) {
81
+ return new NamedImport(name);
82
+ }
83
+ export {
84
+ BindingsImport,
85
+ ModuleImport,
86
+ NamedImport,
87
+ NamespaceImport,
88
+ moduleImport,
89
+ namedImport
90
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var import_vitest = require("vitest");
3
+ var import_Import = require("./Import");
4
+ var import_stringify = require("./stringify");
5
+ (0, import_vitest.test)("module name only", () => {
6
+ (0, import_vitest.expect)((0, import_stringify.stringify)((0, import_Import.moduleImport)("someModule"))).toMatchInlineSnapshot(`"import "someModule""`);
7
+ });
8
+ (0, import_vitest.test)("default", () => {
9
+ const importDecl = (0, import_Import.moduleImport)("myModule").default("mod");
10
+ (0, import_vitest.expect)((0, import_stringify.stringify)(importDecl)).toMatchInlineSnapshot(`"import mod from "myModule""`);
11
+ });
12
+ (0, import_vitest.test)("namespace", () => {
13
+ const importDecl = (0, import_Import.moduleImport)("myModule").asNamespace("ns");
14
+ (0, import_vitest.expect)((0, import_stringify.stringify)(importDecl)).toMatchInlineSnapshot(`"import * as ns from "myModule""`);
15
+ });
16
+ (0, import_vitest.test)("named", () => {
17
+ const importDecl = (0, import_Import.moduleImport)("myModule").named("func");
18
+ (0, import_vitest.expect)((0, import_stringify.stringify)(importDecl)).toMatchInlineSnapshot(`"import { func } from "myModule""`);
19
+ });
20
+ (0, import_vitest.test)("named with alias", () => {
21
+ const importDecl = (0, import_Import.moduleImport)("myModule").named((0, import_Import.namedImport)("func").as("myFunc"));
22
+ (0, import_vitest.expect)((0, import_stringify.stringify)(importDecl)).toMatchInlineSnapshot(`"import { func as myFunc } from "myModule""`);
23
+ });
24
+ (0, import_vitest.test)("multiple named", () => {
25
+ const importDecl = (0, import_Import.moduleImport)("myModule").named("func1").named("func2").named((0, import_Import.namedImport)("func3").as("aliasedFunc3"));
26
+ (0, import_vitest.expect)((0, import_stringify.stringify)(importDecl)).toMatchInlineSnapshot(
27
+ `"import { func1, func2, func3 as aliasedFunc3 } from "myModule""`
28
+ );
29
+ });
30
+ (0, import_vitest.test)("default and named", () => {
31
+ const importDecl = (0, import_Import.moduleImport)("myModule").default("mod").named("func1").named("func2");
32
+ (0, import_vitest.expect)((0, import_stringify.stringify)(importDecl)).toMatchInlineSnapshot(`"import mod, { func1, func2 } from "myModule""`);
33
+ });
@@ -0,0 +1,32 @@
1
+ import { expect, test } from "vitest";
2
+ import { moduleImport, namedImport } from "./Import";
3
+ import { stringify } from "./stringify";
4
+ test("module name only", () => {
5
+ expect(stringify(moduleImport("someModule"))).toMatchInlineSnapshot(`"import "someModule""`);
6
+ });
7
+ test("default", () => {
8
+ const importDecl = moduleImport("myModule").default("mod");
9
+ expect(stringify(importDecl)).toMatchInlineSnapshot(`"import mod from "myModule""`);
10
+ });
11
+ test("namespace", () => {
12
+ const importDecl = moduleImport("myModule").asNamespace("ns");
13
+ expect(stringify(importDecl)).toMatchInlineSnapshot(`"import * as ns from "myModule""`);
14
+ });
15
+ test("named", () => {
16
+ const importDecl = moduleImport("myModule").named("func");
17
+ expect(stringify(importDecl)).toMatchInlineSnapshot(`"import { func } from "myModule""`);
18
+ });
19
+ test("named with alias", () => {
20
+ const importDecl = moduleImport("myModule").named(namedImport("func").as("myFunc"));
21
+ expect(stringify(importDecl)).toMatchInlineSnapshot(`"import { func as myFunc } from "myModule""`);
22
+ });
23
+ test("multiple named", () => {
24
+ const importDecl = moduleImport("myModule").named("func1").named("func2").named(namedImport("func3").as("aliasedFunc3"));
25
+ expect(stringify(importDecl)).toMatchInlineSnapshot(
26
+ `"import { func1, func2, func3 as aliasedFunc3 } from "myModule""`
27
+ );
28
+ });
29
+ test("default and named", () => {
30
+ const importDecl = moduleImport("myModule").default("mod").named("func1").named("func2");
31
+ expect(stringify(importDecl)).toMatchInlineSnapshot(`"import mod, { func1, func2 } from "myModule""`);
32
+ });
@@ -0,0 +1,22 @@
1
+ import { GenericParameter } from './GenericParameter';
2
+ import { Method } from './Method';
3
+ import { NamedType } from './NamedType';
4
+ import { Property } from './Property';
5
+ import { TypeBuilder } from './TypeBuilder';
6
+ import { Writer } from './Writer';
7
+ type InterfaceItem = Method | Property;
8
+ export declare class InterfaceDeclaration extends TypeBuilder {
9
+ readonly name: string;
10
+ needsParenthesisWhenIndexed: boolean;
11
+ private items;
12
+ private genericParameters;
13
+ private extendedTypes;
14
+ constructor(name: string);
15
+ add(item: InterfaceItem): this;
16
+ addMultiple(items: InterfaceItem[]): this;
17
+ addGenericParameter(param: GenericParameter): this;
18
+ extends(type: NamedType): this;
19
+ write(writer: Writer): void;
20
+ }
21
+ export declare function interfaceDeclaration(name: string): InterfaceDeclaration;
22
+ export {};
@@ -0,0 +1,79 @@
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 Interface_exports = {};
20
+ __export(Interface_exports, {
21
+ InterfaceDeclaration: () => InterfaceDeclaration,
22
+ interfaceDeclaration: () => interfaceDeclaration
23
+ });
24
+ module.exports = __toCommonJS(Interface_exports);
25
+ var import_TypeBuilder = require("./TypeBuilder");
26
+ class InterfaceDeclaration extends import_TypeBuilder.TypeBuilder {
27
+ constructor(name) {
28
+ super();
29
+ this.name = name;
30
+ }
31
+ needsParenthesisWhenIndexed = true;
32
+ items = [];
33
+ genericParameters = [];
34
+ extendedTypes = [];
35
+ add(item) {
36
+ this.items.push(item);
37
+ return this;
38
+ }
39
+ addMultiple(items) {
40
+ for (const item of items) {
41
+ this.add(item);
42
+ }
43
+ return this;
44
+ }
45
+ addGenericParameter(param) {
46
+ this.genericParameters.push(param);
47
+ return this;
48
+ }
49
+ extends(type) {
50
+ this.extendedTypes.push(type);
51
+ return this;
52
+ }
53
+ write(writer) {
54
+ writer.write("interface ").write(this.name);
55
+ if (this.genericParameters.length > 0) {
56
+ writer.write("<").writeJoined(", ", this.genericParameters).write(">");
57
+ }
58
+ if (this.extendedTypes.length > 0) {
59
+ writer.write(" extends ").writeJoined(", ", this.extendedTypes);
60
+ }
61
+ if (this.items.length === 0) {
62
+ writer.writeLine(" {}");
63
+ return;
64
+ }
65
+ writer.writeLine(" {").withIndent(() => {
66
+ for (const item of this.items) {
67
+ writer.writeLine(item);
68
+ }
69
+ }).write("}");
70
+ }
71
+ }
72
+ function interfaceDeclaration(name) {
73
+ return new InterfaceDeclaration(name);
74
+ }
75
+ // Annotate the CommonJS export names for ESM import in node:
76
+ 0 && (module.exports = {
77
+ InterfaceDeclaration,
78
+ interfaceDeclaration
79
+ });
@@ -0,0 +1,54 @@
1
+ import { TypeBuilder } from "./TypeBuilder";
2
+ class InterfaceDeclaration extends TypeBuilder {
3
+ constructor(name) {
4
+ super();
5
+ this.name = name;
6
+ }
7
+ needsParenthesisWhenIndexed = true;
8
+ items = [];
9
+ genericParameters = [];
10
+ extendedTypes = [];
11
+ add(item) {
12
+ this.items.push(item);
13
+ return this;
14
+ }
15
+ addMultiple(items) {
16
+ for (const item of items) {
17
+ this.add(item);
18
+ }
19
+ return this;
20
+ }
21
+ addGenericParameter(param) {
22
+ this.genericParameters.push(param);
23
+ return this;
24
+ }
25
+ extends(type) {
26
+ this.extendedTypes.push(type);
27
+ return this;
28
+ }
29
+ write(writer) {
30
+ writer.write("interface ").write(this.name);
31
+ if (this.genericParameters.length > 0) {
32
+ writer.write("<").writeJoined(", ", this.genericParameters).write(">");
33
+ }
34
+ if (this.extendedTypes.length > 0) {
35
+ writer.write(" extends ").writeJoined(", ", this.extendedTypes);
36
+ }
37
+ if (this.items.length === 0) {
38
+ writer.writeLine(" {}");
39
+ return;
40
+ }
41
+ writer.writeLine(" {").withIndent(() => {
42
+ for (const item of this.items) {
43
+ writer.writeLine(item);
44
+ }
45
+ }).write("}");
46
+ }
47
+ }
48
+ function interfaceDeclaration(name) {
49
+ return new InterfaceDeclaration(name);
50
+ }
51
+ export {
52
+ InterfaceDeclaration,
53
+ interfaceDeclaration
54
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -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
+ });