@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.
- package/LICENSE +201 -0
- package/README.md +5 -0
- package/dist/AnyDeclarationBuilder.d.ts +6 -0
- package/dist/AnyDeclarationBuilder.js +16 -0
- package/dist/AnyDeclarationBuilder.mjs +0 -0
- package/dist/ArraySpread.d.ts +8 -0
- package/dist/ArraySpread.js +42 -0
- package/dist/ArraySpread.mjs +17 -0
- package/dist/ArrayType.d.ts +8 -0
- package/dist/ArrayType.js +43 -0
- package/dist/ArrayType.mjs +18 -0
- package/dist/ArrayType.test.d.ts +1 -0
- package/dist/ArrayType.test.js +24 -0
- package/dist/ArrayType.test.mjs +23 -0
- package/dist/BasicBuilder.d.ts +4 -0
- package/dist/BasicBuilder.js +16 -0
- package/dist/BasicBuilder.mjs +0 -0
- package/dist/Class.d.ts +22 -0
- package/dist/Class.js +79 -0
- package/dist/Class.mjs +54 -0
- package/dist/Class.test.d.ts +1 -0
- package/dist/Class.test.js +56 -0
- package/dist/Class.test.mjs +55 -0
- package/dist/ConstDeclaration.d.ts +13 -0
- package/dist/ConstDeclaration.js +49 -0
- package/dist/ConstDeclaration.mjs +24 -0
- package/dist/ConstDeclaration.test.d.ts +1 -0
- package/dist/ConstDeclaration.test.js +19 -0
- package/dist/ConstDeclaration.test.mjs +18 -0
- package/dist/DocComment.d.ts +11 -0
- package/dist/DocComment.js +101 -0
- package/dist/DocComment.mjs +76 -0
- package/dist/DocComment.test.d.ts +1 -0
- package/dist/DocComment.test.js +80 -0
- package/dist/DocComment.test.mjs +79 -0
- package/dist/Export.d.ts +12 -0
- package/dist/Export.js +48 -0
- package/dist/Export.mjs +23 -0
- package/dist/ExportFrom.d.ts +32 -0
- package/dist/ExportFrom.js +98 -0
- package/dist/ExportFrom.mjs +69 -0
- package/dist/ExportFrom.test.d.ts +1 -0
- package/dist/ExportFrom.test.js +25 -0
- package/dist/ExportFrom.test.mjs +24 -0
- package/dist/File.d.ts +15 -0
- package/dist/File.js +57 -0
- package/dist/File.mjs +32 -0
- package/dist/FunctionType.d.ts +17 -0
- package/dist/FunctionType.js +60 -0
- package/dist/FunctionType.mjs +35 -0
- package/dist/FunctionType.test.d.ts +1 -0
- package/dist/FunctionType.test.js +32 -0
- package/dist/FunctionType.test.mjs +31 -0
- package/dist/GenericParameter.d.ts +15 -0
- package/dist/GenericParameter.js +60 -0
- package/dist/GenericParameter.mjs +35 -0
- package/dist/GenericParameter.test.d.ts +1 -0
- package/dist/GenericParameter.test.js +19 -0
- package/dist/GenericParameter.test.mjs +18 -0
- package/dist/Import.d.ts +36 -0
- package/dist/Import.js +119 -0
- package/dist/Import.mjs +90 -0
- package/dist/Import.test.d.ts +1 -0
- package/dist/Import.test.js +33 -0
- package/dist/Import.test.mjs +32 -0
- package/dist/Interface.d.ts +22 -0
- package/dist/Interface.js +79 -0
- package/dist/Interface.mjs +54 -0
- package/dist/Interface.test.d.ts +1 -0
- package/dist/Interface.test.js +56 -0
- package/dist/Interface.test.mjs +55 -0
- package/dist/KeyType.d.ts +9 -0
- package/dist/KeyType.js +44 -0
- package/dist/KeyType.mjs +19 -0
- package/dist/KeyType.test.d.ts +1 -0
- package/dist/KeyType.test.js +28 -0
- package/dist/KeyType.test.mjs +27 -0
- package/dist/KeyofType.d.ts +8 -0
- package/dist/KeyofType.js +47 -0
- package/dist/KeyofType.mjs +22 -0
- package/dist/KeyofType.test.d.ts +1 -0
- package/dist/KeyofType.test.js +28 -0
- package/dist/KeyofType.test.mjs +27 -0
- package/dist/Method.d.ts +20 -0
- package/dist/Method.js +75 -0
- package/dist/Method.mjs +50 -0
- package/dist/Method.test.d.ts +1 -0
- package/dist/Method.test.js +43 -0
- package/dist/Method.test.mjs +42 -0
- package/dist/NamedType.d.ts +10 -0
- package/dist/NamedType.js +50 -0
- package/dist/NamedType.mjs +25 -0
- package/dist/NamedType.test.d.ts +1 -0
- package/dist/NamedType.test.js +15 -0
- package/dist/NamedType.test.mjs +14 -0
- package/dist/NamespaceDeclaration.d.ts +13 -0
- package/dist/NamespaceDeclaration.js +48 -0
- package/dist/NamespaceDeclaration.mjs +23 -0
- package/dist/ObjectType.d.ts +18 -0
- package/dist/ObjectType.js +71 -0
- package/dist/ObjectType.mjs +46 -0
- package/dist/ObjectType.test.d.ts +1 -0
- package/dist/ObjectType.test.js +32 -0
- package/dist/ObjectType.test.mjs +31 -0
- package/dist/Parameter.d.ts +12 -0
- package/dist/Parameter.js +50 -0
- package/dist/Parameter.mjs +25 -0
- package/dist/Parameter.test.d.ts +1 -0
- package/dist/Parameter.test.js +14 -0
- package/dist/Parameter.test.mjs +13 -0
- package/dist/PrimitiveType.d.ts +18 -0
- package/dist/PrimitiveType.js +70 -0
- package/dist/PrimitiveType.mjs +35 -0
- package/dist/Property.d.ts +18 -0
- package/dist/Property.js +75 -0
- package/dist/Property.mjs +50 -0
- package/dist/Property.test.d.ts +1 -0
- package/dist/Property.test.js +37 -0
- package/dist/Property.test.mjs +36 -0
- package/dist/StringLiteralType.d.ts +8 -0
- package/dist/StringLiteralType.js +42 -0
- package/dist/StringLiteralType.mjs +17 -0
- package/dist/TupleType.d.ts +17 -0
- package/dist/TupleType.js +69 -0
- package/dist/TupleType.mjs +42 -0
- package/dist/TupleType.test.d.ts +1 -0
- package/dist/TupleType.test.js +21 -0
- package/dist/TupleType.test.mjs +20 -0
- package/dist/TypeBuilder.d.ts +11 -0
- package/dist/TypeBuilder.js +47 -0
- package/dist/TypeBuilder.mjs +23 -0
- package/dist/TypeDeclaration.d.ts +17 -0
- package/dist/TypeDeclaration.js +62 -0
- package/dist/TypeDeclaration.mjs +37 -0
- package/dist/TypeDeclaration.test.d.ts +1 -0
- package/dist/TypeDeclaration.test.js +28 -0
- package/dist/TypeDeclaration.test.mjs +27 -0
- package/dist/UnionType.d.ts +13 -0
- package/dist/UnionType.js +74 -0
- package/dist/UnionType.mjs +49 -0
- package/dist/UnionType.test.d.ts +1 -0
- package/dist/UnionType.test.js +28 -0
- package/dist/UnionType.test.mjs +27 -0
- package/dist/WellKnownSymbol.d.ts +9 -0
- package/dist/WellKnownSymbol.js +43 -0
- package/dist/WellKnownSymbol.mjs +17 -0
- package/dist/Writer.d.ts +94 -0
- package/dist/Writer.js +175 -0
- package/dist/Writer.mjs +150 -0
- package/dist/Writer.test.d.ts +1 -0
- package/dist/Writer.test.js +100 -0
- package/dist/Writer.test.mjs +99 -0
- package/dist/helpers.d.ts +6 -0
- package/dist/helpers.js +46 -0
- package/dist/helpers.mjs +19 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +84 -0
- package/dist/index.mjs +32 -0
- package/dist/stringify.d.ts +7 -0
- package/dist/stringify.js +44 -0
- package/dist/stringify.mjs +20 -0
- package/package.json +41 -0
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
constructor(name: string);
|
|
21
|
+
as(alias: string): this;
|
|
22
|
+
write(writer: Writer): void;
|
|
23
|
+
}
|
|
24
|
+
export declare class ExportAllFrom implements BasicBuilder {
|
|
25
|
+
private from;
|
|
26
|
+
constructor(from: string);
|
|
27
|
+
asNamespace(namespace: string): NamespaceExport;
|
|
28
|
+
named(binding: string | NamedExport): BindingsExport;
|
|
29
|
+
write(writer: Writer): void;
|
|
30
|
+
}
|
|
31
|
+
export declare function moduleExportFrom(from: string): ExportAllFrom;
|
|
32
|
+
export declare function namedExport(name: string): NamedExport;
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
as(alias) {
|
|
60
|
+
this.alias = alias;
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
write(writer) {
|
|
64
|
+
writer.write(this.name);
|
|
65
|
+
if (this.alias) {
|
|
66
|
+
writer.write(" as ").write(this.alias);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
class ExportAllFrom {
|
|
71
|
+
constructor(from) {
|
|
72
|
+
this.from = from;
|
|
73
|
+
}
|
|
74
|
+
asNamespace(namespace) {
|
|
75
|
+
return new NamespaceExport(this.from, namespace);
|
|
76
|
+
}
|
|
77
|
+
named(binding) {
|
|
78
|
+
return new BindingsExport(this.from).named(binding);
|
|
79
|
+
}
|
|
80
|
+
write(writer) {
|
|
81
|
+
writer.write(`export * from "${this.from}"`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function moduleExportFrom(from) {
|
|
85
|
+
return new ExportAllFrom(from);
|
|
86
|
+
}
|
|
87
|
+
function namedExport(name) {
|
|
88
|
+
return new NamedExport(name);
|
|
89
|
+
}
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {
|
|
92
|
+
BindingsExport,
|
|
93
|
+
ExportAllFrom,
|
|
94
|
+
NamedExport,
|
|
95
|
+
NamespaceExport,
|
|
96
|
+
moduleExportFrom,
|
|
97
|
+
namedExport
|
|
98
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
as(alias) {
|
|
32
|
+
this.alias = alias;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
write(writer) {
|
|
36
|
+
writer.write(this.name);
|
|
37
|
+
if (this.alias) {
|
|
38
|
+
writer.write(" as ").write(this.alias);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
class ExportAllFrom {
|
|
43
|
+
constructor(from) {
|
|
44
|
+
this.from = from;
|
|
45
|
+
}
|
|
46
|
+
asNamespace(namespace) {
|
|
47
|
+
return new NamespaceExport(this.from, namespace);
|
|
48
|
+
}
|
|
49
|
+
named(binding) {
|
|
50
|
+
return new BindingsExport(this.from).named(binding);
|
|
51
|
+
}
|
|
52
|
+
write(writer) {
|
|
53
|
+
writer.write(`export * from "${this.from}"`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function moduleExportFrom(from) {
|
|
57
|
+
return new ExportAllFrom(from);
|
|
58
|
+
}
|
|
59
|
+
function namedExport(name) {
|
|
60
|
+
return new NamedExport(name);
|
|
61
|
+
}
|
|
62
|
+
export {
|
|
63
|
+
BindingsExport,
|
|
64
|
+
ExportAllFrom,
|
|
65
|
+
NamedExport,
|
|
66
|
+
NamespaceExport,
|
|
67
|
+
moduleExportFrom,
|
|
68
|
+
namedExport
|
|
69
|
+
};
|
|
@@ -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,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
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BasicBuilder } from './BasicBuilder';
|
|
2
|
+
import { NamedType } from './NamedType';
|
|
3
|
+
import { TypeBuilder } from './TypeBuilder';
|
|
4
|
+
import { Writer } from './Writer';
|
|
5
|
+
export declare class GenericParameter implements BasicBuilder {
|
|
6
|
+
private name;
|
|
7
|
+
private extendedType?;
|
|
8
|
+
private defaultType?;
|
|
9
|
+
constructor(name: string);
|
|
10
|
+
extends(type: TypeBuilder): this;
|
|
11
|
+
default(type: TypeBuilder): this;
|
|
12
|
+
toArgument(): NamedType;
|
|
13
|
+
write(writer: Writer): void;
|
|
14
|
+
}
|
|
15
|
+
export declare function genericParameter(name: string): GenericParameter;
|
|
@@ -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 GenericParameter_exports = {};
|
|
20
|
+
__export(GenericParameter_exports, {
|
|
21
|
+
GenericParameter: () => GenericParameter,
|
|
22
|
+
genericParameter: () => genericParameter
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(GenericParameter_exports);
|
|
25
|
+
var import_NamedType = require("./NamedType");
|
|
26
|
+
class GenericParameter {
|
|
27
|
+
constructor(name) {
|
|
28
|
+
this.name = name;
|
|
29
|
+
}
|
|
30
|
+
extendedType;
|
|
31
|
+
defaultType;
|
|
32
|
+
extends(type) {
|
|
33
|
+
this.extendedType = type;
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
default(type) {
|
|
37
|
+
this.defaultType = type;
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
toArgument() {
|
|
41
|
+
return new import_NamedType.NamedType(this.name);
|
|
42
|
+
}
|
|
43
|
+
write(writer) {
|
|
44
|
+
writer.write(this.name);
|
|
45
|
+
if (this.extendedType) {
|
|
46
|
+
writer.write(" extends ").write(this.extendedType);
|
|
47
|
+
}
|
|
48
|
+
if (this.defaultType) {
|
|
49
|
+
writer.write(" = ").write(this.defaultType);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function genericParameter(name) {
|
|
54
|
+
return new GenericParameter(name);
|
|
55
|
+
}
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
GenericParameter,
|
|
59
|
+
genericParameter
|
|
60
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { NamedType } from "./NamedType";
|
|
2
|
+
class GenericParameter {
|
|
3
|
+
constructor(name) {
|
|
4
|
+
this.name = name;
|
|
5
|
+
}
|
|
6
|
+
extendedType;
|
|
7
|
+
defaultType;
|
|
8
|
+
extends(type) {
|
|
9
|
+
this.extendedType = type;
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
default(type) {
|
|
13
|
+
this.defaultType = type;
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
toArgument() {
|
|
17
|
+
return new NamedType(this.name);
|
|
18
|
+
}
|
|
19
|
+
write(writer) {
|
|
20
|
+
writer.write(this.name);
|
|
21
|
+
if (this.extendedType) {
|
|
22
|
+
writer.write(" extends ").write(this.extendedType);
|
|
23
|
+
}
|
|
24
|
+
if (this.defaultType) {
|
|
25
|
+
writer.write(" = ").write(this.defaultType);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function genericParameter(name) {
|
|
30
|
+
return new GenericParameter(name);
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
GenericParameter,
|
|
34
|
+
genericParameter
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|