@postxl/generator 0.74.1 → 1.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.
- package/LICENSE +50 -0
- package/README.md +79 -1
- package/dist/generator-manager.class.d.ts +59 -0
- package/dist/generator-manager.class.js +221 -0
- package/dist/generator.class.d.ts +90 -0
- package/dist/generator.class.js +32 -0
- package/dist/generator.context.d.ts +174 -0
- package/dist/generator.context.js +125 -0
- package/dist/helpers/branded.types.d.ts +149 -0
- package/dist/helpers/branded.types.js +111 -0
- package/dist/helpers/config-builder.class.d.ts +27 -0
- package/dist/helpers/config-builder.class.js +54 -0
- package/dist/helpers/import-generator.class.d.ts +70 -0
- package/dist/helpers/import-generator.class.js +166 -0
- package/dist/helpers/importable.types.d.ts +52 -0
- package/dist/helpers/importable.types.js +15 -0
- package/dist/helpers/index-generator.class.d.ts +10 -0
- package/dist/helpers/index-generator.class.js +46 -0
- package/dist/helpers/index.d.ts +8 -0
- package/dist/helpers/index.js +24 -0
- package/dist/helpers/package-json.generator.d.ts +56 -0
- package/dist/helpers/package-json.generator.js +36 -0
- package/dist/helpers/tsconfig.generator.d.ts +1 -0
- package/dist/helpers/tsconfig.generator.js +14 -0
- package/dist/helpers/verify-context.d.ts +4 -0
- package/dist/helpers/verify-context.js +23 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +21 -0
- package/dist/utils/checksum.d.ts +10 -0
- package/dist/utils/checksum.js +132 -0
- package/dist/utils/fs-utils.d.ts +34 -0
- package/dist/utils/fs-utils.js +126 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.js +26 -0
- package/dist/utils/jsdoc.d.ts +12 -0
- package/dist/utils/jsdoc.js +37 -0
- package/dist/utils/lint.d.ts +46 -0
- package/dist/utils/lint.js +154 -0
- package/dist/utils/lockfile.d.ts +7 -0
- package/dist/utils/lockfile.js +80 -0
- package/dist/utils/logger.class.d.ts +25 -0
- package/dist/utils/logger.class.js +55 -0
- package/dist/utils/merge-conflict.d.ts +55 -0
- package/dist/utils/merge-conflict.js +264 -0
- package/dist/utils/path.d.ts +52 -0
- package/dist/utils/path.js +183 -0
- package/dist/utils/prettier-config.d.ts +2 -0
- package/dist/utils/prettier-config.js +13 -0
- package/dist/utils/prettier.d.ts +5 -0
- package/dist/utils/prettier.js +67 -0
- package/dist/utils/prettier.skiptest.d.ts +1 -0
- package/dist/utils/prettier.skiptest.js +22 -0
- package/dist/utils/promise.d.ts +2 -0
- package/dist/utils/promise.js +10 -0
- package/dist/utils/string-functions.d.ts +9 -0
- package/dist/utils/string-functions.js +23 -0
- package/dist/utils/sync-log-result.d.ts +9 -0
- package/dist/utils/sync-log-result.js +90 -0
- package/dist/utils/sync.d.ts +143 -0
- package/dist/utils/sync.js +325 -0
- package/dist/utils/template.d.ts +66 -0
- package/dist/utils/template.js +159 -0
- package/dist/utils/vfs.class.d.ts +115 -0
- package/dist/utils/vfs.class.js +239 -0
- package/dist/utils/zip.d.ts +13 -0
- package/dist/utils/zip.js +40 -0
- package/package.json +57 -34
- package/dist/generator.d.ts +0 -13
- package/dist/generator.js +0 -455
- package/dist/generators/enums/react.generator.d.ts +0 -10
- package/dist/generators/enums/react.generator.js +0 -110
- package/dist/generators/enums/types.generator.d.ts +0 -10
- package/dist/generators/enums/types.generator.js +0 -39
- package/dist/generators/indices/data/module.generator.d.ts +0 -9
- package/dist/generators/indices/data/module.generator.js +0 -60
- package/dist/generators/indices/data/service.generator.d.ts +0 -9
- package/dist/generators/indices/data/service.generator.js +0 -249
- package/dist/generators/indices/data/types.generator.d.ts +0 -9
- package/dist/generators/indices/data/types.generator.js +0 -49
- package/dist/generators/indices/dispatcher-service.generator.d.ts +0 -9
- package/dist/generators/indices/dispatcher-service.generator.js +0 -107
- package/dist/generators/indices/export/class.generator.d.ts +0 -9
- package/dist/generators/indices/export/class.generator.js +0 -140
- package/dist/generators/indices/export/encoder.generator.d.ts +0 -9
- package/dist/generators/indices/export/encoder.generator.js +0 -50
- package/dist/generators/indices/import/convert-functions.generator.d.ts +0 -9
- package/dist/generators/indices/import/convert-functions.generator.js +0 -509
- package/dist/generators/indices/import/decoder.generator.d.ts +0 -9
- package/dist/generators/indices/import/decoder.generator.js +0 -40
- package/dist/generators/indices/import/service.generator.d.ts +0 -9
- package/dist/generators/indices/import/service.generator.js +0 -573
- package/dist/generators/indices/import/types.generator.d.ts +0 -9
- package/dist/generators/indices/import/types.generator.js +0 -242
- package/dist/generators/indices/repositories.generator.d.ts +0 -9
- package/dist/generators/indices/repositories.generator.js +0 -25
- package/dist/generators/indices/routes.generator.d.ts +0 -9
- package/dist/generators/indices/routes.generator.js +0 -29
- package/dist/generators/indices/seed-migration.generator.d.ts +0 -9
- package/dist/generators/indices/seed-migration.generator.js +0 -36
- package/dist/generators/indices/seed-template.generator.d.ts +0 -9
- package/dist/generators/indices/seed-template.generator.js +0 -80
- package/dist/generators/indices/testids.generator.d.ts +0 -7
- package/dist/generators/indices/testids.generator.js +0 -71
- package/dist/generators/indices/types.generator.d.ts +0 -10
- package/dist/generators/indices/types.generator.js +0 -35
- package/dist/generators/indices/update/actiontypes.generator.d.ts +0 -9
- package/dist/generators/indices/update/actiontypes.generator.js +0 -49
- package/dist/generators/indices/update/module.generator.d.ts +0 -9
- package/dist/generators/indices/update/module.generator.js +0 -41
- package/dist/generators/indices/update/service.generator.d.ts +0 -9
- package/dist/generators/indices/update/service.generator.js +0 -34
- package/dist/generators/indices/view/module.generator.d.ts +0 -9
- package/dist/generators/indices/view/module.generator.js +0 -39
- package/dist/generators/indices/view/service.generator.d.ts +0 -9
- package/dist/generators/indices/view/service.generator.js +0 -34
- package/dist/generators/models/admin.page.generator.d.ts +0 -7
- package/dist/generators/models/admin.page.generator.js +0 -74
- package/dist/generators/models/export/encoder.generator.d.ts +0 -9
- package/dist/generators/models/export/encoder.generator.js +0 -51
- package/dist/generators/models/import/decoder.generator.d.ts +0 -9
- package/dist/generators/models/import/decoder.generator.js +0 -148
- package/dist/generators/models/react/context.generator.d.ts +0 -9
- package/dist/generators/models/react/context.generator.js +0 -71
- package/dist/generators/models/react/index.d.ts +0 -10
- package/dist/generators/models/react/index.js +0 -31
- package/dist/generators/models/react/library.generator.d.ts +0 -10
- package/dist/generators/models/react/library.generator.js +0 -94
- package/dist/generators/models/react/lookup.generator.d.ts +0 -9
- package/dist/generators/models/react/lookup.generator.js +0 -175
- package/dist/generators/models/react/modals.generator.d.ts +0 -23
- package/dist/generators/models/react/modals.generator.js +0 -710
- package/dist/generators/models/repository.generator.d.ts +0 -9
- package/dist/generators/models/repository.generator.js +0 -955
- package/dist/generators/models/route.generator.d.ts +0 -9
- package/dist/generators/models/route.generator.js +0 -92
- package/dist/generators/models/seed.generator.d.ts +0 -21
- package/dist/generators/models/seed.generator.js +0 -285
- package/dist/generators/models/stub.generator.d.ts +0 -9
- package/dist/generators/models/stub.generator.js +0 -92
- package/dist/generators/models/types.generator.d.ts +0 -9
- package/dist/generators/models/types.generator.js +0 -125
- package/dist/generators/models/update/service.generator.d.ts +0 -10
- package/dist/generators/models/update/service.generator.js +0 -302
- package/dist/generators/models/view/service.generator.d.ts +0 -10
- package/dist/generators/models/view/service.generator.js +0 -239
- package/dist/lib/attributes.d.ts +0 -114
- package/dist/lib/attributes.js +0 -2
- package/dist/lib/exports.d.ts +0 -45
- package/dist/lib/exports.js +0 -90
- package/dist/lib/imports.d.ts +0 -65
- package/dist/lib/imports.js +0 -114
- package/dist/lib/meta.d.ts +0 -1191
- package/dist/lib/meta.js +0 -434
- package/dist/lib/schema/fields.d.ts +0 -46
- package/dist/lib/schema/fields.js +0 -62
- package/dist/lib/schema/schema.d.ts +0 -466
- package/dist/lib/schema/schema.js +0 -18
- package/dist/lib/schema/types.d.ts +0 -201
- package/dist/lib/schema/types.js +0 -112
- package/dist/lib/serializer.d.ts +0 -15
- package/dist/lib/serializer.js +0 -24
- package/dist/lib/test-id-collector.d.ts +0 -42
- package/dist/lib/test-id-collector.js +0 -53
- package/dist/lib/types.d.ts +0 -7
- package/dist/lib/types.js +0 -13
- package/dist/lib/typescript.d.ts +0 -5
- package/dist/lib/typescript.js +0 -22
- package/dist/lib/utils/ast.d.ts +0 -29
- package/dist/lib/utils/ast.js +0 -23
- package/dist/lib/utils/error.d.ts +0 -17
- package/dist/lib/utils/error.js +0 -52
- package/dist/lib/utils/file.d.ts +0 -10
- package/dist/lib/utils/file.js +0 -56
- package/dist/lib/utils/jsdoc.d.ts +0 -9
- package/dist/lib/utils/jsdoc.js +0 -37
- package/dist/lib/utils/logger.d.ts +0 -17
- package/dist/lib/utils/logger.js +0 -12
- package/dist/lib/utils/string.d.ts +0 -40
- package/dist/lib/utils/string.js +0 -187
- package/dist/lib/utils/types.d.ts +0 -12
- package/dist/lib/utils/types.js +0 -2
- package/dist/lib/zod.d.ts +0 -8
- package/dist/lib/zod.js +0 -60
- package/dist/prisma/attributes.d.ts +0 -21
- package/dist/prisma/attributes.js +0 -175
- package/dist/prisma/client-path.d.ts +0 -7
- package/dist/prisma/client-path.js +0 -29
- package/dist/prisma/parse.d.ts +0 -12
- package/dist/prisma/parse.js +0 -452
|
@@ -0,0 +1,239 @@
|
|
|
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.VirtualFileSystem = void 0;
|
|
37
|
+
const fs = __importStar(require("fs/promises"));
|
|
38
|
+
const minimatch_1 = require("minimatch");
|
|
39
|
+
const utils_1 = require("@postxl/utils");
|
|
40
|
+
const fs_utils_1 = require("./fs-utils");
|
|
41
|
+
const Path = __importStar(require("./path"));
|
|
42
|
+
/**
|
|
43
|
+
* The virtual file system (VFS) represents a file system that can be manipulated in memory.
|
|
44
|
+
*
|
|
45
|
+
* It exposes the following methods:
|
|
46
|
+
* - `write(path, content)`: Writes the given content to the given path
|
|
47
|
+
* - `read(path)`: Reads the content of the given path
|
|
48
|
+
* - `insertFromVfs(path, vfs)`: Inserts the content of the given VFS into the current VFS
|
|
49
|
+
* - `insertFromDisk(path, disk)`: Inserts the content of the given disk into the current VFS
|
|
50
|
+
* - `transform(fn, filter?)`: Transforms the content of all files in the VFS using the given function
|
|
51
|
+
*
|
|
52
|
+
* ## Implementation details
|
|
53
|
+
*
|
|
54
|
+
* All paths are relative to the root of the VFS - and are normalized to use the POSIX path separator.
|
|
55
|
+
* For this we use the `path` utils (path.normalize, path.join, path.parse). All paths are represented
|
|
56
|
+
* as branded strings (`Path.PosixPath`).
|
|
57
|
+
*
|
|
58
|
+
* The file content can either be a (UTF8) string or a Buffer.
|
|
59
|
+
*
|
|
60
|
+
* ## File Pattern Filtering
|
|
61
|
+
*
|
|
62
|
+
* The VFS can be configured with an optional file pattern filter during construction.
|
|
63
|
+
* When a pattern is set, only files matching the pattern will be stored in the VFS.
|
|
64
|
+
* This optimization ensures that linting, formatting, and lock file updates only affect
|
|
65
|
+
* the filtered files, significantly improving performance.
|
|
66
|
+
*/
|
|
67
|
+
class VirtualFileSystem {
|
|
68
|
+
#files = new Map();
|
|
69
|
+
#filePattern;
|
|
70
|
+
/**
|
|
71
|
+
* Constructs a new VirtualFileSystem.
|
|
72
|
+
*
|
|
73
|
+
* @param options - Optional configuration options for the VFS.
|
|
74
|
+
*/
|
|
75
|
+
constructor(options) {
|
|
76
|
+
this.#filePattern = options?.filePattern;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Returns all file names in the VFS.
|
|
80
|
+
*/
|
|
81
|
+
get fileNames() {
|
|
82
|
+
return Array.from(this.#files.keys()).toSorted((a, b) => a.localeCompare(b));
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Returns all files in the VFS.
|
|
86
|
+
*/
|
|
87
|
+
get files() {
|
|
88
|
+
// We return a new Map instance to prevent accidental mutations.
|
|
89
|
+
return new Map(this.#files);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Returns the file pattern filter if one is set.
|
|
93
|
+
*/
|
|
94
|
+
get filePattern() {
|
|
95
|
+
return this.#filePattern;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Checks if a file path matches the VFS file pattern (if one is set).
|
|
99
|
+
* Returns true if no pattern is set, or if the path matches the pattern.
|
|
100
|
+
*/
|
|
101
|
+
matchesPattern(filePath) {
|
|
102
|
+
if (!this.#filePattern) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
// Remove leading slash from filePath for consistent matching
|
|
106
|
+
const normalizedPath = filePath.startsWith('/') ? filePath.slice(1) : filePath;
|
|
107
|
+
// Remove leading slash from pattern if present
|
|
108
|
+
const normalizedPattern = this.#filePattern.startsWith('/') ? this.#filePattern.slice(1) : this.#filePattern;
|
|
109
|
+
return (0, minimatch_1.minimatch)(normalizedPath, normalizedPattern, { dot: true, matchBase: false });
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Writes the given content to the specified path.
|
|
113
|
+
* If a file pattern is set, only files matching the pattern will be stored.
|
|
114
|
+
*/
|
|
115
|
+
write(path, content) {
|
|
116
|
+
const posixPath = Path.normalize(path);
|
|
117
|
+
// Skip files that don't match the pattern
|
|
118
|
+
if (!this.matchesPattern(posixPath)) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
this.#files.set(posixPath, content);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Reads the content of a file from the specified path.
|
|
125
|
+
*/
|
|
126
|
+
get(path) {
|
|
127
|
+
const posixPath = Path.normalize(path);
|
|
128
|
+
return this.#files.get(posixPath);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Reads the content of the specified folder.
|
|
132
|
+
*/
|
|
133
|
+
getFolder(path) {
|
|
134
|
+
const posixPath = Path.normalize(path);
|
|
135
|
+
const vfs = new VirtualFileSystem();
|
|
136
|
+
for (const [filePath, content] of this.#files) {
|
|
137
|
+
if (filePath.startsWith(posixPath)) {
|
|
138
|
+
vfs.write(filePath.slice(posixPath.length), content);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (vfs.fileNames.length === 0) {
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
return vfs;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Inserts the content of another VFS into this VFS at the specified path.
|
|
148
|
+
*/
|
|
149
|
+
insertFromVfs({ vfs, targetPath = '.' }) {
|
|
150
|
+
const basePath = Path.normalize(targetPath);
|
|
151
|
+
for (const [filePath, content] of vfs.files) {
|
|
152
|
+
const combinedPath = Path.join(basePath, filePath);
|
|
153
|
+
// Skip files that don't match the pattern
|
|
154
|
+
if (!this.matchesPattern(combinedPath)) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
this.#files.set(combinedPath, content);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Loads the content from the folder on disk into this VFS at the specified path.
|
|
162
|
+
*/
|
|
163
|
+
async loadFolder({ diskPath, targetPath = '.', recursive = true, filter, }) {
|
|
164
|
+
await this.#readDirectory({
|
|
165
|
+
diskPath: Path.normalize(diskPath),
|
|
166
|
+
targetPath: Path.normalize(targetPath),
|
|
167
|
+
filter,
|
|
168
|
+
recursive,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Loads the content from the file on disk into this VFS at the specified path.
|
|
173
|
+
*/
|
|
174
|
+
async loadFile({ diskPath, targetPath }) {
|
|
175
|
+
const diskPathNormalized = Path.normalize(diskPath);
|
|
176
|
+
const basePath = Path.normalize(targetPath ?? Path.fileName(diskPathNormalized));
|
|
177
|
+
// Skip files that don't match the pattern
|
|
178
|
+
if (!this.matchesPattern(basePath)) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const content = await (0, fs_utils_1.readFile)(diskPathNormalized);
|
|
182
|
+
if (content.isErr()) {
|
|
183
|
+
console.error(`Error reading file: ${diskPath}`);
|
|
184
|
+
throw content.unwrapErr().error;
|
|
185
|
+
}
|
|
186
|
+
this.#files.set(basePath, content.unwrap());
|
|
187
|
+
}
|
|
188
|
+
async #readDirectory({ diskPath, targetPath, filter, recursive, }) {
|
|
189
|
+
const entries = await utils_1.Result.fromPromise(() => fs.readdir(diskPath, { withFileTypes: true }), () => `Folder "${diskPath}" does not exist`);
|
|
190
|
+
if (entries.isErr()) {
|
|
191
|
+
throw new Error(entries.unwrapErr());
|
|
192
|
+
}
|
|
193
|
+
for (const entry of entries.unwrap()) {
|
|
194
|
+
const entryName = Path.normalize(entry.name);
|
|
195
|
+
const entryPath = Path.join(diskPath, entryName);
|
|
196
|
+
const relativePath = Path.join(targetPath, entryName);
|
|
197
|
+
if (filter && !filter(relativePath)) {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (recursive && entry.isDirectory()) {
|
|
201
|
+
await this.#readDirectory({ diskPath: entryPath, targetPath: relativePath, filter, recursive });
|
|
202
|
+
}
|
|
203
|
+
else if (entry.isFile()) {
|
|
204
|
+
// Skip files that don't match the pattern
|
|
205
|
+
if (!this.matchesPattern(relativePath)) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
const content = await (0, fs_utils_1.readFile)(entryPath);
|
|
209
|
+
if (content.isErr()) {
|
|
210
|
+
throw content.unwrapErr();
|
|
211
|
+
}
|
|
212
|
+
this.#files.set(relativePath, content.unwrap());
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Transforms the content of all files using the provided function.
|
|
218
|
+
* An optional filter function can be provided to select specific files.
|
|
219
|
+
*/
|
|
220
|
+
async transform(fn, { filter, onError, } = {}) {
|
|
221
|
+
for (const [path, content] of this.#files) {
|
|
222
|
+
if (!filter || filter(path)) {
|
|
223
|
+
try {
|
|
224
|
+
const newContent = await fn({ content, path });
|
|
225
|
+
this.#files.set(path, newContent);
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
if (onError) {
|
|
229
|
+
onError({ path, content, error });
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
throw error;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
exports.VirtualFileSystem = VirtualFileSystem;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import JSZip from 'jszip';
|
|
2
|
+
type ZipLimits = {
|
|
3
|
+
maxFiles: number;
|
|
4
|
+
maxSize: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Loads a zip file from a buffer and validates the number of files and the total size.
|
|
8
|
+
* Throws an error if the number of files or the total size exceeds the limits.
|
|
9
|
+
*
|
|
10
|
+
* This is to prevent malicious "zip bombs" (see Sonar rule S5042)
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadZip(content: Buffer, limits?: ZipLimits): Promise<JSZip>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
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.loadZip = loadZip;
|
|
7
|
+
const jszip_1 = __importDefault(require("jszip"));
|
|
8
|
+
const defaultLimits = {
|
|
9
|
+
maxFiles: 1000,
|
|
10
|
+
maxSize: 100_000_000, // 100 MB
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Loads a zip file from a buffer and validates the number of files and the total size.
|
|
14
|
+
* Throws an error if the number of files or the total size exceeds the limits.
|
|
15
|
+
*
|
|
16
|
+
* This is to prevent malicious "zip bombs" (see Sonar rule S5042)
|
|
17
|
+
*/
|
|
18
|
+
async function loadZip(content, limits = defaultLimits) {
|
|
19
|
+
const { maxFiles, maxSize } = limits;
|
|
20
|
+
let fileCount = 0;
|
|
21
|
+
let totalSize = 0;
|
|
22
|
+
const zip = new jszip_1.default();
|
|
23
|
+
await zip.loadAsync(content); // NOSONAR - the below code implements the suggested validation
|
|
24
|
+
const fileNames = Object.keys(zip.files);
|
|
25
|
+
for (const fileName of fileNames) {
|
|
26
|
+
fileCount++;
|
|
27
|
+
if (fileCount > maxFiles) {
|
|
28
|
+
throw new Error('Reached max. number of files');
|
|
29
|
+
}
|
|
30
|
+
const file = zip.file(fileName);
|
|
31
|
+
if (file) {
|
|
32
|
+
const fileContent = await file.async('nodebuffer');
|
|
33
|
+
totalSize += fileContent.length;
|
|
34
|
+
if (totalSize > maxSize) {
|
|
35
|
+
throw new Error('Reached max. size');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return zip;
|
|
40
|
+
}
|
package/package.json
CHANGED
|
@@ -1,49 +1,72 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@postxl/generator",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Core package that orchestrates the code generation of a PXL project",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
16
|
+
"author": "PostXL GmbH",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"postxl",
|
|
19
|
+
"pxl",
|
|
20
|
+
"generator",
|
|
21
|
+
"code-generation",
|
|
22
|
+
"typescript",
|
|
23
|
+
"nestjs",
|
|
24
|
+
"react"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=24"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
8
31
|
},
|
|
9
32
|
"files": [
|
|
10
33
|
"dist"
|
|
11
34
|
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc -b tsconfig.build.json",
|
|
37
|
+
"lint": "eslint .",
|
|
38
|
+
"prettier:check": "prettier --check \"**/*.{ts,tsx}\" --config ../../prettier.config.js --ignore-path ../../.prettierignore",
|
|
39
|
+
"test:jest": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest",
|
|
40
|
+
"test:coverage": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --coverage",
|
|
41
|
+
"test:watch": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --watch",
|
|
42
|
+
"test:types": "tsc --noEmit"
|
|
43
|
+
},
|
|
12
44
|
"repository": {
|
|
13
45
|
"type": "git",
|
|
14
|
-
"url": "https://github.com/postxl/
|
|
46
|
+
"url": "https://github.com/postxl/pxl",
|
|
47
|
+
"directory": "packages/generator"
|
|
15
48
|
},
|
|
16
49
|
"dependencies": {
|
|
17
|
-
"@
|
|
18
|
-
"@
|
|
19
|
-
"
|
|
20
|
-
"exceljs": "4.3.0",
|
|
50
|
+
"@eslint/js": "9.10.0",
|
|
51
|
+
"@postxl/schema": "workspace:*",
|
|
52
|
+
"diff": "7.0.0",
|
|
21
53
|
"fast-glob": "3.2.12",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
54
|
+
"globals": "15.12.0",
|
|
55
|
+
"isbinaryfile": "5.0.4",
|
|
56
|
+
"jszip": "3.10.1",
|
|
57
|
+
"minimatch": "^10.0.1",
|
|
58
|
+
"p-limit": "3.1.0"
|
|
26
59
|
},
|
|
27
60
|
"devDependencies": {
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
30
|
-
"@types/eslint": "8.44.7",
|
|
31
|
-
"@types/node": "20.5.0",
|
|
32
|
-
"jest": "29.7.0",
|
|
33
|
-
"prisma": "5.8.1",
|
|
34
|
-
"ts-jest": "29.1.3",
|
|
35
|
-
"ts-node": "10.9.2",
|
|
36
|
-
"ts-toolbelt": "9.6.0",
|
|
37
|
-
"tsconfig-paths": "4.2.0",
|
|
38
|
-
"typescript": "5.4.5"
|
|
39
|
-
},
|
|
40
|
-
"peerDependencies": {
|
|
41
|
-
"prisma": "5.8.1"
|
|
61
|
+
"@types/diff": "5.2.2",
|
|
62
|
+
"@types/eslint__js": "8.42.3"
|
|
42
63
|
},
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
64
|
+
"wallaby": {
|
|
65
|
+
"env": {
|
|
66
|
+
"type": "node",
|
|
67
|
+
"params": {
|
|
68
|
+
"runner": "--experimental-vm-modules"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
48
71
|
}
|
|
49
|
-
}
|
|
72
|
+
}
|
package/dist/generator.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
import * as Schema from './lib/schema/schema';
|
|
3
|
-
import { Logger } from './lib/utils/logger';
|
|
4
|
-
/**
|
|
5
|
-
* Generates PXL files and flushes them to disk.
|
|
6
|
-
*/
|
|
7
|
-
export declare function generate({ models, enums, config, prismaClientPath, logger, }: {
|
|
8
|
-
models: Schema.Model[];
|
|
9
|
-
enums: Schema.Enum[];
|
|
10
|
-
config: Schema.SchemaConfig;
|
|
11
|
-
prismaClientPath: string;
|
|
12
|
-
logger: Logger;
|
|
13
|
-
}): Promise<void>;
|