@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,70 @@
|
|
|
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 PrimitiveType_exports = {};
|
|
20
|
+
__export(PrimitiveType_exports, {
|
|
21
|
+
PrimitiveType: () => PrimitiveType,
|
|
22
|
+
anyType: () => anyType,
|
|
23
|
+
bigintType: () => bigintType,
|
|
24
|
+
booleanType: () => booleanType,
|
|
25
|
+
neverType: () => neverType,
|
|
26
|
+
nullType: () => nullType,
|
|
27
|
+
numberType: () => numberType,
|
|
28
|
+
stringType: () => stringType,
|
|
29
|
+
thisType: () => thisType,
|
|
30
|
+
undefinedType: () => undefinedType,
|
|
31
|
+
unknownType: () => unknownType,
|
|
32
|
+
voidType: () => voidType
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(PrimitiveType_exports);
|
|
35
|
+
var import_TypeBuilder = require("./TypeBuilder");
|
|
36
|
+
class PrimitiveType extends import_TypeBuilder.TypeBuilder {
|
|
37
|
+
constructor(name) {
|
|
38
|
+
super();
|
|
39
|
+
this.name = name;
|
|
40
|
+
}
|
|
41
|
+
write(writer) {
|
|
42
|
+
writer.write(this.name);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const stringType = new PrimitiveType("string");
|
|
46
|
+
const numberType = new PrimitiveType("number");
|
|
47
|
+
const booleanType = new PrimitiveType("boolean");
|
|
48
|
+
const nullType = new PrimitiveType("null");
|
|
49
|
+
const undefinedType = new PrimitiveType("undefined");
|
|
50
|
+
const bigintType = new PrimitiveType("bigint");
|
|
51
|
+
const unknownType = new PrimitiveType("unknown");
|
|
52
|
+
const anyType = new PrimitiveType("any");
|
|
53
|
+
const voidType = new PrimitiveType("void");
|
|
54
|
+
const thisType = new PrimitiveType("this");
|
|
55
|
+
const neverType = new PrimitiveType("never");
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
PrimitiveType,
|
|
59
|
+
anyType,
|
|
60
|
+
bigintType,
|
|
61
|
+
booleanType,
|
|
62
|
+
neverType,
|
|
63
|
+
nullType,
|
|
64
|
+
numberType,
|
|
65
|
+
stringType,
|
|
66
|
+
thisType,
|
|
67
|
+
undefinedType,
|
|
68
|
+
unknownType,
|
|
69
|
+
voidType
|
|
70
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { TypeBuilder } from "./TypeBuilder";
|
|
2
|
+
class PrimitiveType extends TypeBuilder {
|
|
3
|
+
constructor(name) {
|
|
4
|
+
super();
|
|
5
|
+
this.name = name;
|
|
6
|
+
}
|
|
7
|
+
write(writer) {
|
|
8
|
+
writer.write(this.name);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const stringType = new PrimitiveType("string");
|
|
12
|
+
const numberType = new PrimitiveType("number");
|
|
13
|
+
const booleanType = new PrimitiveType("boolean");
|
|
14
|
+
const nullType = new PrimitiveType("null");
|
|
15
|
+
const undefinedType = new PrimitiveType("undefined");
|
|
16
|
+
const bigintType = new PrimitiveType("bigint");
|
|
17
|
+
const unknownType = new PrimitiveType("unknown");
|
|
18
|
+
const anyType = new PrimitiveType("any");
|
|
19
|
+
const voidType = new PrimitiveType("void");
|
|
20
|
+
const thisType = new PrimitiveType("this");
|
|
21
|
+
const neverType = new PrimitiveType("never");
|
|
22
|
+
export {
|
|
23
|
+
PrimitiveType,
|
|
24
|
+
anyType,
|
|
25
|
+
bigintType,
|
|
26
|
+
booleanType,
|
|
27
|
+
neverType,
|
|
28
|
+
nullType,
|
|
29
|
+
numberType,
|
|
30
|
+
stringType,
|
|
31
|
+
thisType,
|
|
32
|
+
undefinedType,
|
|
33
|
+
unknownType,
|
|
34
|
+
voidType
|
|
35
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BasicBuilder } from './BasicBuilder';
|
|
2
|
+
import { DocComment } from './DocComment';
|
|
3
|
+
import { TypeBuilder } from './TypeBuilder';
|
|
4
|
+
import { WellKnownSymbol } from './WellKnownSymbol';
|
|
5
|
+
import { Writer } from './Writer';
|
|
6
|
+
export declare class Property implements BasicBuilder {
|
|
7
|
+
private name;
|
|
8
|
+
private type;
|
|
9
|
+
private isOptional;
|
|
10
|
+
private isReadonly;
|
|
11
|
+
private docComment?;
|
|
12
|
+
constructor(name: string | WellKnownSymbol, type: TypeBuilder);
|
|
13
|
+
optional(): this;
|
|
14
|
+
readonly(): this;
|
|
15
|
+
setDocComment(docComment: DocComment): this;
|
|
16
|
+
write(writer: Writer): void;
|
|
17
|
+
}
|
|
18
|
+
export declare function property(name: string | WellKnownSymbol, type: TypeBuilder): Property;
|
package/dist/Property.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 Property_exports = {};
|
|
20
|
+
__export(Property_exports, {
|
|
21
|
+
Property: () => Property,
|
|
22
|
+
property: () => property
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(Property_exports);
|
|
25
|
+
var import_internals = require("@prisma/internals");
|
|
26
|
+
class Property {
|
|
27
|
+
constructor(name, type) {
|
|
28
|
+
this.name = name;
|
|
29
|
+
this.type = type;
|
|
30
|
+
}
|
|
31
|
+
isOptional = false;
|
|
32
|
+
isReadonly = false;
|
|
33
|
+
docComment;
|
|
34
|
+
optional() {
|
|
35
|
+
this.isOptional = true;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
readonly() {
|
|
39
|
+
this.isReadonly = true;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
setDocComment(docComment) {
|
|
43
|
+
this.docComment = docComment;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
write(writer) {
|
|
47
|
+
if (this.docComment) {
|
|
48
|
+
writer.write(this.docComment);
|
|
49
|
+
}
|
|
50
|
+
if (this.isReadonly) {
|
|
51
|
+
writer.write("readonly ");
|
|
52
|
+
}
|
|
53
|
+
if (typeof this.name === "string") {
|
|
54
|
+
if ((0, import_internals.isValidJsIdentifier)(this.name)) {
|
|
55
|
+
writer.write(this.name);
|
|
56
|
+
} else {
|
|
57
|
+
writer.write("[").write(JSON.stringify(this.name)).write("]");
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
writer.write("[").write(this.name).write("]");
|
|
61
|
+
}
|
|
62
|
+
if (this.isOptional) {
|
|
63
|
+
writer.write("?");
|
|
64
|
+
}
|
|
65
|
+
writer.write(": ").write(this.type);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function property(name, type) {
|
|
69
|
+
return new Property(name, type);
|
|
70
|
+
}
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
Property,
|
|
74
|
+
property
|
|
75
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { isValidJsIdentifier } from "@prisma/internals";
|
|
2
|
+
class Property {
|
|
3
|
+
constructor(name, type) {
|
|
4
|
+
this.name = name;
|
|
5
|
+
this.type = type;
|
|
6
|
+
}
|
|
7
|
+
isOptional = false;
|
|
8
|
+
isReadonly = false;
|
|
9
|
+
docComment;
|
|
10
|
+
optional() {
|
|
11
|
+
this.isOptional = true;
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
readonly() {
|
|
15
|
+
this.isReadonly = true;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
setDocComment(docComment) {
|
|
19
|
+
this.docComment = docComment;
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
write(writer) {
|
|
23
|
+
if (this.docComment) {
|
|
24
|
+
writer.write(this.docComment);
|
|
25
|
+
}
|
|
26
|
+
if (this.isReadonly) {
|
|
27
|
+
writer.write("readonly ");
|
|
28
|
+
}
|
|
29
|
+
if (typeof this.name === "string") {
|
|
30
|
+
if (isValidJsIdentifier(this.name)) {
|
|
31
|
+
writer.write(this.name);
|
|
32
|
+
} else {
|
|
33
|
+
writer.write("[").write(JSON.stringify(this.name)).write("]");
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
writer.write("[").write(this.name).write("]");
|
|
37
|
+
}
|
|
38
|
+
if (this.isOptional) {
|
|
39
|
+
writer.write("?");
|
|
40
|
+
}
|
|
41
|
+
writer.write(": ").write(this.type);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function property(name, type) {
|
|
45
|
+
return new Property(name, type);
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
Property,
|
|
49
|
+
property
|
|
50
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_vitest = require("vitest");
|
|
3
|
+
var import_DocComment = require("./DocComment");
|
|
4
|
+
var import_NamedType = require("./NamedType");
|
|
5
|
+
var import_Property = require("./Property");
|
|
6
|
+
var import_stringify = require("./stringify");
|
|
7
|
+
var import_WellKnownSymbol = require("./WellKnownSymbol");
|
|
8
|
+
const A = (0, import_NamedType.namedType)("A");
|
|
9
|
+
(0, import_vitest.test)("name and type", () => {
|
|
10
|
+
const prop = (0, import_Property.property)("foo", A);
|
|
11
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(prop)).toMatchInlineSnapshot(`"foo: A"`);
|
|
12
|
+
});
|
|
13
|
+
(0, import_vitest.test)("invalid identifier", () => {
|
|
14
|
+
const prop = (0, import_Property.property)("this is not a valid JS identifier", A);
|
|
15
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(prop)).toMatchInlineSnapshot(`"["this is not a valid JS identifier"]: A"`);
|
|
16
|
+
});
|
|
17
|
+
(0, import_vitest.test)("well-known symbol", () => {
|
|
18
|
+
const prop = (0, import_Property.property)(import_WellKnownSymbol.toStringTag, A);
|
|
19
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(prop)).toMatchInlineSnapshot(`"[Symbol.toStringTag]: A"`);
|
|
20
|
+
});
|
|
21
|
+
(0, import_vitest.test)("optional", () => {
|
|
22
|
+
const prop = (0, import_Property.property)("foo", A).optional();
|
|
23
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(prop)).toMatchInlineSnapshot(`"foo?: A"`);
|
|
24
|
+
});
|
|
25
|
+
(0, import_vitest.test)("readonly", () => {
|
|
26
|
+
const prop = (0, import_Property.property)("foo", A).readonly();
|
|
27
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(prop)).toMatchInlineSnapshot(`"readonly foo: A"`);
|
|
28
|
+
});
|
|
29
|
+
(0, import_vitest.test)("with doc comment", () => {
|
|
30
|
+
const prop = (0, import_Property.property)("foo", A).setDocComment((0, import_DocComment.docComment)("This is foo"));
|
|
31
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(prop)).toMatchInlineSnapshot(`
|
|
32
|
+
"/**
|
|
33
|
+
* This is foo
|
|
34
|
+
*/
|
|
35
|
+
foo: A"
|
|
36
|
+
`);
|
|
37
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { docComment } from "./DocComment";
|
|
3
|
+
import { namedType } from "./NamedType";
|
|
4
|
+
import { property } from "./Property";
|
|
5
|
+
import { stringify } from "./stringify";
|
|
6
|
+
import { toStringTag } from "./WellKnownSymbol";
|
|
7
|
+
const A = namedType("A");
|
|
8
|
+
test("name and type", () => {
|
|
9
|
+
const prop = property("foo", A);
|
|
10
|
+
expect(stringify(prop)).toMatchInlineSnapshot(`"foo: A"`);
|
|
11
|
+
});
|
|
12
|
+
test("invalid identifier", () => {
|
|
13
|
+
const prop = property("this is not a valid JS identifier", A);
|
|
14
|
+
expect(stringify(prop)).toMatchInlineSnapshot(`"["this is not a valid JS identifier"]: A"`);
|
|
15
|
+
});
|
|
16
|
+
test("well-known symbol", () => {
|
|
17
|
+
const prop = property(toStringTag, A);
|
|
18
|
+
expect(stringify(prop)).toMatchInlineSnapshot(`"[Symbol.toStringTag]: A"`);
|
|
19
|
+
});
|
|
20
|
+
test("optional", () => {
|
|
21
|
+
const prop = property("foo", A).optional();
|
|
22
|
+
expect(stringify(prop)).toMatchInlineSnapshot(`"foo?: A"`);
|
|
23
|
+
});
|
|
24
|
+
test("readonly", () => {
|
|
25
|
+
const prop = property("foo", A).readonly();
|
|
26
|
+
expect(stringify(prop)).toMatchInlineSnapshot(`"readonly foo: A"`);
|
|
27
|
+
});
|
|
28
|
+
test("with doc comment", () => {
|
|
29
|
+
const prop = property("foo", A).setDocComment(docComment("This is foo"));
|
|
30
|
+
expect(stringify(prop)).toMatchInlineSnapshot(`
|
|
31
|
+
"/**
|
|
32
|
+
* This is foo
|
|
33
|
+
*/
|
|
34
|
+
foo: A"
|
|
35
|
+
`);
|
|
36
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TypeBuilder } from './TypeBuilder';
|
|
2
|
+
import { ValueBuilder } from './ValueBuilder';
|
|
3
|
+
import { Writer } from './Writer';
|
|
4
|
+
export declare class StringLiteralType extends TypeBuilder {
|
|
5
|
+
readonly content: string;
|
|
6
|
+
constructor(content: string);
|
|
7
|
+
write(writer: Writer): void;
|
|
8
|
+
asValue(): StringLiteralValue;
|
|
9
|
+
}
|
|
10
|
+
export declare class StringLiteralValue extends ValueBuilder {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(type: StringLiteralType);
|
|
13
|
+
write(writer: Writer): void;
|
|
14
|
+
}
|
|
15
|
+
export declare function stringLiteral(content: string): StringLiteralType;
|
|
@@ -0,0 +1,58 @@
|
|
|
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 StringLiteralType_exports = {};
|
|
20
|
+
__export(StringLiteralType_exports, {
|
|
21
|
+
StringLiteralType: () => StringLiteralType,
|
|
22
|
+
StringLiteralValue: () => StringLiteralValue,
|
|
23
|
+
stringLiteral: () => stringLiteral
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(StringLiteralType_exports);
|
|
26
|
+
var import_TypeBuilder = require("./TypeBuilder");
|
|
27
|
+
var import_ValueBuilder = require("./ValueBuilder");
|
|
28
|
+
class StringLiteralType extends import_TypeBuilder.TypeBuilder {
|
|
29
|
+
constructor(content) {
|
|
30
|
+
super();
|
|
31
|
+
this.content = content;
|
|
32
|
+
}
|
|
33
|
+
write(writer) {
|
|
34
|
+
writer.write(JSON.stringify(this.content));
|
|
35
|
+
}
|
|
36
|
+
asValue() {
|
|
37
|
+
return new StringLiteralValue(this);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
class StringLiteralValue extends import_ValueBuilder.ValueBuilder {
|
|
41
|
+
#type;
|
|
42
|
+
constructor(type) {
|
|
43
|
+
super();
|
|
44
|
+
this.#type = type;
|
|
45
|
+
}
|
|
46
|
+
write(writer) {
|
|
47
|
+
writer.write(this.#type);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function stringLiteral(content) {
|
|
51
|
+
return new StringLiteralType(content);
|
|
52
|
+
}
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
StringLiteralType,
|
|
56
|
+
StringLiteralValue,
|
|
57
|
+
stringLiteral
|
|
58
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { TypeBuilder } from "./TypeBuilder";
|
|
2
|
+
import { ValueBuilder } from "./ValueBuilder";
|
|
3
|
+
class StringLiteralType extends TypeBuilder {
|
|
4
|
+
constructor(content) {
|
|
5
|
+
super();
|
|
6
|
+
this.content = content;
|
|
7
|
+
}
|
|
8
|
+
write(writer) {
|
|
9
|
+
writer.write(JSON.stringify(this.content));
|
|
10
|
+
}
|
|
11
|
+
asValue() {
|
|
12
|
+
return new StringLiteralValue(this);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
class StringLiteralValue extends ValueBuilder {
|
|
16
|
+
#type;
|
|
17
|
+
constructor(type) {
|
|
18
|
+
super();
|
|
19
|
+
this.#type = type;
|
|
20
|
+
}
|
|
21
|
+
write(writer) {
|
|
22
|
+
writer.write(this.#type);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function stringLiteral(content) {
|
|
26
|
+
return new StringLiteralType(content);
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
StringLiteralType,
|
|
30
|
+
StringLiteralValue,
|
|
31
|
+
stringLiteral
|
|
32
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BasicBuilder } from './BasicBuilder';
|
|
2
|
+
import { TypeBuilder } from './TypeBuilder';
|
|
3
|
+
import { Writer } from './Writer';
|
|
4
|
+
export declare class TupleItem implements BasicBuilder {
|
|
5
|
+
readonly type: TypeBuilder;
|
|
6
|
+
private name;
|
|
7
|
+
constructor(type: TypeBuilder);
|
|
8
|
+
setName(name: string): this;
|
|
9
|
+
write(writer: Writer<undefined>): void;
|
|
10
|
+
}
|
|
11
|
+
export declare class TupleType extends TypeBuilder {
|
|
12
|
+
readonly items: TupleItem[];
|
|
13
|
+
add(item: TypeBuilder | TupleItem): this;
|
|
14
|
+
write(writer: Writer): void;
|
|
15
|
+
}
|
|
16
|
+
export declare function tupleType(): TupleType;
|
|
17
|
+
export declare function tupleItem(type: TypeBuilder): TupleItem;
|
|
@@ -0,0 +1,69 @@
|
|
|
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 TupleType_exports = {};
|
|
20
|
+
__export(TupleType_exports, {
|
|
21
|
+
TupleItem: () => TupleItem,
|
|
22
|
+
TupleType: () => TupleType,
|
|
23
|
+
tupleItem: () => tupleItem,
|
|
24
|
+
tupleType: () => tupleType
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(TupleType_exports);
|
|
27
|
+
var import_TypeBuilder = require("./TypeBuilder");
|
|
28
|
+
class TupleItem {
|
|
29
|
+
constructor(type) {
|
|
30
|
+
this.type = type;
|
|
31
|
+
}
|
|
32
|
+
name;
|
|
33
|
+
setName(name) {
|
|
34
|
+
this.name = name;
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
write(writer) {
|
|
38
|
+
if (this.name) {
|
|
39
|
+
writer.write(this.name).write(": ");
|
|
40
|
+
}
|
|
41
|
+
writer.write(this.type);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
class TupleType extends import_TypeBuilder.TypeBuilder {
|
|
45
|
+
items = [];
|
|
46
|
+
add(item) {
|
|
47
|
+
if (item instanceof import_TypeBuilder.TypeBuilder) {
|
|
48
|
+
item = new TupleItem(item);
|
|
49
|
+
}
|
|
50
|
+
this.items.push(item);
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
write(writer) {
|
|
54
|
+
writer.write("[").writeJoined(", ", this.items).write("]");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function tupleType() {
|
|
58
|
+
return new TupleType();
|
|
59
|
+
}
|
|
60
|
+
function tupleItem(type) {
|
|
61
|
+
return new TupleItem(type);
|
|
62
|
+
}
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
TupleItem,
|
|
66
|
+
TupleType,
|
|
67
|
+
tupleItem,
|
|
68
|
+
tupleType
|
|
69
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { TypeBuilder } from "./TypeBuilder";
|
|
2
|
+
class TupleItem {
|
|
3
|
+
constructor(type) {
|
|
4
|
+
this.type = type;
|
|
5
|
+
}
|
|
6
|
+
name;
|
|
7
|
+
setName(name) {
|
|
8
|
+
this.name = name;
|
|
9
|
+
return this;
|
|
10
|
+
}
|
|
11
|
+
write(writer) {
|
|
12
|
+
if (this.name) {
|
|
13
|
+
writer.write(this.name).write(": ");
|
|
14
|
+
}
|
|
15
|
+
writer.write(this.type);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
class TupleType extends TypeBuilder {
|
|
19
|
+
items = [];
|
|
20
|
+
add(item) {
|
|
21
|
+
if (item instanceof TypeBuilder) {
|
|
22
|
+
item = new TupleItem(item);
|
|
23
|
+
}
|
|
24
|
+
this.items.push(item);
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
write(writer) {
|
|
28
|
+
writer.write("[").writeJoined(", ", this.items).write("]");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function tupleType() {
|
|
32
|
+
return new TupleType();
|
|
33
|
+
}
|
|
34
|
+
function tupleItem(type) {
|
|
35
|
+
return new TupleItem(type);
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
TupleItem,
|
|
39
|
+
TupleType,
|
|
40
|
+
tupleItem,
|
|
41
|
+
tupleType
|
|
42
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_vitest = require("vitest");
|
|
3
|
+
var import_NamedType = require("./NamedType");
|
|
4
|
+
var import_stringify = require("./stringify");
|
|
5
|
+
var import_TupleType = require("./TupleType");
|
|
6
|
+
(0, import_vitest.test)("empty", () => {
|
|
7
|
+
const tuple = (0, import_TupleType.tupleType)();
|
|
8
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(tuple)).toMatchInlineSnapshot(`"[]"`);
|
|
9
|
+
});
|
|
10
|
+
(0, import_vitest.test)("one item", () => {
|
|
11
|
+
const tuple = (0, import_TupleType.tupleType)().add((0, import_NamedType.namedType)("A"));
|
|
12
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(tuple)).toMatchInlineSnapshot(`"[A]"`);
|
|
13
|
+
});
|
|
14
|
+
(0, import_vitest.test)("with named item", () => {
|
|
15
|
+
const tuple = (0, import_TupleType.tupleType)().add((0, import_TupleType.tupleItem)((0, import_NamedType.namedType)("A")).setName("foo"));
|
|
16
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(tuple)).toMatchInlineSnapshot(`"[foo: A]"`);
|
|
17
|
+
});
|
|
18
|
+
(0, import_vitest.test)("multiple items", () => {
|
|
19
|
+
const tuple = (0, import_TupleType.tupleType)().add((0, import_NamedType.namedType)("A")).add((0, import_NamedType.namedType)("B")).add((0, import_NamedType.namedType)("C"));
|
|
20
|
+
(0, import_vitest.expect)((0, import_stringify.stringify)(tuple)).toMatchInlineSnapshot(`"[A, B, C]"`);
|
|
21
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { namedType } from "./NamedType";
|
|
3
|
+
import { stringify } from "./stringify";
|
|
4
|
+
import { tupleItem, tupleType } from "./TupleType";
|
|
5
|
+
test("empty", () => {
|
|
6
|
+
const tuple = tupleType();
|
|
7
|
+
expect(stringify(tuple)).toMatchInlineSnapshot(`"[]"`);
|
|
8
|
+
});
|
|
9
|
+
test("one item", () => {
|
|
10
|
+
const tuple = tupleType().add(namedType("A"));
|
|
11
|
+
expect(stringify(tuple)).toMatchInlineSnapshot(`"[A]"`);
|
|
12
|
+
});
|
|
13
|
+
test("with named item", () => {
|
|
14
|
+
const tuple = tupleType().add(tupleItem(namedType("A")).setName("foo"));
|
|
15
|
+
expect(stringify(tuple)).toMatchInlineSnapshot(`"[foo: A]"`);
|
|
16
|
+
});
|
|
17
|
+
test("multiple items", () => {
|
|
18
|
+
const tuple = tupleType().add(namedType("A")).add(namedType("B")).add(namedType("C"));
|
|
19
|
+
expect(stringify(tuple)).toMatchInlineSnapshot(`"[A, B, C]"`);
|
|
20
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BasicBuilder } from './BasicBuilder';
|
|
2
|
+
import type { KeyType } from './KeyType';
|
|
3
|
+
import { Writer } from './Writer';
|
|
4
|
+
export declare abstract class TypeBuilder implements BasicBuilder {
|
|
5
|
+
needsParenthesisWhenIndexed: boolean;
|
|
6
|
+
needsParenthesisInKeyof: boolean;
|
|
7
|
+
needsParenthesisInUnion: boolean;
|
|
8
|
+
abstract write(writer: Writer): void;
|
|
9
|
+
subKey(key: string): KeyType;
|
|
10
|
+
writeIndexed(writer: Writer): void;
|
|
11
|
+
}
|
|
@@ -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 TypeBuilder_exports = {};
|
|
20
|
+
__export(TypeBuilder_exports, {
|
|
21
|
+
TypeBuilder: () => TypeBuilder
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(TypeBuilder_exports);
|
|
24
|
+
class TypeBuilder {
|
|
25
|
+
// TODO(@SevInf): this should be replaced with precedence system that would
|
|
26
|
+
// automatically add parenthesis where they are needed
|
|
27
|
+
needsParenthesisWhenIndexed = false;
|
|
28
|
+
needsParenthesisInKeyof = false;
|
|
29
|
+
needsParenthesisInUnion = false;
|
|
30
|
+
subKey(key) {
|
|
31
|
+
const { KeyType } = require("./KeyType");
|
|
32
|
+
return new KeyType(this, key);
|
|
33
|
+
}
|
|
34
|
+
writeIndexed(writer) {
|
|
35
|
+
if (this.needsParenthesisWhenIndexed) {
|
|
36
|
+
writer.write("(");
|
|
37
|
+
}
|
|
38
|
+
writer.write(this);
|
|
39
|
+
if (this.needsParenthesisWhenIndexed) {
|
|
40
|
+
writer.write(")");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
TypeBuilder
|
|
47
|
+
});
|