@postxl/generator 0.4.0 → 0.6.0

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 (94) hide show
  1. package/dist/{src/generator.js → generator.js} +42 -59
  2. package/dist/{src/generators → generators}/enums/react.generator.d.ts +1 -1
  3. package/dist/{src/generators → generators}/enums/react.generator.js +2 -2
  4. package/dist/{src/generators → generators}/indices/repositories.generator.js +2 -2
  5. package/dist/{src/generators → generators}/indices/seed.generator.js +1 -1
  6. package/dist/{src/generators → generators}/indices/stubs.generator.js +1 -1
  7. package/dist/{src/generators → generators}/indices/types.generator.js +2 -2
  8. package/dist/{src/generators → generators}/models/react.generator/index.d.ts +1 -1
  9. package/dist/{src/generators → generators}/models/react.generator/index.js +18 -13
  10. package/dist/{src/generators → generators}/models/react.generator/library.generator.d.ts +3 -0
  11. package/dist/{src/generators → generators}/models/react.generator/library.generator.js +3 -0
  12. package/dist/{src/generators → generators}/models/react.generator/lookup.generator.js +21 -16
  13. package/dist/{src/lib → lib}/exports.d.ts +17 -2
  14. package/dist/{src/lib → lib}/exports.js +24 -2
  15. package/package.json +6 -6
  16. package/dist/jest.config.d.ts +0 -3
  17. package/dist/jest.config.js +0 -17
  18. package/dist/src/lib/vfs.d.ts +0 -137
  19. package/dist/src/lib/vfs.js +0 -431
  20. package/dist/tests/attributes.test.d.ts +0 -1
  21. package/dist/tests/attributes.test.js +0 -76
  22. package/dist/tests/file.test.d.ts +0 -1
  23. package/dist/tests/file.test.js +0 -26
  24. package/dist/tests/utils/random.d.ts +0 -3
  25. package/dist/tests/utils/random.js +0 -15
  26. package/dist/tests/vfs.test.d.ts +0 -1
  27. package/dist/tests/vfs.test.js +0 -74
  28. package/dist/tsconfig.tsbuildinfo +0 -1
  29. /package/dist/{src/generator.d.ts → generator.d.ts} +0 -0
  30. /package/dist/{src/generators → generators}/enums/types.generator.d.ts +0 -0
  31. /package/dist/{src/generators → generators}/enums/types.generator.js +0 -0
  32. /package/dist/{src/generators → generators}/indices/datamockmodule.generator.d.ts +0 -0
  33. /package/dist/{src/generators → generators}/indices/datamockmodule.generator.js +0 -0
  34. /package/dist/{src/generators → generators}/indices/datamodule.generator.d.ts +0 -0
  35. /package/dist/{src/generators → generators}/indices/datamodule.generator.js +0 -0
  36. /package/dist/{src/generators → generators}/indices/dataservice.generator.d.ts +0 -0
  37. /package/dist/{src/generators → generators}/indices/dataservice.generator.js +0 -0
  38. /package/dist/{src/generators → generators}/indices/emptydatabasemigration.generator.d.ts +0 -0
  39. /package/dist/{src/generators → generators}/indices/emptydatabasemigration.generator.js +0 -0
  40. /package/dist/{src/generators → generators}/indices/repositories.generator.d.ts +0 -0
  41. /package/dist/{src/generators → generators}/indices/seed.generator.d.ts +0 -0
  42. /package/dist/{src/generators → generators}/indices/stubs.generator.d.ts +0 -0
  43. /package/dist/{src/generators → generators}/indices/testdataservice.generator.d.ts +0 -0
  44. /package/dist/{src/generators → generators}/indices/testdataservice.generator.js +0 -0
  45. /package/dist/{src/generators → generators}/indices/types.generator.d.ts +0 -0
  46. /package/dist/{src/generators → generators}/models/react.generator/context.generator.d.ts +0 -0
  47. /package/dist/{src/generators → generators}/models/react.generator/context.generator.js +0 -0
  48. /package/dist/{src/generators → generators}/models/react.generator/lookup.generator.d.ts +0 -0
  49. /package/dist/{src/generators → generators}/models/react.generator/modals.generator.d.ts +0 -0
  50. /package/dist/{src/generators → generators}/models/react.generator/modals.generator.js +0 -0
  51. /package/dist/{src/generators → generators}/models/repository.generator.d.ts +0 -0
  52. /package/dist/{src/generators → generators}/models/repository.generator.js +0 -0
  53. /package/dist/{src/generators → generators}/models/route.generator.d.ts +0 -0
  54. /package/dist/{src/generators → generators}/models/route.generator.js +0 -0
  55. /package/dist/{src/generators → generators}/models/seed.generator.d.ts +0 -0
  56. /package/dist/{src/generators → generators}/models/seed.generator.js +0 -0
  57. /package/dist/{src/generators → generators}/models/stub.generator.d.ts +0 -0
  58. /package/dist/{src/generators → generators}/models/stub.generator.js +0 -0
  59. /package/dist/{src/generators → generators}/models/types.generator.d.ts +0 -0
  60. /package/dist/{src/generators → generators}/models/types.generator.js +0 -0
  61. /package/dist/{src/lib → lib}/attributes.d.ts +0 -0
  62. /package/dist/{src/lib → lib}/attributes.js +0 -0
  63. /package/dist/{src/lib → lib}/imports.d.ts +0 -0
  64. /package/dist/{src/lib → lib}/imports.js +0 -0
  65. /package/dist/{src/lib → lib}/meta.d.ts +0 -0
  66. /package/dist/{src/lib → lib}/meta.js +0 -0
  67. /package/dist/{src/lib → lib}/schema/fields.d.ts +0 -0
  68. /package/dist/{src/lib → lib}/schema/fields.js +0 -0
  69. /package/dist/{src/lib → lib}/schema/schema.d.ts +0 -0
  70. /package/dist/{src/lib → lib}/schema/schema.js +0 -0
  71. /package/dist/{src/lib → lib}/schema/types.d.ts +0 -0
  72. /package/dist/{src/lib → lib}/schema/types.js +0 -0
  73. /package/dist/{src/lib → lib}/schema/zod.d.ts +0 -0
  74. /package/dist/{src/lib → lib}/schema/zod.js +0 -0
  75. /package/dist/{src/lib → lib}/serializer.d.ts +0 -0
  76. /package/dist/{src/lib → lib}/serializer.js +0 -0
  77. /package/dist/{src/lib → lib}/types.d.ts +0 -0
  78. /package/dist/{src/lib → lib}/types.js +0 -0
  79. /package/dist/{src/lib → lib}/utils/error.d.ts +0 -0
  80. /package/dist/{src/lib → lib}/utils/error.js +0 -0
  81. /package/dist/{src/lib → lib}/utils/file.d.ts +0 -0
  82. /package/dist/{src/lib → lib}/utils/file.js +0 -0
  83. /package/dist/{src/lib → lib}/utils/logger.d.ts +0 -0
  84. /package/dist/{src/lib → lib}/utils/logger.js +0 -0
  85. /package/dist/{src/lib → lib}/utils/string.d.ts +0 -0
  86. /package/dist/{src/lib → lib}/utils/string.js +0 -0
  87. /package/dist/{src/lib → lib}/utils/types.d.ts +0 -0
  88. /package/dist/{src/lib → lib}/utils/types.js +0 -0
  89. /package/dist/{src/prisma → prisma}/attributes.d.ts +0 -0
  90. /package/dist/{src/prisma → prisma}/attributes.js +0 -0
  91. /package/dist/{src/prisma → prisma}/client-path.d.ts +0 -0
  92. /package/dist/{src/prisma → prisma}/client-path.js +0 -0
  93. /package/dist/{src/prisma → prisma}/parse.d.ts +0 -0
  94. /package/dist/{src/prisma → prisma}/parse.js +0 -0
@@ -1,137 +0,0 @@
1
- import * as prettier from 'prettier';
2
- type FileWriteError = 'EIP' | 'EISDIR';
3
- type FileReadError = 'ENF' | 'EISDIR';
4
- type FileStatus = 'UNCHANGED' | 'WRITTEN' | 'SKIPPED';
5
- /**
6
- * A utility class that helps you manage a collection of files.
7
- */
8
- export declare class VirtualFS {
9
- /**
10
- * Human readable messages for file write errors.
11
- */
12
- static WRITE_ERROR_MESSAGES: {
13
- [Key in FileWriteError]: string;
14
- };
15
- /**
16
- * Human readable messages for file read errors.
17
- */
18
- static READ_ERROR_MESSAGES: {
19
- [Key in FileReadError]: string;
20
- };
21
- private _files;
22
- constructor(files?: {
23
- [key: string]: string;
24
- });
25
- /**
26
- * Returns the chunks of the resolved path.
27
- */
28
- private _parse;
29
- /**
30
- * Writes the given contents to the given path. Path should be a relative path from the root
31
- * of the virtual file system with no special characters.
32
- */
33
- write(path: string, content: string): {
34
- ok: true;
35
- } | {
36
- ok: false;
37
- path: string;
38
- err: FileWriteError;
39
- };
40
- /**
41
- * Appends given content to the file at a given path if it exists.
42
- */
43
- append(path: string, content: string): {
44
- ok: true;
45
- } | {
46
- ok: false;
47
- path: string;
48
- err: FileWriteError | FileReadError;
49
- };
50
- /**
51
- * Copies given files to the given path.
52
- */
53
- copy(files: VirtualFS, path: string): void;
54
- /**
55
- * Lists all files and folders in the given path.
56
- */
57
- list(path: string): {
58
- kind: 'FILE' | 'FOLDER';
59
- name: string;
60
- }[];
61
- /**
62
- * Returns a dictionary of all files in the virtual file system indexed by their paths.
63
- */
64
- files(): {
65
- [path: string]: string;
66
- };
67
- /**
68
- * Lets you read the contents of a file in the given path.
69
- */
70
- read(path: string): {
71
- ok: true;
72
- content: string;
73
- } | {
74
- ok: false;
75
- path: string;
76
- err: FileReadError;
77
- };
78
- /**
79
- * Writes files to the given path, overriding managed files and ignoring
80
- * detached files (i.e. files that don't have a checksum value).
81
- *
82
- * Returns a list of paths that were written.
83
- */
84
- flush(relativeOutPath: string, force?: boolean): Promise<{
85
- status: FileStatus;
86
- path: string;
87
- }[]>;
88
- /**
89
- * Writes the contents of the file to a given path. If there's already a file there,
90
- * it checks the checksum and overrides it if the content hasn't changed.
91
- *
92
- * Returns `true` if the file was written, `false` if it wasn't.
93
- */
94
- private _safeWriteUTF8File;
95
- /**
96
- * Tries to read a file at a given path and surpresses the error if it fails to do so.
97
- */
98
- private _safeReadUTF8File;
99
- private static CHECKSUM_PREFIX;
100
- private static META_PREFIX;
101
- /**
102
- * Returns the checksum of the given content, ignoring
103
- * the line containing the checksum if present.
104
- */
105
- private _calculateContentChecksum;
106
- /**
107
- * Adds the checksum indicator to the given content.
108
- */
109
- private _appendChecksumToContent;
110
- /**
111
- * Adds arbitrary meta information to the given content.
112
- *
113
- * NOTE: This only changes when the content changes regardless of the change of the meta value.
114
- */
115
- private _appendMetaToContent;
116
- /**
117
- * Extracts the checksum from the given content.
118
- */
119
- private _extractChecksumFromContent;
120
- /**
121
- * Creates a new file system from the given directory.
122
- */
123
- static fromDirectory(cwd: string): Promise<VirtualFS>;
124
- /**
125
- * Walks the file tree, calling the given function for each file.
126
- */
127
- walk(fn: (path: string, content: string) => void): void;
128
- /**
129
- * Transforms files in the file system.
130
- */
131
- transform(fn: (path: string, content: string) => string): void;
132
- /**
133
- * Formats the file system using configuration in the given directory.
134
- */
135
- format(options?: prettier.Options | null): void;
136
- }
137
- export {};
@@ -1,431 +0,0 @@
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 (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __asyncValues = (this && this.__asyncValues) || function (o) {
35
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
36
- var m = o[Symbol.asyncIterator], i;
37
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
38
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
39
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
40
- };
41
- var __importDefault = (this && this.__importDefault) || function (mod) {
42
- return (mod && mod.__esModule) ? mod : { "default": mod };
43
- };
44
- Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.VirtualFS = void 0;
46
- const crypto = __importStar(require("crypto"));
47
- const prettier = __importStar(require("prettier"));
48
- const nodepath = __importStar(require("path"));
49
- const nodefs = __importStar(require("fs"));
50
- const util_1 = require("util");
51
- const fast_glob_1 = __importDefault(require("fast-glob"));
52
- const error_1 = require("./utils/error");
53
- const mkdir = (0, util_1.promisify)(nodefs.mkdir);
54
- const writefile = (0, util_1.promisify)(nodefs.writeFile);
55
- const readfile = (0, util_1.promisify)(nodefs.readFile);
56
- /**
57
- * A utility class that helps you manage a collection of files.
58
- */
59
- class VirtualFS {
60
- constructor(files) {
61
- this._files = { kind: 'FOLDER', children: {} };
62
- if (files) {
63
- for (const path in files) {
64
- this.write(path, files[path]);
65
- }
66
- }
67
- }
68
- /**
69
- * Returns the chunks of the resolved path.
70
- */
71
- _parse(path) {
72
- const parts = path.split('/');
73
- if (parts.length === 0) {
74
- return [];
75
- }
76
- // Remove the first empty string if the path starts with a slash.
77
- if (parts[0] === '' || parts[0] === '.') {
78
- parts.shift();
79
- }
80
- const resolved = [];
81
- while (parts.length > 0) {
82
- const part = parts.shift();
83
- if (part === '..') {
84
- resolved.pop();
85
- continue;
86
- }
87
- if (part === '.') {
88
- continue;
89
- }
90
- if (part === '' && parts.length > 0) {
91
- console.warn(`Empty subpath in path: ${path}`);
92
- continue;
93
- }
94
- resolved.push(part);
95
- }
96
- return resolved;
97
- }
98
- /**
99
- * Writes the given contents to the given path. Path should be a relative path from the root
100
- * of the virtual file system with no special characters.
101
- */
102
- write(path, content) {
103
- const parts = this._parse(path);
104
- let folder = parts.shift();
105
- let cwd = this._files;
106
- while (folder != null) {
107
- // We reached a file along the while descending the system.
108
- if (cwd.kind === 'FILE') {
109
- return { ok: false, path, err: 'EISDIR' };
110
- }
111
- if (cwd.kind === 'FOLDER') {
112
- // We found the folder where the file should be created.
113
- if (parts.length === 0 && folder !== '') {
114
- cwd.children[folder] = { kind: 'FILE', content };
115
- return { ok: true };
116
- }
117
- // Folder doesn't exist yet.
118
- if (cwd.children[folder] == null) {
119
- cwd.children[folder] = { kind: 'FOLDER', children: {} };
120
- }
121
- cwd = cwd.children[folder];
122
- folder = parts.shift();
123
- continue;
124
- }
125
- return { ok: false, path, err: 'EIP' };
126
- }
127
- return { ok: false, path, err: 'EIP' };
128
- }
129
- /**
130
- * Appends given content to the file at a given path if it exists.
131
- */
132
- append(path, content) {
133
- const existing = this.read(path);
134
- if (!existing.ok) {
135
- return existing;
136
- }
137
- return this.write(path, existing.content + '\n' + content);
138
- }
139
- /**
140
- * Copies given files to the given path.
141
- */
142
- copy(files, path) {
143
- walk(files._files, path, (path, content) => this.write(path, content));
144
- }
145
- /**
146
- * Lists all files and folders in the given path.
147
- */
148
- list(path) {
149
- const parts = this._parse(path);
150
- let folder = parts.shift();
151
- let cwd = this._files;
152
- // Descend the tree until we reach the folder we want to list.
153
- while (folder != null) {
154
- // It's possible that the path ends with a slash.
155
- if (folder === '' && parts.length === 0) {
156
- break;
157
- }
158
- if (cwd.kind === 'FOLDER' && cwd.children.hasOwnProperty(folder)) {
159
- cwd = cwd.children[folder];
160
- folder = parts.shift();
161
- continue;
162
- }
163
- return [];
164
- }
165
- // List items.
166
- const items = [];
167
- if (cwd.kind === 'FOLDER') {
168
- for (const [name, child] of Object.entries(cwd.children)) {
169
- items.push({ kind: child.kind, name });
170
- }
171
- }
172
- return items;
173
- }
174
- /**
175
- * Returns a dictionary of all files in the virtual file system indexed by their paths.
176
- */
177
- files() {
178
- const fs = {};
179
- walk(this._files, '/', (path, content) => {
180
- fs[path] = content;
181
- });
182
- return fs;
183
- }
184
- /**
185
- * Lets you read the contents of a file in the given path.
186
- */
187
- read(path) {
188
- const parts = this._parse(path);
189
- let folder = parts.shift();
190
- let cwd = this._files;
191
- while (folder != null) {
192
- if (cwd.kind === 'FOLDER' && cwd.children.hasOwnProperty(folder)) {
193
- cwd = cwd.children[folder];
194
- folder = parts.shift();
195
- continue;
196
- }
197
- return { ok: false, path, err: 'ENF' };
198
- }
199
- if (cwd.kind === 'FILE' && parts.length === 0) {
200
- return { ok: true, content: cwd.content };
201
- }
202
- return { ok: false, path, err: 'ENF' };
203
- }
204
- /**
205
- * Writes files to the given path, overriding managed files and ignoring
206
- * detached files (i.e. files that don't have a checksum value).
207
- *
208
- * Returns a list of paths that were written.
209
- */
210
- flush(relativeOutPath, force = false) {
211
- return __awaiter(this, void 0, void 0, function* () {
212
- const targetdir = nodepath.resolve(relativeOutPath);
213
- const tasks = Object.entries(this.files()).map(([path, content]) => __awaiter(this, void 0, void 0, function* () {
214
- const fullPath = nodepath.join(targetdir, path);
215
- const status = yield this._safeWriteUTF8File({ target: fullPath, content, force });
216
- return { path, status };
217
- }));
218
- const entries = yield Promise.all(tasks);
219
- return entries;
220
- });
221
- }
222
- /**
223
- * Writes the contents of the file to a given path. If there's already a file there,
224
- * it checks the checksum and overrides it if the content hasn't changed.
225
- *
226
- * Returns `true` if the file was written, `false` if it wasn't.
227
- */
228
- _safeWriteUTF8File({ target, content, force, }) {
229
- return __awaiter(this, void 0, void 0, function* () {
230
- const dir = nodepath.dirname(target);
231
- yield mkdir(dir, { recursive: true });
232
- const checksum = this._calculateContentChecksum(content);
233
- let status = 'WRITTEN';
234
- const currentFileContent = yield this._safeReadUTF8File(target);
235
- if (currentFileContent != null) {
236
- // NOTE: If the content of the file hasn't changed, then the calculated checksum
237
- // should match the one that's currently in the file.
238
- const currentChecksum = this._extractChecksumFromContent(currentFileContent);
239
- const expectedChecksum = this._calculateContentChecksum(currentFileContent);
240
- if (currentChecksum !== expectedChecksum) {
241
- status = 'SKIPPED';
242
- }
243
- else if (currentChecksum === checksum) {
244
- // NOTE: We only check the checksum. It's possible that the content of the file changed
245
- // in a way that doesn't affect the checksum (e.g. empty lines and spaces).
246
- status = 'UNCHANGED';
247
- }
248
- }
249
- // We manually override the status if the `force` flag is set.
250
- if (force) {
251
- status = 'WRITTEN';
252
- }
253
- if (status === 'WRITTEN') {
254
- const contentWithDate = this._appendMetaToContent(content, `date: ${new Date().toISOString()}`);
255
- const contentWithChecksum = this._appendChecksumToContent(contentWithDate);
256
- yield writefile(target, contentWithChecksum, { encoding: 'utf-8' });
257
- }
258
- return status;
259
- });
260
- }
261
- /**
262
- * Tries to read a file at a given path and surpresses the error if it fails to do so.
263
- */
264
- _safeReadUTF8File(target) {
265
- return __awaiter(this, void 0, void 0, function* () {
266
- try {
267
- const content = yield readfile(target, { encoding: 'utf-8' });
268
- return content;
269
- }
270
- catch (err) {
271
- return null;
272
- }
273
- });
274
- }
275
- /**
276
- * Returns the checksum of the given content, ignoring
277
- * the line containing the checksum if present.
278
- */
279
- _calculateContentChecksum(content) {
280
- const lines = content.split('\n');
281
- // Take the content and return SHA checksum
282
- const hash = crypto.createHash('sha256', {});
283
- for (let i = 0; i < lines.length; i++) {
284
- const line = lines[i].trim();
285
- if (line.length === 0 || line.startsWith(VirtualFS.CHECKSUM_PREFIX) || line.startsWith(VirtualFS.META_PREFIX)) {
286
- continue;
287
- }
288
- hash.update(line);
289
- }
290
- return hash.digest('hex');
291
- }
292
- /**
293
- * Adds the checksum indicator to the given content.
294
- */
295
- _appendChecksumToContent(content) {
296
- const checksum = this._calculateContentChecksum(content);
297
- // NOTE: We add a newline character to make Prettier happy. According to POSIX standard,
298
- // files should end with a newline - and Prettier obeys that. As the checksum
299
- // is added after we ran Prettier, we need to add the newline manually
300
- return content + '\n' + VirtualFS.CHECKSUM_PREFIX + checksum + '\n';
301
- }
302
- /**
303
- * Adds arbitrary meta information to the given content.
304
- *
305
- * NOTE: This only changes when the content changes regardless of the change of the meta value.
306
- */
307
- _appendMetaToContent(content, meta) {
308
- // NOTE: We add a newline character to make Prettier happy. According to POSIX standard,
309
- // files should end with a newline - and Prettier obeys that. As the checksum
310
- // is added after we ran Prettier, we need to add the newline manually
311
- return content + '\n' + VirtualFS.META_PREFIX + meta + '\n';
312
- }
313
- /**
314
- * Extracts the checksum from the given content.
315
- */
316
- _extractChecksumFromContent(content) {
317
- const lines = content.split('\n');
318
- for (let i = 0; i < lines.length; i++) {
319
- if (lines[i].includes(VirtualFS.CHECKSUM_PREFIX)) {
320
- return lines[i].replace(VirtualFS.CHECKSUM_PREFIX, '').replace('\r', '');
321
- }
322
- }
323
- return null;
324
- }
325
- /**
326
- * Creates a new file system from the given directory.
327
- */
328
- static fromDirectory(cwd) {
329
- var _a, e_1, _b, _c;
330
- return __awaiter(this, void 0, void 0, function* () {
331
- const fs = new VirtualFS();
332
- const entries = fast_glob_1.default.stream('**/*', { cwd, dot: true, onlyFiles: true });
333
- try {
334
- for (var _d = true, entries_1 = __asyncValues(entries), entries_1_1; entries_1_1 = yield entries_1.next(), _a = entries_1_1.done, !_a;) {
335
- _c = entries_1_1.value;
336
- _d = false;
337
- try {
338
- const entry = _c;
339
- const content = yield readfile(nodepath.join(cwd, entry.toString()), { encoding: 'utf-8' });
340
- fs.write(entry.toString(), content);
341
- }
342
- finally {
343
- _d = true;
344
- }
345
- }
346
- }
347
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
348
- finally {
349
- try {
350
- if (!_d && !_a && (_b = entries_1.return)) yield _b.call(entries_1);
351
- }
352
- finally { if (e_1) throw e_1.error; }
353
- }
354
- return fs;
355
- });
356
- }
357
- /**
358
- * Walks the file tree, calling the given function for each file.
359
- */
360
- walk(fn) {
361
- walk(this._files, '/', fn);
362
- }
363
- /**
364
- * Transforms files in the file system.
365
- */
366
- transform(fn) {
367
- this.walk((path, content) => {
368
- this.write(path, fn(path, content));
369
- });
370
- }
371
- /**
372
- * Formats the file system using configuration in the given directory.
373
- */
374
- format(options = null) {
375
- this.transform((path, content) => {
376
- var _a;
377
- const ext = nodepath.extname(path);
378
- let parser = undefined;
379
- if (ext === '.js' || ext === '.jsx') {
380
- parser = 'babel';
381
- }
382
- if (ext === '.ts' || ext === '.tsx') {
383
- parser = 'typescript';
384
- }
385
- if (ext === '.sql') {
386
- return content;
387
- }
388
- try {
389
- return prettier.format(content, Object.assign(Object.assign({}, options), { parser }));
390
- }
391
- catch (err) {
392
- (0, error_1.throwError)(`
393
- ${content}\n\n
394
- Failed to format ${path}\n\n
395
- Code fragment:\n\n
396
- ${(_a = err.codeFrame) !== null && _a !== void 0 ? _a : 'No code frame available'}}`);
397
- }
398
- });
399
- }
400
- }
401
- /**
402
- * Human readable messages for file write errors.
403
- */
404
- VirtualFS.WRITE_ERROR_MESSAGES = {
405
- EIP: 'Invalid path',
406
- EISDIR: 'Is a directory',
407
- };
408
- /**
409
- * Human readable messages for file read errors.
410
- */
411
- VirtualFS.READ_ERROR_MESSAGES = {
412
- ENF: 'No such file or directory',
413
- EISDIR: 'Is a directory',
414
- };
415
- // We add a collection of random strings that will never appear in the code otherwise.
416
- VirtualFS.CHECKSUM_PREFIX = `// PostXL checksum (#@!):`;
417
- VirtualFS.META_PREFIX = `// PostXL meta (#@!) `;
418
- exports.VirtualFS = VirtualFS;
419
- // MARK: - Utilities
420
- /**
421
- * Walks the file tree, calling the given function for each file, prepending the starting path.
422
- */
423
- function walk(tree, path, fn) {
424
- if (tree.kind === 'FILE') {
425
- fn(path, tree.content);
426
- return;
427
- }
428
- for (const [name, child] of Object.entries(tree.children)) {
429
- walk(child, nodepath.join(path, name), fn);
430
- }
431
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const attributes_1 = require("../src/prisma/attributes");
4
- describe('argument parser', () => {
5
- test('Blank argument should return blank string', () => {
6
- expect((0, attributes_1.parseArgumentToStringOrStringArray)('')).toEqual('');
7
- });
8
- test('Argument without quotes should return as is', () => {
9
- expect((0, attributes_1.parseArgumentToStringOrStringArray)('example')).toEqual('example');
10
- });
11
- test('Argument with quotes should return without quotes', () => {
12
- expect((0, attributes_1.parseArgumentToStringOrStringArray)('"example"')).toEqual('example');
13
- });
14
- test('Argument with escaped quotes should return without quotes', () => {
15
- expect((0, attributes_1.parseArgumentToStringOrStringArray)('"example \\"with quotes\\""')).toEqual('example "with quotes"');
16
- });
17
- test('Argument with array of strings should convert to array', () => {
18
- expect((0, attributes_1.parseArgumentToStringOrStringArray)('["example1", "example2"]')).toEqual(['example1', 'example2']);
19
- });
20
- });
21
- describe('attribute parser', () => {
22
- test('Missing documentation should return blank object', () => {
23
- expect((0, attributes_1.parseAttributesFromDocumentation)({})).toEqual({});
24
- });
25
- test('Entries without "@@" should be ignored', () => {
26
- expect((0, attributes_1.parseAttributesFromDocumentation)({ documentation: 'Some documentation' })).toEqual({});
27
- });
28
- test('Entries with "@@" should be parsed', () => {
29
- expect((0, attributes_1.parseAttributesFromDocumentation)({ documentation: '@@ignore()' })).toEqual({ ignore: '' });
30
- });
31
- test('Attributes should be converted to camelCase', () => {
32
- expect((0, attributes_1.parseAttributesFromDocumentation)({ documentation: '@@IGNORE()' })).toEqual({ iGNORE: '' });
33
- });
34
- });
35
- describe('model attribute: ignore', () => {
36
- test('should default to false', () => {
37
- expect((0, attributes_1.getModelAttributes)({}).ignore).toBe(false);
38
- expect((0, attributes_1.getModelAttributes)({ documentation: '' }).ignore).toBe(false);
39
- expect((0, attributes_1.getModelAttributes)({ documentation: '@@test()' }).ignore).toBe(false);
40
- });
41
- test('should be true if @@ignore attribute is provided', () => {
42
- expect((0, attributes_1.getModelAttributes)({ documentation: '@@ignore()' }).ignore).toBe(true);
43
- });
44
- });
45
- describe('field attribute: ignore', () => {
46
- test('should default to false', () => {
47
- expect((0, attributes_1.getFieldAttributes)({}).ignore).toBe(false);
48
- expect((0, attributes_1.getFieldAttributes)({ documentation: '' }).ignore).toBe(false);
49
- expect((0, attributes_1.getFieldAttributes)({ documentation: '@@test()' }).ignore).toBe(false);
50
- });
51
- test('should be true if @@ignore attribute is provided', () => {
52
- expect((0, attributes_1.getFieldAttributes)({ documentation: '@@ignore()' }).ignore).toBe(true);
53
- });
54
- test('should be true if Prisma field has isIgnored flag set to true', () => {
55
- expect((0, attributes_1.getFieldAttributes)({ isIgnored: true }).ignore).toBe(true);
56
- });
57
- });
58
- describe('field attributes: example and examples', () => {
59
- test('should default to undefined', () => {
60
- expect((0, attributes_1.getFieldAttributes)({}).examples).toBe(undefined);
61
- });
62
- test('should parse "@@examples" attribute', () => {
63
- expect((0, attributes_1.getFieldAttributes)({ documentation: '@@examples("test")' }).examples).toStrictEqual(['test']);
64
- });
65
- test('should parse "@@example" attribute', () => {
66
- expect((0, attributes_1.getFieldAttributes)({ documentation: '@@example("test")' }).examples).toStrictEqual(['test']);
67
- });
68
- test('should give precedence to "@@examples" over "@@example" attribute', () => {
69
- expect((0, attributes_1.getFieldAttributes)({ documentation: '@@example("B")\n@@examples("A")' }).examples).toStrictEqual([
70
- 'A',
71
- ]);
72
- });
73
- test('should parse "@@example" attribute with an array of examples', () => {
74
- expect((0, attributes_1.getFieldAttributes)({ documentation: '@@example("A", "B")' }).examples).toStrictEqual(['A', 'B']);
75
- });
76
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const file_1 = require("../src/lib/utils/file");
4
- describe('virtual file system', () => {
5
- test('correctly resolves path to the same file', () => {
6
- expect((0, file_1.getRelativePath)({ from: 'a/b/c', to: 'a/b/c' })).toEqual('./c');
7
- });
8
- test('correctly resolves path to a file in the same folder', () => {
9
- expect((0, file_1.getRelativePath)({ from: 'a/b/c', to: 'a/b/d' })).toEqual('./d');
10
- });
11
- test('correclty, resolves path to a file in a parent folder', () => {
12
- expect((0, file_1.getRelativePath)({ from: 'a/b/c', to: 'a/d' })).toEqual('../d');
13
- });
14
- test('correctly resolves completely different paths', () => {
15
- expect((0, file_1.getRelativePath)({ from: 'a/b/c', to: 'd/e/f' })).toEqual('../../d/e/f');
16
- });
17
- test('correctly resolves path to a package', () => {
18
- expect((0, file_1.getRelativePath)({ from: 'a/b/c', to: '@lib/package' })).toEqual('@lib/package');
19
- });
20
- test('correctly resolves relative paths', () => {
21
- expect((0, file_1.getRelativePath)({
22
- from: './backend/libs/data/src/services/data.module',
23
- to: './backend/libs/data/src/repositories/country.repository',
24
- })).toEqual('../repositories/country.repository');
25
- });
26
- });
@@ -1,3 +0,0 @@
1
- export declare namespace RandomUtils {
2
- function generateRandomAlphaNumericString(len: number): string;
3
- }