@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
package/dist/KeyType.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TypeBuilder } from "./TypeBuilder";
|
|
2
|
+
class KeyType extends TypeBuilder {
|
|
3
|
+
constructor(baseType, key) {
|
|
4
|
+
super();
|
|
5
|
+
this.baseType = baseType;
|
|
6
|
+
this.key = key;
|
|
7
|
+
}
|
|
8
|
+
write(writer) {
|
|
9
|
+
this.baseType.writeIndexed(writer);
|
|
10
|
+
writer.write("[").write(`"${this.key}"`).write("]");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function keyType(baseType, key) {
|
|
14
|
+
return new KeyType(baseType, key);
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
KeyType,
|
|
18
|
+
keyType
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_vitest = require("vitest");
|
|
3
|
+
var import_ArrayType = require("./ArrayType");
|
|
4
|
+
var import_FunctionType = require("./FunctionType");
|
|
5
|
+
var import_KeyType = require("./KeyType");
|
|
6
|
+
var import_NamedType = require("./NamedType");
|
|
7
|
+
var import_ObjectType = require("./ObjectType");
|
|
8
|
+
var import_stringify = require("./stringify");
|
|
9
|
+
var import_UnionType = require("./UnionType");
|
|
10
|
+
const A = (0, import_NamedType.namedType)("A");
|
|
11
|
+
const B = (0, import_NamedType.namedType)("B");
|
|
12
|
+
const C = (0, import_NamedType.namedType)("C");
|
|
13
|
+
(0, import_vitest.test)("simple only", () => {
|
|
14
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyType.keyType)(A, "foo"))).toMatchInlineSnapshot(`"A["foo"]"`);
|
|
15
|
+
});
|
|
16
|
+
(0, import_vitest.test)("with object type", () => {
|
|
17
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyType.keyType)((0, import_ObjectType.objectType)(), "toString"))).toMatchInlineSnapshot(`"({})["toString"]"`);
|
|
18
|
+
});
|
|
19
|
+
(0, import_vitest.test)("with array type", () => {
|
|
20
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyType.keyType)((0, import_ArrayType.array)(A), "length"))).toMatchInlineSnapshot(`"A[]["length"]"`);
|
|
21
|
+
});
|
|
22
|
+
(0, import_vitest.test)("with function type", () => {
|
|
23
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyType.keyType)((0, import_FunctionType.functionType)(), "length"))).toMatchInlineSnapshot(`"(() => void)["length"]"`);
|
|
24
|
+
});
|
|
25
|
+
(0, import_vitest.test)("with union type", () => {
|
|
26
|
+
const union = (0, import_UnionType.unionType)(A).addVariant(B).addVariant(C);
|
|
27
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyType.keyType)(union, "foo"))).toMatchInlineSnapshot(`"(A | B | C)["foo"]"`);
|
|
28
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { array } from "./ArrayType";
|
|
3
|
+
import { functionType } from "./FunctionType";
|
|
4
|
+
import { keyType } from "./KeyType";
|
|
5
|
+
import { namedType } from "./NamedType";
|
|
6
|
+
import { objectType } from "./ObjectType";
|
|
7
|
+
import { stringify } from "./stringify";
|
|
8
|
+
import { unionType } from "./UnionType";
|
|
9
|
+
const A = namedType("A");
|
|
10
|
+
const B = namedType("B");
|
|
11
|
+
const C = namedType("C");
|
|
12
|
+
test("simple only", () => {
|
|
13
|
+
expect(stringify(keyType(A, "foo"))).toMatchInlineSnapshot(`"A["foo"]"`);
|
|
14
|
+
});
|
|
15
|
+
test("with object type", () => {
|
|
16
|
+
expect(stringify(keyType(objectType(), "toString"))).toMatchInlineSnapshot(`"({})["toString"]"`);
|
|
17
|
+
});
|
|
18
|
+
test("with array type", () => {
|
|
19
|
+
expect(stringify(keyType(array(A), "length"))).toMatchInlineSnapshot(`"A[]["length"]"`);
|
|
20
|
+
});
|
|
21
|
+
test("with function type", () => {
|
|
22
|
+
expect(stringify(keyType(functionType(), "length"))).toMatchInlineSnapshot(`"(() => void)["length"]"`);
|
|
23
|
+
});
|
|
24
|
+
test("with union type", () => {
|
|
25
|
+
const union = unionType(A).addVariant(B).addVariant(C);
|
|
26
|
+
expect(stringify(keyType(union, "foo"))).toMatchInlineSnapshot(`"(A | B | C)["foo"]"`);
|
|
27
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TypeBuilder } from './TypeBuilder';
|
|
2
|
+
import { Writer } from './Writer';
|
|
3
|
+
export declare class KeyofType extends TypeBuilder {
|
|
4
|
+
baseType: TypeBuilder;
|
|
5
|
+
constructor(baseType: TypeBuilder);
|
|
6
|
+
write(writer: Writer): void;
|
|
7
|
+
}
|
|
8
|
+
export declare function keyOfType(baseType: TypeBuilder): KeyofType;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var KeyofType_exports = {};
|
|
20
|
+
__export(KeyofType_exports, {
|
|
21
|
+
KeyofType: () => KeyofType,
|
|
22
|
+
keyOfType: () => keyOfType
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(KeyofType_exports);
|
|
25
|
+
var import_TypeBuilder = require("./TypeBuilder");
|
|
26
|
+
class KeyofType extends import_TypeBuilder.TypeBuilder {
|
|
27
|
+
constructor(baseType) {
|
|
28
|
+
super();
|
|
29
|
+
this.baseType = baseType;
|
|
30
|
+
}
|
|
31
|
+
write(writer) {
|
|
32
|
+
writer.write(`keyof `);
|
|
33
|
+
if (this.baseType.needsParenthesisInKeyof) {
|
|
34
|
+
writer.write("(").write(this.baseType).write(")");
|
|
35
|
+
} else {
|
|
36
|
+
writer.write(this.baseType);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function keyOfType(baseType) {
|
|
41
|
+
return new KeyofType(baseType);
|
|
42
|
+
}
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
KeyofType,
|
|
46
|
+
keyOfType
|
|
47
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TypeBuilder } from "./TypeBuilder";
|
|
2
|
+
class KeyofType extends TypeBuilder {
|
|
3
|
+
constructor(baseType) {
|
|
4
|
+
super();
|
|
5
|
+
this.baseType = baseType;
|
|
6
|
+
}
|
|
7
|
+
write(writer) {
|
|
8
|
+
writer.write(`keyof `);
|
|
9
|
+
if (this.baseType.needsParenthesisInKeyof) {
|
|
10
|
+
writer.write("(").write(this.baseType).write(")");
|
|
11
|
+
} else {
|
|
12
|
+
writer.write(this.baseType);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function keyOfType(baseType) {
|
|
17
|
+
return new KeyofType(baseType);
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
KeyofType,
|
|
21
|
+
keyOfType
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_vitest = require("vitest");
|
|
3
|
+
var import_ArrayType = require("./ArrayType");
|
|
4
|
+
var import_FunctionType = require("./FunctionType");
|
|
5
|
+
var import_KeyofType = require("./KeyofType");
|
|
6
|
+
var import_NamedType = require("./NamedType");
|
|
7
|
+
var import_ObjectType = require("./ObjectType");
|
|
8
|
+
var import_stringify = require("./stringify");
|
|
9
|
+
var import_UnionType = require("./UnionType");
|
|
10
|
+
const A = (0, import_NamedType.namedType)("A");
|
|
11
|
+
const B = (0, import_NamedType.namedType)("B");
|
|
12
|
+
const C = (0, import_NamedType.namedType)("C");
|
|
13
|
+
(0, import_vitest.test)("simple only", () => {
|
|
14
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyofType.keyOfType)(A))).toMatchInlineSnapshot(`"keyof A"`);
|
|
15
|
+
});
|
|
16
|
+
(0, import_vitest.test)("with object type", () => {
|
|
17
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyofType.keyOfType)((0, import_ObjectType.objectType)()))).toMatchInlineSnapshot(`"keyof {}"`);
|
|
18
|
+
});
|
|
19
|
+
(0, import_vitest.test)("with array type", () => {
|
|
20
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyofType.keyOfType)((0, import_ArrayType.array)(A)))).toMatchInlineSnapshot(`"keyof A[]"`);
|
|
21
|
+
});
|
|
22
|
+
(0, import_vitest.test)("with function type", () => {
|
|
23
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyofType.keyOfType)((0, import_FunctionType.functionType)()))).toMatchInlineSnapshot(`"keyof (() => void)"`);
|
|
24
|
+
});
|
|
25
|
+
(0, import_vitest.test)("with union type", () => {
|
|
26
|
+
const union = (0, import_UnionType.unionType)(A).addVariant(B).addVariant(C);
|
|
27
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)((0, import_KeyofType.keyOfType)(union))).toMatchInlineSnapshot(`"keyof (A | B | C)"`);
|
|
28
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { array } from "./ArrayType";
|
|
3
|
+
import { functionType } from "./FunctionType";
|
|
4
|
+
import { keyOfType } from "./KeyofType";
|
|
5
|
+
import { namedType } from "./NamedType";
|
|
6
|
+
import { objectType } from "./ObjectType";
|
|
7
|
+
import { stringify } from "./stringify";
|
|
8
|
+
import { unionType } from "./UnionType";
|
|
9
|
+
const A = namedType("A");
|
|
10
|
+
const B = namedType("B");
|
|
11
|
+
const C = namedType("C");
|
|
12
|
+
test("simple only", () => {
|
|
13
|
+
expect(stringify(keyOfType(A))).toMatchInlineSnapshot(`"keyof A"`);
|
|
14
|
+
});
|
|
15
|
+
test("with object type", () => {
|
|
16
|
+
expect(stringify(keyOfType(objectType()))).toMatchInlineSnapshot(`"keyof {}"`);
|
|
17
|
+
});
|
|
18
|
+
test("with array type", () => {
|
|
19
|
+
expect(stringify(keyOfType(array(A)))).toMatchInlineSnapshot(`"keyof A[]"`);
|
|
20
|
+
});
|
|
21
|
+
test("with function type", () => {
|
|
22
|
+
expect(stringify(keyOfType(functionType()))).toMatchInlineSnapshot(`"keyof (() => void)"`);
|
|
23
|
+
});
|
|
24
|
+
test("with union type", () => {
|
|
25
|
+
const union = unionType(A).addVariant(B).addVariant(C);
|
|
26
|
+
expect(stringify(keyOfType(union))).toMatchInlineSnapshot(`"keyof (A | B | C)"`);
|
|
27
|
+
});
|
package/dist/Method.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BasicBuilder } from './BasicBuilder';
|
|
2
|
+
import { DocComment } from './DocComment';
|
|
3
|
+
import { GenericParameter } from './GenericParameter';
|
|
4
|
+
import { Parameter } from './Parameter';
|
|
5
|
+
import { TypeBuilder } from './TypeBuilder';
|
|
6
|
+
import { Writer } from './Writer';
|
|
7
|
+
export declare class Method implements BasicBuilder {
|
|
8
|
+
private name;
|
|
9
|
+
private docComment?;
|
|
10
|
+
private returnType;
|
|
11
|
+
private parameters;
|
|
12
|
+
private genericParameters;
|
|
13
|
+
constructor(name: string);
|
|
14
|
+
setDocComment(docComment: DocComment): this;
|
|
15
|
+
setReturnType(returnType: TypeBuilder): this;
|
|
16
|
+
addParameter(param: Parameter): this;
|
|
17
|
+
addGenericParameter(param: GenericParameter): this;
|
|
18
|
+
write(writer: Writer): void;
|
|
19
|
+
}
|
|
20
|
+
export declare function method(name: string): Method;
|
package/dist/Method.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var Method_exports = {};
|
|
20
|
+
__export(Method_exports, {
|
|
21
|
+
Method: () => Method,
|
|
22
|
+
method: () => method
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(Method_exports);
|
|
25
|
+
var import_PrimitiveType = require("./PrimitiveType");
|
|
26
|
+
class Method {
|
|
27
|
+
constructor(name) {
|
|
28
|
+
this.name = name;
|
|
29
|
+
}
|
|
30
|
+
docComment;
|
|
31
|
+
returnType = import_PrimitiveType.voidType;
|
|
32
|
+
parameters = [];
|
|
33
|
+
genericParameters = [];
|
|
34
|
+
setDocComment(docComment) {
|
|
35
|
+
this.docComment = docComment;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
setReturnType(returnType) {
|
|
39
|
+
this.returnType = returnType;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
addParameter(param) {
|
|
43
|
+
this.parameters.push(param);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
addGenericParameter(param) {
|
|
47
|
+
this.genericParameters.push(param);
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
write(writer) {
|
|
51
|
+
if (this.docComment) {
|
|
52
|
+
writer.write(this.docComment);
|
|
53
|
+
}
|
|
54
|
+
writer.write(this.name);
|
|
55
|
+
if (this.genericParameters.length > 0) {
|
|
56
|
+
writer.write("<").writeJoined(", ", this.genericParameters).write(">");
|
|
57
|
+
}
|
|
58
|
+
writer.write("(");
|
|
59
|
+
if (this.parameters.length > 0) {
|
|
60
|
+
writer.writeJoined(", ", this.parameters);
|
|
61
|
+
}
|
|
62
|
+
writer.write(")");
|
|
63
|
+
if (this.name !== "constructor") {
|
|
64
|
+
writer.write(": ").write(this.returnType);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function method(name) {
|
|
69
|
+
return new Method(name);
|
|
70
|
+
}
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
Method,
|
|
74
|
+
method
|
|
75
|
+
});
|
package/dist/Method.mjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { voidType } from "./PrimitiveType";
|
|
2
|
+
class Method {
|
|
3
|
+
constructor(name) {
|
|
4
|
+
this.name = name;
|
|
5
|
+
}
|
|
6
|
+
docComment;
|
|
7
|
+
returnType = voidType;
|
|
8
|
+
parameters = [];
|
|
9
|
+
genericParameters = [];
|
|
10
|
+
setDocComment(docComment) {
|
|
11
|
+
this.docComment = docComment;
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
setReturnType(returnType) {
|
|
15
|
+
this.returnType = returnType;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
addParameter(param) {
|
|
19
|
+
this.parameters.push(param);
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
addGenericParameter(param) {
|
|
23
|
+
this.genericParameters.push(param);
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
write(writer) {
|
|
27
|
+
if (this.docComment) {
|
|
28
|
+
writer.write(this.docComment);
|
|
29
|
+
}
|
|
30
|
+
writer.write(this.name);
|
|
31
|
+
if (this.genericParameters.length > 0) {
|
|
32
|
+
writer.write("<").writeJoined(", ", this.genericParameters).write(">");
|
|
33
|
+
}
|
|
34
|
+
writer.write("(");
|
|
35
|
+
if (this.parameters.length > 0) {
|
|
36
|
+
writer.writeJoined(", ", this.parameters);
|
|
37
|
+
}
|
|
38
|
+
writer.write(")");
|
|
39
|
+
if (this.name !== "constructor") {
|
|
40
|
+
writer.write(": ").write(this.returnType);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function method(name) {
|
|
45
|
+
return new Method(name);
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
Method,
|
|
49
|
+
method
|
|
50
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_vitest = require("vitest");
|
|
3
|
+
var import_DocComment = require("./DocComment");
|
|
4
|
+
var import_GenericParameter = require("./GenericParameter");
|
|
5
|
+
var import_Method = require("./Method");
|
|
6
|
+
var import_NamedType = require("./NamedType");
|
|
7
|
+
var import_Parameter = require("./Parameter");
|
|
8
|
+
var import_stringify = require("./stringify");
|
|
9
|
+
const A = (0, import_NamedType.namedType)("A");
|
|
10
|
+
const B = (0, import_NamedType.namedType)("B");
|
|
11
|
+
(0, import_vitest.test)("name only", () => {
|
|
12
|
+
const m = (0, import_Method.method)("doThings");
|
|
13
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(m)).toMatchInlineSnapshot(`"doThings(): void"`);
|
|
14
|
+
});
|
|
15
|
+
(0, import_vitest.test)("with return type", () => {
|
|
16
|
+
const m = (0, import_Method.method)("doThings").setReturnType(A);
|
|
17
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(m)).toMatchInlineSnapshot(`"doThings(): A"`);
|
|
18
|
+
});
|
|
19
|
+
(0, import_vitest.test)("with doc comment", () => {
|
|
20
|
+
const m = (0, import_Method.method)("doThings").setDocComment((0, import_DocComment.docComment)("Does things"));
|
|
21
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(m)).toMatchInlineSnapshot(`
|
|
22
|
+
"/**
|
|
23
|
+
* Does things
|
|
24
|
+
*/
|
|
25
|
+
doThings(): void"
|
|
26
|
+
`);
|
|
27
|
+
});
|
|
28
|
+
(0, import_vitest.test)("with parameter", () => {
|
|
29
|
+
const m = (0, import_Method.method)("doThings").addParameter((0, import_Parameter.parameter)("foo", A));
|
|
30
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(m)).toMatchInlineSnapshot(`"doThings(foo: A): void"`);
|
|
31
|
+
});
|
|
32
|
+
(0, import_vitest.test)("with multiple parameters", () => {
|
|
33
|
+
const m = (0, import_Method.method)("doThings").addParameter((0, import_Parameter.parameter)("foo", A)).addParameter((0, import_Parameter.parameter)("foo", B));
|
|
34
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(m)).toMatchInlineSnapshot(`"doThings(foo: A, foo: B): void"`);
|
|
35
|
+
});
|
|
36
|
+
(0, import_vitest.test)("with generic parameter", () => {
|
|
37
|
+
const m = (0, import_Method.method)("doThings").addGenericParameter((0, import_GenericParameter.genericParameter)("T"));
|
|
38
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(m)).toMatchInlineSnapshot(`"doThings<T>(): void"`);
|
|
39
|
+
});
|
|
40
|
+
(0, import_vitest.test)("with multiple generic parameters", () => {
|
|
41
|
+
const m = (0, import_Method.method)("doThings").addGenericParameter((0, import_GenericParameter.genericParameter)("T")).addGenericParameter((0, import_GenericParameter.genericParameter)("U"));
|
|
42
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(m)).toMatchInlineSnapshot(`"doThings<T, U>(): void"`);
|
|
43
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { docComment } from "./DocComment";
|
|
3
|
+
import { genericParameter } from "./GenericParameter";
|
|
4
|
+
import { method } from "./Method";
|
|
5
|
+
import { namedType } from "./NamedType";
|
|
6
|
+
import { parameter } from "./Parameter";
|
|
7
|
+
import { stringify } from "./stringify";
|
|
8
|
+
const A = namedType("A");
|
|
9
|
+
const B = namedType("B");
|
|
10
|
+
test("name only", () => {
|
|
11
|
+
const m = method("doThings");
|
|
12
|
+
expect(stringify(m)).toMatchInlineSnapshot(`"doThings(): void"`);
|
|
13
|
+
});
|
|
14
|
+
test("with return type", () => {
|
|
15
|
+
const m = method("doThings").setReturnType(A);
|
|
16
|
+
expect(stringify(m)).toMatchInlineSnapshot(`"doThings(): A"`);
|
|
17
|
+
});
|
|
18
|
+
test("with doc comment", () => {
|
|
19
|
+
const m = method("doThings").setDocComment(docComment("Does things"));
|
|
20
|
+
expect(stringify(m)).toMatchInlineSnapshot(`
|
|
21
|
+
"/**
|
|
22
|
+
* Does things
|
|
23
|
+
*/
|
|
24
|
+
doThings(): void"
|
|
25
|
+
`);
|
|
26
|
+
});
|
|
27
|
+
test("with parameter", () => {
|
|
28
|
+
const m = method("doThings").addParameter(parameter("foo", A));
|
|
29
|
+
expect(stringify(m)).toMatchInlineSnapshot(`"doThings(foo: A): void"`);
|
|
30
|
+
});
|
|
31
|
+
test("with multiple parameters", () => {
|
|
32
|
+
const m = method("doThings").addParameter(parameter("foo", A)).addParameter(parameter("foo", B));
|
|
33
|
+
expect(stringify(m)).toMatchInlineSnapshot(`"doThings(foo: A, foo: B): void"`);
|
|
34
|
+
});
|
|
35
|
+
test("with generic parameter", () => {
|
|
36
|
+
const m = method("doThings").addGenericParameter(genericParameter("T"));
|
|
37
|
+
expect(stringify(m)).toMatchInlineSnapshot(`"doThings<T>(): void"`);
|
|
38
|
+
});
|
|
39
|
+
test("with multiple generic parameters", () => {
|
|
40
|
+
const m = method("doThings").addGenericParameter(genericParameter("T")).addGenericParameter(genericParameter("U"));
|
|
41
|
+
expect(stringify(m)).toMatchInlineSnapshot(`"doThings<T, U>(): void"`);
|
|
42
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TypeBuilder } from './TypeBuilder';
|
|
2
|
+
import { Writer } from './Writer';
|
|
3
|
+
export declare class NamedType extends TypeBuilder {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly genericArguments: TypeBuilder[];
|
|
6
|
+
constructor(name: string);
|
|
7
|
+
addGenericArgument(type: TypeBuilder): this;
|
|
8
|
+
write(writer: Writer): void;
|
|
9
|
+
}
|
|
10
|
+
export declare function namedType(name: string): NamedType;
|
|
@@ -0,0 +1,50 @@
|
|
|
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 NamedType_exports = {};
|
|
20
|
+
__export(NamedType_exports, {
|
|
21
|
+
NamedType: () => NamedType,
|
|
22
|
+
namedType: () => namedType
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(NamedType_exports);
|
|
25
|
+
var import_TypeBuilder = require("./TypeBuilder");
|
|
26
|
+
class NamedType extends import_TypeBuilder.TypeBuilder {
|
|
27
|
+
constructor(name) {
|
|
28
|
+
super();
|
|
29
|
+
this.name = name;
|
|
30
|
+
}
|
|
31
|
+
genericArguments = [];
|
|
32
|
+
addGenericArgument(type) {
|
|
33
|
+
this.genericArguments.push(type);
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
write(writer) {
|
|
37
|
+
writer.write(this.name);
|
|
38
|
+
if (this.genericArguments.length > 0) {
|
|
39
|
+
writer.write("<").writeJoined(", ", this.genericArguments).write(">");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function namedType(name) {
|
|
44
|
+
return new NamedType(name);
|
|
45
|
+
}
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
NamedType,
|
|
49
|
+
namedType
|
|
50
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TypeBuilder } from "./TypeBuilder";
|
|
2
|
+
class NamedType extends TypeBuilder {
|
|
3
|
+
constructor(name) {
|
|
4
|
+
super();
|
|
5
|
+
this.name = name;
|
|
6
|
+
}
|
|
7
|
+
genericArguments = [];
|
|
8
|
+
addGenericArgument(type) {
|
|
9
|
+
this.genericArguments.push(type);
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
write(writer) {
|
|
13
|
+
writer.write(this.name);
|
|
14
|
+
if (this.genericArguments.length > 0) {
|
|
15
|
+
writer.write("<").writeJoined(", ", this.genericArguments).write(">");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function namedType(name) {
|
|
20
|
+
return new NamedType(name);
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
NamedType,
|
|
24
|
+
namedType
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_vitest = require("vitest");
|
|
3
|
+
var import_NamedType = require("./NamedType");
|
|
4
|
+
var import_stringify = require("./stringify");
|
|
5
|
+
(0, import_vitest.test)("name only", () => {
|
|
6
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)((0, import_NamedType.namedType)("MyType"))).toMatchInlineSnapshot(`"MyType"`);
|
|
7
|
+
});
|
|
8
|
+
(0, import_vitest.test)("with generic argument", () => {
|
|
9
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)((0, import_NamedType.namedType)("MyType").addGenericArgument((0, import_NamedType.namedType)("Foo")))).toMatchInlineSnapshot(`"MyType<Foo>"`);
|
|
10
|
+
});
|
|
11
|
+
(0, import_vitest.test)("with multiple generic arguments", () => {
|
|
12
|
+
(0, import_vitest.expect)(
|
|
13
|
+
(0, import_stringify.stringify)((0, import_NamedType.namedType)("MyType").addGenericArgument((0, import_NamedType.namedType)("Foo")).addGenericArgument((0, import_NamedType.namedType)("Bar")))
|
|
14
|
+
).toMatchInlineSnapshot(`"MyType<Foo, Bar>"`);
|
|
15
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { namedType } from "./NamedType";
|
|
3
|
+
import { stringify } from "./stringify";
|
|
4
|
+
test("name only", () => {
|
|
5
|
+
expect(stringify(namedType("MyType"))).toMatchInlineSnapshot(`"MyType"`);
|
|
6
|
+
});
|
|
7
|
+
test("with generic argument", () => {
|
|
8
|
+
expect(stringify(namedType("MyType").addGenericArgument(namedType("Foo")))).toMatchInlineSnapshot(`"MyType<Foo>"`);
|
|
9
|
+
});
|
|
10
|
+
test("with multiple generic arguments", () => {
|
|
11
|
+
expect(
|
|
12
|
+
stringify(namedType("MyType").addGenericArgument(namedType("Foo")).addGenericArgument(namedType("Bar")))
|
|
13
|
+
).toMatchInlineSnapshot(`"MyType<Foo, Bar>"`);
|
|
14
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AnyDeclarationBuilder } from './AnyDeclarationBuilder';
|
|
2
|
+
import { BasicBuilder } from './BasicBuilder';
|
|
3
|
+
import { Export } from './Export';
|
|
4
|
+
import { Writer } from './Writer';
|
|
5
|
+
export type NamespaceItem = AnyDeclarationBuilder | Export<AnyDeclarationBuilder>;
|
|
6
|
+
export declare class NamespaceDeclaration implements BasicBuilder {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
private items;
|
|
9
|
+
constructor(name: string);
|
|
10
|
+
add(declaration: NamespaceItem): void;
|
|
11
|
+
write(writer: Writer<undefined>): void;
|
|
12
|
+
}
|
|
13
|
+
export declare function namespace(name: string): NamespaceDeclaration;
|
|
@@ -0,0 +1,48 @@
|
|
|
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 NamespaceDeclaration_exports = {};
|
|
20
|
+
__export(NamespaceDeclaration_exports, {
|
|
21
|
+
NamespaceDeclaration: () => NamespaceDeclaration,
|
|
22
|
+
namespace: () => namespace
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(NamespaceDeclaration_exports);
|
|
25
|
+
class NamespaceDeclaration {
|
|
26
|
+
constructor(name) {
|
|
27
|
+
this.name = name;
|
|
28
|
+
}
|
|
29
|
+
items = [];
|
|
30
|
+
add(declaration) {
|
|
31
|
+
this.items.push(declaration);
|
|
32
|
+
}
|
|
33
|
+
write(writer) {
|
|
34
|
+
writer.writeLine(`namespace ${this.name} {`).withIndent(() => {
|
|
35
|
+
for (const item of this.items) {
|
|
36
|
+
writer.writeLine(item);
|
|
37
|
+
}
|
|
38
|
+
}).write("}");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function namespace(name) {
|
|
42
|
+
return new NamespaceDeclaration(name);
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
NamespaceDeclaration,
|
|
47
|
+
namespace
|
|
48
|
+
});
|