@zenstackhq/orm 3.6.0 → 3.6.2
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/dist/index.cjs +18 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +175 -160
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -1629,6 +1629,7 @@ var PostgresCrudDialect = class PostgresCrudDialect extends LateralJoinDialectBa
|
|
|
1629
1629
|
return value;
|
|
1630
1630
|
}
|
|
1631
1631
|
});
|
|
1632
|
+
pg.types.setTypeParser(pg.types.builtins.DATE, (v) => /* @__PURE__ */ new Date(`${v}T00:00:00Z`));
|
|
1632
1633
|
}).catch(() => {});
|
|
1633
1634
|
}
|
|
1634
1635
|
}
|
|
@@ -2491,12 +2492,17 @@ var ZodSchemaFactory = class {
|
|
|
2491
2492
|
return schema;
|
|
2492
2493
|
}
|
|
2493
2494
|
makeDateTimeValueSchema() {
|
|
2494
|
-
const schema = zod.z.union([
|
|
2495
|
+
const schema = zod.z.union([
|
|
2496
|
+
zod.z.iso.datetime(),
|
|
2497
|
+
zod.z.iso.date(),
|
|
2498
|
+
zod.z.date()
|
|
2499
|
+
]);
|
|
2495
2500
|
this.registerSchema("DateTime", schema);
|
|
2496
2501
|
return schema;
|
|
2497
2502
|
}
|
|
2498
2503
|
makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2499
|
-
const
|
|
2504
|
+
const filterValueSchema = this.makeDateTimeValueSchema();
|
|
2505
|
+
const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => zod.z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2500
2506
|
"_count",
|
|
2501
2507
|
"_min",
|
|
2502
2508
|
"_max"
|
|
@@ -5532,6 +5538,7 @@ var QueryNameMapper = class extends kysely.OperationNodeTransformer {
|
|
|
5532
5538
|
modelToTableMap = /* @__PURE__ */ new Map();
|
|
5533
5539
|
fieldToColumnMap = /* @__PURE__ */ new Map();
|
|
5534
5540
|
enumTypeMap = /* @__PURE__ */ new Map();
|
|
5541
|
+
joinTableSchemaMap = /* @__PURE__ */ new Map();
|
|
5535
5542
|
scopes = [];
|
|
5536
5543
|
dialect;
|
|
5537
5544
|
constructor(client) {
|
|
@@ -5550,6 +5557,13 @@ var QueryNameMapper = class extends kysely.OperationNodeTransformer {
|
|
|
5550
5557
|
const mappedName = this.getMappedName(enumDef);
|
|
5551
5558
|
if (mappedName) this.enumTypeMap.set(enumName, mappedName);
|
|
5552
5559
|
}
|
|
5560
|
+
if (client.$schema.provider.type === "postgresql") for (const modelName of Object.keys(client.$schema.models)) for (const fieldDef of getModelFields(this.schema, modelName, { relations: true })) {
|
|
5561
|
+
const m2m = getManyToManyRelation(this.schema, modelName, fieldDef.name);
|
|
5562
|
+
if (m2m && !this.joinTableSchemaMap.has(m2m.joinTable)) {
|
|
5563
|
+
const owningModel = [modelName, m2m.otherModel].sort()[0];
|
|
5564
|
+
this.joinTableSchemaMap.set(m2m.joinTable, this.getTableSchema(owningModel) ?? "public");
|
|
5565
|
+
}
|
|
5566
|
+
}
|
|
5553
5567
|
}
|
|
5554
5568
|
get schema() {
|
|
5555
5569
|
return this.client.$schema;
|
|
@@ -5813,8 +5827,9 @@ var QueryNameMapper = class extends kysely.OperationNodeTransformer {
|
|
|
5813
5827
|
}
|
|
5814
5828
|
getTableSchema(model) {
|
|
5815
5829
|
if (this.schema.provider.type !== "postgresql") return;
|
|
5830
|
+
if (!this.schema.models[model]) return this.joinTableSchemaMap.get(model) ?? "public";
|
|
5816
5831
|
let schema = this.schema.provider.defaultSchema ?? "public";
|
|
5817
|
-
const schemaAttr = this.schema.models[model]
|
|
5832
|
+
const schemaAttr = this.schema.models[model].attributes?.find((attr) => attr.name === "@@schema");
|
|
5818
5833
|
if (schemaAttr) {
|
|
5819
5834
|
const mapArg = schemaAttr.args?.find((arg) => arg.name === "map");
|
|
5820
5835
|
if (mapArg && mapArg.value.kind === "literal") schema = mapArg.value.value;
|