@prisma/ts-builders 6.6.0-dev.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +5 -0
  3. package/dist/AnyDeclarationBuilder.d.ts +6 -0
  4. package/dist/AnyDeclarationBuilder.js +16 -0
  5. package/dist/AnyDeclarationBuilder.mjs +0 -0
  6. package/dist/ArraySpread.d.ts +8 -0
  7. package/dist/ArraySpread.js +42 -0
  8. package/dist/ArraySpread.mjs +17 -0
  9. package/dist/ArrayType.d.ts +8 -0
  10. package/dist/ArrayType.js +43 -0
  11. package/dist/ArrayType.mjs +18 -0
  12. package/dist/ArrayType.test.d.ts +1 -0
  13. package/dist/ArrayType.test.js +24 -0
  14. package/dist/ArrayType.test.mjs +23 -0
  15. package/dist/BasicBuilder.d.ts +4 -0
  16. package/dist/BasicBuilder.js +16 -0
  17. package/dist/BasicBuilder.mjs +0 -0
  18. package/dist/Class.d.ts +22 -0
  19. package/dist/Class.js +79 -0
  20. package/dist/Class.mjs +54 -0
  21. package/dist/Class.test.d.ts +1 -0
  22. package/dist/Class.test.js +56 -0
  23. package/dist/Class.test.mjs +55 -0
  24. package/dist/ConstDeclaration.d.ts +13 -0
  25. package/dist/ConstDeclaration.js +49 -0
  26. package/dist/ConstDeclaration.mjs +24 -0
  27. package/dist/ConstDeclaration.test.d.ts +1 -0
  28. package/dist/ConstDeclaration.test.js +19 -0
  29. package/dist/ConstDeclaration.test.mjs +18 -0
  30. package/dist/DocComment.d.ts +11 -0
  31. package/dist/DocComment.js +101 -0
  32. package/dist/DocComment.mjs +76 -0
  33. package/dist/DocComment.test.d.ts +1 -0
  34. package/dist/DocComment.test.js +80 -0
  35. package/dist/DocComment.test.mjs +79 -0
  36. package/dist/Export.d.ts +12 -0
  37. package/dist/Export.js +48 -0
  38. package/dist/Export.mjs +23 -0
  39. package/dist/ExportFrom.d.ts +32 -0
  40. package/dist/ExportFrom.js +98 -0
  41. package/dist/ExportFrom.mjs +69 -0
  42. package/dist/ExportFrom.test.d.ts +1 -0
  43. package/dist/ExportFrom.test.js +25 -0
  44. package/dist/ExportFrom.test.mjs +24 -0
  45. package/dist/File.d.ts +15 -0
  46. package/dist/File.js +57 -0
  47. package/dist/File.mjs +32 -0
  48. package/dist/FunctionType.d.ts +17 -0
  49. package/dist/FunctionType.js +60 -0
  50. package/dist/FunctionType.mjs +35 -0
  51. package/dist/FunctionType.test.d.ts +1 -0
  52. package/dist/FunctionType.test.js +32 -0
  53. package/dist/FunctionType.test.mjs +31 -0
  54. package/dist/GenericParameter.d.ts +15 -0
  55. package/dist/GenericParameter.js +60 -0
  56. package/dist/GenericParameter.mjs +35 -0
  57. package/dist/GenericParameter.test.d.ts +1 -0
  58. package/dist/GenericParameter.test.js +19 -0
  59. package/dist/GenericParameter.test.mjs +18 -0
  60. package/dist/Import.d.ts +36 -0
  61. package/dist/Import.js +119 -0
  62. package/dist/Import.mjs +90 -0
  63. package/dist/Import.test.d.ts +1 -0
  64. package/dist/Import.test.js +33 -0
  65. package/dist/Import.test.mjs +32 -0
  66. package/dist/Interface.d.ts +22 -0
  67. package/dist/Interface.js +79 -0
  68. package/dist/Interface.mjs +54 -0
  69. package/dist/Interface.test.d.ts +1 -0
  70. package/dist/Interface.test.js +56 -0
  71. package/dist/Interface.test.mjs +55 -0
  72. package/dist/KeyType.d.ts +9 -0
  73. package/dist/KeyType.js +44 -0
  74. package/dist/KeyType.mjs +19 -0
  75. package/dist/KeyType.test.d.ts +1 -0
  76. package/dist/KeyType.test.js +28 -0
  77. package/dist/KeyType.test.mjs +27 -0
  78. package/dist/KeyofType.d.ts +8 -0
  79. package/dist/KeyofType.js +47 -0
  80. package/dist/KeyofType.mjs +22 -0
  81. package/dist/KeyofType.test.d.ts +1 -0
  82. package/dist/KeyofType.test.js +28 -0
  83. package/dist/KeyofType.test.mjs +27 -0
  84. package/dist/Method.d.ts +20 -0
  85. package/dist/Method.js +75 -0
  86. package/dist/Method.mjs +50 -0
  87. package/dist/Method.test.d.ts +1 -0
  88. package/dist/Method.test.js +43 -0
  89. package/dist/Method.test.mjs +42 -0
  90. package/dist/NamedType.d.ts +10 -0
  91. package/dist/NamedType.js +50 -0
  92. package/dist/NamedType.mjs +25 -0
  93. package/dist/NamedType.test.d.ts +1 -0
  94. package/dist/NamedType.test.js +15 -0
  95. package/dist/NamedType.test.mjs +14 -0
  96. package/dist/NamespaceDeclaration.d.ts +13 -0
  97. package/dist/NamespaceDeclaration.js +48 -0
  98. package/dist/NamespaceDeclaration.mjs +23 -0
  99. package/dist/ObjectType.d.ts +18 -0
  100. package/dist/ObjectType.js +71 -0
  101. package/dist/ObjectType.mjs +46 -0
  102. package/dist/ObjectType.test.d.ts +1 -0
  103. package/dist/ObjectType.test.js +32 -0
  104. package/dist/ObjectType.test.mjs +31 -0
  105. package/dist/Parameter.d.ts +12 -0
  106. package/dist/Parameter.js +50 -0
  107. package/dist/Parameter.mjs +25 -0
  108. package/dist/Parameter.test.d.ts +1 -0
  109. package/dist/Parameter.test.js +14 -0
  110. package/dist/Parameter.test.mjs +13 -0
  111. package/dist/PrimitiveType.d.ts +18 -0
  112. package/dist/PrimitiveType.js +70 -0
  113. package/dist/PrimitiveType.mjs +35 -0
  114. package/dist/Property.d.ts +18 -0
  115. package/dist/Property.js +75 -0
  116. package/dist/Property.mjs +50 -0
  117. package/dist/Property.test.d.ts +1 -0
  118. package/dist/Property.test.js +37 -0
  119. package/dist/Property.test.mjs +36 -0
  120. package/dist/StringLiteralType.d.ts +8 -0
  121. package/dist/StringLiteralType.js +42 -0
  122. package/dist/StringLiteralType.mjs +17 -0
  123. package/dist/TupleType.d.ts +17 -0
  124. package/dist/TupleType.js +69 -0
  125. package/dist/TupleType.mjs +42 -0
  126. package/dist/TupleType.test.d.ts +1 -0
  127. package/dist/TupleType.test.js +21 -0
  128. package/dist/TupleType.test.mjs +20 -0
  129. package/dist/TypeBuilder.d.ts +11 -0
  130. package/dist/TypeBuilder.js +47 -0
  131. package/dist/TypeBuilder.mjs +23 -0
  132. package/dist/TypeDeclaration.d.ts +17 -0
  133. package/dist/TypeDeclaration.js +62 -0
  134. package/dist/TypeDeclaration.mjs +37 -0
  135. package/dist/TypeDeclaration.test.d.ts +1 -0
  136. package/dist/TypeDeclaration.test.js +28 -0
  137. package/dist/TypeDeclaration.test.mjs +27 -0
  138. package/dist/UnionType.d.ts +13 -0
  139. package/dist/UnionType.js +74 -0
  140. package/dist/UnionType.mjs +49 -0
  141. package/dist/UnionType.test.d.ts +1 -0
  142. package/dist/UnionType.test.js +28 -0
  143. package/dist/UnionType.test.mjs +27 -0
  144. package/dist/WellKnownSymbol.d.ts +9 -0
  145. package/dist/WellKnownSymbol.js +43 -0
  146. package/dist/WellKnownSymbol.mjs +17 -0
  147. package/dist/Writer.d.ts +94 -0
  148. package/dist/Writer.js +175 -0
  149. package/dist/Writer.mjs +150 -0
  150. package/dist/Writer.test.d.ts +1 -0
  151. package/dist/Writer.test.js +100 -0
  152. package/dist/Writer.test.mjs +99 -0
  153. package/dist/helpers.d.ts +6 -0
  154. package/dist/helpers.js +46 -0
  155. package/dist/helpers.mjs +19 -0
  156. package/dist/index.d.ts +32 -0
  157. package/dist/index.js +84 -0
  158. package/dist/index.mjs +32 -0
  159. package/dist/stringify.d.ts +7 -0
  160. package/dist/stringify.js +44 -0
  161. package/dist/stringify.mjs +20 -0
  162. package/package.json +41 -0
@@ -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;
@@ -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;
@@ -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
+ });