@postxl/generator 0.0.1

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 (95) hide show
  1. package/README.md +3 -0
  2. package/dist/jest.config.d.ts +3 -0
  3. package/dist/src/generator.d.ts +12 -0
  4. package/dist/src/generator.js +164 -0
  5. package/dist/src/generators/enums/react.generator.d.ts +10 -0
  6. package/dist/src/generators/enums/react.generator.js +81 -0
  7. package/dist/src/generators/enums/types.generator.d.ts +10 -0
  8. package/dist/src/generators/enums/types.generator.js +18 -0
  9. package/dist/src/generators/indices/datamockmodule.generator.d.ts +9 -0
  10. package/dist/src/generators/indices/datamockmodule.generator.js +104 -0
  11. package/dist/src/generators/indices/datamodule.generator.d.ts +9 -0
  12. package/dist/src/generators/indices/datamodule.generator.js +128 -0
  13. package/dist/src/generators/indices/dataservice.generator.d.ts +9 -0
  14. package/dist/src/generators/indices/dataservice.generator.js +47 -0
  15. package/dist/src/generators/indices/repositories.generator.d.ts +9 -0
  16. package/dist/src/generators/indices/repositories.generator.js +17 -0
  17. package/dist/src/generators/indices/seed.generator.d.ts +9 -0
  18. package/dist/src/generators/indices/seed.generator.js +17 -0
  19. package/dist/src/generators/indices/stubs.generator.d.ts +9 -0
  20. package/dist/src/generators/indices/stubs.generator.js +17 -0
  21. package/dist/src/generators/indices/testdataservice.generator.d.ts +7 -0
  22. package/dist/src/generators/indices/testdataservice.generator.js +61 -0
  23. package/dist/src/generators/indices/types.generator.d.ts +10 -0
  24. package/dist/src/generators/indices/types.generator.js +21 -0
  25. package/dist/src/generators/models/react.generator/context.generator.d.ts +9 -0
  26. package/dist/src/generators/models/react.generator/context.generator.js +66 -0
  27. package/dist/src/generators/models/react.generator/index.d.ts +10 -0
  28. package/dist/src/generators/models/react.generator/index.js +32 -0
  29. package/dist/src/generators/models/react.generator/library.generator.d.ts +9 -0
  30. package/dist/src/generators/models/react.generator/library.generator.js +113 -0
  31. package/dist/src/generators/models/react.generator/lookup.generator.d.ts +9 -0
  32. package/dist/src/generators/models/react.generator/lookup.generator.js +97 -0
  33. package/dist/src/generators/models/react.generator/modals.generator.d.ts +23 -0
  34. package/dist/src/generators/models/react.generator/modals.generator.js +521 -0
  35. package/dist/src/generators/models/repository.generator.d.ts +9 -0
  36. package/dist/src/generators/models/repository.generator.js +282 -0
  37. package/dist/src/generators/models/route.generator.d.ts +16 -0
  38. package/dist/src/generators/models/route.generator.js +112 -0
  39. package/dist/src/generators/models/seed.generator.d.ts +20 -0
  40. package/dist/src/generators/models/seed.generator.js +185 -0
  41. package/dist/src/generators/models/stub.generator.d.ts +9 -0
  42. package/dist/src/generators/models/stub.generator.js +74 -0
  43. package/dist/src/generators/models/types.generator.d.ts +9 -0
  44. package/dist/src/generators/models/types.generator.js +116 -0
  45. package/dist/src/lib/attributes.d.ts +43 -0
  46. package/dist/src/lib/attributes.js +2 -0
  47. package/dist/src/lib/exports.d.ts +26 -0
  48. package/dist/src/lib/exports.js +38 -0
  49. package/dist/src/lib/imports.d.ts +35 -0
  50. package/dist/src/lib/imports.js +55 -0
  51. package/dist/src/lib/meta.d.ts +359 -0
  52. package/dist/src/lib/meta.js +195 -0
  53. package/dist/src/lib/schema/fields.d.ts +35 -0
  54. package/dist/src/lib/schema/fields.js +49 -0
  55. package/dist/src/lib/schema/schema.d.ts +275 -0
  56. package/dist/src/lib/schema/schema.js +2 -0
  57. package/dist/src/lib/schema/types.d.ts +72 -0
  58. package/dist/src/lib/schema/types.js +41 -0
  59. package/dist/src/lib/schema/zod.d.ts +8 -0
  60. package/dist/src/lib/schema/zod.js +44 -0
  61. package/dist/src/lib/serializer.d.ts +15 -0
  62. package/dist/src/lib/serializer.js +24 -0
  63. package/dist/src/lib/utils/error.d.ts +5 -0
  64. package/dist/src/lib/utils/error.js +13 -0
  65. package/dist/src/lib/utils/file.d.ts +10 -0
  66. package/dist/src/lib/utils/file.js +54 -0
  67. package/dist/src/lib/utils/logger.d.ts +11 -0
  68. package/dist/src/lib/utils/logger.js +2 -0
  69. package/dist/src/lib/utils/string.d.ts +29 -0
  70. package/dist/src/lib/utils/string.js +75 -0
  71. package/dist/src/lib/utils/types.d.ts +12 -0
  72. package/dist/src/lib/utils/types.js +2 -0
  73. package/dist/src/lib/vfs.d.ts +137 -0
  74. package/dist/src/lib/vfs.js +419 -0
  75. package/dist/src/prisma/attributes.d.ts +17 -0
  76. package/dist/src/prisma/attributes.js +80 -0
  77. package/dist/src/prisma/client-path.d.ts +7 -0
  78. package/dist/src/prisma/client-path.js +29 -0
  79. package/dist/src/prisma/parse.d.ts +12 -0
  80. package/dist/src/prisma/parse.js +276 -0
  81. package/dist/tests/attributes.test.d.ts +1 -0
  82. package/dist/tests/attributes.test.js +76 -0
  83. package/dist/tests/file.test.d.ts +1 -0
  84. package/dist/tests/file.test.js +26 -0
  85. package/dist/tests/utils/random.d.ts +3 -0
  86. package/dist/tests/utils/random.js +15 -0
  87. package/dist/tests/vfs.test.d.ts +1 -0
  88. package/dist/tests/vfs.test.js +74 -0
  89. package/dist/tsconfig.tsbuildinfo +1 -0
  90. package/jest.config.ts +18 -0
  91. package/package.json +42 -0
  92. package/tests/attributes.test.ts +91 -0
  93. package/tests/file.test.ts +32 -0
  94. package/tests/utils/random.ts +11 -0
  95. package/tests/vfs.test.ts +92 -0
@@ -0,0 +1,275 @@
1
+ import { FieldAttributes, ModelAttributes } from '../attributes';
2
+ import { Prettify } from '../utils/types';
3
+ import * as Types from './types';
4
+ /**
5
+ * A shared configuration of the schema.
6
+ *
7
+ * NOTE: This may be accessed in every model, field and enumerator.
8
+ */
9
+ export type SchemaConfig = {
10
+ /**
11
+ * Project scope to use in TypeScript imports (e.g. `mca` for `@mca/types`).
12
+ */
13
+ project: string;
14
+ paths: {
15
+ /**
16
+ * Path to the directory containing model type definitions.
17
+ *
18
+ * NOTE: Metadata assumes that project is set up so that certain parts of the code
19
+ * may reference type definitions using `@project/types` import.
20
+ */
21
+ modelTypeDefinitionsPath: Types.Path;
22
+ /**
23
+ * Path to the directory containing data library definitions.
24
+ *
25
+ * NOTE: Metadata assumes that project is set up so that certain parts of the code
26
+ * may reference data library using `@project/data` import.
27
+ */
28
+ dataLibPath: Types.Path;
29
+ /**
30
+ * Path to the directory containing mock data samples.
31
+ *
32
+ * NOTE: Metadata assumes that project is set up so that certain parts of the code
33
+ * may reference mock data using `@project/seed` import.
34
+ */
35
+ seedPath: Types.Path;
36
+ /**
37
+ * Path to the directory containing React components.
38
+ *
39
+ * NOTE: Metadata assumes that the project is set up so that React components
40
+ * may be referenced using `@project/react` import.
41
+ */
42
+ reactFolderPath: Types.Path;
43
+ /**
44
+ * Path to the directory containing trpc routes.
45
+ */
46
+ trpcRoutesFolderPath: Types.Path;
47
+ };
48
+ /**
49
+ * Seed to use for random generation.
50
+ */
51
+ randomSeed: number;
52
+ /**
53
+ * Whether the generator should overwrite existing files.
54
+ */
55
+ force: boolean;
56
+ };
57
+ export type Model = Prettify<ModelCore & ModelFields>;
58
+ /**
59
+ * The model's core properties (i.e. without fields)
60
+ */
61
+ export type ModelCore = {
62
+ /**
63
+ * Name of the model (e.g. Aggregation)
64
+ */
65
+ name: string;
66
+ /**
67
+ * Description of the model, ideally providing business background and detailed information
68
+ */
69
+ description?: string;
70
+ /**
71
+ * Name of the models type (e.g. Aggregation)
72
+ */
73
+ typeName: Types.TypeName;
74
+ /**
75
+ * Name of the model in the source, e.g. in the database (e.g. aggregation)
76
+ *
77
+ * Note: Should be only relevant to repository generator
78
+ * @internal
79
+ */
80
+ sourceName: string;
81
+ /**
82
+ * Type of the ID field that is specific to this model, e.g. `AggregationId`.
83
+ */
84
+ brandedIdType: Types.TypeName;
85
+ /**
86
+ * Attributes of the model
87
+ * @see ModelAttributes
88
+ */
89
+ attributes: ModelAttributes;
90
+ /**
91
+ * A global schema configuration.
92
+ */
93
+ schemaConfig: SchemaConfig;
94
+ };
95
+ export type ModelFields = {
96
+ /**
97
+ * The id field of the model
98
+ */
99
+ idField: FieldId;
100
+ /**
101
+ * The property of the model that identifies the default row.
102
+ */
103
+ defaultField?: Field;
104
+ /**
105
+ * The property of the model that is used to define the name/label
106
+ *
107
+ * By default, this is maps to the `name` field - but using the `@label` attribute, other fields can be used.
108
+ */
109
+ nameField?: FieldScalar;
110
+ /**
111
+ * All fields of the model
112
+ */
113
+ fields: Field[];
114
+ };
115
+ /**
116
+ * A field of a model.
117
+ * Note: Different field types are represented as discriminant unions.
118
+ */
119
+ export type Field = FieldId | FieldScalar | FieldRelation | FieldEnum;
120
+ /**
121
+ * The properties shared by all field types.
122
+ */
123
+ export type FieldCore = {
124
+ /**
125
+ * Name of the field and variable (e.g. name)
126
+ *
127
+ * Note: The type of the name is narrowed by each field type.
128
+ */
129
+ name: string;
130
+ /**
131
+ * Description of the field, ideally providing business background and detailed information
132
+ */
133
+ description?: string;
134
+ /**
135
+ * True if the field is not nullable.
136
+ */
137
+ isRequired: boolean;
138
+ /**
139
+ * A dictionary of raw attributes of the model indexed by their name.
140
+ */
141
+ attributes: FieldAttributes;
142
+ /**
143
+ * Name of the field in the source e.g. in the database (e.g. Id)
144
+ */
145
+ sourceName: string;
146
+ /**
147
+ * Validation rule for the field.
148
+ */
149
+ validation?: Validation;
150
+ /**
151
+ * A global schema configuration.
152
+ */
153
+ schemaConfig: SchemaConfig;
154
+ };
155
+ export type Validation = {
156
+ type: 'int';
157
+ } | {
158
+ type: 'float';
159
+ };
160
+ /**
161
+ * A scalar field, i.e. a string, number, boolean, Date
162
+ */
163
+ export type FieldScalar = Prettify<Omit<FieldCore, 'name'> & {
164
+ kind: 'scalar';
165
+ /**
166
+ * Name of the field and variable (e.g. name)
167
+ */
168
+ name: string;
169
+ /**
170
+ * Name of the scalar TypeScript type, e.g. string
171
+ */
172
+ typeName: Types.TypeName;
173
+ /**
174
+ * If true, each element is unique.
175
+ * Note: This is ensured by the repository/database
176
+ */
177
+ isUnique: boolean;
178
+ /**
179
+ * True if the id field is an autoIncremented field.
180
+ */
181
+ isGenerated: boolean;
182
+ }>;
183
+ /**
184
+ * The id field of a model. A model can only have one id field.
185
+ */
186
+ export type FieldId = Prettify<Omit<FieldCore, 'name'> & {
187
+ kind: 'id';
188
+ /**
189
+ * Name of the field and variable (e.g. id)
190
+ */
191
+ name: string;
192
+ /**
193
+ * Model that this ID field identifies.
194
+ */
195
+ model: ModelCore;
196
+ /**
197
+ * If true, each element is unique.
198
+ * Note: This is ensured by the repository/database
199
+ */
200
+ isUnique: boolean;
201
+ /**
202
+ * True if the id field is an autoIncremented field.
203
+ */
204
+ isGenerated: boolean;
205
+ /**
206
+ * Name of the unbranded TypeScript type of the id field, e.g. string
207
+ *
208
+ * Note: This should only be used in the type generator - all other generators
209
+ * should use the branded type "typeName"!
210
+ */
211
+ unbrandedTypeName: Types.TypeName;
212
+ }>;
213
+ /**
214
+ * A relation field, representing a "to-relation" in the schema.
215
+ */
216
+ export type FieldRelation = Prettify<Omit<FieldCore, 'name'> & {
217
+ kind: 'relation';
218
+ /**
219
+ * Name of the field and variable (e.g. aggregationId)
220
+ */
221
+ name: string;
222
+ /**
223
+ * Name of the unbranded TypeScript type of the field, e.g. string
224
+ *
225
+ * Note: This should only be used in the type generator - all other generators
226
+ * should use the branded type "typeName"!
227
+ *
228
+ * @internal
229
+ */
230
+ unbrandedTypeName: Types.TypeName;
231
+ /**
232
+ * The referenced model
233
+ */
234
+ relationToModel: ModelCore;
235
+ }>;
236
+ /**
237
+ * An enum field, e.g. a field that can only have a value of a specific enum.
238
+ */
239
+ export type FieldEnum = Prettify<Omit<FieldCore, 'name'> & {
240
+ kind: 'enum';
241
+ /**
242
+ * Name of the field and variable (e.g. language)
243
+ */
244
+ name: string;
245
+ /**
246
+ * Name of the TypeScript type of the field, e.g. Language
247
+ */
248
+ typeName: Types.TypeName;
249
+ /**
250
+ * Enum definition of the field.
251
+ */
252
+ enumerator: Enum;
253
+ }>;
254
+ /**
255
+ * Definition of an enum, consisting of a name and a list of enum members.
256
+ */
257
+ export type Enum = {
258
+ name: string;
259
+ /**
260
+ * TypeScript type that should be used to reference an enumerator.
261
+ */
262
+ typeName: Types.TypeName;
263
+ /**
264
+ * Name of the enum as it appears in the source (e.g. in the Prisma file).
265
+ */
266
+ sourceName: string;
267
+ /**
268
+ * List of enum members, e.g. [EN, DE]
269
+ */
270
+ values: string[];
271
+ /**
272
+ * A global schema configuration.
273
+ */
274
+ schemaConfig: SchemaConfig;
275
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Name of a Typescript type, e.g. "Aggregation".
3
+ */
4
+ export type TypeName = string & {
5
+ readonly typeName: unique symbol;
6
+ };
7
+ /**
8
+ * Brands a raw string to a TypeScript Type identifier.
9
+ */
10
+ export declare const toTypeName: (t: string) => TypeName;
11
+ /**
12
+ * The name of a function (e.g. "toAggregation").
13
+ */
14
+ export type Function = string & {
15
+ readonly functionName: unique symbol;
16
+ };
17
+ /**
18
+ * Converts a string to a branded function name.
19
+ */
20
+ export declare const toFunction: (t: string) => Function;
21
+ /**
22
+ * The name of a class, e.g. "AggregationRepository".
23
+ */
24
+ export type ClassName = string & {
25
+ readonly className: unique symbol;
26
+ };
27
+ /**
28
+ * Converts a raw string to a branded ClassName.
29
+ */
30
+ export declare const toClassName: (t: string) => ClassName;
31
+ /**
32
+ * The name of a variable or a property in the generated code.
33
+ */
34
+ export type VariableName = string & {
35
+ readonly variableName: unique symbol;
36
+ };
37
+ /**
38
+ * Converts a string to a branded VariableName.
39
+ */
40
+ export declare const toVariableName: (t: string) => VariableName;
41
+ /**
42
+ * A name of the file without a file extension, e.g. "aggregation.type".
43
+ */
44
+ export type FileName = string & {
45
+ readonly fileName: unique symbol;
46
+ };
47
+ /**
48
+ * Lets you brand a string value as a name of the file.
49
+ *
50
+ * NOTE: THIS SHOULD NOT BE A PATH!
51
+ */
52
+ export declare const toFileName: (t: string) => FileName;
53
+ /**
54
+ * A name of the folder without the trailing and leading slash (e.g. "aggregation").
55
+ */
56
+ export type FolderName = string & {
57
+ readonly folderName: unique symbol;
58
+ };
59
+ /**
60
+ * Converts a string to a branded FolderName.
61
+ */
62
+ export declare const toFolderName: (t: string) => FolderName;
63
+ /**
64
+ * A relative or absolute path to a file or folder.
65
+ */
66
+ export type Path = string & {
67
+ readonly fileName: unique symbol;
68
+ };
69
+ /**
70
+ * Converts a string to a branded FileName.
71
+ */
72
+ export declare const toPath: (t: string) => Path;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ // MARK: - Generated content related types
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.toPath = exports.toFolderName = exports.toFileName = exports.toVariableName = exports.toClassName = exports.toFunction = exports.toTypeName = void 0;
5
+ /**
6
+ * Brands a raw string to a TypeScript Type identifier.
7
+ */
8
+ const toTypeName = (t) => t;
9
+ exports.toTypeName = toTypeName;
10
+ /**
11
+ * Converts a string to a branded function name.
12
+ */
13
+ const toFunction = (t) => t;
14
+ exports.toFunction = toFunction;
15
+ /**
16
+ * Converts a raw string to a branded ClassName.
17
+ */
18
+ const toClassName = (t) => t;
19
+ exports.toClassName = toClassName;
20
+ /**
21
+ * Converts a string to a branded VariableName.
22
+ */
23
+ const toVariableName = (t) => t;
24
+ exports.toVariableName = toVariableName;
25
+ /**
26
+ * Lets you brand a string value as a name of the file.
27
+ *
28
+ * NOTE: THIS SHOULD NOT BE A PATH!
29
+ */
30
+ const toFileName = (t) => t;
31
+ exports.toFileName = toFileName;
32
+ /**
33
+ * Converts a string to a branded FolderName.
34
+ */
35
+ const toFolderName = (t) => t;
36
+ exports.toFolderName = toFolderName;
37
+ /**
38
+ * Converts a string to a branded FileName.
39
+ */
40
+ const toPath = (t) => t;
41
+ exports.toPath = toPath;
@@ -0,0 +1,8 @@
1
+ import { Field } from './schema';
2
+ /**
3
+ * Returns the string defining the zod decoder for a given field.
4
+ */
5
+ export declare const getZodDecoderDefinition: ({ field, allowAnyOptionalField, }: {
6
+ field: Field;
7
+ allowAnyOptionalField?: boolean | undefined;
8
+ }) => string;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getZodDecoderDefinition = void 0;
7
+ const assert_never_1 = __importDefault(require("assert-never"));
8
+ const meta_1 = require("../meta");
9
+ /**
10
+ * Returns the string defining the zod decoder for a given field.
11
+ */
12
+ const getZodDecoderDefinition = ({ field, allowAnyOptionalField, }) => {
13
+ let definition = getZodTypeDefinition(field);
14
+ if (field.kind === 'id') {
15
+ const idModelMeta = (0, meta_1.getModelMetadata)({ model: field.model });
16
+ definition += `.transform(${idModelMeta.types.toBrandedIdTypeFnName})`;
17
+ }
18
+ if (field.kind === 'relation') {
19
+ const refModelMeta = (0, meta_1.getModelMetadata)({ model: field.relationToModel });
20
+ definition += `.transform(${refModelMeta.types.toBrandedIdTypeFnName})`;
21
+ }
22
+ if (!field.isRequired) {
23
+ definition += `.nullable()`;
24
+ }
25
+ if (allowAnyOptionalField) {
26
+ definition += `.optional()`;
27
+ }
28
+ return definition;
29
+ };
30
+ exports.getZodDecoderDefinition = getZodDecoderDefinition;
31
+ function getZodTypeDefinition(field) {
32
+ switch (field.kind) {
33
+ case 'scalar':
34
+ return `${field.typeName}()`;
35
+ case 'enum':
36
+ return `enum([${field.enumerator.values.map((v) => `'${v}'`).join(', ')}])`;
37
+ case 'id':
38
+ return `${field.unbrandedTypeName}()`;
39
+ case 'relation':
40
+ return `${field.unbrandedTypeName}()`;
41
+ default:
42
+ (0, assert_never_1.default)(field);
43
+ }
44
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Lets you serialize a string content easily.
3
+ */
4
+ export declare class Serializer {
5
+ private _content;
6
+ constructor();
7
+ /**
8
+ * Appends given content to the file and inserts a newline.
9
+ */
10
+ append(content: string): void;
11
+ /**
12
+ * Returns the contents of the serializer.
13
+ */
14
+ print(): string;
15
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Serializer = void 0;
4
+ /**
5
+ * Lets you serialize a string content easily.
6
+ */
7
+ class Serializer {
8
+ constructor() {
9
+ this._content = '';
10
+ }
11
+ /**
12
+ * Appends given content to the file and inserts a newline.
13
+ */
14
+ append(content) {
15
+ this._content += `${content}\n`;
16
+ }
17
+ /**
18
+ * Returns the contents of the serializer.
19
+ */
20
+ print() {
21
+ return this._content;
22
+ }
23
+ }
24
+ exports.Serializer = Serializer;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Prisma generator often overwrites any error message because of some concurrency issues.
3
+ * By showing the error via console.log and throwing it again, we ensure that the error message is shown.
4
+ */
5
+ export declare function throwError(message: string): never;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throwError = void 0;
4
+ /**
5
+ * Prisma generator often overwrites any error message because of some concurrency issues.
6
+ * By showing the error via console.log and throwing it again, we ensure that the error message is shown.
7
+ */
8
+ function throwError(message) {
9
+ const m = ` ❌❌❌ ${message}`;
10
+ console.error(m);
11
+ throw new Error(m);
12
+ }
13
+ exports.throwError = throwError;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Returns the relative path from one file (e.g. current file) to another file
3
+ * assuming that both files have the same starting point (e.g. from `/a` to `/b/c` is `./b/c`).
4
+ *
5
+ * If the referenced file is a package, then we return the package reference (e.g. `@lib/package`).
6
+ */
7
+ export declare function getRelativePath({ from, to }: {
8
+ from: string;
9
+ to: string;
10
+ }): string;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRelativePath = void 0;
4
+ /**
5
+ * Returns the relative path from one file (e.g. current file) to another file
6
+ * assuming that both files have the same starting point (e.g. from `/a` to `/b/c` is `./b/c`).
7
+ *
8
+ * If the referenced file is a package, then we return the package reference (e.g. `@lib/package`).
9
+ */
10
+ function getRelativePath({ from, to }) {
11
+ if (to.startsWith('@')) {
12
+ return to;
13
+ }
14
+ const fromParts = _resolvePath(from);
15
+ const toParts = _resolvePath(to);
16
+ // NOTE: We expect that from value references a file of a file in a given folder.
17
+ // Relative to that file, we need to remove it.
18
+ fromParts.pop();
19
+ // Remove common parts.
20
+ while (fromParts.length > 0 && toParts.length > 0 && fromParts[0] === toParts[0]) {
21
+ fromParts.shift();
22
+ toParts.shift();
23
+ }
24
+ // Add ../ for each remaining part in fromParts.
25
+ const relativePath = fromParts
26
+ .map(() => '..')
27
+ .concat(toParts)
28
+ .join('/');
29
+ if (relativePath.startsWith('.')) {
30
+ return relativePath;
31
+ }
32
+ return `./${relativePath}`;
33
+ }
34
+ exports.getRelativePath = getRelativePath;
35
+ /**
36
+ * Returns a list of folders leading from the root to the referenecd file or folder and removes
37
+ * any positional paths.
38
+ */
39
+ function _resolvePath(path) {
40
+ const chunks = path.split('/');
41
+ const resolved = [];
42
+ while (chunks.length > 0) {
43
+ const chunk = chunks.shift();
44
+ if (chunk === '..') {
45
+ resolved.pop();
46
+ continue;
47
+ }
48
+ if (chunk === '.') {
49
+ continue;
50
+ }
51
+ resolved.push(chunk);
52
+ }
53
+ return resolved;
54
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * A generic logger interface.
3
+ * Compatible with the `@prisma/internals` logger and console.
4
+ */
5
+ export interface Logger {
6
+ log(...data: any[]): void;
7
+ warn(message: any, ...optionalParams: any[]): void;
8
+ info(message: any, ...optionalParams: any[]): void;
9
+ error(message: any, ...optionalParams: any[]): void;
10
+ query(message: any, ...optionalParams: any[]): void;
11
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Returns the same string with a lowercase first letter.
3
+ */
4
+ export declare const uncapitalize: (str: string) => string;
5
+ /**
6
+ * Returns the camelCase version of the given string.
7
+ */
8
+ export declare const toCamelCase: (str: string) => string;
9
+ /**
10
+ * Returns the PascalCase version of the given string.
11
+ */
12
+ export declare const toPascalCase: (str: string) => string;
13
+ /**
14
+ * Returns a pluralized version of the given string based on the count.
15
+ */
16
+ export declare const pluralize: (s: string, count?: number) => string;
17
+ /**
18
+ * Converts each line of a string to a commented line
19
+ */
20
+ export declare const commentLines: (lines: string) => string;
21
+ /**
22
+ * Provide all relevant conjugation of a name
23
+ */
24
+ export declare const conjugateNames: (name: string) => {
25
+ PascalCase: string;
26
+ camelCase: string;
27
+ pluralized: string;
28
+ uncapitalizedPlural: string;
29
+ };