@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
package/dist/Writer.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
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 Writer_exports = {};
|
|
20
|
+
__export(Writer_exports, {
|
|
21
|
+
INDENT_SIZE: () => INDENT_SIZE,
|
|
22
|
+
Writer: () => Writer
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(Writer_exports);
|
|
25
|
+
const INDENT_SIZE = 2;
|
|
26
|
+
class Writer {
|
|
27
|
+
constructor(startingIndent = 0, context) {
|
|
28
|
+
this.context = context;
|
|
29
|
+
this.currentIndent = startingIndent;
|
|
30
|
+
}
|
|
31
|
+
lines = [];
|
|
32
|
+
currentLine = "";
|
|
33
|
+
currentIndent = 0;
|
|
34
|
+
marginSymbol;
|
|
35
|
+
afterNextNewLineCallback;
|
|
36
|
+
/**
|
|
37
|
+
* Adds provided value to the current line. Does not end the line.
|
|
38
|
+
*
|
|
39
|
+
* @param value
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
write(value) {
|
|
43
|
+
if (typeof value === "string") {
|
|
44
|
+
this.currentLine += value;
|
|
45
|
+
} else {
|
|
46
|
+
value.write(this);
|
|
47
|
+
}
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Adds several `values` to the current line, separated by `separator`. Both values and separator
|
|
52
|
+
* can also be `Builder` instances for more advanced formatting.
|
|
53
|
+
*
|
|
54
|
+
* @param separator
|
|
55
|
+
* @param values
|
|
56
|
+
* @param writeItem allow to customize how individual item is written
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
writeJoined(separator, values, writeItem = (item, w) => w.write(item)) {
|
|
60
|
+
const last = values.length - 1;
|
|
61
|
+
for (let i = 0; i < values.length; i++) {
|
|
62
|
+
writeItem(values[i], this);
|
|
63
|
+
if (i !== last) {
|
|
64
|
+
this.write(separator);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Adds a string to current line, flushes current line and starts a new line.
|
|
71
|
+
* @param line
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
74
|
+
writeLine(line) {
|
|
75
|
+
return this.write(line).newLine();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Flushes current line and starts a new line. New line starts at previously configured indentation level
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
newLine() {
|
|
82
|
+
this.lines.push(this.indentedCurrentLine());
|
|
83
|
+
this.currentLine = "";
|
|
84
|
+
this.marginSymbol = void 0;
|
|
85
|
+
const afterNextNewLineCallback = this.afterNextNewLineCallback;
|
|
86
|
+
this.afterNextNewLineCallback = void 0;
|
|
87
|
+
afterNextNewLineCallback?.();
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Increases indentation level by 1, calls provided callback and then decreases indentation again.
|
|
92
|
+
* Could be used for writing indented blocks of text:
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* writer
|
|
97
|
+
* .writeLine('{')
|
|
98
|
+
* .withIndent(() => {
|
|
99
|
+
* writer.writeLine('foo: 123');
|
|
100
|
+
* writer.writeLine('bar: 456');
|
|
101
|
+
* })
|
|
102
|
+
* .writeLine('}')
|
|
103
|
+
* ```
|
|
104
|
+
* @param callback
|
|
105
|
+
* @returns
|
|
106
|
+
*/
|
|
107
|
+
withIndent(callback) {
|
|
108
|
+
this.indent();
|
|
109
|
+
callback(this);
|
|
110
|
+
this.unindent();
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Calls provided callback next time when new line is started.
|
|
115
|
+
* Callback is called after old line have already been flushed and a new
|
|
116
|
+
* line have been started. Can be used for adding "between the lines" decorations,
|
|
117
|
+
* such as underlines.
|
|
118
|
+
*
|
|
119
|
+
* @param callback
|
|
120
|
+
* @returns
|
|
121
|
+
*/
|
|
122
|
+
afterNextNewline(callback) {
|
|
123
|
+
this.afterNextNewLineCallback = callback;
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Increases indentation level of the current line by 1
|
|
128
|
+
* @returns
|
|
129
|
+
*/
|
|
130
|
+
indent() {
|
|
131
|
+
this.currentIndent++;
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Decreases indentation level of the current line by 1, if it is possible
|
|
136
|
+
* @returns
|
|
137
|
+
*/
|
|
138
|
+
unindent() {
|
|
139
|
+
if (this.currentIndent > 0) {
|
|
140
|
+
this.currentIndent--;
|
|
141
|
+
}
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Adds a symbol, that will replace the first character of the current line (including indentation)
|
|
146
|
+
* when it is flushed. Can be used for adding markers to the line.
|
|
147
|
+
*
|
|
148
|
+
* Note: if indentation level of the line is 0, it will replace the first actually printed character
|
|
149
|
+
* of the line. Use with caution.
|
|
150
|
+
* @param symbol
|
|
151
|
+
* @returns
|
|
152
|
+
*/
|
|
153
|
+
addMarginSymbol(symbol) {
|
|
154
|
+
this.marginSymbol = symbol;
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
toString() {
|
|
158
|
+
return this.lines.concat(this.indentedCurrentLine()).join("\n");
|
|
159
|
+
}
|
|
160
|
+
getCurrentLineLength() {
|
|
161
|
+
return this.currentLine.length;
|
|
162
|
+
}
|
|
163
|
+
indentedCurrentLine() {
|
|
164
|
+
const line = this.currentLine.padStart(this.currentLine.length + INDENT_SIZE * this.currentIndent);
|
|
165
|
+
if (this.marginSymbol) {
|
|
166
|
+
return this.marginSymbol + line.slice(1);
|
|
167
|
+
}
|
|
168
|
+
return line;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
172
|
+
0 && (module.exports = {
|
|
173
|
+
INDENT_SIZE,
|
|
174
|
+
Writer
|
|
175
|
+
});
|
package/dist/Writer.mjs
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
const INDENT_SIZE = 2;
|
|
2
|
+
class Writer {
|
|
3
|
+
constructor(startingIndent = 0, context) {
|
|
4
|
+
this.context = context;
|
|
5
|
+
this.currentIndent = startingIndent;
|
|
6
|
+
}
|
|
7
|
+
lines = [];
|
|
8
|
+
currentLine = "";
|
|
9
|
+
currentIndent = 0;
|
|
10
|
+
marginSymbol;
|
|
11
|
+
afterNextNewLineCallback;
|
|
12
|
+
/**
|
|
13
|
+
* Adds provided value to the current line. Does not end the line.
|
|
14
|
+
*
|
|
15
|
+
* @param value
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
write(value) {
|
|
19
|
+
if (typeof value === "string") {
|
|
20
|
+
this.currentLine += value;
|
|
21
|
+
} else {
|
|
22
|
+
value.write(this);
|
|
23
|
+
}
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Adds several `values` to the current line, separated by `separator`. Both values and separator
|
|
28
|
+
* can also be `Builder` instances for more advanced formatting.
|
|
29
|
+
*
|
|
30
|
+
* @param separator
|
|
31
|
+
* @param values
|
|
32
|
+
* @param writeItem allow to customize how individual item is written
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
writeJoined(separator, values, writeItem = (item, w) => w.write(item)) {
|
|
36
|
+
const last = values.length - 1;
|
|
37
|
+
for (let i = 0; i < values.length; i++) {
|
|
38
|
+
writeItem(values[i], this);
|
|
39
|
+
if (i !== last) {
|
|
40
|
+
this.write(separator);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Adds a string to current line, flushes current line and starts a new line.
|
|
47
|
+
* @param line
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
writeLine(line) {
|
|
51
|
+
return this.write(line).newLine();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Flushes current line and starts a new line. New line starts at previously configured indentation level
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
newLine() {
|
|
58
|
+
this.lines.push(this.indentedCurrentLine());
|
|
59
|
+
this.currentLine = "";
|
|
60
|
+
this.marginSymbol = void 0;
|
|
61
|
+
const afterNextNewLineCallback = this.afterNextNewLineCallback;
|
|
62
|
+
this.afterNextNewLineCallback = void 0;
|
|
63
|
+
afterNextNewLineCallback?.();
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Increases indentation level by 1, calls provided callback and then decreases indentation again.
|
|
68
|
+
* Could be used for writing indented blocks of text:
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* writer
|
|
73
|
+
* .writeLine('{')
|
|
74
|
+
* .withIndent(() => {
|
|
75
|
+
* writer.writeLine('foo: 123');
|
|
76
|
+
* writer.writeLine('bar: 456');
|
|
77
|
+
* })
|
|
78
|
+
* .writeLine('}')
|
|
79
|
+
* ```
|
|
80
|
+
* @param callback
|
|
81
|
+
* @returns
|
|
82
|
+
*/
|
|
83
|
+
withIndent(callback) {
|
|
84
|
+
this.indent();
|
|
85
|
+
callback(this);
|
|
86
|
+
this.unindent();
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Calls provided callback next time when new line is started.
|
|
91
|
+
* Callback is called after old line have already been flushed and a new
|
|
92
|
+
* line have been started. Can be used for adding "between the lines" decorations,
|
|
93
|
+
* such as underlines.
|
|
94
|
+
*
|
|
95
|
+
* @param callback
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
afterNextNewline(callback) {
|
|
99
|
+
this.afterNextNewLineCallback = callback;
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Increases indentation level of the current line by 1
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
indent() {
|
|
107
|
+
this.currentIndent++;
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Decreases indentation level of the current line by 1, if it is possible
|
|
112
|
+
* @returns
|
|
113
|
+
*/
|
|
114
|
+
unindent() {
|
|
115
|
+
if (this.currentIndent > 0) {
|
|
116
|
+
this.currentIndent--;
|
|
117
|
+
}
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Adds a symbol, that will replace the first character of the current line (including indentation)
|
|
122
|
+
* when it is flushed. Can be used for adding markers to the line.
|
|
123
|
+
*
|
|
124
|
+
* Note: if indentation level of the line is 0, it will replace the first actually printed character
|
|
125
|
+
* of the line. Use with caution.
|
|
126
|
+
* @param symbol
|
|
127
|
+
* @returns
|
|
128
|
+
*/
|
|
129
|
+
addMarginSymbol(symbol) {
|
|
130
|
+
this.marginSymbol = symbol;
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
toString() {
|
|
134
|
+
return this.lines.concat(this.indentedCurrentLine()).join("\n");
|
|
135
|
+
}
|
|
136
|
+
getCurrentLineLength() {
|
|
137
|
+
return this.currentLine.length;
|
|
138
|
+
}
|
|
139
|
+
indentedCurrentLine() {
|
|
140
|
+
const line = this.currentLine.padStart(this.currentLine.length + INDENT_SIZE * this.currentIndent);
|
|
141
|
+
if (this.marginSymbol) {
|
|
142
|
+
return this.marginSymbol + line.slice(1);
|
|
143
|
+
}
|
|
144
|
+
return line;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
export {
|
|
148
|
+
INDENT_SIZE,
|
|
149
|
+
Writer
|
|
150
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_vitest = require("vitest");
|
|
3
|
+
var import_Writer = require("./Writer");
|
|
4
|
+
(0, import_vitest.test)("write string", () => {
|
|
5
|
+
const writer = new import_Writer.Writer(0, void 0);
|
|
6
|
+
writer.write("A").write("B").write("C");
|
|
7
|
+
(0, import_vitest.expect)(writer.toString()).toBe("ABC");
|
|
8
|
+
});
|
|
9
|
+
(0, import_vitest.test)("write builder", () => {
|
|
10
|
+
const builder = {
|
|
11
|
+
write(writer2) {
|
|
12
|
+
writer2.write("hello from builder");
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const writer = new import_Writer.Writer(0, void 0);
|
|
16
|
+
writer.write(builder);
|
|
17
|
+
(0, import_vitest.expect)(writer.toString()).toBe("hello from builder");
|
|
18
|
+
});
|
|
19
|
+
(0, import_vitest.test)("newLine", () => {
|
|
20
|
+
const writer = new import_Writer.Writer(0, void 0);
|
|
21
|
+
writer.newLine();
|
|
22
|
+
(0, import_vitest.expect)(writer.toString()).toBe("\n");
|
|
23
|
+
});
|
|
24
|
+
(0, import_vitest.test)("writeLine", () => {
|
|
25
|
+
const writer = new import_Writer.Writer(0, void 0);
|
|
26
|
+
writer.writeLine("A").writeLine("B").writeLine("C");
|
|
27
|
+
(0, import_vitest.expect)(writer.toString()).toBe("A\nB\nC\n");
|
|
28
|
+
});
|
|
29
|
+
(0, import_vitest.test)("writeJoined with strings", () => {
|
|
30
|
+
const writer = new import_Writer.Writer(0, void 0);
|
|
31
|
+
writer.writeJoined(", ", ["A", "B", "C"]);
|
|
32
|
+
(0, import_vitest.expect)(writer.toString()).toBe("A, B, C");
|
|
33
|
+
});
|
|
34
|
+
(0, import_vitest.test)("writeJoined with builder values", () => {
|
|
35
|
+
const writer = new import_Writer.Writer(0, void 0);
|
|
36
|
+
const builder = {
|
|
37
|
+
write(writer2) {
|
|
38
|
+
writer2.write("builder");
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
writer.writeJoined(", ", [builder, builder, builder]);
|
|
42
|
+
(0, import_vitest.expect)(writer.toString()).toBe("builder, builder, builder");
|
|
43
|
+
});
|
|
44
|
+
(0, import_vitest.test)("writeJoined with builder separator", () => {
|
|
45
|
+
const writer = new import_Writer.Writer(0, void 0);
|
|
46
|
+
const separator = {
|
|
47
|
+
write(writer2) {
|
|
48
|
+
writer2.write("|");
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
writer.writeJoined(separator, ["A", "B", "C"]);
|
|
52
|
+
(0, import_vitest.expect)(writer.toString()).toBe("A|B|C");
|
|
53
|
+
});
|
|
54
|
+
(0, import_vitest.test)("writeJoined empty", () => {
|
|
55
|
+
const writer = new import_Writer.Writer(0, void 0);
|
|
56
|
+
writer.writeJoined(", ", []);
|
|
57
|
+
(0, import_vitest.expect)(writer.toString()).toBe("");
|
|
58
|
+
});
|
|
59
|
+
(0, import_vitest.test)("indent", () => {
|
|
60
|
+
const writer = new import_Writer.Writer(0, void 0);
|
|
61
|
+
writer.indent().write("A");
|
|
62
|
+
(0, import_vitest.expect)(writer.toString()).toBe(" A");
|
|
63
|
+
});
|
|
64
|
+
(0, import_vitest.test)("indent + unindent", () => {
|
|
65
|
+
const writer = new import_Writer.Writer(0, void 0);
|
|
66
|
+
writer.writeLine("A").indent().writeLine("B").unindent().writeLine("C");
|
|
67
|
+
(0, import_vitest.expect)(writer.toString()).toBe("A\n B\nC\n");
|
|
68
|
+
});
|
|
69
|
+
(0, import_vitest.test)("unindent beyond 0", () => {
|
|
70
|
+
const writer = new import_Writer.Writer(0, void 0);
|
|
71
|
+
writer.unindent().unindent().write("A");
|
|
72
|
+
(0, import_vitest.expect)(writer.toString()).toBe("A");
|
|
73
|
+
});
|
|
74
|
+
(0, import_vitest.test)("withIndent", () => {
|
|
75
|
+
const writer = new import_Writer.Writer(0, void 0);
|
|
76
|
+
writer.writeLine("A").withIndent(() => writer.writeLine("B")).writeLine("C");
|
|
77
|
+
(0, import_vitest.expect)(writer.toString()).toBe("A\n B\nC\n");
|
|
78
|
+
});
|
|
79
|
+
(0, import_vitest.test)("after next newline callback", () => {
|
|
80
|
+
const writer = new import_Writer.Writer(0, void 0);
|
|
81
|
+
writer.afterNextNewline(() => {
|
|
82
|
+
writer.writeLine("---");
|
|
83
|
+
});
|
|
84
|
+
writer.writeLine("foo");
|
|
85
|
+
writer.writeLine("bar");
|
|
86
|
+
(0, import_vitest.expect)(writer.toString()).toBe("foo\n---\nbar\n");
|
|
87
|
+
});
|
|
88
|
+
(0, import_vitest.test)("margin symbol", () => {
|
|
89
|
+
const writer = new import_Writer.Writer(0, void 0);
|
|
90
|
+
writer.writeLine("{").withIndent(() => {
|
|
91
|
+
writer.addMarginSymbol("+").writeLine("foo").writeLine("bar");
|
|
92
|
+
}).writeLine("}");
|
|
93
|
+
(0, import_vitest.expect)(writer.toString()).toMatchInlineSnapshot(`
|
|
94
|
+
"{
|
|
95
|
+
+ foo
|
|
96
|
+
bar
|
|
97
|
+
}
|
|
98
|
+
"
|
|
99
|
+
`);
|
|
100
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { Writer } from "./Writer";
|
|
3
|
+
test("write string", () => {
|
|
4
|
+
const writer = new Writer(0, void 0);
|
|
5
|
+
writer.write("A").write("B").write("C");
|
|
6
|
+
expect(writer.toString()).toBe("ABC");
|
|
7
|
+
});
|
|
8
|
+
test("write builder", () => {
|
|
9
|
+
const builder = {
|
|
10
|
+
write(writer2) {
|
|
11
|
+
writer2.write("hello from builder");
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const writer = new Writer(0, void 0);
|
|
15
|
+
writer.write(builder);
|
|
16
|
+
expect(writer.toString()).toBe("hello from builder");
|
|
17
|
+
});
|
|
18
|
+
test("newLine", () => {
|
|
19
|
+
const writer = new Writer(0, void 0);
|
|
20
|
+
writer.newLine();
|
|
21
|
+
expect(writer.toString()).toBe("\n");
|
|
22
|
+
});
|
|
23
|
+
test("writeLine", () => {
|
|
24
|
+
const writer = new Writer(0, void 0);
|
|
25
|
+
writer.writeLine("A").writeLine("B").writeLine("C");
|
|
26
|
+
expect(writer.toString()).toBe("A\nB\nC\n");
|
|
27
|
+
});
|
|
28
|
+
test("writeJoined with strings", () => {
|
|
29
|
+
const writer = new Writer(0, void 0);
|
|
30
|
+
writer.writeJoined(", ", ["A", "B", "C"]);
|
|
31
|
+
expect(writer.toString()).toBe("A, B, C");
|
|
32
|
+
});
|
|
33
|
+
test("writeJoined with builder values", () => {
|
|
34
|
+
const writer = new Writer(0, void 0);
|
|
35
|
+
const builder = {
|
|
36
|
+
write(writer2) {
|
|
37
|
+
writer2.write("builder");
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
writer.writeJoined(", ", [builder, builder, builder]);
|
|
41
|
+
expect(writer.toString()).toBe("builder, builder, builder");
|
|
42
|
+
});
|
|
43
|
+
test("writeJoined with builder separator", () => {
|
|
44
|
+
const writer = new Writer(0, void 0);
|
|
45
|
+
const separator = {
|
|
46
|
+
write(writer2) {
|
|
47
|
+
writer2.write("|");
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
writer.writeJoined(separator, ["A", "B", "C"]);
|
|
51
|
+
expect(writer.toString()).toBe("A|B|C");
|
|
52
|
+
});
|
|
53
|
+
test("writeJoined empty", () => {
|
|
54
|
+
const writer = new Writer(0, void 0);
|
|
55
|
+
writer.writeJoined(", ", []);
|
|
56
|
+
expect(writer.toString()).toBe("");
|
|
57
|
+
});
|
|
58
|
+
test("indent", () => {
|
|
59
|
+
const writer = new Writer(0, void 0);
|
|
60
|
+
writer.indent().write("A");
|
|
61
|
+
expect(writer.toString()).toBe(" A");
|
|
62
|
+
});
|
|
63
|
+
test("indent + unindent", () => {
|
|
64
|
+
const writer = new Writer(0, void 0);
|
|
65
|
+
writer.writeLine("A").indent().writeLine("B").unindent().writeLine("C");
|
|
66
|
+
expect(writer.toString()).toBe("A\n B\nC\n");
|
|
67
|
+
});
|
|
68
|
+
test("unindent beyond 0", () => {
|
|
69
|
+
const writer = new Writer(0, void 0);
|
|
70
|
+
writer.unindent().unindent().write("A");
|
|
71
|
+
expect(writer.toString()).toBe("A");
|
|
72
|
+
});
|
|
73
|
+
test("withIndent", () => {
|
|
74
|
+
const writer = new Writer(0, void 0);
|
|
75
|
+
writer.writeLine("A").withIndent(() => writer.writeLine("B")).writeLine("C");
|
|
76
|
+
expect(writer.toString()).toBe("A\n B\nC\n");
|
|
77
|
+
});
|
|
78
|
+
test("after next newline callback", () => {
|
|
79
|
+
const writer = new Writer(0, void 0);
|
|
80
|
+
writer.afterNextNewline(() => {
|
|
81
|
+
writer.writeLine("---");
|
|
82
|
+
});
|
|
83
|
+
writer.writeLine("foo");
|
|
84
|
+
writer.writeLine("bar");
|
|
85
|
+
expect(writer.toString()).toBe("foo\n---\nbar\n");
|
|
86
|
+
});
|
|
87
|
+
test("margin symbol", () => {
|
|
88
|
+
const writer = new Writer(0, void 0);
|
|
89
|
+
writer.writeLine("{").withIndent(() => {
|
|
90
|
+
writer.addMarginSymbol("+").writeLine("foo").writeLine("bar");
|
|
91
|
+
}).writeLine("}");
|
|
92
|
+
expect(writer.toString()).toMatchInlineSnapshot(`
|
|
93
|
+
"{
|
|
94
|
+
+ foo
|
|
95
|
+
bar
|
|
96
|
+
}
|
|
97
|
+
"
|
|
98
|
+
`);
|
|
99
|
+
});
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
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 helpers_exports = {};
|
|
20
|
+
__export(helpers_exports, {
|
|
21
|
+
omit: () => omit
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(helpers_exports);
|
|
24
|
+
var import_NamedType = require("./NamedType");
|
|
25
|
+
function omit(type, keyType) {
|
|
26
|
+
return (0, import_NamedType.namedType)("Omit").addGenericArgument(type).addGenericArgument(keyType);
|
|
27
|
+
}
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
omit
|
|
31
|
+
});
|
package/dist/helpers.mjs
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export * from './AnyDeclarationBuilder';
|
|
2
|
+
export * from './ArraySpread';
|
|
3
|
+
export * from './ArrayType';
|
|
4
|
+
export * from './BasicBuilder';
|
|
5
|
+
export * from './Class';
|
|
6
|
+
export * from './ConstDeclaration';
|
|
7
|
+
export * from './DocComment';
|
|
8
|
+
export * from './Export';
|
|
9
|
+
export * from './ExportFrom';
|
|
10
|
+
export * from './File';
|
|
11
|
+
export * from './FunctionCall';
|
|
12
|
+
export * from './FunctionType';
|
|
13
|
+
export * from './GenericParameter';
|
|
14
|
+
export * from './helpers';
|
|
15
|
+
export * from './Import';
|
|
16
|
+
export * from './Interface';
|
|
17
|
+
export * from './KeyofType';
|
|
18
|
+
export * from './KeyType';
|
|
19
|
+
export * from './Method';
|
|
20
|
+
export * from './NamedType';
|
|
21
|
+
export * from './NamedValue';
|
|
22
|
+
export * from './NamespaceDeclaration';
|
|
23
|
+
export * from './ObjectType';
|
|
24
|
+
export * from './Parameter';
|
|
25
|
+
export * from './PrimitiveType';
|
|
26
|
+
export * from './Property';
|
|
27
|
+
export * from './stringify';
|
|
28
|
+
export * from './StringLiteralType';
|
|
29
|
+
export * from './TupleType';
|
|
30
|
+
export * from './TypeBuilder';
|
|
31
|
+
export * from './TypeDeclaration';
|
|
32
|
+
export * from './UnionType';
|
|
33
|
+
export * from './ValueBuilder';
|
|
34
|
+
export * from './WellKnownSymbol';
|
|
35
|
+
export * from './Writer';
|