@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,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,8 @@
|
|
|
1
|
+
import { ValueBuilder } from './ValueBuilder';
|
|
2
|
+
import { Writer } from './Writer';
|
|
3
|
+
export declare class NamedValue extends ValueBuilder {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(name: string);
|
|
6
|
+
write(writer: Writer): void;
|
|
7
|
+
}
|
|
8
|
+
export declare function namedValue(name: string): NamedValue;
|
|
@@ -0,0 +1,43 @@
|
|
|
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 NamedValue_exports = {};
|
|
20
|
+
__export(NamedValue_exports, {
|
|
21
|
+
NamedValue: () => NamedValue,
|
|
22
|
+
namedValue: () => namedValue
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(NamedValue_exports);
|
|
25
|
+
var import_ValueBuilder = require("./ValueBuilder");
|
|
26
|
+
class NamedValue extends import_ValueBuilder.ValueBuilder {
|
|
27
|
+
#name;
|
|
28
|
+
constructor(name) {
|
|
29
|
+
super();
|
|
30
|
+
this.#name = name;
|
|
31
|
+
}
|
|
32
|
+
write(writer) {
|
|
33
|
+
writer.write(this.#name);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function namedValue(name) {
|
|
37
|
+
return new NamedValue(name);
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
NamedValue,
|
|
42
|
+
namedValue
|
|
43
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ValueBuilder } from "./ValueBuilder";
|
|
2
|
+
class NamedValue extends ValueBuilder {
|
|
3
|
+
#name;
|
|
4
|
+
constructor(name) {
|
|
5
|
+
super();
|
|
6
|
+
this.#name = name;
|
|
7
|
+
}
|
|
8
|
+
write(writer) {
|
|
9
|
+
writer.write(this.#name);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function namedValue(name) {
|
|
13
|
+
return new NamedValue(name);
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
NamedValue,
|
|
17
|
+
namedValue
|
|
18
|
+
};
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class NamespaceDeclaration {
|
|
2
|
+
constructor(name) {
|
|
3
|
+
this.name = name;
|
|
4
|
+
}
|
|
5
|
+
items = [];
|
|
6
|
+
add(declaration) {
|
|
7
|
+
this.items.push(declaration);
|
|
8
|
+
}
|
|
9
|
+
write(writer) {
|
|
10
|
+
writer.writeLine(`namespace ${this.name} {`).withIndent(() => {
|
|
11
|
+
for (const item of this.items) {
|
|
12
|
+
writer.writeLine(item);
|
|
13
|
+
}
|
|
14
|
+
}).write("}");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function namespace(name) {
|
|
18
|
+
return new NamespaceDeclaration(name);
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
NamespaceDeclaration,
|
|
22
|
+
namespace
|
|
23
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Method } from './Method';
|
|
2
|
+
import { Property } from './Property';
|
|
3
|
+
import { TypeBuilder } from './TypeBuilder';
|
|
4
|
+
import { Writer } from './Writer';
|
|
5
|
+
type ObjectTypeItem = Method | Property;
|
|
6
|
+
export declare class ObjectType extends TypeBuilder {
|
|
7
|
+
needsParenthesisWhenIndexed: boolean;
|
|
8
|
+
private items;
|
|
9
|
+
private inline;
|
|
10
|
+
add(item: ObjectTypeItem): this;
|
|
11
|
+
addMultiple(items: ObjectTypeItem[]): this;
|
|
12
|
+
formatInline(): this;
|
|
13
|
+
write(writer: Writer): void;
|
|
14
|
+
private writeMultiline;
|
|
15
|
+
private writeInline;
|
|
16
|
+
}
|
|
17
|
+
export declare function objectType(): ObjectType;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
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 ObjectType_exports = {};
|
|
20
|
+
__export(ObjectType_exports, {
|
|
21
|
+
ObjectType: () => ObjectType,
|
|
22
|
+
objectType: () => objectType
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(ObjectType_exports);
|
|
25
|
+
var import_TypeBuilder = require("./TypeBuilder");
|
|
26
|
+
class ObjectType extends import_TypeBuilder.TypeBuilder {
|
|
27
|
+
needsParenthesisWhenIndexed = true;
|
|
28
|
+
items = [];
|
|
29
|
+
inline = false;
|
|
30
|
+
add(item) {
|
|
31
|
+
this.items.push(item);
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
addMultiple(items) {
|
|
35
|
+
for (const item of items) {
|
|
36
|
+
this.add(item);
|
|
37
|
+
}
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
formatInline() {
|
|
41
|
+
this.inline = true;
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
write(writer) {
|
|
45
|
+
if (this.items.length === 0) {
|
|
46
|
+
writer.write("{}");
|
|
47
|
+
} else if (this.inline) {
|
|
48
|
+
this.writeInline(writer);
|
|
49
|
+
} else {
|
|
50
|
+
this.writeMultiline(writer);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
writeMultiline(writer) {
|
|
54
|
+
writer.writeLine("{").withIndent(() => {
|
|
55
|
+
for (const item of this.items) {
|
|
56
|
+
writer.writeLine(item);
|
|
57
|
+
}
|
|
58
|
+
}).write("}");
|
|
59
|
+
}
|
|
60
|
+
writeInline(writer) {
|
|
61
|
+
writer.write("{ ").writeJoined(", ", this.items).write(" }");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function objectType() {
|
|
65
|
+
return new ObjectType();
|
|
66
|
+
}
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
ObjectType,
|
|
70
|
+
objectType
|
|
71
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { TypeBuilder } from "./TypeBuilder";
|
|
2
|
+
class ObjectType extends TypeBuilder {
|
|
3
|
+
needsParenthesisWhenIndexed = true;
|
|
4
|
+
items = [];
|
|
5
|
+
inline = false;
|
|
6
|
+
add(item) {
|
|
7
|
+
this.items.push(item);
|
|
8
|
+
return this;
|
|
9
|
+
}
|
|
10
|
+
addMultiple(items) {
|
|
11
|
+
for (const item of items) {
|
|
12
|
+
this.add(item);
|
|
13
|
+
}
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
formatInline() {
|
|
17
|
+
this.inline = true;
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
write(writer) {
|
|
21
|
+
if (this.items.length === 0) {
|
|
22
|
+
writer.write("{}");
|
|
23
|
+
} else if (this.inline) {
|
|
24
|
+
this.writeInline(writer);
|
|
25
|
+
} else {
|
|
26
|
+
this.writeMultiline(writer);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
writeMultiline(writer) {
|
|
30
|
+
writer.writeLine("{").withIndent(() => {
|
|
31
|
+
for (const item of this.items) {
|
|
32
|
+
writer.writeLine(item);
|
|
33
|
+
}
|
|
34
|
+
}).write("}");
|
|
35
|
+
}
|
|
36
|
+
writeInline(writer) {
|
|
37
|
+
writer.write("{ ").writeJoined(", ", this.items).write(" }");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function objectType() {
|
|
41
|
+
return new ObjectType();
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
ObjectType,
|
|
45
|
+
objectType
|
|
46
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_vitest = require("vitest");
|
|
3
|
+
var import_Method = require("./Method");
|
|
4
|
+
var import_NamedType = require("./NamedType");
|
|
5
|
+
var import_ObjectType = require("./ObjectType");
|
|
6
|
+
var import_Property = require("./Property");
|
|
7
|
+
var import_stringify = require("./stringify");
|
|
8
|
+
const A = (0, import_NamedType.namedType)("A");
|
|
9
|
+
(0, import_vitest.test)("empty", () => {
|
|
10
|
+
const obj = (0, import_ObjectType.objectType)();
|
|
11
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(obj)).toMatchInlineSnapshot(`"{}"`);
|
|
12
|
+
});
|
|
13
|
+
(0, import_vitest.test)("with property", () => {
|
|
14
|
+
const obj = (0, import_ObjectType.objectType)().add((0, import_Property.property)("foo", A));
|
|
15
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(obj)).toMatchInlineSnapshot(`
|
|
16
|
+
"{
|
|
17
|
+
foo: A
|
|
18
|
+
}"
|
|
19
|
+
`);
|
|
20
|
+
});
|
|
21
|
+
(0, import_vitest.test)("with method", () => {
|
|
22
|
+
const obj = (0, import_ObjectType.objectType)().add((0, import_Method.method)("doThing"));
|
|
23
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(obj)).toMatchInlineSnapshot(`
|
|
24
|
+
"{
|
|
25
|
+
doThing(): void
|
|
26
|
+
}"
|
|
27
|
+
`);
|
|
28
|
+
});
|
|
29
|
+
(0, import_vitest.test)("inline formatting", () => {
|
|
30
|
+
const obj = (0, import_ObjectType.objectType)().add((0, import_Property.property)("foo", A)).formatInline();
|
|
31
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(obj)).toMatchInlineSnapshot(`"{ foo: A }"`);
|
|
32
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { method } from "./Method";
|
|
3
|
+
import { namedType } from "./NamedType";
|
|
4
|
+
import { objectType } from "./ObjectType";
|
|
5
|
+
import { property } from "./Property";
|
|
6
|
+
import { stringify } from "./stringify";
|
|
7
|
+
const A = namedType("A");
|
|
8
|
+
test("empty", () => {
|
|
9
|
+
const obj = objectType();
|
|
10
|
+
expect(stringify(obj)).toMatchInlineSnapshot(`"{}"`);
|
|
11
|
+
});
|
|
12
|
+
test("with property", () => {
|
|
13
|
+
const obj = objectType().add(property("foo", A));
|
|
14
|
+
expect(stringify(obj)).toMatchInlineSnapshot(`
|
|
15
|
+
"{
|
|
16
|
+
foo: A
|
|
17
|
+
}"
|
|
18
|
+
`);
|
|
19
|
+
});
|
|
20
|
+
test("with method", () => {
|
|
21
|
+
const obj = objectType().add(method("doThing"));
|
|
22
|
+
expect(stringify(obj)).toMatchInlineSnapshot(`
|
|
23
|
+
"{
|
|
24
|
+
doThing(): void
|
|
25
|
+
}"
|
|
26
|
+
`);
|
|
27
|
+
});
|
|
28
|
+
test("inline formatting", () => {
|
|
29
|
+
const obj = objectType().add(property("foo", A)).formatInline();
|
|
30
|
+
expect(stringify(obj)).toMatchInlineSnapshot(`"{ foo: A }"`);
|
|
31
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BasicBuilder } from './BasicBuilder';
|
|
2
|
+
import { TypeBuilder } from './TypeBuilder';
|
|
3
|
+
import { Writer } from './Writer';
|
|
4
|
+
export declare class Parameter implements BasicBuilder {
|
|
5
|
+
private name;
|
|
6
|
+
private type;
|
|
7
|
+
private isOptional;
|
|
8
|
+
constructor(name: string, type: TypeBuilder);
|
|
9
|
+
optional(): this;
|
|
10
|
+
write(writer: Writer): void;
|
|
11
|
+
}
|
|
12
|
+
export declare function parameter(name: string, type: TypeBuilder): Parameter;
|
|
@@ -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 Parameter_exports = {};
|
|
20
|
+
__export(Parameter_exports, {
|
|
21
|
+
Parameter: () => Parameter,
|
|
22
|
+
parameter: () => parameter
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(Parameter_exports);
|
|
25
|
+
class Parameter {
|
|
26
|
+
constructor(name, type) {
|
|
27
|
+
this.name = name;
|
|
28
|
+
this.type = type;
|
|
29
|
+
}
|
|
30
|
+
isOptional = false;
|
|
31
|
+
optional() {
|
|
32
|
+
this.isOptional = true;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
write(writer) {
|
|
36
|
+
writer.write(this.name);
|
|
37
|
+
if (this.isOptional) {
|
|
38
|
+
writer.write("?");
|
|
39
|
+
}
|
|
40
|
+
writer.write(": ").write(this.type);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function parameter(name, type) {
|
|
44
|
+
return new Parameter(name, type);
|
|
45
|
+
}
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
Parameter,
|
|
49
|
+
parameter
|
|
50
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class Parameter {
|
|
2
|
+
constructor(name, type) {
|
|
3
|
+
this.name = name;
|
|
4
|
+
this.type = type;
|
|
5
|
+
}
|
|
6
|
+
isOptional = false;
|
|
7
|
+
optional() {
|
|
8
|
+
this.isOptional = true;
|
|
9
|
+
return this;
|
|
10
|
+
}
|
|
11
|
+
write(writer) {
|
|
12
|
+
writer.write(this.name);
|
|
13
|
+
if (this.isOptional) {
|
|
14
|
+
writer.write("?");
|
|
15
|
+
}
|
|
16
|
+
writer.write(": ").write(this.type);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function parameter(name, type) {
|
|
20
|
+
return new Parameter(name, type);
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
Parameter,
|
|
24
|
+
parameter
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_vitest = require("vitest");
|
|
3
|
+
var import_NamedType = require("./NamedType");
|
|
4
|
+
var import_Parameter = require("./Parameter");
|
|
5
|
+
var import_stringify = require("./stringify");
|
|
6
|
+
const A = (0, import_NamedType.namedType)("A");
|
|
7
|
+
(0, import_vitest.test)("name and type", () => {
|
|
8
|
+
const param = (0, import_Parameter.parameter)("foo", A);
|
|
9
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(param)).toMatchInlineSnapshot(`"foo: A"`);
|
|
10
|
+
});
|
|
11
|
+
(0, import_vitest.test)("optional", () => {
|
|
12
|
+
const param = (0, import_Parameter.parameter)("foo", A).optional();
|
|
13
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(param)).toMatchInlineSnapshot(`"foo?: A"`);
|
|
14
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { namedType } from "./NamedType";
|
|
3
|
+
import { parameter } from "./Parameter";
|
|
4
|
+
import { stringify } from "./stringify";
|
|
5
|
+
const A = namedType("A");
|
|
6
|
+
test("name and type", () => {
|
|
7
|
+
const param = parameter("foo", A);
|
|
8
|
+
expect(stringify(param)).toMatchInlineSnapshot(`"foo: A"`);
|
|
9
|
+
});
|
|
10
|
+
test("optional", () => {
|
|
11
|
+
const param = parameter("foo", A).optional();
|
|
12
|
+
expect(stringify(param)).toMatchInlineSnapshot(`"foo?: A"`);
|
|
13
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TypeBuilder } from './TypeBuilder';
|
|
2
|
+
import { Writer } from './Writer';
|
|
3
|
+
export declare class PrimitiveType extends TypeBuilder {
|
|
4
|
+
private name;
|
|
5
|
+
constructor(name: string);
|
|
6
|
+
write(writer: Writer): void;
|
|
7
|
+
}
|
|
8
|
+
export declare const stringType: PrimitiveType;
|
|
9
|
+
export declare const numberType: PrimitiveType;
|
|
10
|
+
export declare const booleanType: PrimitiveType;
|
|
11
|
+
export declare const nullType: PrimitiveType;
|
|
12
|
+
export declare const undefinedType: PrimitiveType;
|
|
13
|
+
export declare const bigintType: PrimitiveType;
|
|
14
|
+
export declare const unknownType: PrimitiveType;
|
|
15
|
+
export declare const anyType: PrimitiveType;
|
|
16
|
+
export declare const voidType: PrimitiveType;
|
|
17
|
+
export declare const thisType: PrimitiveType;
|
|
18
|
+
export declare const neverType: PrimitiveType;
|