wabe 0.6.3 → 0.6.4
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.d.ts +12 -2
- package/dist/index.js +47 -32
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -408,8 +408,18 @@ export declare class DatabaseController<T extends WabeTypes> {
|
|
|
408
408
|
}>;
|
|
409
409
|
selectWithoutPointers: Select;
|
|
410
410
|
};
|
|
411
|
-
_isRelationField(
|
|
412
|
-
|
|
411
|
+
_isRelationField({ pointerField, currentClassName, context, originClassName, }: {
|
|
412
|
+
pointerField: string;
|
|
413
|
+
originClassName: string;
|
|
414
|
+
context: WabeContext<T>;
|
|
415
|
+
currentClassName?: string;
|
|
416
|
+
}): boolean | undefined;
|
|
417
|
+
_isPointerField({ pointerField, currentClassName, context, originClassName, }: {
|
|
418
|
+
originClassName: string;
|
|
419
|
+
context: WabeContext<T>;
|
|
420
|
+
pointerField: string;
|
|
421
|
+
currentClassName?: string;
|
|
422
|
+
}): boolean | undefined;
|
|
413
423
|
_getWhereObjectWithPointerOrRelation<U extends keyof T["types"]>(className: U, where: WhereType<T, U>, context: WabeContext<T>): Promise<Partial<{
|
|
414
424
|
[P in keyof T["types"][U]]: (T["types"][U][P] extends infer T_1 ? T_1 extends T["types"][U][P] ? T_1 extends string | number | boolean ? true : false : never : never) extends false ? Partial<T["types"][U][P]> extends infer T_2 ? {
|
|
415
425
|
[P_1 in keyof T_2]: (Partial<T["types"][U][P]>[P_1] extends infer T_3 ? T_3 extends Partial<T["types"][U][P]>[P_1] ? T_3 extends string | number | boolean ? true : false : never : never) extends false ? Partial<Partial<T["types"][U][P]>[P_1]> extends infer T_4 ? {
|
package/dist/index.js
CHANGED
|
@@ -59500,15 +59500,25 @@ class DatabaseController2 {
|
|
|
59500
59500
|
};
|
|
59501
59501
|
}, { pointers: {}, selectWithoutPointers: {} });
|
|
59502
59502
|
}
|
|
59503
|
-
_isRelationField(
|
|
59504
|
-
|
|
59503
|
+
_isRelationField({
|
|
59504
|
+
pointerField,
|
|
59505
|
+
currentClassName,
|
|
59506
|
+
context,
|
|
59507
|
+
originClassName
|
|
59508
|
+
}) {
|
|
59509
|
+
if (!currentClassName)
|
|
59505
59510
|
return false;
|
|
59506
|
-
return context.wabe.config.schema?.classes?.some((c) => c.name.toLowerCase() === originClassName.toLowerCase() && Object.
|
|
59511
|
+
return context.wabe.config.schema?.classes?.some((c) => c.name.toLowerCase() === originClassName.toLowerCase() && Object.entries(c.fields).find(([fieldName, field]) => fieldName === pointerField && field.type === "Relation" && field.class.toLowerCase() === currentClassName.toLowerCase()));
|
|
59507
59512
|
}
|
|
59508
|
-
_isPointerField(
|
|
59509
|
-
|
|
59513
|
+
_isPointerField({
|
|
59514
|
+
pointerField,
|
|
59515
|
+
currentClassName,
|
|
59516
|
+
context,
|
|
59517
|
+
originClassName
|
|
59518
|
+
}) {
|
|
59519
|
+
if (!currentClassName)
|
|
59510
59520
|
return false;
|
|
59511
|
-
return context.wabe.config.schema?.classes?.some((c) => c.name.toLowerCase() === originClassName.toLowerCase() && Object.
|
|
59521
|
+
return context.wabe.config.schema?.classes?.some((c) => c.name.toLowerCase() === originClassName.toLowerCase() && Object.entries(c.fields).find(([fieldName, field]) => fieldName === pointerField && field.type === "Pointer" && field.class.toLowerCase() === currentClassName.toLowerCase()));
|
|
59512
59522
|
}
|
|
59513
59523
|
async _getWhereObjectWithPointerOrRelation(className, where, context) {
|
|
59514
59524
|
const whereKeys = Object.keys(where);
|
|
@@ -59629,7 +59639,12 @@ class DatabaseController2 {
|
|
|
59629
59639
|
}) {
|
|
59630
59640
|
return Object.entries(pointers).reduce(async (acc, [pointerField, { className: currentClassName, select: currentSelect }]) => {
|
|
59631
59641
|
const accObject = await acc;
|
|
59632
|
-
const isPointer = this._isPointerField(
|
|
59642
|
+
const isPointer = this._isPointerField({
|
|
59643
|
+
originClassName,
|
|
59644
|
+
context,
|
|
59645
|
+
currentClassName,
|
|
59646
|
+
pointerField
|
|
59647
|
+
});
|
|
59633
59648
|
if (isPointer) {
|
|
59634
59649
|
if (!object[pointerField]) {
|
|
59635
59650
|
return {
|
|
@@ -59649,8 +59664,13 @@ class DatabaseController2 {
|
|
|
59649
59664
|
[pointerField]: objectOfPointerClass
|
|
59650
59665
|
};
|
|
59651
59666
|
}
|
|
59652
|
-
const isRelation = this._isRelationField(
|
|
59653
|
-
|
|
59667
|
+
const isRelation = this._isRelationField({
|
|
59668
|
+
originClassName,
|
|
59669
|
+
context,
|
|
59670
|
+
currentClassName,
|
|
59671
|
+
pointerField
|
|
59672
|
+
});
|
|
59673
|
+
if (isRelation && object[pointerField]) {
|
|
59654
59674
|
const relationObjects = await this.getObjects({
|
|
59655
59675
|
className: currentClassName,
|
|
59656
59676
|
select: currentSelect,
|
|
@@ -64209,8 +64229,6 @@ var add = async ({
|
|
|
64209
64229
|
}) => {
|
|
64210
64230
|
if (typeOfExecution === "create")
|
|
64211
64231
|
return add2;
|
|
64212
|
-
const classInSchema = getClassFromClassName(className, context.wabe.config);
|
|
64213
|
-
const fieldInClass = classInSchema.fields[fieldName];
|
|
64214
64232
|
if (typeOfExecution === "update" && id) {
|
|
64215
64233
|
const currentValue = await context.wabe.controllers.database.getObject({
|
|
64216
64234
|
className,
|
|
@@ -64222,22 +64240,14 @@ var add = async ({
|
|
|
64222
64240
|
}
|
|
64223
64241
|
if (typeOfExecution === "updateMany" && where) {
|
|
64224
64242
|
const allObjectsMatchedWithWhere = await context.wabe.controllers.database.getObjects({
|
|
64225
|
-
className
|
|
64243
|
+
className,
|
|
64226
64244
|
where,
|
|
64227
64245
|
select: { [fieldName]: true },
|
|
64228
64246
|
context
|
|
64229
64247
|
});
|
|
64230
|
-
|
|
64248
|
+
return Promise.all(allObjectsMatchedWithWhere.flatMap((object) => {
|
|
64231
64249
|
const currentValue = object[fieldName];
|
|
64232
|
-
return
|
|
64233
|
-
className: classInSchema.fields[fieldName].class,
|
|
64234
|
-
id: object.id,
|
|
64235
|
-
data: {
|
|
64236
|
-
[fieldName]: [...currentValue || [], ...add2]
|
|
64237
|
-
},
|
|
64238
|
-
context,
|
|
64239
|
-
select: {}
|
|
64240
|
-
});
|
|
64250
|
+
return [...currentValue || [], ...add2];
|
|
64241
64251
|
}));
|
|
64242
64252
|
}
|
|
64243
64253
|
};
|
|
@@ -64252,6 +64262,7 @@ var remove = async ({
|
|
|
64252
64262
|
}) => {
|
|
64253
64263
|
if (typeOfExecution === "create")
|
|
64254
64264
|
return [];
|
|
64265
|
+
const classInSchema = getClassFromClassName(className, context.wabe.config);
|
|
64255
64266
|
if (typeOfExecution === "update" && id) {
|
|
64256
64267
|
const currentValue = await context.wabe.controllers.database.getObject({
|
|
64257
64268
|
className,
|
|
@@ -64260,6 +64271,12 @@ var remove = async ({
|
|
|
64260
64271
|
context
|
|
64261
64272
|
});
|
|
64262
64273
|
const olderValues = [currentValue?.id || ""];
|
|
64274
|
+
await context.wabe.controllers.database.deleteObjects({
|
|
64275
|
+
className: classInSchema.fields[fieldName].class,
|
|
64276
|
+
where: { id: { in: remove2 } },
|
|
64277
|
+
context,
|
|
64278
|
+
select: {}
|
|
64279
|
+
});
|
|
64263
64280
|
return olderValues.filter((olderValue) => !remove2.includes(olderValue));
|
|
64264
64281
|
}
|
|
64265
64282
|
if (typeOfExecution === "updateMany" && where) {
|
|
@@ -64269,17 +64286,15 @@ var remove = async ({
|
|
|
64269
64286
|
select: { id: true },
|
|
64270
64287
|
context
|
|
64271
64288
|
});
|
|
64272
|
-
await
|
|
64289
|
+
await context.wabe.controllers.database.deleteObjects({
|
|
64290
|
+
className: classInSchema.fields[fieldName].class,
|
|
64291
|
+
where: { id: { in: remove2 } },
|
|
64292
|
+
context,
|
|
64293
|
+
select: {}
|
|
64294
|
+
});
|
|
64295
|
+
return Promise.all(allObjectsMatchedWithWhere.flatMap((object) => {
|
|
64273
64296
|
const olderValues = object[fieldName]?.[fieldName] || [];
|
|
64274
|
-
return
|
|
64275
|
-
className,
|
|
64276
|
-
id: object.id,
|
|
64277
|
-
data: {
|
|
64278
|
-
[fieldName]: olderValues.filter((olderValue) => !remove2.includes(olderValue))
|
|
64279
|
-
},
|
|
64280
|
-
context,
|
|
64281
|
-
select: {}
|
|
64282
|
-
});
|
|
64297
|
+
return olderValues.filter((olderValue) => !remove2.includes(olderValue));
|
|
64283
64298
|
}));
|
|
64284
64299
|
}
|
|
64285
64300
|
};
|