@buka/nestjs-kit 4.4.11 → 4.4.13
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 +15 -0
- package/dist/index.d.mts +111 -22
- package/dist/index.d.ts +111 -22
- package/dist/index.js +63 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -29
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -822,8 +822,14 @@ var ModelRegister = class {
|
|
|
822
822
|
* ```
|
|
823
823
|
*/
|
|
824
824
|
static getModelPropertyKeys(target) {
|
|
825
|
-
const
|
|
826
|
-
|
|
825
|
+
const keys = /* @__PURE__ */ new Set();
|
|
826
|
+
let current = target;
|
|
827
|
+
while (current && current !== Object) {
|
|
828
|
+
const metadata = this.getModel(current);
|
|
829
|
+
if (metadata) for (const key of metadata.propertyKeys) keys.add(key);
|
|
830
|
+
current = Object.getPrototypeOf(current.prototype)?.constructor ?? null;
|
|
831
|
+
}
|
|
832
|
+
return Array.from(keys);
|
|
827
833
|
}
|
|
828
834
|
static getProperties(target) {
|
|
829
835
|
return this.getModelPropertyKeys(target).map((propertyKey) => this.getProperty(target, propertyKey)).filter((property) => !!property);
|
|
@@ -1574,6 +1580,27 @@ function swaggerMetadataToJsonSchema(metadata) {
|
|
|
1574
1580
|
}
|
|
1575
1581
|
//#endregion
|
|
1576
1582
|
//#region src/modules/core/converters/filter-query-type/get-filter-query-schema.ts
|
|
1583
|
+
/**
|
|
1584
|
+
* 为单个标量属性生成 filter 操作符的 Swagger schema。
|
|
1585
|
+
*
|
|
1586
|
+
* 生成 `{ type: 'object', properties: { eq: ..., ne: ..., in: [...], ... } }` 结构,
|
|
1587
|
+
* 值类型取自原始 Swagger metadata(如 `{ type: 'string' }`),无 metadata 时兜底为 `string`。
|
|
1588
|
+
*/
|
|
1589
|
+
function getScalarOperatorSchema(classRef, propertyKey) {
|
|
1590
|
+
const propertySchema = {
|
|
1591
|
+
type: "object",
|
|
1592
|
+
properties: {},
|
|
1593
|
+
additionalProperties: false
|
|
1594
|
+
};
|
|
1595
|
+
const originalSchema = getMetadata$1(classRef, propertyKey);
|
|
1596
|
+
const operators = getPropertyOperators(classRef, propertyKey);
|
|
1597
|
+
for (const operator of operators) if (["in", "nin"].includes(operator)) propertySchema.properties[operator] = {
|
|
1598
|
+
type: "array",
|
|
1599
|
+
items: originalSchema ? swaggerMetadataToJsonSchema(originalSchema) : { type: "string" }
|
|
1600
|
+
};
|
|
1601
|
+
else propertySchema.properties[operator] = originalSchema ? swaggerMetadataToJsonSchema(originalSchema) : { type: "string" };
|
|
1602
|
+
return propertySchema;
|
|
1603
|
+
}
|
|
1577
1604
|
function getObjectSchema(classRef, visited = /* @__PURE__ */ new WeakSet()) {
|
|
1578
1605
|
const properties = {};
|
|
1579
1606
|
const requiredKeys = [];
|
|
@@ -1586,38 +1613,28 @@ function getObjectSchema(classRef, visited = /* @__PURE__ */ new WeakSet()) {
|
|
|
1586
1613
|
for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
|
|
1587
1614
|
if (typeof propertyKey !== "string") continue;
|
|
1588
1615
|
const propertyMetadata = ModelRegister.getProperty(classRef, propertyKey);
|
|
1589
|
-
const isCollection = propertyMetadata?.association?.kind === "1:m" || propertyMetadata?.association?.kind === "m:n";
|
|
1590
|
-
const isRelation = !!propertyMetadata?.association;
|
|
1591
1616
|
if (!!!propertyMetadata?.optional) requiredKeys.push(propertyKey);
|
|
1592
|
-
if (
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
if (
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
} else {
|
|
1607
|
-
const propertySchema = {
|
|
1617
|
+
if (propertyMetadata?.kind === "scalar" || propertyMetadata?.kind === "enum") properties[propertyKey] = getScalarOperatorSchema(classRef, propertyKey);
|
|
1618
|
+
else if (propertyMetadata?.kind === "composite" && propertyMetadata.type) {
|
|
1619
|
+
const compositeType = propertyMetadata.type();
|
|
1620
|
+
if (ModelRegister.isModel(compositeType) && !visited.has(compositeType)) properties[propertyKey] = getObjectSchema(compositeType, visited);
|
|
1621
|
+
else properties[propertyKey] = getScalarOperatorSchema(classRef, propertyKey);
|
|
1622
|
+
} else if (propertyMetadata?.kind === "list" || propertyMetadata?.kind === "dictionary") {
|
|
1623
|
+
let elementSchema;
|
|
1624
|
+
if (propertyMetadata.type && !isScalarClass(propertyMetadata.type)) {
|
|
1625
|
+
const elementType = propertyMetadata.type();
|
|
1626
|
+
if (ModelRegister.isModel(elementType) && !visited.has(elementType)) elementSchema = getObjectSchema(elementType, visited);
|
|
1627
|
+
else elementSchema = getScalarOperatorSchema(classRef, propertyKey);
|
|
1628
|
+
} else elementSchema = getScalarOperatorSchema(classRef, propertyKey);
|
|
1629
|
+
const operators = getCollectionOperators(classRef, propertyKey);
|
|
1630
|
+
const wrapper = {
|
|
1608
1631
|
type: "object",
|
|
1609
1632
|
properties: {},
|
|
1610
1633
|
additionalProperties: false
|
|
1611
1634
|
};
|
|
1612
|
-
const
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
type: "array",
|
|
1616
|
-
items: originalSchema ? swaggerMetadataToJsonSchema(originalSchema) : { type: "string" }
|
|
1617
|
-
};
|
|
1618
|
-
else propertySchema.properties[operator] = originalSchema ? swaggerMetadataToJsonSchema(originalSchema) : { type: "string" };
|
|
1619
|
-
properties[propertyKey] = propertySchema;
|
|
1620
|
-
}
|
|
1635
|
+
for (const operator of operators) wrapper.properties[operator] = elementSchema;
|
|
1636
|
+
properties[propertyKey] = wrapper;
|
|
1637
|
+
} else properties[propertyKey] = getScalarOperatorSchema(classRef, propertyKey);
|
|
1621
1638
|
}
|
|
1622
1639
|
if (requiredKeys.length > 0) schema.required = requiredKeys;
|
|
1623
1640
|
return schema;
|
|
@@ -1722,6 +1739,23 @@ function createFilterQueryObjectClassRef(classRef, visited = /* @__PURE__ */ new
|
|
|
1722
1739
|
optional: isOptional
|
|
1723
1740
|
})(FilterQueryObjectClass.prototype, propertyKey);
|
|
1724
1741
|
}
|
|
1742
|
+
} else if (propertyMetadata?.kind === "composite" && propertyMetadata?.type) {
|
|
1743
|
+
const compositeType = propertyMetadata.type();
|
|
1744
|
+
if (ModelRegister.isModel(compositeType) && !visited.has(compositeType)) {
|
|
1745
|
+
const sub = createFilterQueryObjectClassRef(compositeType, visited);
|
|
1746
|
+
Composite({
|
|
1747
|
+
type: () => sub,
|
|
1748
|
+
optional: isOptional
|
|
1749
|
+
})(FilterQueryObjectClass.prototype, propertyKey);
|
|
1750
|
+
if (!isOptional) HasAnyKey(getFilterQueryOperators(classRef, propertyKey) || getPropertyOperators(classRef, propertyKey))(FilterQueryObjectClass.prototype, propertyKey);
|
|
1751
|
+
} else {
|
|
1752
|
+
const propertyClass = createFilterQueryPropertyClassRef(classRef, propertyKey);
|
|
1753
|
+
Composite({
|
|
1754
|
+
type: () => propertyClass,
|
|
1755
|
+
optional: isOptional
|
|
1756
|
+
})(FilterQueryObjectClass.prototype, propertyKey);
|
|
1757
|
+
if (!isOptional) HasAnyKey(getPropertyOperators(classRef, propertyKey))(FilterQueryObjectClass.prototype, propertyKey);
|
|
1758
|
+
}
|
|
1725
1759
|
} else {
|
|
1726
1760
|
const propertyClass = createFilterQueryPropertyClassRef(classRef, propertyKey);
|
|
1727
1761
|
Composite({
|