@dudousxd/nestjs-codegen 0.28.0 → 0.29.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.
- package/CHANGELOG.md +8 -0
- package/README.md +10 -8
- package/dist/cli/main.cjs +1 -1
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +1 -1
- package/dist/cli/main.js.map +1 -1
- package/dist/index.cjs +79 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -14
- package/dist/index.d.ts +27 -14
- package/dist/index.js +80 -29
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +1 -1
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.js +1 -1
- package/dist/nest/index.js.map +1 -1
- package/package.json +4 -3
package/dist/index.d.cts
CHANGED
|
@@ -378,18 +378,29 @@ declare const DEFAULT_SANDBOX_KIT_OUTPUT = ".genui/sandbox-kit.json";
|
|
|
378
378
|
interface WriteSandboxKitDocsOptions {
|
|
379
379
|
root: string;
|
|
380
380
|
output: string;
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
381
|
+
components?: string | readonly string[];
|
|
382
|
+
styles?: string | readonly string[];
|
|
383
|
+
wrapper?: string;
|
|
384
|
+
stylesDocs?: string;
|
|
384
385
|
tsconfig?: string;
|
|
385
386
|
}
|
|
387
|
+
/** The same options as the agent's Vite plugin (`@dudousxd/nestjs-agent/vite`). */
|
|
386
388
|
interface GenuiSandboxKitOptions {
|
|
387
|
-
/**
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
389
|
+
/**
|
|
390
|
+
* Modules whose exports are the kit's React components: files, globs, directories or packages
|
|
391
|
+
* (`web/components/ui`, `src/genui/kit.ts`, `@mui/material`). Default: the first shadcn
|
|
392
|
+
* `components/ui` dir found.
|
|
393
|
+
*/
|
|
394
|
+
components?: string | readonly string[];
|
|
395
|
+
/**
|
|
396
|
+
* The app's style entry files (plain CSS, Sass, a Tailwind stylesheet…): what the model is told
|
|
397
|
+
* about the styles (Tailwind tokens, or the CSS class vocabulary) and the theme's variables.
|
|
398
|
+
*/
|
|
399
|
+
styles?: string | readonly string[];
|
|
400
|
+
/** A module whose default export wraps the model's App (theme providers). */
|
|
401
|
+
wrapper?: string;
|
|
402
|
+
/** Guidance on the styles for the model: a markdown file, or the text itself. */
|
|
403
|
+
stylesDocs?: string;
|
|
393
404
|
/** The tsconfig the component prop types are read through. */
|
|
394
405
|
tsconfig?: string;
|
|
395
406
|
/**
|
|
@@ -408,15 +419,17 @@ interface GenuiSandboxKitOptions {
|
|
|
408
419
|
}
|
|
409
420
|
/**
|
|
410
421
|
* Writes the generative-UI **sandbox kit docs** — the app's design-system components (shadcn
|
|
411
|
-
* `components/ui` by default) with the props read from their TypeScript types
|
|
422
|
+
* `components/ui` by default) with the props read from their TypeScript types, and what its
|
|
423
|
+
* `styles` are (Tailwind tokens, or a CSS class vocabulary, and the theme's variables) — to
|
|
412
424
|
* `.genui/sandbox-kit.json`, where the `@dudousxd/nestjs-agent` server reads them.
|
|
413
425
|
*
|
|
414
426
|
* Runs on every generate pass (one-shot CLI, `--watch`, and the Nest module's watcher). The
|
|
415
427
|
* descriptor lives outside `outDir`, so it is written by the generator itself, not through
|
|
416
|
-
* `emitFiles`; the kit files, stylesheets and
|
|
417
|
-
* a component regenerates in watch mode and a
|
|
428
|
+
* `emitFiles`; the kit files, the stylesheets (and what they import) and the descriptor are
|
|
429
|
+
* tracked as inputs, so editing a component or a stylesheet regenerates in watch mode and a
|
|
430
|
+
* deleted descriptor is rewritten.
|
|
418
431
|
*
|
|
419
|
-
* Needs the optional peer `@dudousxd/nestjs-agent-core` (>=0.
|
|
432
|
+
* Needs the optional peer `@dudousxd/nestjs-agent-core` (>=0.53.0) unless `generate` is given.
|
|
420
433
|
*/
|
|
421
434
|
declare function genuiSandboxKit(options?: GenuiSandboxKitOptions): CodegenExtension;
|
|
422
435
|
|
|
@@ -435,6 +448,6 @@ interface FastDiscoveryOptions {
|
|
|
435
448
|
}
|
|
436
449
|
declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
|
|
437
450
|
|
|
438
|
-
declare const VERSION = "0.
|
|
451
|
+
declare const VERSION = "0.29.0";
|
|
439
452
|
|
|
440
453
|
export { type ChainModuleRendererOptions, CodegenError, type CodegenManifest, ConfigError, DEFAULT_SANDBOX_KIT_OUTPUT, DriftGuardError, type EntryPoint, type FastDiscoveryOptions, type GenuiSandboxKitOptions, type JsonSchema, type MocksEmitOptions, type OpenApiDocument, type OpenApiEmitOptions, type OpenApiInfo, RenderContext, RenderedModule, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type WatchOptions, type Watcher, type WriteSandboxKitDocsOptions, acquireLock, buildMocksFile, buildOpenApiSpec, createChainModuleRenderer, defineConfig, discoverContractsFast, emitApi, emitForms, emitMocks, emitOpenApi, emitRoutes, extractSchemaFromDto, generate, genuiSandboxKit, loadConfig, renderTsType, resolveConfig, schemaModuleToJsonSchema, schemaNodeToJsonSchema, toObjectKey, typeNameFor, watch };
|
package/dist/index.d.ts
CHANGED
|
@@ -378,18 +378,29 @@ declare const DEFAULT_SANDBOX_KIT_OUTPUT = ".genui/sandbox-kit.json";
|
|
|
378
378
|
interface WriteSandboxKitDocsOptions {
|
|
379
379
|
root: string;
|
|
380
380
|
output: string;
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
381
|
+
components?: string | readonly string[];
|
|
382
|
+
styles?: string | readonly string[];
|
|
383
|
+
wrapper?: string;
|
|
384
|
+
stylesDocs?: string;
|
|
384
385
|
tsconfig?: string;
|
|
385
386
|
}
|
|
387
|
+
/** The same options as the agent's Vite plugin (`@dudousxd/nestjs-agent/vite`). */
|
|
386
388
|
interface GenuiSandboxKitOptions {
|
|
387
|
-
/**
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
389
|
+
/**
|
|
390
|
+
* Modules whose exports are the kit's React components: files, globs, directories or packages
|
|
391
|
+
* (`web/components/ui`, `src/genui/kit.ts`, `@mui/material`). Default: the first shadcn
|
|
392
|
+
* `components/ui` dir found.
|
|
393
|
+
*/
|
|
394
|
+
components?: string | readonly string[];
|
|
395
|
+
/**
|
|
396
|
+
* The app's style entry files (plain CSS, Sass, a Tailwind stylesheet…): what the model is told
|
|
397
|
+
* about the styles (Tailwind tokens, or the CSS class vocabulary) and the theme's variables.
|
|
398
|
+
*/
|
|
399
|
+
styles?: string | readonly string[];
|
|
400
|
+
/** A module whose default export wraps the model's App (theme providers). */
|
|
401
|
+
wrapper?: string;
|
|
402
|
+
/** Guidance on the styles for the model: a markdown file, or the text itself. */
|
|
403
|
+
stylesDocs?: string;
|
|
393
404
|
/** The tsconfig the component prop types are read through. */
|
|
394
405
|
tsconfig?: string;
|
|
395
406
|
/**
|
|
@@ -408,15 +419,17 @@ interface GenuiSandboxKitOptions {
|
|
|
408
419
|
}
|
|
409
420
|
/**
|
|
410
421
|
* Writes the generative-UI **sandbox kit docs** — the app's design-system components (shadcn
|
|
411
|
-
* `components/ui` by default) with the props read from their TypeScript types
|
|
422
|
+
* `components/ui` by default) with the props read from their TypeScript types, and what its
|
|
423
|
+
* `styles` are (Tailwind tokens, or a CSS class vocabulary, and the theme's variables) — to
|
|
412
424
|
* `.genui/sandbox-kit.json`, where the `@dudousxd/nestjs-agent` server reads them.
|
|
413
425
|
*
|
|
414
426
|
* Runs on every generate pass (one-shot CLI, `--watch`, and the Nest module's watcher). The
|
|
415
427
|
* descriptor lives outside `outDir`, so it is written by the generator itself, not through
|
|
416
|
-
* `emitFiles`; the kit files, stylesheets and
|
|
417
|
-
* a component regenerates in watch mode and a
|
|
428
|
+
* `emitFiles`; the kit files, the stylesheets (and what they import) and the descriptor are
|
|
429
|
+
* tracked as inputs, so editing a component or a stylesheet regenerates in watch mode and a
|
|
430
|
+
* deleted descriptor is rewritten.
|
|
418
431
|
*
|
|
419
|
-
* Needs the optional peer `@dudousxd/nestjs-agent-core` (>=0.
|
|
432
|
+
* Needs the optional peer `@dudousxd/nestjs-agent-core` (>=0.53.0) unless `generate` is given.
|
|
420
433
|
*/
|
|
421
434
|
declare function genuiSandboxKit(options?: GenuiSandboxKitOptions): CodegenExtension;
|
|
422
435
|
|
|
@@ -435,6 +448,6 @@ interface FastDiscoveryOptions {
|
|
|
435
448
|
}
|
|
436
449
|
declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
|
|
437
450
|
|
|
438
|
-
declare const VERSION = "0.
|
|
451
|
+
declare const VERSION = "0.29.0";
|
|
439
452
|
|
|
440
453
|
export { type ChainModuleRendererOptions, CodegenError, type CodegenManifest, ConfigError, DEFAULT_SANDBOX_KIT_OUTPUT, DriftGuardError, type EntryPoint, type FastDiscoveryOptions, type GenuiSandboxKitOptions, type JsonSchema, type MocksEmitOptions, type OpenApiDocument, type OpenApiEmitOptions, type OpenApiInfo, RenderContext, RenderedModule, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type WatchOptions, type Watcher, type WriteSandboxKitDocsOptions, acquireLock, buildMocksFile, buildOpenApiSpec, createChainModuleRenderer, defineConfig, discoverContractsFast, emitApi, emitForms, emitMocks, emitOpenApi, emitRoutes, extractSchemaFromDto, generate, genuiSandboxKit, loadConfig, renderTsType, resolveConfig, schemaModuleToJsonSchema, schemaNodeToJsonSchema, toObjectKey, typeNameFor, watch };
|
package/dist/index.js
CHANGED
|
@@ -6143,7 +6143,7 @@ function createChainModuleRenderer(opts) {
|
|
|
6143
6143
|
}
|
|
6144
6144
|
|
|
6145
6145
|
// src/extension/genui-sandbox-kit.ts
|
|
6146
|
-
import { existsSync as existsSync2 } from "fs";
|
|
6146
|
+
import { existsSync as existsSync2, statSync } from "fs";
|
|
6147
6147
|
import { dirname as dirname5, isAbsolute as isAbsolute3, resolve as resolve6 } from "path";
|
|
6148
6148
|
import fg4 from "fast-glob";
|
|
6149
6149
|
var GENUI_KIT_MODULE = "@dudousxd/nestjs-agent-core/genui/kit";
|
|
@@ -6155,6 +6155,12 @@ var DEFAULT_KIT_DIRS = [
|
|
|
6155
6155
|
"app/components/ui",
|
|
6156
6156
|
"components/ui"
|
|
6157
6157
|
];
|
|
6158
|
+
var LEGACY_OPTIONS = {
|
|
6159
|
+
entry: "`entry: X` is now `components: X`",
|
|
6160
|
+
include: "`include: G` is now `components: G` (globs, files, directories or packages)",
|
|
6161
|
+
css: "`css: G` is now `styles: G` (the app's style entry files)"
|
|
6162
|
+
};
|
|
6163
|
+
var MIN_CORE = "0.53.0";
|
|
6158
6164
|
async function loadKitModule(specifier = GENUI_KIT_MODULE) {
|
|
6159
6165
|
let mod;
|
|
6160
6166
|
try {
|
|
@@ -6163,19 +6169,24 @@ async function loadKitModule(specifier = GENUI_KIT_MODULE) {
|
|
|
6163
6169
|
const code = err.code;
|
|
6164
6170
|
if (code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") {
|
|
6165
6171
|
throw new CodegenError(
|
|
6166
|
-
`genuiSandboxKit() needs "${GENUI_KIT_MODULE}" \u2014 install @dudousxd/nestjs-agent-core
|
|
6172
|
+
`genuiSandboxKit() needs "${GENUI_KIT_MODULE}" \u2014 install @dudousxd/nestjs-agent-core@>=${MIN_CORE}, or pass \`generate\` to genuiSandboxKit().`
|
|
6167
6173
|
);
|
|
6168
6174
|
}
|
|
6169
6175
|
if (code === "ERR_PACKAGE_PATH_NOT_EXPORTED") {
|
|
6170
6176
|
throw new CodegenError(
|
|
6171
|
-
`genuiSandboxKit() needs "${GENUI_KIT_MODULE}", which the installed @dudousxd/nestjs-agent-core does not export \u2014 upgrade it to
|
|
6177
|
+
`genuiSandboxKit() needs "${GENUI_KIT_MODULE}", which the installed @dudousxd/nestjs-agent-core does not export \u2014 upgrade it to >=${MIN_CORE}.`
|
|
6172
6178
|
);
|
|
6173
6179
|
}
|
|
6174
6180
|
throw err;
|
|
6175
6181
|
}
|
|
6176
6182
|
if (typeof mod.writeSandboxKitDocs !== "function") {
|
|
6177
6183
|
throw new CodegenError(
|
|
6178
|
-
`"${GENUI_KIT_MODULE}" has no writeSandboxKitDocs export \u2014 upgrade @dudousxd/nestjs-agent-core to
|
|
6184
|
+
`"${GENUI_KIT_MODULE}" has no writeSandboxKitDocs export \u2014 upgrade @dudousxd/nestjs-agent-core to >=${MIN_CORE}.`
|
|
6185
|
+
);
|
|
6186
|
+
}
|
|
6187
|
+
if (typeof mod.resolveStyleEntries !== "function") {
|
|
6188
|
+
throw new CodegenError(
|
|
6189
|
+
`The installed @dudousxd/nestjs-agent-core predates genuiSandboxKit({ components, styles, wrapper }) \u2014 upgrade it to >=${MIN_CORE}.`
|
|
6179
6190
|
);
|
|
6180
6191
|
}
|
|
6181
6192
|
return mod;
|
|
@@ -6189,52 +6200,92 @@ function globBase(glob) {
|
|
|
6189
6200
|
return base.join("/");
|
|
6190
6201
|
}
|
|
6191
6202
|
function resolveKitFilesLocally(root, options) {
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
+
const specs = options.components === void 0 ? DEFAULT_KIT_DIRS.filter((dir) => existsSync2(resolve6(root, dir))).slice(0, 1) : typeof options.components === "string" ? [options.components] : [...options.components];
|
|
6204
|
+
const files = [];
|
|
6205
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
6206
|
+
for (const spec of specs) {
|
|
6207
|
+
if (/[*?{]/.test(spec)) {
|
|
6208
|
+
files.push(...fg4.sync(spec, { cwd: root, absolute: true, onlyFiles: true }));
|
|
6209
|
+
dirs.add(resolve6(root, globBase(spec)));
|
|
6210
|
+
continue;
|
|
6211
|
+
}
|
|
6212
|
+
const path = isAbsolute3(spec) ? spec : resolve6(root, spec);
|
|
6213
|
+
if (existsSync2(path) && statSync(path).isDirectory()) {
|
|
6214
|
+
files.push(...fg4.sync("*.{tsx,jsx,ts,js}", { cwd: path, absolute: true, onlyFiles: true }));
|
|
6215
|
+
dirs.add(path);
|
|
6216
|
+
} else if (existsSync2(path)) {
|
|
6217
|
+
files.push(path);
|
|
6218
|
+
dirs.add(dirname5(path));
|
|
6219
|
+
}
|
|
6220
|
+
}
|
|
6221
|
+
if (options.wrapper !== void 0) {
|
|
6222
|
+
const wrapper = isAbsolute3(options.wrapper) ? options.wrapper : resolve6(root, options.wrapper);
|
|
6223
|
+
if (existsSync2(wrapper)) files.push(wrapper);
|
|
6224
|
+
}
|
|
6225
|
+
if (files.length === 0 && dirs.size === 0) return null;
|
|
6226
|
+
return { files: [...new Set(files)].sort(), dirs: [...dirs] };
|
|
6203
6227
|
}
|
|
6204
6228
|
function genuiSandboxKit(options = {}) {
|
|
6229
|
+
const legacy = Object.keys(LEGACY_OPTIONS).filter(
|
|
6230
|
+
(key) => options[key] !== void 0
|
|
6231
|
+
);
|
|
6232
|
+
if (legacy.length > 0) {
|
|
6233
|
+
throw new CodegenError(
|
|
6234
|
+
`genuiSandboxKit(): ${legacy.map((key) => `\`${key}\``).join(", ")} ${legacy.length > 1 ? "were" : "was"} removed \u2014 ${legacy.map((key) => LEGACY_OPTIONS[key]).join("; ")}. The options are now the agent's Vite plugin's: components, styles, wrapper, stylesDocs.`
|
|
6235
|
+
);
|
|
6236
|
+
}
|
|
6205
6237
|
const output = options.output ?? DEFAULT_SANDBOX_KIT_OUTPUT;
|
|
6206
6238
|
const source = {
|
|
6207
|
-
...options.
|
|
6208
|
-
...options.
|
|
6239
|
+
...options.components !== void 0 ? { components: options.components } : {},
|
|
6240
|
+
...options.wrapper !== void 0 ? { wrapper: options.wrapper } : {}
|
|
6209
6241
|
};
|
|
6210
6242
|
const extension = {
|
|
6211
6243
|
name: "genui-sandbox-kit",
|
|
6212
6244
|
// Not read by the host: serialized into the config hash, so changing an option
|
|
6213
6245
|
// invalidates skip-when-unchanged.
|
|
6214
|
-
options: {
|
|
6246
|
+
options: {
|
|
6247
|
+
...source,
|
|
6248
|
+
styles: options.styles,
|
|
6249
|
+
stylesDocs: options.stylesDocs,
|
|
6250
|
+
tsconfig: options.tsconfig,
|
|
6251
|
+
output
|
|
6252
|
+
},
|
|
6215
6253
|
async emitFiles(ctx) {
|
|
6216
6254
|
const root = ctx.cwd;
|
|
6217
6255
|
let generate2 = options.generate;
|
|
6218
|
-
let
|
|
6256
|
+
let mod;
|
|
6219
6257
|
if (!generate2) {
|
|
6220
|
-
|
|
6258
|
+
mod = await loadKitModule(options.kitModule);
|
|
6221
6259
|
generate2 = mod.writeSandboxKitDocs;
|
|
6222
|
-
if (typeof mod.resolveSandboxKitFiles === "function") {
|
|
6223
|
-
resolveFiles = mod.resolveSandboxKitFiles;
|
|
6224
|
-
}
|
|
6225
6260
|
}
|
|
6226
|
-
const
|
|
6261
|
+
const resolveFiles = mod?.resolveSandboxKitFiles ?? resolveKitFilesLocally;
|
|
6262
|
+
let kit = null;
|
|
6263
|
+
try {
|
|
6264
|
+
kit = resolveFiles(root, source);
|
|
6265
|
+
} catch {
|
|
6266
|
+
kit = null;
|
|
6267
|
+
}
|
|
6227
6268
|
if (kit) ctx.trackInput(...kit.files, ...kit.dirs);
|
|
6228
|
-
if (options.
|
|
6229
|
-
const
|
|
6230
|
-
|
|
6269
|
+
if (options.styles !== void 0) {
|
|
6270
|
+
const entries = mod?.resolveStyleEntries ? mod.resolveStyleEntries(root, options.styles).files : fg4.sync(typeof options.styles === "string" ? [options.styles] : [...options.styles], {
|
|
6271
|
+
cwd: root,
|
|
6272
|
+
absolute: true,
|
|
6273
|
+
onlyFiles: true
|
|
6274
|
+
});
|
|
6275
|
+
const files = mod?.collectStyleSources ? mod.collectStyleSources(entries).map((source2) => source2.file) : entries;
|
|
6276
|
+
ctx.trackInput(.../* @__PURE__ */ new Set([...entries, ...files]));
|
|
6277
|
+
}
|
|
6278
|
+
if (options.stylesDocs !== void 0 && !options.stylesDocs.includes("\n")) {
|
|
6279
|
+
const guide = isAbsolute3(options.stylesDocs) ? options.stylesDocs : resolve6(root, options.stylesDocs);
|
|
6280
|
+
if (existsSync2(guide)) ctx.trackInput(guide);
|
|
6231
6281
|
}
|
|
6232
6282
|
ctx.trackInput(isAbsolute3(output) ? output : resolve6(root, output));
|
|
6233
6283
|
await generate2({
|
|
6234
6284
|
root,
|
|
6235
6285
|
output,
|
|
6236
6286
|
...source,
|
|
6237
|
-
...options.
|
|
6287
|
+
...options.styles !== void 0 ? { styles: options.styles } : {},
|
|
6288
|
+
...options.stylesDocs !== void 0 ? { stylesDocs: options.stylesDocs } : {},
|
|
6238
6289
|
...options.tsconfig !== void 0 ? { tsconfig: options.tsconfig } : {}
|
|
6239
6290
|
});
|
|
6240
6291
|
return [];
|
|
@@ -6244,7 +6295,7 @@ function genuiSandboxKit(options = {}) {
|
|
|
6244
6295
|
}
|
|
6245
6296
|
|
|
6246
6297
|
// src/index.ts
|
|
6247
|
-
var VERSION = "0.
|
|
6298
|
+
var VERSION = "0.29.0";
|
|
6248
6299
|
export {
|
|
6249
6300
|
CodegenError,
|
|
6250
6301
|
ConfigError,
|