@postxl/generator 0.74.2 → 1.0.3

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 (189) hide show
  1. package/LICENSE +50 -0
  2. package/README.md +79 -1
  3. package/dist/generator-manager.class.d.ts +59 -0
  4. package/dist/generator-manager.class.js +221 -0
  5. package/dist/generator.class.d.ts +90 -0
  6. package/dist/generator.class.js +32 -0
  7. package/dist/generator.context.d.ts +174 -0
  8. package/dist/generator.context.js +125 -0
  9. package/dist/helpers/branded.types.d.ts +149 -0
  10. package/dist/helpers/branded.types.js +111 -0
  11. package/dist/helpers/config-builder.class.d.ts +27 -0
  12. package/dist/helpers/config-builder.class.js +54 -0
  13. package/dist/helpers/import-generator.class.d.ts +70 -0
  14. package/dist/helpers/import-generator.class.js +166 -0
  15. package/dist/helpers/importable.types.d.ts +52 -0
  16. package/dist/helpers/importable.types.js +15 -0
  17. package/dist/helpers/index-generator.class.d.ts +10 -0
  18. package/dist/helpers/index-generator.class.js +46 -0
  19. package/dist/helpers/index.d.ts +8 -0
  20. package/dist/helpers/index.js +24 -0
  21. package/dist/helpers/package-json.generator.d.ts +56 -0
  22. package/dist/helpers/package-json.generator.js +36 -0
  23. package/dist/helpers/tsconfig.generator.d.ts +1 -0
  24. package/dist/helpers/tsconfig.generator.js +14 -0
  25. package/dist/helpers/verify-context.d.ts +4 -0
  26. package/dist/helpers/verify-context.js +23 -0
  27. package/dist/index.d.ts +5 -0
  28. package/dist/index.js +21 -0
  29. package/dist/utils/checksum.d.ts +10 -0
  30. package/dist/utils/checksum.js +132 -0
  31. package/dist/utils/fs-utils.d.ts +34 -0
  32. package/dist/utils/fs-utils.js +126 -0
  33. package/dist/utils/index.d.ts +10 -0
  34. package/dist/utils/index.js +26 -0
  35. package/dist/utils/jsdoc.d.ts +12 -0
  36. package/dist/utils/jsdoc.js +37 -0
  37. package/dist/utils/lint.d.ts +46 -0
  38. package/dist/utils/lint.js +154 -0
  39. package/dist/utils/lockfile.d.ts +7 -0
  40. package/dist/utils/lockfile.js +80 -0
  41. package/dist/utils/logger.class.d.ts +25 -0
  42. package/dist/utils/logger.class.js +55 -0
  43. package/dist/utils/merge-conflict.d.ts +55 -0
  44. package/dist/utils/merge-conflict.js +264 -0
  45. package/dist/utils/path.d.ts +52 -0
  46. package/dist/utils/path.js +183 -0
  47. package/dist/utils/prettier-config.d.ts +2 -0
  48. package/dist/utils/prettier-config.js +13 -0
  49. package/dist/utils/prettier.d.ts +5 -0
  50. package/dist/utils/prettier.js +67 -0
  51. package/dist/utils/prettier.skiptest.d.ts +1 -0
  52. package/dist/utils/prettier.skiptest.js +22 -0
  53. package/dist/utils/promise.d.ts +2 -0
  54. package/dist/utils/promise.js +10 -0
  55. package/dist/utils/string-functions.d.ts +9 -0
  56. package/dist/utils/string-functions.js +23 -0
  57. package/dist/utils/sync-log-result.d.ts +9 -0
  58. package/dist/utils/sync-log-result.js +90 -0
  59. package/dist/utils/sync.d.ts +143 -0
  60. package/dist/utils/sync.js +325 -0
  61. package/dist/utils/template.d.ts +66 -0
  62. package/dist/utils/template.js +159 -0
  63. package/dist/utils/vfs.class.d.ts +115 -0
  64. package/dist/utils/vfs.class.js +239 -0
  65. package/dist/utils/zip.d.ts +13 -0
  66. package/dist/utils/zip.js +40 -0
  67. package/package.json +53 -31
  68. package/dist/generator.d.ts +0 -13
  69. package/dist/generator.js +0 -455
  70. package/dist/generators/enums/react.generator.d.ts +0 -10
  71. package/dist/generators/enums/react.generator.js +0 -110
  72. package/dist/generators/enums/types.generator.d.ts +0 -10
  73. package/dist/generators/enums/types.generator.js +0 -39
  74. package/dist/generators/indices/data/module.generator.d.ts +0 -9
  75. package/dist/generators/indices/data/module.generator.js +0 -60
  76. package/dist/generators/indices/data/service.generator.d.ts +0 -9
  77. package/dist/generators/indices/data/service.generator.js +0 -249
  78. package/dist/generators/indices/data/types.generator.d.ts +0 -9
  79. package/dist/generators/indices/data/types.generator.js +0 -49
  80. package/dist/generators/indices/dispatcher-service.generator.d.ts +0 -9
  81. package/dist/generators/indices/dispatcher-service.generator.js +0 -107
  82. package/dist/generators/indices/export/class.generator.d.ts +0 -9
  83. package/dist/generators/indices/export/class.generator.js +0 -140
  84. package/dist/generators/indices/export/encoder.generator.d.ts +0 -9
  85. package/dist/generators/indices/export/encoder.generator.js +0 -50
  86. package/dist/generators/indices/import/convert-functions.generator.d.ts +0 -9
  87. package/dist/generators/indices/import/convert-functions.generator.js +0 -509
  88. package/dist/generators/indices/import/decoder.generator.d.ts +0 -9
  89. package/dist/generators/indices/import/decoder.generator.js +0 -40
  90. package/dist/generators/indices/import/service.generator.d.ts +0 -9
  91. package/dist/generators/indices/import/service.generator.js +0 -573
  92. package/dist/generators/indices/import/types.generator.d.ts +0 -9
  93. package/dist/generators/indices/import/types.generator.js +0 -242
  94. package/dist/generators/indices/repositories.generator.d.ts +0 -9
  95. package/dist/generators/indices/repositories.generator.js +0 -25
  96. package/dist/generators/indices/routes.generator.d.ts +0 -9
  97. package/dist/generators/indices/routes.generator.js +0 -29
  98. package/dist/generators/indices/seed-migration.generator.d.ts +0 -9
  99. package/dist/generators/indices/seed-migration.generator.js +0 -36
  100. package/dist/generators/indices/seed-template.generator.d.ts +0 -9
  101. package/dist/generators/indices/seed-template.generator.js +0 -80
  102. package/dist/generators/indices/testids.generator.d.ts +0 -7
  103. package/dist/generators/indices/testids.generator.js +0 -71
  104. package/dist/generators/indices/types.generator.d.ts +0 -10
  105. package/dist/generators/indices/types.generator.js +0 -35
  106. package/dist/generators/indices/update/actiontypes.generator.d.ts +0 -9
  107. package/dist/generators/indices/update/actiontypes.generator.js +0 -49
  108. package/dist/generators/indices/update/module.generator.d.ts +0 -9
  109. package/dist/generators/indices/update/module.generator.js +0 -41
  110. package/dist/generators/indices/update/service.generator.d.ts +0 -9
  111. package/dist/generators/indices/update/service.generator.js +0 -34
  112. package/dist/generators/indices/view/module.generator.d.ts +0 -9
  113. package/dist/generators/indices/view/module.generator.js +0 -39
  114. package/dist/generators/indices/view/service.generator.d.ts +0 -9
  115. package/dist/generators/indices/view/service.generator.js +0 -34
  116. package/dist/generators/models/admin.page.generator.d.ts +0 -7
  117. package/dist/generators/models/admin.page.generator.js +0 -74
  118. package/dist/generators/models/export/encoder.generator.d.ts +0 -9
  119. package/dist/generators/models/export/encoder.generator.js +0 -51
  120. package/dist/generators/models/import/decoder.generator.d.ts +0 -9
  121. package/dist/generators/models/import/decoder.generator.js +0 -148
  122. package/dist/generators/models/react/context.generator.d.ts +0 -9
  123. package/dist/generators/models/react/context.generator.js +0 -71
  124. package/dist/generators/models/react/index.d.ts +0 -10
  125. package/dist/generators/models/react/index.js +0 -31
  126. package/dist/generators/models/react/library.generator.d.ts +0 -10
  127. package/dist/generators/models/react/library.generator.js +0 -94
  128. package/dist/generators/models/react/lookup.generator.d.ts +0 -9
  129. package/dist/generators/models/react/lookup.generator.js +0 -175
  130. package/dist/generators/models/react/modals.generator.d.ts +0 -23
  131. package/dist/generators/models/react/modals.generator.js +0 -710
  132. package/dist/generators/models/repository.generator.d.ts +0 -9
  133. package/dist/generators/models/repository.generator.js +0 -955
  134. package/dist/generators/models/route.generator.d.ts +0 -9
  135. package/dist/generators/models/route.generator.js +0 -92
  136. package/dist/generators/models/seed.generator.d.ts +0 -21
  137. package/dist/generators/models/seed.generator.js +0 -285
  138. package/dist/generators/models/stub.generator.d.ts +0 -9
  139. package/dist/generators/models/stub.generator.js +0 -92
  140. package/dist/generators/models/types.generator.d.ts +0 -9
  141. package/dist/generators/models/types.generator.js +0 -125
  142. package/dist/generators/models/update/service.generator.d.ts +0 -10
  143. package/dist/generators/models/update/service.generator.js +0 -302
  144. package/dist/generators/models/view/service.generator.d.ts +0 -10
  145. package/dist/generators/models/view/service.generator.js +0 -239
  146. package/dist/lib/attributes.d.ts +0 -114
  147. package/dist/lib/attributes.js +0 -2
  148. package/dist/lib/exports.d.ts +0 -45
  149. package/dist/lib/exports.js +0 -90
  150. package/dist/lib/imports.d.ts +0 -65
  151. package/dist/lib/imports.js +0 -114
  152. package/dist/lib/meta.d.ts +0 -1191
  153. package/dist/lib/meta.js +0 -434
  154. package/dist/lib/schema/fields.d.ts +0 -46
  155. package/dist/lib/schema/fields.js +0 -62
  156. package/dist/lib/schema/schema.d.ts +0 -466
  157. package/dist/lib/schema/schema.js +0 -18
  158. package/dist/lib/schema/types.d.ts +0 -201
  159. package/dist/lib/schema/types.js +0 -112
  160. package/dist/lib/serializer.d.ts +0 -15
  161. package/dist/lib/serializer.js +0 -24
  162. package/dist/lib/test-id-collector.d.ts +0 -42
  163. package/dist/lib/test-id-collector.js +0 -53
  164. package/dist/lib/types.d.ts +0 -7
  165. package/dist/lib/types.js +0 -13
  166. package/dist/lib/typescript.d.ts +0 -5
  167. package/dist/lib/typescript.js +0 -22
  168. package/dist/lib/utils/ast.d.ts +0 -29
  169. package/dist/lib/utils/ast.js +0 -23
  170. package/dist/lib/utils/error.d.ts +0 -17
  171. package/dist/lib/utils/error.js +0 -52
  172. package/dist/lib/utils/file.d.ts +0 -10
  173. package/dist/lib/utils/file.js +0 -56
  174. package/dist/lib/utils/jsdoc.d.ts +0 -9
  175. package/dist/lib/utils/jsdoc.js +0 -37
  176. package/dist/lib/utils/logger.d.ts +0 -17
  177. package/dist/lib/utils/logger.js +0 -12
  178. package/dist/lib/utils/string.d.ts +0 -40
  179. package/dist/lib/utils/string.js +0 -187
  180. package/dist/lib/utils/types.d.ts +0 -12
  181. package/dist/lib/utils/types.js +0 -2
  182. package/dist/lib/zod.d.ts +0 -8
  183. package/dist/lib/zod.js +0 -60
  184. package/dist/prisma/attributes.d.ts +0 -21
  185. package/dist/prisma/attributes.js +0 -175
  186. package/dist/prisma/client-path.d.ts +0 -7
  187. package/dist/prisma/client-path.js +0 -29
  188. package/dist/prisma/parse.d.ts +0 -12
  189. package/dist/prisma/parse.js +0 -452
@@ -0,0 +1,174 @@
1
+ import * as Schema from '@postxl/schema';
2
+ import { Conjugated } from '@postxl/utils';
3
+ import { VariableName } from './helpers/branded.types';
4
+ import { VirtualFileSystem } from './utils/vfs.class';
5
+ /**
6
+ * Baseline context for all generators.
7
+ *
8
+ * It provides the VirtualFileSystem, the schema as well as a map of all models and enums.
9
+ * `models` and `enums` are generic maps - each generator can add its own context to the models' and enums' context.
10
+ */
11
+ export type Context = {
12
+ /**
13
+ * The virtual files system that generators can write to
14
+ */
15
+ vfs: VirtualFileSystem;
16
+ /**
17
+ * The parsed project schema
18
+ */
19
+ schema: Schema.ProjectSchema;
20
+ /**
21
+ * Contains the context for each schema model.
22
+ * Each generator can extend these contexts with its own content.
23
+ */
24
+ models: Map<Schema.ModelName, ModelContext>;
25
+ /**
26
+ * Contains the context for each schema enum.
27
+ * Each generator can extend these contexts with its own content.
28
+ */
29
+ enums: Map<Schema.EnumName, EnumContext>;
30
+ /**
31
+ * Global options for the handling of the generation process (e.g. log settings, etc.)
32
+ */
33
+ options: GeneratorOptions;
34
+ };
35
+ export type ModelContext = Schema.Model & {
36
+ /**
37
+ * A user friendly name (in singular)
38
+ *
39
+ * User friendly name is very generic and meant to be used in log messages, comments,
40
+ * errors - and any other places where the user shall read about it!
41
+ * It is not meant to be used for variables, class names, etc. In code, you should
42
+ * use a more specific name for your purposes (e.g. `reactCreateModalComponentName`).
43
+ */
44
+ userFriendlyName: string;
45
+ /**
46
+ * A user friendly name in plural form
47
+ *
48
+ * User friendly name is very generic and meant to be used in log messages, comments,
49
+ * errors - and any other places where the user shall read about it!
50
+ * It is not meant to be used for variables, class names, etc. In code, you should
51
+ * use a more specific name for your purposes (e.g. `reactCreateModalComponentName`).
52
+ */
53
+ userFriendlyNamePlural: string;
54
+ /**
55
+ * The name of the model in singular form.
56
+ *
57
+ * This name is meant to be used in internal variables only.
58
+ * For any variables, class names, etc. that are exposed, please use a more specific name.
59
+ * (e.g. `reactCreateModalComponentName`)
60
+ */
61
+ internalSingularName: VariableName;
62
+ /**
63
+ * The name of the capitalized model in singular form.
64
+ *
65
+ * This name is meant to be used in internal types only.
66
+ * For any types, class names, etc. that are exposed, please use a more specific name.
67
+ */
68
+ internalSingularNameCapitalized: VariableName;
69
+ /**
70
+ * The name of the model in plural form.
71
+ *
72
+ * This name is meant to be used in internal variables only.
73
+ * For any variables, class names, etc. that are exposed, please use a more specific name.
74
+ * (e.g. `reactCreateModalComponentName`)
75
+ */
76
+ internalPluralName: VariableName;
77
+ /**
78
+ * The name of the capitalized model in plural form.
79
+ *
80
+ * This name is meant to be used in internal types only.
81
+ * For any variables, class names, etc. that are exposed, please use a more specific name.
82
+ */
83
+ internalPluralNameCapitalized: VariableName;
84
+ /**
85
+ * Internal cache for conjugated names.
86
+ *
87
+ * IMPORTANT: Do not use these names in generated code. Instead, they are provided to allow
88
+ * easy creation of names in the registration functions!
89
+ *
90
+ * @internal
91
+ */
92
+ _conjugated: Conjugated;
93
+ /**
94
+ * Convenience set of related model names referenced by relation and discriminated union
95
+ * fields in this model.
96
+ *
97
+ * Only names (not entire model contexts) are provided so that the models' enhanced
98
+ * contexts can be retrieved during generation (ie. after all generators have registered their
99
+ * model contexts).
100
+ */
101
+ relatedModelNames: Set<Schema.ModelName>;
102
+ };
103
+ export type EnumContext = Schema.Enum & {
104
+ /**
105
+ * A user friendly name (in singular)
106
+ *
107
+ * User friendly name is very generic and meant to be used in log messages, comments,
108
+ * errors - and any other places where the user shall read about it!
109
+ * It is not meant to be used for variables, class names, etc. In code, you should
110
+ * use a more specific name for your purposes (e.g. `reactCreateModalComponentName`).
111
+ */
112
+ userFriendlyName: string;
113
+ /**
114
+ * A user friendly name in plural form
115
+ *
116
+ * User friendly name is very generic and meant to be used in log messages, comments,
117
+ * errors - and any other places where the user shall read about it!
118
+ * It is not meant to be used for variables, class names, etc. In code, you should
119
+ * use a more specific name for your purposes (e.g. `reactCreateModalComponentName`).
120
+ */
121
+ userFriendlyPluralName: string;
122
+ /**
123
+ * Internal cache for conjugated names.
124
+ *
125
+ * IMPORTANT: Do not use these names in generated code. Instead, they are provided to allow
126
+ * easy creation of names in the registration functions!
127
+ *
128
+ * @internal
129
+ */
130
+ _conjugated: Conjugated;
131
+ };
132
+ export type GeneratorOptions = {
133
+ /**
134
+ * If true, the generator will continue generation even if it encounters errors.
135
+ *
136
+ * Default: false
137
+ */
138
+ readonly ignoreErrors: boolean;
139
+ errors: string[];
140
+ /**
141
+ * Optional glob pattern to filter files during generation (e.g., '**\/*.ts' or 'backend/libs/**').
142
+ * When specified, only files matching this pattern will be processed (generated, linted, formatted, and synced).
143
+ *
144
+ * Default: undefined (no filtering)
145
+ */
146
+ filePattern?: string;
147
+ };
148
+ export type ExtendContext<Context, ContextExtension> = Context & ContextExtension;
149
+ export type ExtendModelContext<Context, ModelContextExtension> = Context extends {
150
+ models: Map<infer K, infer V>;
151
+ } ? Omit<Context, 'models'> & {
152
+ models: Map<K, V & ModelContextExtension>;
153
+ } : never;
154
+ export type ExtendEnumContext<Context, EnumContextExtension> = Context extends {
155
+ enums: Map<infer K, infer V>;
156
+ } ? Omit<Context, 'enums'> & {
157
+ enums: Map<K, V & EnumContextExtension>;
158
+ } : never;
159
+ export type ExtendContextAndModel<Context, Extension, ModelContextExtension> = ExtendModelContext<ExtendContext<Context, Extension>, ModelContextExtension>;
160
+ export type ExtendContextAndModelAndEnum<Context, Extension, ModelContextExtension, EnumContextExtension> = ExtendEnumContext<ExtendModelContext<ExtendContext<Context, Extension>, ModelContextExtension>, EnumContextExtension>;
161
+ export type InferModelContext<Context> = Context extends {
162
+ models: Map<any, infer V>;
163
+ } ? V : never;
164
+ export type InferEnumContext<Context> = Context extends {
165
+ enums: Map<any, infer V>;
166
+ } ? V : never;
167
+ export declare function prepareBaseContext(schema: Schema.ProjectSchema, opts?: Partial<GeneratorOptions>): Context;
168
+ /**
169
+ * Helper function for tests to create a mock schema.
170
+ */
171
+ export declare function mockSchema(schema?: Partial<Schema.ProjectSchema>): Schema.ProjectSchema;
172
+ export declare function mockSchemaWithDefaultModels(schema?: Partial<Schema.ProjectSchema>): Schema.ProjectSchema;
173
+ export declare function getBaseModelContext(model: Schema.Model): ModelContext;
174
+ export declare function getBaseEnumContext(enumSchema: Schema.Enum): EnumContext;
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.prepareBaseContext = prepareBaseContext;
37
+ exports.mockSchema = mockSchema;
38
+ exports.mockSchemaWithDefaultModels = mockSchemaWithDefaultModels;
39
+ exports.getBaseModelContext = getBaseModelContext;
40
+ exports.getBaseEnumContext = getBaseEnumContext;
41
+ const Schema = __importStar(require("@postxl/schema"));
42
+ const utils_1 = require("@postxl/utils");
43
+ const branded_types_1 = require("./helpers/branded.types");
44
+ const vfs_class_1 = require("./utils/vfs.class");
45
+ const defaultGeneratorOptions = {
46
+ ignoreErrors: false,
47
+ errors: [],
48
+ };
49
+ function prepareBaseContext(schema, opts = defaultGeneratorOptions) {
50
+ const options = { ...defaultGeneratorOptions, ...opts };
51
+ const models = new Map();
52
+ const enums = new Map();
53
+ for (const model of schema.models.values()) {
54
+ models.set(model.name, getBaseModelContext(model));
55
+ }
56
+ for (const enumSchema of schema.enums.values()) {
57
+ enums.set(enumSchema.name, getBaseEnumContext(enumSchema));
58
+ }
59
+ return {
60
+ schema: schema,
61
+ vfs: new vfs_class_1.VirtualFileSystem(options.filePattern ? { filePattern: options.filePattern } : undefined),
62
+ models,
63
+ enums,
64
+ options,
65
+ };
66
+ }
67
+ /**
68
+ * Helper function for tests to create a mock schema.
69
+ */
70
+ function mockSchema(schema = {}) {
71
+ return {
72
+ name: 'PXL Mock',
73
+ slug: 'pxl-mock',
74
+ projectType: { kind: 'standalone' },
75
+ models: new Map(),
76
+ enums: new Map(),
77
+ ...schema,
78
+ };
79
+ }
80
+ function mockSchemaWithDefaultModels(schema = {}) {
81
+ return Schema.zProjectSchema.parse({
82
+ name: 'PXL Mock',
83
+ slug: 'pxl-mock',
84
+ projectType: { kind: 'standalone' },
85
+ ...schema,
86
+ });
87
+ }
88
+ function getBaseModelContext(model) {
89
+ const { PascalCase, camelCase, uncapitalizedPlural, capitalized, capitalizedPlural } = (0, utils_1.conjugateNames)(model.name);
90
+ const relatedModelNames = new Set();
91
+ extractModelNamesFromFields(model.fields, relatedModelNames);
92
+ return {
93
+ ...model,
94
+ userFriendlyName: PascalCase,
95
+ userFriendlyNamePlural: capitalizedPlural,
96
+ internalSingularName: (0, branded_types_1.toVariableName)(camelCase),
97
+ internalSingularNameCapitalized: (0, branded_types_1.toVariableName)(capitalized),
98
+ internalPluralName: (0, branded_types_1.toVariableName)(uncapitalizedPlural),
99
+ internalPluralNameCapitalized: (0, branded_types_1.toVariableName)(capitalizedPlural),
100
+ _conjugated: (0, utils_1.conjugateNames)(model.name),
101
+ relatedModelNames,
102
+ };
103
+ }
104
+ function getBaseEnumContext(enumSchema) {
105
+ const { PascalCase, capitalizedPlural } = (0, utils_1.conjugateNames)(enumSchema.name);
106
+ return {
107
+ ...enumSchema,
108
+ userFriendlyName: PascalCase,
109
+ userFriendlyPluralName: capitalizedPlural,
110
+ _conjugated: (0, utils_1.conjugateNames)(enumSchema.name),
111
+ };
112
+ }
113
+ function extractModelNamesFromFields(fields, models) {
114
+ for (const field of fields.values()) {
115
+ if (field.kind === 'relation' && field.referencedModelName) {
116
+ models.add(field.referencedModelName);
117
+ }
118
+ else if (field.kind === 'discriminatedUnion') {
119
+ extractModelNamesFromFields(field.commonFields, models);
120
+ for (const member of field.members.values()) {
121
+ extractModelNamesFromFields(member.fields, models);
122
+ }
123
+ }
124
+ }
125
+ }
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Utility types and functions that brand strings with a specific prefix.
3
+ *
4
+ * The following types are available:
5
+ *
6
+ * Generator related types:
7
+ * - `GeneratorInterfaceId`
8
+ *
9
+ * Code related types:
10
+ * - `TypeName` (and `AnnotatedTypeName` for runtime type checking)
11
+ * - `FunctionName`
12
+ * - `ClassName`
13
+ * - `PackageName` - a package name from npm, JSR or monorepo, e.g. "@postxl/utils"
14
+ * - `ConstantValue` - a constant value that is used in the generated code, e.g. "POSTXL"
15
+ * - `DiscriminantValue` - a discriminant value, used to discriminate union types, e.g. "create", "update", "delete"
16
+ *
17
+ * Path and file related types:
18
+ * - `FileName` - file without a file extension, e.g. "aggregation.type" (no path!)
19
+ * - `FolderName` - a folder without the trailing and leading slash (e.g. "aggregation").
20
+ * - `FilePath` - a relative or absolute path to a file or folder.
21
+ *
22
+ * The following names are provided by the schema package and not part of this file:
23
+ * - `ModelName`
24
+ * - `FieldName`
25
+ * - `EnumName`
26
+ *
27
+ * We use Zod's `.brand()` method to brand strings with a specific prefix.
28
+ *
29
+ * Additionally, we provide the following union types:
30
+ * - `Importable`: TypeName | FunctionName | ClassName
31
+ * - `ImportPaths`: FilePath | PackageName
32
+ */
33
+ import z from 'zod';
34
+ declare const zGeneratorInterfaceId: z.ZodBranded<z.ZodString, "PXL.GeneratorInterfaceId">;
35
+ /**
36
+ * A generator interface id that is used identify what interface a generator implements.
37
+ */
38
+ export type GeneratorInterfaceId = z.infer<typeof zGeneratorInterfaceId>;
39
+ export declare const toGeneratorInterfaceId: (input: string) => string & z.BRAND<"PXL.GeneratorInterfaceId">;
40
+ declare const zTypeName: z.ZodBranded<z.ZodBranded<z.ZodString, "PXL.TypeName">, "PXL.Importable">;
41
+ /**
42
+ * A type name that is used to refer to a type in the generated code.
43
+ */
44
+ export type TypeName = z.infer<typeof zTypeName>;
45
+ export declare const toTypeName: (input: string) => string & z.BRAND<"PXL.TypeName"> & z.BRAND<"PXL.Importable">;
46
+ /**
47
+ * A TypeName that is annotated with the kind of the type.
48
+ * Note: This is used when distinguishing between kinds is required at runtime.
49
+ */
50
+ export type AnnotatedTypeName = {
51
+ typeName: TypeName;
52
+ kind: 'TypeName';
53
+ };
54
+ /**
55
+ * Converts a branded string to a branded TypeName.
56
+ */
57
+ export declare const toAnnotatedTypeName: (name: TypeName) => AnnotatedTypeName;
58
+ /**
59
+ * Type guard to check if a given type is an AnnotatedTypeName.
60
+ */
61
+ export declare const isAnnotatedTypeName: (t: string | AnnotatedTypeName) => t is AnnotatedTypeName;
62
+ declare const zFunctionName: z.ZodBranded<z.ZodBranded<z.ZodString, "PXL.FunctionName">, "PXL.Importable">;
63
+ /**
64
+ * A function name that is used to refer to a function in the generated code.
65
+ */
66
+ export type FunctionName = z.infer<typeof zFunctionName>;
67
+ export declare const toFunctionName: (input: string) => string & z.BRAND<"PXL.FunctionName"> & z.BRAND<"PXL.Importable">;
68
+ declare const zVariableName: z.ZodBranded<z.ZodBranded<z.ZodString, "PXL.VariableName">, "PXL.Importable">;
69
+ /**
70
+ * A variable name that is used to refer to a variable in the generated code.
71
+ */
72
+ export type VariableName = z.infer<typeof zVariableName>;
73
+ export declare const toVariableName: (input: string) => string & z.BRAND<"PXL.VariableName"> & z.BRAND<"PXL.Importable">;
74
+ declare const zPostXlPackageName: z.ZodBranded<z.ZodEffects<z.ZodString, string, string>, "PXL.PackageName">;
75
+ /**
76
+ * A package name that is used to refer to a package in the generated code.
77
+ */
78
+ export declare const toPostXlPackageName: (input: string) => string & z.BRAND<"PXL.PackageName">;
79
+ export declare const toPackageName: (input: string) => string & z.BRAND<"PXL.PackageName">;
80
+ /**
81
+ * A package name that is used to refer to a package name that is provided via
82
+ * in package.json or is a NodeJS module.
83
+ * E.g. "fs", "random", "@nestjs/common".
84
+ */
85
+ export type PackageName = z.infer<typeof zPostXlPackageName>;
86
+ declare const zClassName: z.ZodBranded<z.ZodBranded<z.ZodString, "PXL.ClassName">, "PXL.Importable">;
87
+ /**
88
+ * A class name that is used to refer to a class in the generated code.
89
+ */
90
+ export type ClassName = z.infer<typeof zClassName>;
91
+ export declare const toClassName: (input: string) => string & z.BRAND<"PXL.ClassName"> & z.BRAND<"PXL.Importable">;
92
+ declare const zConstantName: z.ZodBranded<z.ZodBranded<z.ZodString, "PXL.ConstantName">, "PXL.Importable">;
93
+ /**
94
+ * A constant name that is used to refer to a constant in the generated code.
95
+ */
96
+ export type ConstantName = z.infer<typeof zConstantName>;
97
+ export declare const toConstantName: (input: string) => string & z.BRAND<"PXL.ConstantName"> & z.BRAND<"PXL.Importable">;
98
+ declare const zConstantValue: z.ZodBranded<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>, "PXL.ConstantValue">;
99
+ /**
100
+ * A constant value that is used in the generated code.
101
+ */
102
+ export type ConstantValue = z.infer<typeof zConstantValue>;
103
+ export declare const toConstantValue: (input: string | number | boolean | null) => (string | number | boolean | null) & z.BRAND<"PXL.ConstantValue">;
104
+ declare const zDiscriminantValue: z.ZodBranded<z.ZodString, "PXL.DiscriminantValue">;
105
+ /**
106
+ * A discriminant value, used to discriminate union types.
107
+ */
108
+ export type DiscriminantValue = z.infer<typeof zDiscriminantValue>;
109
+ export declare const toDiscriminantValue: (input: string) => string & z.BRAND<"PXL.DiscriminantValue">;
110
+ declare const zFileName: z.ZodBranded<z.ZodString, "PXL.FileName">;
111
+ /**
112
+ * A file name that is used to refer to a file in the generated code.
113
+ */
114
+ export type FileName = z.infer<typeof zFileName>;
115
+ export declare const toFileName: (input: string) => string & z.BRAND<"PXL.FileName">;
116
+ declare const zFolderName: z.ZodBranded<z.ZodString, "PXL.FolderName">;
117
+ /**
118
+ * A folder name that is used to refer to a folder in the generated code.
119
+ */
120
+ export type FolderName = z.infer<typeof zFolderName>;
121
+ export declare const toFolderName: (input: string) => string & z.BRAND<"PXL.FolderName">;
122
+ declare const zFilePath: z.ZodBranded<z.ZodString, "PXL.FilePath">;
123
+ /**
124
+ * A file path that is used to refer to a file in the generated code.
125
+ */
126
+ export type FilePath = z.infer<typeof zFilePath>;
127
+ export declare const toFilePath: (input: string) => string & z.BRAND<"PXL.FilePath">;
128
+ declare const zBackendModuleName: z.ZodBranded<z.ZodString, "PXL.BackendModuleName">;
129
+ /**
130
+ * A backend module name that is used to refer to a module in the backend.
131
+ * E.g. `@actions`.
132
+ */
133
+ export type BackendModuleName = z.infer<typeof zBackendModuleName>;
134
+ export declare const toBackendModuleName: (input: string) => string & z.BRAND<"PXL.BackendModuleName">;
135
+ declare const zBackendModuleLocation: z.ZodBranded<z.ZodString, "PXL.BackendModuleLocation">;
136
+ /**
137
+ * A module location is a reference to a file in a locale backend module.
138
+ * E.g. `@actions/actions.types`.
139
+ *
140
+ * Background: In the backend, we do not use index.ts barrel files to control the export
141
+ * of entries from a module, as this leads to problems that are very hard to debug.
142
+ * (see (NestJS recommendation)[https://docs.nestjs.com/faq/common-errors#cannot-resolve-dependency-error]).
143
+ * Therefore, we need to reference the actual file together with the package name.
144
+ */
145
+ export type BackendModuleLocation = z.infer<typeof zBackendModuleLocation>;
146
+ export declare const toBackendModuleLocation: (input: `@${string}`) => string & z.BRAND<"PXL.BackendModuleLocation">;
147
+ export type ImportableTypes = TypeName | FunctionName | ClassName | ConstantName | AnnotatedTypeName;
148
+ export type ImportPaths = FilePath | PackageName | BackendModuleLocation;
149
+ export {};
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ /**
3
+ * Utility types and functions that brand strings with a specific prefix.
4
+ *
5
+ * The following types are available:
6
+ *
7
+ * Generator related types:
8
+ * - `GeneratorInterfaceId`
9
+ *
10
+ * Code related types:
11
+ * - `TypeName` (and `AnnotatedTypeName` for runtime type checking)
12
+ * - `FunctionName`
13
+ * - `ClassName`
14
+ * - `PackageName` - a package name from npm, JSR or monorepo, e.g. "@postxl/utils"
15
+ * - `ConstantValue` - a constant value that is used in the generated code, e.g. "POSTXL"
16
+ * - `DiscriminantValue` - a discriminant value, used to discriminate union types, e.g. "create", "update", "delete"
17
+ *
18
+ * Path and file related types:
19
+ * - `FileName` - file without a file extension, e.g. "aggregation.type" (no path!)
20
+ * - `FolderName` - a folder without the trailing and leading slash (e.g. "aggregation").
21
+ * - `FilePath` - a relative or absolute path to a file or folder.
22
+ *
23
+ * The following names are provided by the schema package and not part of this file:
24
+ * - `ModelName`
25
+ * - `FieldName`
26
+ * - `EnumName`
27
+ *
28
+ * We use Zod's `.brand()` method to brand strings with a specific prefix.
29
+ *
30
+ * Additionally, we provide the following union types:
31
+ * - `Importable`: TypeName | FunctionName | ClassName
32
+ * - `ImportPaths`: FilePath | PackageName
33
+ */
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.toBackendModuleLocation = exports.toBackendModuleName = exports.toFilePath = exports.toFolderName = exports.toFileName = exports.toDiscriminantValue = exports.toConstantValue = exports.toConstantName = exports.toClassName = exports.toPackageName = exports.toPostXlPackageName = exports.toVariableName = exports.toFunctionName = exports.isAnnotatedTypeName = exports.toAnnotatedTypeName = exports.toTypeName = exports.toGeneratorInterfaceId = void 0;
39
+ const zod_1 = __importDefault(require("zod"));
40
+ const zGeneratorInterfaceId = zod_1.default.string().brand('PXL.GeneratorInterfaceId');
41
+ const toGeneratorInterfaceId = (input) => zGeneratorInterfaceId.parse(input);
42
+ exports.toGeneratorInterfaceId = toGeneratorInterfaceId;
43
+ const zTypeName = zod_1.default.string().brand('PXL.TypeName').brand('PXL.Importable');
44
+ const toTypeName = (input) => zTypeName.parse(input);
45
+ exports.toTypeName = toTypeName;
46
+ /**
47
+ * Converts a branded string to a branded TypeName.
48
+ */
49
+ const toAnnotatedTypeName = (name) => ({
50
+ typeName: name,
51
+ kind: 'TypeName',
52
+ });
53
+ exports.toAnnotatedTypeName = toAnnotatedTypeName;
54
+ /**
55
+ * Type guard to check if a given type is an AnnotatedTypeName.
56
+ */
57
+ const isAnnotatedTypeName = (t) => typeof t === 'object' && t.kind === 'TypeName';
58
+ exports.isAnnotatedTypeName = isAnnotatedTypeName;
59
+ const zFunctionName = zod_1.default.string().brand('PXL.FunctionName').brand('PXL.Importable');
60
+ const toFunctionName = (input) => zFunctionName.parse(input);
61
+ exports.toFunctionName = toFunctionName;
62
+ const zVariableName = zod_1.default.string().brand('PXL.VariableName').brand('PXL.Importable');
63
+ const toVariableName = (input) => zVariableName.parse(input);
64
+ exports.toVariableName = toVariableName;
65
+ const zPostXlPackageName = zod_1.default
66
+ .string()
67
+ .refine((name) => name.startsWith('@postxl/'), (name) => ({ message: `Package name must start with "@postxl/", got "${name}"!` }))
68
+ .brand('PXL.PackageName');
69
+ /**
70
+ * A package name that is used to refer to a package in the generated code.
71
+ */
72
+ const toPostXlPackageName = (input) => zPostXlPackageName.parse(input);
73
+ exports.toPostXlPackageName = toPostXlPackageName;
74
+ const zPackageName = zod_1.default
75
+ .string()
76
+ //TODO: To be debugged:
77
+ // .refine(
78
+ // // Source: https://github.com/dword-design/package-name-regex/blob/806bbaafb3b9deab270b071b76a0f4e0bcfc1be9/src/index.js#L2
79
+ // (name) => /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(name),
80
+ // (name) => ({ message: `Package name must be a valid package name, get ${name}"!` }),
81
+ // )
82
+ .brand('PXL.PackageName');
83
+ const toPackageName = (input) => zPackageName.parse(input);
84
+ exports.toPackageName = toPackageName;
85
+ const zClassName = zod_1.default.string().brand('PXL.ClassName').brand('PXL.Importable');
86
+ const toClassName = (input) => zClassName.parse(input);
87
+ exports.toClassName = toClassName;
88
+ const zConstantName = zod_1.default.string().brand('PXL.ConstantName').brand('PXL.Importable');
89
+ const toConstantName = (input) => zConstantName.parse(input);
90
+ exports.toConstantName = toConstantName;
91
+ const zConstantValue = zod_1.default.union([zod_1.default.string(), zod_1.default.number(), zod_1.default.boolean(), zod_1.default.null()]).brand('PXL.ConstantValue');
92
+ const toConstantValue = (input) => zConstantValue.parse(input);
93
+ exports.toConstantValue = toConstantValue;
94
+ const zDiscriminantValue = zod_1.default.string().brand('PXL.DiscriminantValue');
95
+ const toDiscriminantValue = (input) => zDiscriminantValue.parse(input);
96
+ exports.toDiscriminantValue = toDiscriminantValue;
97
+ const zFileName = zod_1.default.string().brand('PXL.FileName');
98
+ const toFileName = (input) => zFileName.parse(input);
99
+ exports.toFileName = toFileName;
100
+ const zFolderName = zod_1.default.string().brand('PXL.FolderName');
101
+ const toFolderName = (input) => zFolderName.parse(input);
102
+ exports.toFolderName = toFolderName;
103
+ const zFilePath = zod_1.default.string().brand('PXL.FilePath');
104
+ const toFilePath = (input) => zFilePath.parse(input);
105
+ exports.toFilePath = toFilePath;
106
+ const zBackendModuleName = zod_1.default.string().brand('PXL.BackendModuleName');
107
+ const toBackendModuleName = (input) => zBackendModuleName.parse(input);
108
+ exports.toBackendModuleName = toBackendModuleName;
109
+ const zBackendModuleLocation = zod_1.default.string().brand('PXL.BackendModuleLocation');
110
+ const toBackendModuleLocation = (input) => zBackendModuleLocation.parse(input);
111
+ exports.toBackendModuleLocation = toBackendModuleLocation;
@@ -0,0 +1,27 @@
1
+ import { DeepPartial } from '@postxl/utils';
2
+ /**
3
+ * A utility class that allows to build a configuration object incrementally.
4
+ *
5
+ * Example usage:
6
+ * ```ts
7
+ * const config = new ConfigBuilder({ a: [1, 2], b: { c: 3 } })
8
+ * .with({ a: [3, 4] })
9
+ * .with({ b: { d: 4 } })
10
+ * .with({ c: 'x' })
11
+ * .done()
12
+ * ```
13
+ *
14
+ * The resulting config will be:
15
+ * ```ts
16
+ * { a: [1, 2, 3, 4], b: { c: 3, d: 4 }, c: 'x' }
17
+ * ```
18
+ */
19
+ export declare class ConfigBuilder<Config extends Record<string, unknown>> {
20
+ #private;
21
+ constructor(base: Config);
22
+ /**
23
+ * Updates the current configuration with the given partial update.
24
+ */
25
+ with(update: DeepPartial<Config>): this;
26
+ done(): Config;
27
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigBuilder = void 0;
4
+ /**
5
+ * A utility class that allows to build a configuration object incrementally.
6
+ *
7
+ * Example usage:
8
+ * ```ts
9
+ * const config = new ConfigBuilder({ a: [1, 2], b: { c: 3 } })
10
+ * .with({ a: [3, 4] })
11
+ * .with({ b: { d: 4 } })
12
+ * .with({ c: 'x' })
13
+ * .done()
14
+ * ```
15
+ *
16
+ * The resulting config will be:
17
+ * ```ts
18
+ * { a: [1, 2, 3, 4], b: { c: 3, d: 4 }, c: 'x' }
19
+ * ```
20
+ */
21
+ class ConfigBuilder {
22
+ #config;
23
+ constructor(base) {
24
+ this.#config = base;
25
+ }
26
+ /**
27
+ * Deep merge two objects.
28
+ */
29
+ #deepMerge(target, source) {
30
+ for (const key in source) {
31
+ if (Array.isArray(source[key])) {
32
+ target[key] = Array.isArray(target[key]) ? [...target[key], ...source[key]] : source[key];
33
+ }
34
+ else if (source[key] !== null && typeof source[key] === 'object') {
35
+ target[key] = this.#deepMerge(target[key] || {}, source[key]);
36
+ }
37
+ else {
38
+ target[key] = source[key];
39
+ }
40
+ }
41
+ return target;
42
+ }
43
+ /**
44
+ * Updates the current configuration with the given partial update.
45
+ */
46
+ with(update) {
47
+ this.#config = this.#deepMerge(this.#config, update);
48
+ return this;
49
+ }
50
+ done() {
51
+ return this.#config;
52
+ }
53
+ }
54
+ exports.ConfigBuilder = ConfigBuilder;