@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.
- 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 +16 -0
- package/dist/ConstDeclaration.js +60 -0
- package/dist/ConstDeclaration.mjs +35 -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 +34 -0
- package/dist/ExportFrom.js +106 -0
- package/dist/ExportFrom.mjs +77 -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/FunctionCall.d.ts +9 -0
- package/dist/FunctionCall.js +49 -0
- package/dist/FunctionCall.mjs +24 -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 +38 -0
- package/dist/Import.js +127 -0
- package/dist/Import.mjs +98 -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/NamedValue.d.ts +8 -0
- package/dist/NamedValue.js +43 -0
- package/dist/NamedValue.mjs +18 -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 +15 -0
- package/dist/StringLiteralType.js +58 -0
- package/dist/StringLiteralType.mjs +32 -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/ValueBuilder.d.ts +12 -0
- package/dist/ValueBuilder.js +46 -0
- package/dist/ValueBuilder.mjs +21 -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 +3 -0
- package/dist/helpers.js +31 -0
- package/dist/helpers.mjs +7 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +90 -0
- package/dist/index.mjs +35 -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,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_vitest = require("vitest");
|
|
3
|
+
var import_Class = require("./Class");
|
|
4
|
+
var import_GenericParameter = require("./GenericParameter");
|
|
5
|
+
var import_Method = require("./Method");
|
|
6
|
+
var import_NamedType = require("./NamedType");
|
|
7
|
+
var import_Property = require("./Property");
|
|
8
|
+
var import_stringify = require("./stringify");
|
|
9
|
+
const A = (0, import_NamedType.namedType)("A");
|
|
10
|
+
(0, import_vitest.test)("empty", () => {
|
|
11
|
+
const obj = (0, import_Class.classDeclaration)("MyClass");
|
|
12
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(obj)).toMatchInlineSnapshot(`
|
|
13
|
+
"class MyClass {}
|
|
14
|
+
"
|
|
15
|
+
`);
|
|
16
|
+
});
|
|
17
|
+
(0, import_vitest.test)("with property", () => {
|
|
18
|
+
const obj = (0, import_Class.classDeclaration)("SomeClass").add((0, import_Property.property)("foo", A));
|
|
19
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(obj)).toMatchInlineSnapshot(`
|
|
20
|
+
"class SomeClass {
|
|
21
|
+
foo: A
|
|
22
|
+
}"
|
|
23
|
+
`);
|
|
24
|
+
});
|
|
25
|
+
(0, import_vitest.test)("with method", () => {
|
|
26
|
+
const obj = (0, import_Class.classDeclaration)("MyClass").add((0, import_Method.method)("doThing"));
|
|
27
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(obj)).toMatchInlineSnapshot(`
|
|
28
|
+
"class MyClass {
|
|
29
|
+
doThing(): void
|
|
30
|
+
}"
|
|
31
|
+
`);
|
|
32
|
+
});
|
|
33
|
+
(0, import_vitest.test)("with generic parameter", () => {
|
|
34
|
+
const obj = (0, import_Class.classDeclaration)("SomeClass").addGenericParameter((0, import_GenericParameter.genericParameter)("T").extends((0, import_NamedType.namedType)("U"))).add((0, import_Property.property)("foo", A));
|
|
35
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(obj)).toMatchInlineSnapshot(`
|
|
36
|
+
"class SomeClass<T extends U> {
|
|
37
|
+
foo: A
|
|
38
|
+
}"
|
|
39
|
+
`);
|
|
40
|
+
});
|
|
41
|
+
(0, import_vitest.test)("extending the type", () => {
|
|
42
|
+
const obj = (0, import_Class.classDeclaration)("SomeClass").extends((0, import_NamedType.namedType)("Foo")).add((0, import_Property.property)("foo", A));
|
|
43
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(obj)).toMatchInlineSnapshot(`
|
|
44
|
+
"class SomeClass extends Foo {
|
|
45
|
+
foo: A
|
|
46
|
+
}"
|
|
47
|
+
`);
|
|
48
|
+
});
|
|
49
|
+
(0, import_vitest.test)("extending multiple types", () => {
|
|
50
|
+
const obj = (0, import_Class.classDeclaration)("SomeClass").extends((0, import_NamedType.namedType)("Foo")).extends((0, import_NamedType.namedType)("Bar")).add((0, import_Property.property)("foo", A));
|
|
51
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(obj)).toMatchInlineSnapshot(`
|
|
52
|
+
"class SomeClass extends Foo, Bar {
|
|
53
|
+
foo: A
|
|
54
|
+
}"
|
|
55
|
+
`);
|
|
56
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { classDeclaration } from "./Class";
|
|
3
|
+
import { genericParameter } from "./GenericParameter";
|
|
4
|
+
import { method } from "./Method";
|
|
5
|
+
import { namedType } from "./NamedType";
|
|
6
|
+
import { property } from "./Property";
|
|
7
|
+
import { stringify } from "./stringify";
|
|
8
|
+
const A = namedType("A");
|
|
9
|
+
test("empty", () => {
|
|
10
|
+
const obj = classDeclaration("MyClass");
|
|
11
|
+
expect(stringify(obj)).toMatchInlineSnapshot(`
|
|
12
|
+
"class MyClass {}
|
|
13
|
+
"
|
|
14
|
+
`);
|
|
15
|
+
});
|
|
16
|
+
test("with property", () => {
|
|
17
|
+
const obj = classDeclaration("SomeClass").add(property("foo", A));
|
|
18
|
+
expect(stringify(obj)).toMatchInlineSnapshot(`
|
|
19
|
+
"class SomeClass {
|
|
20
|
+
foo: A
|
|
21
|
+
}"
|
|
22
|
+
`);
|
|
23
|
+
});
|
|
24
|
+
test("with method", () => {
|
|
25
|
+
const obj = classDeclaration("MyClass").add(method("doThing"));
|
|
26
|
+
expect(stringify(obj)).toMatchInlineSnapshot(`
|
|
27
|
+
"class MyClass {
|
|
28
|
+
doThing(): void
|
|
29
|
+
}"
|
|
30
|
+
`);
|
|
31
|
+
});
|
|
32
|
+
test("with generic parameter", () => {
|
|
33
|
+
const obj = classDeclaration("SomeClass").addGenericParameter(genericParameter("T").extends(namedType("U"))).add(property("foo", A));
|
|
34
|
+
expect(stringify(obj)).toMatchInlineSnapshot(`
|
|
35
|
+
"class SomeClass<T extends U> {
|
|
36
|
+
foo: A
|
|
37
|
+
}"
|
|
38
|
+
`);
|
|
39
|
+
});
|
|
40
|
+
test("extending the type", () => {
|
|
41
|
+
const obj = classDeclaration("SomeClass").extends(namedType("Foo")).add(property("foo", A));
|
|
42
|
+
expect(stringify(obj)).toMatchInlineSnapshot(`
|
|
43
|
+
"class SomeClass extends Foo {
|
|
44
|
+
foo: A
|
|
45
|
+
}"
|
|
46
|
+
`);
|
|
47
|
+
});
|
|
48
|
+
test("extending multiple types", () => {
|
|
49
|
+
const obj = classDeclaration("SomeClass").extends(namedType("Foo")).extends(namedType("Bar")).add(property("foo", A));
|
|
50
|
+
expect(stringify(obj)).toMatchInlineSnapshot(`
|
|
51
|
+
"class SomeClass extends Foo, Bar {
|
|
52
|
+
foo: A
|
|
53
|
+
}"
|
|
54
|
+
`);
|
|
55
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BasicBuilder } from './BasicBuilder';
|
|
2
|
+
import { DocComment } from './DocComment';
|
|
3
|
+
import { TypeBuilder } from './TypeBuilder';
|
|
4
|
+
import { ValueBuilder } from './ValueBuilder';
|
|
5
|
+
import { Writer } from './Writer';
|
|
6
|
+
export declare class ConstDeclaration implements BasicBuilder {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly type?: TypeBuilder | undefined;
|
|
9
|
+
private docComment?;
|
|
10
|
+
private value?;
|
|
11
|
+
constructor(name: string, type?: TypeBuilder | undefined);
|
|
12
|
+
setDocComment(docComment: DocComment): this;
|
|
13
|
+
setValue(value: ValueBuilder): this;
|
|
14
|
+
write(writer: Writer): void;
|
|
15
|
+
}
|
|
16
|
+
export declare function constDeclaration(name: string, type?: TypeBuilder): ConstDeclaration;
|
|
@@ -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 ConstDeclaration_exports = {};
|
|
20
|
+
__export(ConstDeclaration_exports, {
|
|
21
|
+
ConstDeclaration: () => ConstDeclaration,
|
|
22
|
+
constDeclaration: () => constDeclaration
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(ConstDeclaration_exports);
|
|
25
|
+
class ConstDeclaration {
|
|
26
|
+
constructor(name, type) {
|
|
27
|
+
this.name = name;
|
|
28
|
+
this.type = type;
|
|
29
|
+
}
|
|
30
|
+
docComment;
|
|
31
|
+
value;
|
|
32
|
+
setDocComment(docComment) {
|
|
33
|
+
this.docComment = docComment;
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
setValue(value) {
|
|
37
|
+
this.value = value;
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
write(writer) {
|
|
41
|
+
if (this.docComment) {
|
|
42
|
+
writer.write(this.docComment);
|
|
43
|
+
}
|
|
44
|
+
writer.write("const ").write(this.name);
|
|
45
|
+
if (this.type) {
|
|
46
|
+
writer.write(": ").write(this.type);
|
|
47
|
+
}
|
|
48
|
+
if (this.value) {
|
|
49
|
+
writer.write(" = ").write(this.value);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function constDeclaration(name, type) {
|
|
54
|
+
return new ConstDeclaration(name, type);
|
|
55
|
+
}
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
ConstDeclaration,
|
|
59
|
+
constDeclaration
|
|
60
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
class ConstDeclaration {
|
|
2
|
+
constructor(name, type) {
|
|
3
|
+
this.name = name;
|
|
4
|
+
this.type = type;
|
|
5
|
+
}
|
|
6
|
+
docComment;
|
|
7
|
+
value;
|
|
8
|
+
setDocComment(docComment) {
|
|
9
|
+
this.docComment = docComment;
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
setValue(value) {
|
|
13
|
+
this.value = value;
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
write(writer) {
|
|
17
|
+
if (this.docComment) {
|
|
18
|
+
writer.write(this.docComment);
|
|
19
|
+
}
|
|
20
|
+
writer.write("const ").write(this.name);
|
|
21
|
+
if (this.type) {
|
|
22
|
+
writer.write(": ").write(this.type);
|
|
23
|
+
}
|
|
24
|
+
if (this.value) {
|
|
25
|
+
writer.write(" = ").write(this.value);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function constDeclaration(name, type) {
|
|
30
|
+
return new ConstDeclaration(name, type);
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
ConstDeclaration,
|
|
34
|
+
constDeclaration
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_vitest = require("vitest");
|
|
3
|
+
var import_ConstDeclaration = require("./ConstDeclaration");
|
|
4
|
+
var import_DocComment = require("./DocComment");
|
|
5
|
+
var import_NamedType = require("./NamedType");
|
|
6
|
+
var import_stringify = require("./stringify");
|
|
7
|
+
const A = (0, import_NamedType.namedType)("A");
|
|
8
|
+
(0, import_vitest.test)("basic", () => {
|
|
9
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)((0, import_ConstDeclaration.constDeclaration)("B", A))).toMatchInlineSnapshot(`"const B: A"`);
|
|
10
|
+
});
|
|
11
|
+
(0, import_vitest.test)("with doc comment", () => {
|
|
12
|
+
const decl = (0, import_ConstDeclaration.constDeclaration)("B", A).setDocComment((0, import_DocComment.docComment)("Some important value"));
|
|
13
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(decl)).toMatchInlineSnapshot(`
|
|
14
|
+
"/**
|
|
15
|
+
* Some important value
|
|
16
|
+
*/
|
|
17
|
+
const B: A"
|
|
18
|
+
`);
|
|
19
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { constDeclaration } from "./ConstDeclaration";
|
|
3
|
+
import { docComment } from "./DocComment";
|
|
4
|
+
import { namedType } from "./NamedType";
|
|
5
|
+
import { stringify } from "./stringify";
|
|
6
|
+
const A = namedType("A");
|
|
7
|
+
test("basic", () => {
|
|
8
|
+
expect(stringify(constDeclaration("B", A))).toMatchInlineSnapshot(`"const B: A"`);
|
|
9
|
+
});
|
|
10
|
+
test("with doc comment", () => {
|
|
11
|
+
const decl = constDeclaration("B", A).setDocComment(docComment("Some important value"));
|
|
12
|
+
expect(stringify(decl)).toMatchInlineSnapshot(`
|
|
13
|
+
"/**
|
|
14
|
+
* Some important value
|
|
15
|
+
*/
|
|
16
|
+
const B: A"
|
|
17
|
+
`);
|
|
18
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BasicBuilder } from './BasicBuilder';
|
|
2
|
+
import { Writer } from './Writer';
|
|
3
|
+
export declare class DocComment implements BasicBuilder {
|
|
4
|
+
readonly lines: string[];
|
|
5
|
+
constructor(startingText?: string);
|
|
6
|
+
addText(text: string): this;
|
|
7
|
+
write(writer: Writer): Writer<undefined>;
|
|
8
|
+
}
|
|
9
|
+
declare function docComment(strings: TemplateStringsArray, ...args: string[]): DocComment;
|
|
10
|
+
declare function docComment(startingText?: string): DocComment;
|
|
11
|
+
export { docComment };
|
|
@@ -0,0 +1,101 @@
|
|
|
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 DocComment_exports = {};
|
|
20
|
+
__export(DocComment_exports, {
|
|
21
|
+
DocComment: () => DocComment,
|
|
22
|
+
docComment: () => docComment
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(DocComment_exports);
|
|
25
|
+
class DocComment {
|
|
26
|
+
lines = [];
|
|
27
|
+
constructor(startingText) {
|
|
28
|
+
if (startingText) {
|
|
29
|
+
this.addText(startingText);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
addText(text) {
|
|
33
|
+
this.lines.push(...text.split("\n"));
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
write(writer) {
|
|
37
|
+
writer.writeLine("/**");
|
|
38
|
+
for (const line of this.lines) {
|
|
39
|
+
writer.writeLine(` * ${line}`);
|
|
40
|
+
}
|
|
41
|
+
writer.writeLine(" */");
|
|
42
|
+
return writer;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function docComment(firstParameter, ...args) {
|
|
46
|
+
if (typeof firstParameter === "string" || typeof firstParameter === "undefined") {
|
|
47
|
+
return new DocComment(firstParameter);
|
|
48
|
+
}
|
|
49
|
+
return docCommentTag(firstParameter, args);
|
|
50
|
+
}
|
|
51
|
+
function docCommentTag(strings, args) {
|
|
52
|
+
const docComment2 = new DocComment();
|
|
53
|
+
const fullText = strings.flatMap((str, i) => {
|
|
54
|
+
if (i < args.length) {
|
|
55
|
+
return [str, args[i]];
|
|
56
|
+
}
|
|
57
|
+
return [str];
|
|
58
|
+
}).join("");
|
|
59
|
+
const lines = trimEmptyLines(fullText.split("\n"));
|
|
60
|
+
if (lines.length === 0) {
|
|
61
|
+
return docComment2;
|
|
62
|
+
}
|
|
63
|
+
const indent = getIndent(lines[0]);
|
|
64
|
+
for (const line of lines) {
|
|
65
|
+
docComment2.addText(line.slice(indent));
|
|
66
|
+
}
|
|
67
|
+
return docComment2;
|
|
68
|
+
}
|
|
69
|
+
function trimEmptyLines(lines) {
|
|
70
|
+
const firstLine = findFirstNonEmptyLine(lines);
|
|
71
|
+
const lastLine = findLastNonEmptyLine(lines);
|
|
72
|
+
if (firstLine === -1 || lastLine === -1) {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
return lines.slice(firstLine, lastLine + 1);
|
|
76
|
+
}
|
|
77
|
+
function findFirstNonEmptyLine(lines) {
|
|
78
|
+
return lines.findIndex((line) => !isEmptyLine(line));
|
|
79
|
+
}
|
|
80
|
+
function findLastNonEmptyLine(lines) {
|
|
81
|
+
let i = lines.length - 1;
|
|
82
|
+
while (i > 0 && isEmptyLine(lines[i])) {
|
|
83
|
+
i--;
|
|
84
|
+
}
|
|
85
|
+
return i;
|
|
86
|
+
}
|
|
87
|
+
function isEmptyLine(line) {
|
|
88
|
+
return line.trim().length === 0;
|
|
89
|
+
}
|
|
90
|
+
function getIndent(line) {
|
|
91
|
+
let indent = 0;
|
|
92
|
+
while (line[indent] === " ") {
|
|
93
|
+
indent++;
|
|
94
|
+
}
|
|
95
|
+
return indent;
|
|
96
|
+
}
|
|
97
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
98
|
+
0 && (module.exports = {
|
|
99
|
+
DocComment,
|
|
100
|
+
docComment
|
|
101
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
class DocComment {
|
|
2
|
+
lines = [];
|
|
3
|
+
constructor(startingText) {
|
|
4
|
+
if (startingText) {
|
|
5
|
+
this.addText(startingText);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
addText(text) {
|
|
9
|
+
this.lines.push(...text.split("\n"));
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
write(writer) {
|
|
13
|
+
writer.writeLine("/**");
|
|
14
|
+
for (const line of this.lines) {
|
|
15
|
+
writer.writeLine(` * ${line}`);
|
|
16
|
+
}
|
|
17
|
+
writer.writeLine(" */");
|
|
18
|
+
return writer;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function docComment(firstParameter, ...args) {
|
|
22
|
+
if (typeof firstParameter === "string" || typeof firstParameter === "undefined") {
|
|
23
|
+
return new DocComment(firstParameter);
|
|
24
|
+
}
|
|
25
|
+
return docCommentTag(firstParameter, args);
|
|
26
|
+
}
|
|
27
|
+
function docCommentTag(strings, args) {
|
|
28
|
+
const docComment2 = new DocComment();
|
|
29
|
+
const fullText = strings.flatMap((str, i) => {
|
|
30
|
+
if (i < args.length) {
|
|
31
|
+
return [str, args[i]];
|
|
32
|
+
}
|
|
33
|
+
return [str];
|
|
34
|
+
}).join("");
|
|
35
|
+
const lines = trimEmptyLines(fullText.split("\n"));
|
|
36
|
+
if (lines.length === 0) {
|
|
37
|
+
return docComment2;
|
|
38
|
+
}
|
|
39
|
+
const indent = getIndent(lines[0]);
|
|
40
|
+
for (const line of lines) {
|
|
41
|
+
docComment2.addText(line.slice(indent));
|
|
42
|
+
}
|
|
43
|
+
return docComment2;
|
|
44
|
+
}
|
|
45
|
+
function trimEmptyLines(lines) {
|
|
46
|
+
const firstLine = findFirstNonEmptyLine(lines);
|
|
47
|
+
const lastLine = findLastNonEmptyLine(lines);
|
|
48
|
+
if (firstLine === -1 || lastLine === -1) {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
return lines.slice(firstLine, lastLine + 1);
|
|
52
|
+
}
|
|
53
|
+
function findFirstNonEmptyLine(lines) {
|
|
54
|
+
return lines.findIndex((line) => !isEmptyLine(line));
|
|
55
|
+
}
|
|
56
|
+
function findLastNonEmptyLine(lines) {
|
|
57
|
+
let i = lines.length - 1;
|
|
58
|
+
while (i > 0 && isEmptyLine(lines[i])) {
|
|
59
|
+
i--;
|
|
60
|
+
}
|
|
61
|
+
return i;
|
|
62
|
+
}
|
|
63
|
+
function isEmptyLine(line) {
|
|
64
|
+
return line.trim().length === 0;
|
|
65
|
+
}
|
|
66
|
+
function getIndent(line) {
|
|
67
|
+
let indent = 0;
|
|
68
|
+
while (line[indent] === " ") {
|
|
69
|
+
indent++;
|
|
70
|
+
}
|
|
71
|
+
return indent;
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
DocComment,
|
|
75
|
+
docComment
|
|
76
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_vitest = require("vitest");
|
|
3
|
+
var import_DocComment = require("./DocComment");
|
|
4
|
+
var import_stringify = require("./stringify");
|
|
5
|
+
(0, import_vitest.test)("empty", () => {
|
|
6
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)((0, import_DocComment.docComment)())).toMatchInlineSnapshot(`
|
|
7
|
+
"/**
|
|
8
|
+
*/
|
|
9
|
+
"
|
|
10
|
+
`);
|
|
11
|
+
});
|
|
12
|
+
(0, import_vitest.test)("one line", () => {
|
|
13
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)((0, import_DocComment.docComment)("I am comment"))).toMatchInlineSnapshot(`
|
|
14
|
+
"/**
|
|
15
|
+
* I am comment
|
|
16
|
+
*/
|
|
17
|
+
"
|
|
18
|
+
`);
|
|
19
|
+
});
|
|
20
|
+
(0, import_vitest.test)("multiline", () => {
|
|
21
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)((0, import_DocComment.docComment)("first\nsecond"))).toMatchInlineSnapshot(`
|
|
22
|
+
"/**
|
|
23
|
+
* first
|
|
24
|
+
* second
|
|
25
|
+
*/
|
|
26
|
+
"
|
|
27
|
+
`);
|
|
28
|
+
});
|
|
29
|
+
(0, import_vitest.test)("multiple addText calls", () => {
|
|
30
|
+
const comment = (0, import_DocComment.docComment)("Line 1").addText("Line 2").addText("Line 3");
|
|
31
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(comment)).toMatchInlineSnapshot(`
|
|
32
|
+
"/**
|
|
33
|
+
* Line 1
|
|
34
|
+
* Line 2
|
|
35
|
+
* Line 3
|
|
36
|
+
*/
|
|
37
|
+
"
|
|
38
|
+
`);
|
|
39
|
+
});
|
|
40
|
+
(0, import_vitest.test)("tagged template - empty", () => {
|
|
41
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(import_DocComment.docComment``)).toMatchInlineSnapshot(`
|
|
42
|
+
"/**
|
|
43
|
+
*/
|
|
44
|
+
"
|
|
45
|
+
`);
|
|
46
|
+
});
|
|
47
|
+
(0, import_vitest.test)("tagged template - spaces only", () => {
|
|
48
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(import_DocComment.docComment` `)).toMatchInlineSnapshot(`
|
|
49
|
+
"/**
|
|
50
|
+
*/
|
|
51
|
+
"
|
|
52
|
+
`);
|
|
53
|
+
});
|
|
54
|
+
(0, import_vitest.test)("tagged template - with content", () => {
|
|
55
|
+
const comment = import_DocComment.docComment`
|
|
56
|
+
This is a multiline comment
|
|
57
|
+
- this line should be indented
|
|
58
|
+
And this should be not
|
|
59
|
+
`;
|
|
60
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(comment)).toMatchInlineSnapshot(`
|
|
61
|
+
"/**
|
|
62
|
+
* This is a multiline comment
|
|
63
|
+
* - this line should be indented
|
|
64
|
+
* And this should be not
|
|
65
|
+
*/
|
|
66
|
+
"
|
|
67
|
+
`);
|
|
68
|
+
});
|
|
69
|
+
(0, import_vitest.test)("tagged template - with substitutions", () => {
|
|
70
|
+
const name = "World";
|
|
71
|
+
const comment = import_DocComment.docComment`
|
|
72
|
+
Hello, ${name}!
|
|
73
|
+
`;
|
|
74
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(comment)).toMatchInlineSnapshot(`
|
|
75
|
+
"/**
|
|
76
|
+
* Hello, World!
|
|
77
|
+
*/
|
|
78
|
+
"
|
|
79
|
+
`);
|
|
80
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { docComment } from "./DocComment";
|
|
3
|
+
import { stringify } from "./stringify";
|
|
4
|
+
test("empty", () => {
|
|
5
|
+
expect(stringify(docComment())).toMatchInlineSnapshot(`
|
|
6
|
+
"/**
|
|
7
|
+
*/
|
|
8
|
+
"
|
|
9
|
+
`);
|
|
10
|
+
});
|
|
11
|
+
test("one line", () => {
|
|
12
|
+
expect(stringify(docComment("I am comment"))).toMatchInlineSnapshot(`
|
|
13
|
+
"/**
|
|
14
|
+
* I am comment
|
|
15
|
+
*/
|
|
16
|
+
"
|
|
17
|
+
`);
|
|
18
|
+
});
|
|
19
|
+
test("multiline", () => {
|
|
20
|
+
expect(stringify(docComment("first\nsecond"))).toMatchInlineSnapshot(`
|
|
21
|
+
"/**
|
|
22
|
+
* first
|
|
23
|
+
* second
|
|
24
|
+
*/
|
|
25
|
+
"
|
|
26
|
+
`);
|
|
27
|
+
});
|
|
28
|
+
test("multiple addText calls", () => {
|
|
29
|
+
const comment = docComment("Line 1").addText("Line 2").addText("Line 3");
|
|
30
|
+
expect(stringify(comment)).toMatchInlineSnapshot(`
|
|
31
|
+
"/**
|
|
32
|
+
* Line 1
|
|
33
|
+
* Line 2
|
|
34
|
+
* Line 3
|
|
35
|
+
*/
|
|
36
|
+
"
|
|
37
|
+
`);
|
|
38
|
+
});
|
|
39
|
+
test("tagged template - empty", () => {
|
|
40
|
+
expect(stringify(docComment``)).toMatchInlineSnapshot(`
|
|
41
|
+
"/**
|
|
42
|
+
*/
|
|
43
|
+
"
|
|
44
|
+
`);
|
|
45
|
+
});
|
|
46
|
+
test("tagged template - spaces only", () => {
|
|
47
|
+
expect(stringify(docComment` `)).toMatchInlineSnapshot(`
|
|
48
|
+
"/**
|
|
49
|
+
*/
|
|
50
|
+
"
|
|
51
|
+
`);
|
|
52
|
+
});
|
|
53
|
+
test("tagged template - with content", () => {
|
|
54
|
+
const comment = docComment`
|
|
55
|
+
This is a multiline comment
|
|
56
|
+
- this line should be indented
|
|
57
|
+
And this should be not
|
|
58
|
+
`;
|
|
59
|
+
expect(stringify(comment)).toMatchInlineSnapshot(`
|
|
60
|
+
"/**
|
|
61
|
+
* This is a multiline comment
|
|
62
|
+
* - this line should be indented
|
|
63
|
+
* And this should be not
|
|
64
|
+
*/
|
|
65
|
+
"
|
|
66
|
+
`);
|
|
67
|
+
});
|
|
68
|
+
test("tagged template - with substitutions", () => {
|
|
69
|
+
const name = "World";
|
|
70
|
+
const comment = docComment`
|
|
71
|
+
Hello, ${name}!
|
|
72
|
+
`;
|
|
73
|
+
expect(stringify(comment)).toMatchInlineSnapshot(`
|
|
74
|
+
"/**
|
|
75
|
+
* Hello, World!
|
|
76
|
+
*/
|
|
77
|
+
"
|
|
78
|
+
`);
|
|
79
|
+
});
|
package/dist/Export.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AnyDeclarationBuilder } from './AnyDeclarationBuilder';
|
|
2
|
+
import { BasicBuilder } from './BasicBuilder';
|
|
3
|
+
import { DocComment } from './DocComment';
|
|
4
|
+
import { Writer } from './Writer';
|
|
5
|
+
export declare class Export<Decl extends AnyDeclarationBuilder> implements BasicBuilder {
|
|
6
|
+
readonly declaration: Decl;
|
|
7
|
+
private docComment?;
|
|
8
|
+
constructor(declaration: Decl);
|
|
9
|
+
setDocComment(docComment: DocComment): this;
|
|
10
|
+
write(writer: Writer): void;
|
|
11
|
+
}
|
|
12
|
+
export declare function moduleExport<Decl extends AnyDeclarationBuilder>(declaration: Decl): Export<Decl>;
|
package/dist/Export.js
ADDED
|
@@ -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 Export_exports = {};
|
|
20
|
+
__export(Export_exports, {
|
|
21
|
+
Export: () => Export,
|
|
22
|
+
moduleExport: () => moduleExport
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(Export_exports);
|
|
25
|
+
class Export {
|
|
26
|
+
constructor(declaration) {
|
|
27
|
+
this.declaration = declaration;
|
|
28
|
+
}
|
|
29
|
+
docComment;
|
|
30
|
+
setDocComment(docComment) {
|
|
31
|
+
this.docComment = docComment;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
write(writer) {
|
|
35
|
+
if (this.docComment) {
|
|
36
|
+
writer.write(this.docComment);
|
|
37
|
+
}
|
|
38
|
+
writer.write("export ").write(this.declaration);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function moduleExport(declaration) {
|
|
42
|
+
return new Export(declaration);
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
Export,
|
|
47
|
+
moduleExport
|
|
48
|
+
});
|