@dudousxd/nestjs-codegen 0.22.1 → 0.24.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 +32 -0
- package/dist/cli/main.cjs +27 -7
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +27 -7
- package/dist/cli/main.js.map +1 -1
- package/dist/extension/index.d.cts +1 -1
- package/dist/extension/index.d.ts +1 -1
- package/dist/{index-BsptKWwz.d.cts → index-Ce3YnfwS.d.cts} +19 -0
- package/dist/{index-BsptKWwz.d.ts → index-Ce3YnfwS.d.ts} +19 -0
- package/dist/index.cjs +27 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +27 -7
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +27 -7
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.d.cts +1 -1
- package/dist/nest/index.d.ts +1 -1
- package/dist/nest/index.js +27 -7
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { m as ApiClientLayer, n as ApiHeaderContribution, o as ApiModuleDeps, C as CodegenExtension, p as EmittedFile, E as ExtensionContext, L as LeafModel, q as RequestModel, s as RequestShape, t as defineExtension, u as requestShape } from '../index-
|
|
1
|
+
export { m as ApiClientLayer, n as ApiHeaderContribution, o as ApiModuleDeps, C as CodegenExtension, p as EmittedFile, E as ExtensionContext, L as LeafModel, q as RequestModel, s as RequestShape, t as defineExtension, u as requestShape } from '../index-Ce3YnfwS.cjs';
|
|
2
2
|
import 'ts-morph';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { m as ApiClientLayer, n as ApiHeaderContribution, o as ApiModuleDeps, C as CodegenExtension, p as EmittedFile, E as ExtensionContext, L as LeafModel, q as RequestModel, s as RequestShape, t as defineExtension, u as requestShape } from '../index-
|
|
1
|
+
export { m as ApiClientLayer, n as ApiHeaderContribution, o as ApiModuleDeps, C as CodegenExtension, p as EmittedFile, E as ExtensionContext, L as LeafModel, q as RequestModel, s as RequestShape, t as defineExtension, u as requestShape } from '../index-Ce3YnfwS.js';
|
|
2
2
|
import 'ts-morph';
|
|
@@ -430,7 +430,26 @@ type FieldTypeKind = 'string' | 'number' | 'boolean' | 'date' | 'json' | 'unknow
|
|
|
430
430
|
interface FilterFieldType {
|
|
431
431
|
/** Field name, e.g. 'age' or 'tasks.id' (dot-notation for relations). */
|
|
432
432
|
name: string;
|
|
433
|
+
/**
|
|
434
|
+
* What the COLUMN is — the semantics an operator set is derived from. A DATE
|
|
435
|
+
* column is `date` here even when its value arrives as a string.
|
|
436
|
+
*/
|
|
433
437
|
kind: FieldTypeKind;
|
|
438
|
+
/**
|
|
439
|
+
* What the VALUE is, when that differs from {@link kind}.
|
|
440
|
+
*
|
|
441
|
+
* A mapped column declares two things that can both be true and disagree:
|
|
442
|
+
* `@Property({ columnType: 'date', type: DateType }) x?: Opt<string>` is a
|
|
443
|
+
* DATE column whose JS value is `'YYYY-MM-DD'`. Collapsing them loses one or
|
|
444
|
+
* the other — answer `string` and the field stops accepting the ordering and
|
|
445
|
+
* range operators the column supports; answer `date` and the emitted type
|
|
446
|
+
* promises a `Date` the value never holds, which a type-preserving wire
|
|
447
|
+
* format like superjson then contradicts at runtime.
|
|
448
|
+
*
|
|
449
|
+
* So the two travel separately: `kind` gates operators, this types the value.
|
|
450
|
+
* Absent when they agree, which is the overwhelming majority of columns.
|
|
451
|
+
*/
|
|
452
|
+
valueKind?: FieldTypeKind;
|
|
434
453
|
/** String/number-literal union members (enums), if any. */
|
|
435
454
|
enumValues?: string[];
|
|
436
455
|
/** Whether the field's TS type includes null/undefined. */
|
|
@@ -430,7 +430,26 @@ type FieldTypeKind = 'string' | 'number' | 'boolean' | 'date' | 'json' | 'unknow
|
|
|
430
430
|
interface FilterFieldType {
|
|
431
431
|
/** Field name, e.g. 'age' or 'tasks.id' (dot-notation for relations). */
|
|
432
432
|
name: string;
|
|
433
|
+
/**
|
|
434
|
+
* What the COLUMN is — the semantics an operator set is derived from. A DATE
|
|
435
|
+
* column is `date` here even when its value arrives as a string.
|
|
436
|
+
*/
|
|
433
437
|
kind: FieldTypeKind;
|
|
438
|
+
/**
|
|
439
|
+
* What the VALUE is, when that differs from {@link kind}.
|
|
440
|
+
*
|
|
441
|
+
* A mapped column declares two things that can both be true and disagree:
|
|
442
|
+
* `@Property({ columnType: 'date', type: DateType }) x?: Opt<string>` is a
|
|
443
|
+
* DATE column whose JS value is `'YYYY-MM-DD'`. Collapsing them loses one or
|
|
444
|
+
* the other — answer `string` and the field stops accepting the ordering and
|
|
445
|
+
* range operators the column supports; answer `date` and the emitted type
|
|
446
|
+
* promises a `Date` the value never holds, which a type-preserving wire
|
|
447
|
+
* format like superjson then contradicts at runtime.
|
|
448
|
+
*
|
|
449
|
+
* So the two travel separately: `kind` gates operators, this types the value.
|
|
450
|
+
* Absent when they agree, which is the overwhelming majority of columns.
|
|
451
|
+
*/
|
|
452
|
+
valueKind?: FieldTypeKind;
|
|
434
453
|
/** String/number-literal union members (enums), if any. */
|
|
435
454
|
enumValues?: string[];
|
|
436
455
|
/** Whether the field's TS type includes null/undefined. */
|
package/dist/index.cjs
CHANGED
|
@@ -1401,6 +1401,7 @@ function classifyTypeKeyword(raw) {
|
|
|
1401
1401
|
function markNullable(r, nullable) {
|
|
1402
1402
|
return nullable ? { ...r, nullable: true } : r;
|
|
1403
1403
|
}
|
|
1404
|
+
var TRANSPARENT_TYPE_BRANDS = /* @__PURE__ */ new Set(["Opt", "Hidden"]);
|
|
1404
1405
|
function classifyTypeNode(typeNode, sourceFile, project, opts) {
|
|
1405
1406
|
if (import_ts_morph4.Node.isUnionTypeNode(typeNode)) {
|
|
1406
1407
|
let nullable = false;
|
|
@@ -1459,6 +1460,11 @@ function classifyTypeNode(typeNode, sourceFile, project, opts) {
|
|
|
1459
1460
|
const refName = typeNode.getTypeName().getText();
|
|
1460
1461
|
if (refName === "Date") return { kind: "date" };
|
|
1461
1462
|
if (refName === "Record" || refName === "Object") return { kind: "json" };
|
|
1463
|
+
const unwrapped = TRANSPARENT_TYPE_BRANDS.has(refName) ? typeNode.getTypeArguments()[0] : void 0;
|
|
1464
|
+
if (unwrapped) {
|
|
1465
|
+
const inner = classifyTypeNode(unwrapped, sourceFile, project, opts);
|
|
1466
|
+
return inner;
|
|
1467
|
+
}
|
|
1462
1468
|
const typeRef = opts?.resolveRef?.(refName) ?? null;
|
|
1463
1469
|
const en = resolveEnumValues(refName, sourceFile, project);
|
|
1464
1470
|
if (en) {
|
|
@@ -1529,12 +1535,19 @@ function classifyFromColumnDecorator(prop, sourceFile, project) {
|
|
|
1529
1535
|
return { kind: "string" };
|
|
1530
1536
|
}
|
|
1531
1537
|
}
|
|
1532
|
-
const
|
|
1533
|
-
|
|
1538
|
+
for (const key of ["columnType", "type"]) {
|
|
1539
|
+
const typeProp = arg.getProperty(key);
|
|
1540
|
+
if (!typeProp || !import_ts_morph4.Node.isPropertyAssignment(typeProp)) continue;
|
|
1534
1541
|
const init = typeProp.getInitializer();
|
|
1535
|
-
if (init
|
|
1542
|
+
if (!init) continue;
|
|
1543
|
+
if (import_ts_morph4.Node.isStringLiteral(init)) {
|
|
1536
1544
|
const kind = classifyTypeKeyword(init.getLiteralValue());
|
|
1537
1545
|
if (kind) return { kind };
|
|
1546
|
+
continue;
|
|
1547
|
+
}
|
|
1548
|
+
if (import_ts_morph4.Node.isIdentifier(init)) {
|
|
1549
|
+
const kind = classifyTypeKeyword(init.getText());
|
|
1550
|
+
if (kind) return { kind };
|
|
1538
1551
|
}
|
|
1539
1552
|
}
|
|
1540
1553
|
}
|
|
@@ -1546,12 +1559,18 @@ function classifyFromColumnDecorator(prop, sourceFile, project) {
|
|
|
1546
1559
|
function classifyFieldType(prop, sourceFile, project) {
|
|
1547
1560
|
let nullable = prop.hasQuestionToken();
|
|
1548
1561
|
const typeNode = prop.getTypeNode();
|
|
1562
|
+
const fromDecorator = classifyFromColumnDecorator(prop, sourceFile, project);
|
|
1549
1563
|
if (typeNode) {
|
|
1550
1564
|
const r = classifyTypeNode(typeNode, sourceFile, project);
|
|
1551
1565
|
if (r.nullable) nullable = true;
|
|
1552
|
-
if (r.kind !== "unknown")
|
|
1566
|
+
if (r.kind !== "unknown") {
|
|
1567
|
+
const conflicts = fromDecorator !== null && fromDecorator.kind !== "unknown" && fromDecorator.kind !== r.kind;
|
|
1568
|
+
if (conflicts) {
|
|
1569
|
+
return markNullable({ ...fromDecorator, valueKind: r.kind }, nullable);
|
|
1570
|
+
}
|
|
1571
|
+
return markNullable(r, nullable);
|
|
1572
|
+
}
|
|
1553
1573
|
}
|
|
1554
|
-
const fromDecorator = classifyFromColumnDecorator(prop, sourceFile, project);
|
|
1555
1574
|
if (fromDecorator) {
|
|
1556
1575
|
return markNullable(fromDecorator, nullable || fromDecorator.nullable === true);
|
|
1557
1576
|
}
|
|
@@ -1559,6 +1578,7 @@ function classifyFieldType(prop, sourceFile, project) {
|
|
|
1559
1578
|
}
|
|
1560
1579
|
function toFilterFieldType(name, r) {
|
|
1561
1580
|
const ft = { name, kind: r.kind };
|
|
1581
|
+
if (r.valueKind && r.valueKind !== r.kind) ft.valueKind = r.valueKind;
|
|
1562
1582
|
if (r.enumValues && r.enumValues.length > 0) ft.enumValues = r.enumValues;
|
|
1563
1583
|
if (r.nullable) ft.nullable = true;
|
|
1564
1584
|
if (r.numericEnum) ft.numericEnum = true;
|
|
@@ -3364,7 +3384,7 @@ function kindToTs(kind, enumValues, numericEnum) {
|
|
|
3364
3384
|
}
|
|
3365
3385
|
function emitFieldTypesLiteral(fts) {
|
|
3366
3386
|
const entries = fts.map((f) => {
|
|
3367
|
-
let t = f.typeRef ? f.typeRef.name : kindToTs(f.kind, f.enumValues, f.numericEnum);
|
|
3387
|
+
let t = f.typeRef ? f.typeRef.name : kindToTs(f.valueKind ?? f.kind, f.enumValues, f.numericEnum);
|
|
3368
3388
|
if (f.nullable) t = `${t} | null`;
|
|
3369
3389
|
return `${JSON.stringify(f.name)}: ${t}`;
|
|
3370
3390
|
});
|
|
@@ -5371,7 +5391,7 @@ function createChainModuleRenderer(opts) {
|
|
|
5371
5391
|
}
|
|
5372
5392
|
|
|
5373
5393
|
// src/index.ts
|
|
5374
|
-
var VERSION = "0.
|
|
5394
|
+
var VERSION = "0.24.0";
|
|
5375
5395
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5376
5396
|
0 && (module.exports = {
|
|
5377
5397
|
CodegenError,
|