@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,23 @@
1
+ class Export {
2
+ constructor(declaration) {
3
+ this.declaration = declaration;
4
+ }
5
+ docComment;
6
+ setDocComment(docComment) {
7
+ this.docComment = docComment;
8
+ return this;
9
+ }
10
+ write(writer) {
11
+ if (this.docComment) {
12
+ writer.write(this.docComment);
13
+ }
14
+ writer.write("export ").write(this.declaration);
15
+ }
16
+ }
17
+ function moduleExport(declaration) {
18
+ return new Export(declaration);
19
+ }
20
+ export {
21
+ Export,
22
+ moduleExport
23
+ };
@@ -0,0 +1,34 @@
1
+ import { BasicBuilder } from './BasicBuilder';
2
+ import { Writer } from './Writer';
3
+ export type ExportFrom = NamespaceExport | BindingsExport | ExportAllFrom;
4
+ export declare class NamespaceExport implements BasicBuilder {
5
+ private from;
6
+ private namespace;
7
+ constructor(from: string, namespace: string);
8
+ write(writer: Writer<undefined>): void;
9
+ }
10
+ export declare class BindingsExport implements BasicBuilder {
11
+ private from;
12
+ private namedExports;
13
+ constructor(from: string);
14
+ named(namedExport: string | NamedExport): this;
15
+ write(writer: Writer<undefined>): void;
16
+ }
17
+ export declare class NamedExport implements BasicBuilder {
18
+ readonly name: string;
19
+ private alias;
20
+ private type;
21
+ constructor(name: string);
22
+ as(alias: string): this;
23
+ typeOnly(): this;
24
+ write(writer: Writer): void;
25
+ }
26
+ export declare class ExportAllFrom implements BasicBuilder {
27
+ private from;
28
+ constructor(from: string);
29
+ asNamespace(namespace: string): NamespaceExport;
30
+ named(binding: string | NamedExport): BindingsExport;
31
+ write(writer: Writer): void;
32
+ }
33
+ export declare function moduleExportFrom(from: string): ExportAllFrom;
34
+ export declare function namedExport(name: string): NamedExport;
@@ -0,0 +1,106 @@
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 ExportFrom_exports = {};
20
+ __export(ExportFrom_exports, {
21
+ BindingsExport: () => BindingsExport,
22
+ ExportAllFrom: () => ExportAllFrom,
23
+ NamedExport: () => NamedExport,
24
+ NamespaceExport: () => NamespaceExport,
25
+ moduleExportFrom: () => moduleExportFrom,
26
+ namedExport: () => namedExport
27
+ });
28
+ module.exports = __toCommonJS(ExportFrom_exports);
29
+ class NamespaceExport {
30
+ constructor(from, namespace) {
31
+ this.from = from;
32
+ this.namespace = namespace;
33
+ }
34
+ write(writer) {
35
+ writer.write(`export * as ${this.namespace} from '${this.from}'`);
36
+ }
37
+ }
38
+ class BindingsExport {
39
+ constructor(from) {
40
+ this.from = from;
41
+ }
42
+ namedExports = [];
43
+ named(namedExport2) {
44
+ if (typeof namedExport2 === "string") {
45
+ namedExport2 = new NamedExport(namedExport2);
46
+ }
47
+ this.namedExports.push(namedExport2);
48
+ return this;
49
+ }
50
+ write(writer) {
51
+ writer.write("export ").write("{ ").writeJoined(", ", this.namedExports).write(" }").write(` from "${this.from}"`);
52
+ }
53
+ }
54
+ class NamedExport {
55
+ constructor(name) {
56
+ this.name = name;
57
+ }
58
+ alias;
59
+ type = false;
60
+ as(alias) {
61
+ this.alias = alias;
62
+ return this;
63
+ }
64
+ typeOnly() {
65
+ this.type = true;
66
+ return this;
67
+ }
68
+ write(writer) {
69
+ if (this.type) {
70
+ writer.write("type ");
71
+ }
72
+ writer.write(this.name);
73
+ if (this.alias) {
74
+ writer.write(" as ").write(this.alias);
75
+ }
76
+ }
77
+ }
78
+ class ExportAllFrom {
79
+ constructor(from) {
80
+ this.from = from;
81
+ }
82
+ asNamespace(namespace) {
83
+ return new NamespaceExport(this.from, namespace);
84
+ }
85
+ named(binding) {
86
+ return new BindingsExport(this.from).named(binding);
87
+ }
88
+ write(writer) {
89
+ writer.write(`export * from "${this.from}"`);
90
+ }
91
+ }
92
+ function moduleExportFrom(from) {
93
+ return new ExportAllFrom(from);
94
+ }
95
+ function namedExport(name) {
96
+ return new NamedExport(name);
97
+ }
98
+ // Annotate the CommonJS export names for ESM import in node:
99
+ 0 && (module.exports = {
100
+ BindingsExport,
101
+ ExportAllFrom,
102
+ NamedExport,
103
+ NamespaceExport,
104
+ moduleExportFrom,
105
+ namedExport
106
+ });
@@ -0,0 +1,77 @@
1
+ class NamespaceExport {
2
+ constructor(from, namespace) {
3
+ this.from = from;
4
+ this.namespace = namespace;
5
+ }
6
+ write(writer) {
7
+ writer.write(`export * as ${this.namespace} from '${this.from}'`);
8
+ }
9
+ }
10
+ class BindingsExport {
11
+ constructor(from) {
12
+ this.from = from;
13
+ }
14
+ namedExports = [];
15
+ named(namedExport2) {
16
+ if (typeof namedExport2 === "string") {
17
+ namedExport2 = new NamedExport(namedExport2);
18
+ }
19
+ this.namedExports.push(namedExport2);
20
+ return this;
21
+ }
22
+ write(writer) {
23
+ writer.write("export ").write("{ ").writeJoined(", ", this.namedExports).write(" }").write(` from "${this.from}"`);
24
+ }
25
+ }
26
+ class NamedExport {
27
+ constructor(name) {
28
+ this.name = name;
29
+ }
30
+ alias;
31
+ type = false;
32
+ as(alias) {
33
+ this.alias = alias;
34
+ return this;
35
+ }
36
+ typeOnly() {
37
+ this.type = true;
38
+ return this;
39
+ }
40
+ write(writer) {
41
+ if (this.type) {
42
+ writer.write("type ");
43
+ }
44
+ writer.write(this.name);
45
+ if (this.alias) {
46
+ writer.write(" as ").write(this.alias);
47
+ }
48
+ }
49
+ }
50
+ class ExportAllFrom {
51
+ constructor(from) {
52
+ this.from = from;
53
+ }
54
+ asNamespace(namespace) {
55
+ return new NamespaceExport(this.from, namespace);
56
+ }
57
+ named(binding) {
58
+ return new BindingsExport(this.from).named(binding);
59
+ }
60
+ write(writer) {
61
+ writer.write(`export * from "${this.from}"`);
62
+ }
63
+ }
64
+ function moduleExportFrom(from) {
65
+ return new ExportAllFrom(from);
66
+ }
67
+ function namedExport(name) {
68
+ return new NamedExport(name);
69
+ }
70
+ export {
71
+ BindingsExport,
72
+ ExportAllFrom,
73
+ NamedExport,
74
+ NamespaceExport,
75
+ moduleExportFrom,
76
+ namedExport
77
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var import_vitest = require("vitest");
3
+ var import_ExportFrom = require("./ExportFrom");
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_ExportFrom.moduleExportFrom)("someModule"))).toMatchInlineSnapshot(`"export * from "someModule""`);
7
+ });
8
+ (0, import_vitest.test)("namespace", () => {
9
+ const exportDecl = (0, import_ExportFrom.moduleExportFrom)("myModule").asNamespace("ns");
10
+ (0, import_vitest.expect)((0, import_stringify.stringify)(exportDecl)).toMatchInlineSnapshot(`"export * as ns from 'myModule'"`);
11
+ });
12
+ (0, import_vitest.test)("named", () => {
13
+ const exportDecl = (0, import_ExportFrom.moduleExportFrom)("myModule").named("func");
14
+ (0, import_vitest.expect)((0, import_stringify.stringify)(exportDecl)).toMatchInlineSnapshot(`"export { func } from "myModule""`);
15
+ });
16
+ (0, import_vitest.test)("named with alias", () => {
17
+ const exportDecl = (0, import_ExportFrom.moduleExportFrom)("myModule").named((0, import_ExportFrom.namedExport)("func").as("myFunc"));
18
+ (0, import_vitest.expect)((0, import_stringify.stringify)(exportDecl)).toMatchInlineSnapshot(`"export { func as myFunc } from "myModule""`);
19
+ });
20
+ (0, import_vitest.test)("multiple named", () => {
21
+ const exportDecl = (0, import_ExportFrom.moduleExportFrom)("myModule").named("func1").named("func2").named((0, import_ExportFrom.namedExport)("func3").as("aliasedFunc3"));
22
+ (0, import_vitest.expect)((0, import_stringify.stringify)(exportDecl)).toMatchInlineSnapshot(
23
+ `"export { func1, func2, func3 as aliasedFunc3 } from "myModule""`
24
+ );
25
+ });
@@ -0,0 +1,24 @@
1
+ import { expect, test } from "vitest";
2
+ import { moduleExportFrom, namedExport } from "./ExportFrom";
3
+ import { stringify } from "./stringify";
4
+ test("module name only", () => {
5
+ expect(stringify(moduleExportFrom("someModule"))).toMatchInlineSnapshot(`"export * from "someModule""`);
6
+ });
7
+ test("namespace", () => {
8
+ const exportDecl = moduleExportFrom("myModule").asNamespace("ns");
9
+ expect(stringify(exportDecl)).toMatchInlineSnapshot(`"export * as ns from 'myModule'"`);
10
+ });
11
+ test("named", () => {
12
+ const exportDecl = moduleExportFrom("myModule").named("func");
13
+ expect(stringify(exportDecl)).toMatchInlineSnapshot(`"export { func } from "myModule""`);
14
+ });
15
+ test("named with alias", () => {
16
+ const exportDecl = moduleExportFrom("myModule").named(namedExport("func").as("myFunc"));
17
+ expect(stringify(exportDecl)).toMatchInlineSnapshot(`"export { func as myFunc } from "myModule""`);
18
+ });
19
+ test("multiple named", () => {
20
+ const exportDecl = moduleExportFrom("myModule").named("func1").named("func2").named(namedExport("func3").as("aliasedFunc3"));
21
+ expect(stringify(exportDecl)).toMatchInlineSnapshot(
22
+ `"export { func1, func2, func3 as aliasedFunc3 } from "myModule""`
23
+ );
24
+ });
package/dist/File.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { AnyDeclarationBuilder } from './AnyDeclarationBuilder';
2
+ import { BasicBuilder } from './BasicBuilder';
3
+ import { Export } from './Export';
4
+ import { ExportFrom } from './ExportFrom';
5
+ import { Import } from './Import';
6
+ import { Writer } from './Writer';
7
+ export type FileItem = AnyDeclarationBuilder | Export<any> | ExportFrom;
8
+ export declare class File implements BasicBuilder {
9
+ private imports;
10
+ private declarations;
11
+ addImport(moduleImport: Import): this;
12
+ add(declaration: FileItem): void;
13
+ write(writer: Writer<undefined>): void;
14
+ }
15
+ export declare function file(): File;
package/dist/File.js ADDED
@@ -0,0 +1,57 @@
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 File_exports = {};
20
+ __export(File_exports, {
21
+ File: () => File,
22
+ file: () => file
23
+ });
24
+ module.exports = __toCommonJS(File_exports);
25
+ class File {
26
+ imports = [];
27
+ declarations = [];
28
+ addImport(moduleImport) {
29
+ this.imports.push(moduleImport);
30
+ return this;
31
+ }
32
+ add(declaration) {
33
+ this.declarations.push(declaration);
34
+ }
35
+ write(writer) {
36
+ for (const moduleImport of this.imports) {
37
+ writer.writeLine(moduleImport);
38
+ }
39
+ if (this.imports.length > 0) {
40
+ writer.newLine();
41
+ }
42
+ for (const [i, declaration] of this.declarations.entries()) {
43
+ writer.writeLine(declaration);
44
+ if (i < this.declarations.length - 1) {
45
+ writer.newLine();
46
+ }
47
+ }
48
+ }
49
+ }
50
+ function file() {
51
+ return new File();
52
+ }
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ File,
56
+ file
57
+ });
package/dist/File.mjs ADDED
@@ -0,0 +1,32 @@
1
+ class File {
2
+ imports = [];
3
+ declarations = [];
4
+ addImport(moduleImport) {
5
+ this.imports.push(moduleImport);
6
+ return this;
7
+ }
8
+ add(declaration) {
9
+ this.declarations.push(declaration);
10
+ }
11
+ write(writer) {
12
+ for (const moduleImport of this.imports) {
13
+ writer.writeLine(moduleImport);
14
+ }
15
+ if (this.imports.length > 0) {
16
+ writer.newLine();
17
+ }
18
+ for (const [i, declaration] of this.declarations.entries()) {
19
+ writer.writeLine(declaration);
20
+ if (i < this.declarations.length - 1) {
21
+ writer.newLine();
22
+ }
23
+ }
24
+ }
25
+ }
26
+ function file() {
27
+ return new File();
28
+ }
29
+ export {
30
+ File,
31
+ file
32
+ };
@@ -0,0 +1,9 @@
1
+ import { ValueBuilder } from './ValueBuilder';
2
+ import { Writer } from './Writer';
3
+ export declare class FunctionCall extends ValueBuilder {
4
+ #private;
5
+ constructor(name: string, args: ValueBuilder[]);
6
+ addArgument(arg: ValueBuilder): this;
7
+ write(writer: Writer): void;
8
+ }
9
+ export declare function functionCall(name: string, args?: ValueBuilder[]): FunctionCall;
@@ -0,0 +1,49 @@
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 FunctionCall_exports = {};
20
+ __export(FunctionCall_exports, {
21
+ FunctionCall: () => FunctionCall,
22
+ functionCall: () => functionCall
23
+ });
24
+ module.exports = __toCommonJS(FunctionCall_exports);
25
+ var import_ValueBuilder = require("./ValueBuilder");
26
+ class FunctionCall extends import_ValueBuilder.ValueBuilder {
27
+ #name;
28
+ #args;
29
+ constructor(name, args) {
30
+ super();
31
+ this.#name = name;
32
+ this.#args = args;
33
+ }
34
+ addArgument(arg) {
35
+ this.#args.push(arg);
36
+ return this;
37
+ }
38
+ write(writer) {
39
+ writer.write(this.#name).write("(").writeJoined(", ", this.#args).write(")");
40
+ }
41
+ }
42
+ function functionCall(name, args = []) {
43
+ return new FunctionCall(name, args);
44
+ }
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ FunctionCall,
48
+ functionCall
49
+ });
@@ -0,0 +1,24 @@
1
+ import { ValueBuilder } from "./ValueBuilder";
2
+ class FunctionCall extends ValueBuilder {
3
+ #name;
4
+ #args;
5
+ constructor(name, args) {
6
+ super();
7
+ this.#name = name;
8
+ this.#args = args;
9
+ }
10
+ addArgument(arg) {
11
+ this.#args.push(arg);
12
+ return this;
13
+ }
14
+ write(writer) {
15
+ writer.write(this.#name).write("(").writeJoined(", ", this.#args).write(")");
16
+ }
17
+ }
18
+ function functionCall(name, args = []) {
19
+ return new FunctionCall(name, args);
20
+ }
21
+ export {
22
+ FunctionCall,
23
+ functionCall
24
+ };
@@ -0,0 +1,17 @@
1
+ import { GenericParameter } from './GenericParameter';
2
+ import { Parameter } from './Parameter';
3
+ import { TypeBuilder } from './TypeBuilder';
4
+ import { Writer } from './Writer';
5
+ export declare class FunctionType extends TypeBuilder {
6
+ needsParenthesisWhenIndexed: boolean;
7
+ needsParenthesisInKeyof: boolean;
8
+ needsParenthesisInUnion: boolean;
9
+ private returnType;
10
+ private parameters;
11
+ private genericParameters;
12
+ setReturnType(returnType: TypeBuilder): this;
13
+ addParameter(param: Parameter): this;
14
+ addGenericParameter(param: GenericParameter): this;
15
+ write(writer: Writer): void;
16
+ }
17
+ export declare function functionType(): FunctionType;
@@ -0,0 +1,60 @@
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 FunctionType_exports = {};
20
+ __export(FunctionType_exports, {
21
+ FunctionType: () => FunctionType,
22
+ functionType: () => functionType
23
+ });
24
+ module.exports = __toCommonJS(FunctionType_exports);
25
+ var import_PrimitiveType = require("./PrimitiveType");
26
+ var import_TypeBuilder = require("./TypeBuilder");
27
+ class FunctionType extends import_TypeBuilder.TypeBuilder {
28
+ needsParenthesisWhenIndexed = true;
29
+ needsParenthesisInKeyof = true;
30
+ needsParenthesisInUnion = true;
31
+ returnType = import_PrimitiveType.voidType;
32
+ parameters = [];
33
+ genericParameters = [];
34
+ setReturnType(returnType) {
35
+ this.returnType = returnType;
36
+ return this;
37
+ }
38
+ addParameter(param) {
39
+ this.parameters.push(param);
40
+ return this;
41
+ }
42
+ addGenericParameter(param) {
43
+ this.genericParameters.push(param);
44
+ return this;
45
+ }
46
+ write(writer) {
47
+ if (this.genericParameters.length > 0) {
48
+ writer.write("<").writeJoined(", ", this.genericParameters).write(">");
49
+ }
50
+ writer.write("(").writeJoined(", ", this.parameters).write(") => ").write(this.returnType);
51
+ }
52
+ }
53
+ function functionType() {
54
+ return new FunctionType();
55
+ }
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ FunctionType,
59
+ functionType
60
+ });
@@ -0,0 +1,35 @@
1
+ import { voidType } from "./PrimitiveType";
2
+ import { TypeBuilder } from "./TypeBuilder";
3
+ class FunctionType extends TypeBuilder {
4
+ needsParenthesisWhenIndexed = true;
5
+ needsParenthesisInKeyof = true;
6
+ needsParenthesisInUnion = true;
7
+ returnType = voidType;
8
+ parameters = [];
9
+ genericParameters = [];
10
+ setReturnType(returnType) {
11
+ this.returnType = returnType;
12
+ return this;
13
+ }
14
+ addParameter(param) {
15
+ this.parameters.push(param);
16
+ return this;
17
+ }
18
+ addGenericParameter(param) {
19
+ this.genericParameters.push(param);
20
+ return this;
21
+ }
22
+ write(writer) {
23
+ if (this.genericParameters.length > 0) {
24
+ writer.write("<").writeJoined(", ", this.genericParameters).write(">");
25
+ }
26
+ writer.write("(").writeJoined(", ", this.parameters).write(") => ").write(this.returnType);
27
+ }
28
+ }
29
+ function functionType() {
30
+ return new FunctionType();
31
+ }
32
+ export {
33
+ FunctionType,
34
+ functionType
35
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var import_vitest = require("vitest");
3
+ var import_FunctionType = require("./FunctionType");
4
+ var import_GenericParameter = require("./GenericParameter");
5
+ var import_NamedType = require("./NamedType");
6
+ var import_Parameter = require("./Parameter");
7
+ var import_stringify = require("./stringify");
8
+ const A = (0, import_NamedType.namedType)("A");
9
+ const B = (0, import_NamedType.namedType)("B");
10
+ (0, import_vitest.test)("basic", () => {
11
+ (0, import_vitest.expect)((0, import_stringify.stringify)((0, import_FunctionType.functionType)())).toMatchInlineSnapshot(`"() => void"`);
12
+ });
13
+ (0, import_vitest.test)("with return type", () => {
14
+ const func = (0, import_FunctionType.functionType)().setReturnType(A);
15
+ (0, import_vitest.expect)((0, import_stringify.stringify)(func)).toMatchInlineSnapshot(`"() => A"`);
16
+ });
17
+ (0, import_vitest.test)("with parameter", () => {
18
+ const func = (0, import_FunctionType.functionType)().addParameter((0, import_Parameter.parameter)("param", A));
19
+ (0, import_vitest.expect)((0, import_stringify.stringify)(func)).toMatchInlineSnapshot(`"(param: A) => void"`);
20
+ });
21
+ (0, import_vitest.test)("with multiple parameters", () => {
22
+ const func = (0, import_FunctionType.functionType)().addParameter((0, import_Parameter.parameter)("param1", A)).addParameter((0, import_Parameter.parameter)("param2", B));
23
+ (0, import_vitest.expect)((0, import_stringify.stringify)(func)).toMatchInlineSnapshot(`"(param1: A, param2: B) => void"`);
24
+ });
25
+ (0, import_vitest.test)("with generic parameter", () => {
26
+ const func = (0, import_FunctionType.functionType)().addGenericParameter((0, import_GenericParameter.genericParameter)("T"));
27
+ (0, import_vitest.expect)((0, import_stringify.stringify)(func)).toMatchInlineSnapshot(`"<T>() => void"`);
28
+ });
29
+ (0, import_vitest.test)("with multiple generic parameters", () => {
30
+ const func = (0, import_FunctionType.functionType)().addGenericParameter((0, import_GenericParameter.genericParameter)("T")).addGenericParameter((0, import_GenericParameter.genericParameter)("U"));
31
+ (0, import_vitest.expect)((0, import_stringify.stringify)(func)).toMatchInlineSnapshot(`"<T, U>() => void"`);
32
+ });
@@ -0,0 +1,31 @@
1
+ import { expect, test } from "vitest";
2
+ import { functionType } from "./FunctionType";
3
+ import { genericParameter } from "./GenericParameter";
4
+ import { namedType } from "./NamedType";
5
+ import { parameter } from "./Parameter";
6
+ import { stringify } from "./stringify";
7
+ const A = namedType("A");
8
+ const B = namedType("B");
9
+ test("basic", () => {
10
+ expect(stringify(functionType())).toMatchInlineSnapshot(`"() => void"`);
11
+ });
12
+ test("with return type", () => {
13
+ const func = functionType().setReturnType(A);
14
+ expect(stringify(func)).toMatchInlineSnapshot(`"() => A"`);
15
+ });
16
+ test("with parameter", () => {
17
+ const func = functionType().addParameter(parameter("param", A));
18
+ expect(stringify(func)).toMatchInlineSnapshot(`"(param: A) => void"`);
19
+ });
20
+ test("with multiple parameters", () => {
21
+ const func = functionType().addParameter(parameter("param1", A)).addParameter(parameter("param2", B));
22
+ expect(stringify(func)).toMatchInlineSnapshot(`"(param1: A, param2: B) => void"`);
23
+ });
24
+ test("with generic parameter", () => {
25
+ const func = functionType().addGenericParameter(genericParameter("T"));
26
+ expect(stringify(func)).toMatchInlineSnapshot(`"<T>() => void"`);
27
+ });
28
+ test("with multiple generic parameters", () => {
29
+ const func = functionType().addGenericParameter(genericParameter("T")).addGenericParameter(genericParameter("U"));
30
+ expect(stringify(func)).toMatchInlineSnapshot(`"<T, U>() => void"`);
31
+ });