rads-db 3.0.47 → 3.0.49
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 +17 -3
- package/dist/index.d.ts +11 -4
- package/dist/index.mjs +17 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -688,7 +688,6 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
|
|
|
688
688
|
return docsToSave;
|
|
689
689
|
}
|
|
690
690
|
async function verifyMany(args, ctx) {
|
|
691
|
-
console.log("verMany");
|
|
692
691
|
if (driverInstance.verifyMany) {
|
|
693
692
|
return driverInstance.verifyMany(args, ctx);
|
|
694
693
|
}
|
|
@@ -741,10 +740,25 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
|
|
|
741
740
|
await afterPut(docArgsToSave, ctx, computedContext);
|
|
742
741
|
return { _logs, cursor, correctCount, incorrectCount, incorrectDocs };
|
|
743
742
|
}
|
|
743
|
+
function construct(key2) {
|
|
744
|
+
const type = schema[key2];
|
|
745
|
+
const result2 = {};
|
|
746
|
+
if (!type.fields)
|
|
747
|
+
return {};
|
|
748
|
+
if (type.fields.id && type.decorators.entity)
|
|
749
|
+
result2.id = uuid.v4();
|
|
750
|
+
for (const [fieldName, field] of Object.entries(type.fields)) {
|
|
751
|
+
if (field.defaultValue)
|
|
752
|
+
result2[fieldName] = field.defaultValue;
|
|
753
|
+
if (field.defaultValueClass)
|
|
754
|
+
result2[fieldName] = construct(field.defaultValueClass);
|
|
755
|
+
}
|
|
756
|
+
return result2;
|
|
757
|
+
}
|
|
744
758
|
const result = {
|
|
745
759
|
// No deleteMany / deleteAll on purpose - it's a dangerous operation, let them use driver instead
|
|
746
|
-
|
|
747
|
-
|
|
760
|
+
construct() {
|
|
761
|
+
return construct(key);
|
|
748
762
|
},
|
|
749
763
|
getMany,
|
|
750
764
|
putMany,
|
package/dist/index.d.ts
CHANGED
|
@@ -64,17 +64,24 @@ interface GetResponseIncludeSelect<E, I> {
|
|
|
64
64
|
type GetResponseNoInclude<E, EN extends keyof EntityMeta> = {
|
|
65
65
|
[K in keyof E]: K extends keyof EntityMeta[EN]['relations'] ? KeepArray<E[K], RelationData<EN, K>> : E[K];
|
|
66
66
|
};
|
|
67
|
-
type
|
|
67
|
+
type DeepPartialWithNulls<T> = {
|
|
68
68
|
[K in keyof T]?: NonNullable<T[K]> extends any[] ? DeepPartial<NonNullable<T[K]>[number]>[] : NonNullable<T[K]> extends Record<string, any> ? DeepPartial<T[K]> | null : T[K] | null;
|
|
69
69
|
};
|
|
70
|
+
type DeepPartial<T> = {
|
|
71
|
+
[K in keyof T]?: NonNullable<T[K]> extends any[] ? DeepPartial<NonNullable<T[K]>[number]>[] : NonNullable<T[K]> extends Record<string, any> ? DeepPartial<T[K]> : T[K];
|
|
72
|
+
};
|
|
70
73
|
type Relation<T extends {
|
|
71
74
|
id: any;
|
|
72
75
|
}, K extends Exclude<keyof T, 'id'> = never> = Pick<T, K | 'id'> & DeepPartial<T>;
|
|
73
76
|
type PutArgs<T> = {
|
|
74
77
|
id: string;
|
|
75
|
-
} &
|
|
78
|
+
} & DeepPartialWithNulls<T>;
|
|
79
|
+
type DeepKeys<T> = T extends object ? {
|
|
80
|
+
[K in (string | number) & keyof T]: `${`.${K}` | (`${K}` extends `${number}` ? `[${K}]` : never)}${'' | DeepKeys<T[K]>}`;
|
|
81
|
+
}[(string | number) & keyof T] : never;
|
|
76
82
|
interface EntityMethods<E, EN extends keyof EntityMeta, W> {
|
|
77
|
-
|
|
83
|
+
/** Returns object with with random UUID as `id` and prefilled default values */
|
|
84
|
+
construct(): E;
|
|
78
85
|
/** Used to access underlying mechanism of storage directly.
|
|
79
86
|
* Warning: bypasses all rads features - schema won't be validated, default values won't be filled, etc. */
|
|
80
87
|
driver: Driver;
|
|
@@ -421,4 +428,4 @@ declare function createRadsDb(args?: CreateRadsDbArgs): RadsDb;
|
|
|
421
428
|
*/
|
|
422
429
|
declare function createRadsDbClient(args?: CreateRadsDbClientArgs): RadsDb;
|
|
423
430
|
|
|
424
|
-
export { Change, ComputedContext, ComputedContextGlobal, ComputedDecoratorArgs, CreateRadsArgsDrivers, CreateRadsDbArgs, CreateRadsDbArgsNormalized, CreateRadsDbClientArgs, DeepPartial, Driver, DriverConstructor, EntityDecoratorArgs, EntityMethods, EnumDefinition, FieldDecoratorArgs, FieldDefinition, FileSystemNode, FileUploadArgs, FileUploadDriver, FileUploadResult, GenerateClientNormalizedOptions, GenerateClientOptions, GetAggArgs, GetAggArgsAgg, GetAggArgsAny, GetAggResponse, GetArgs, GetArgsAny, GetArgsInclude, GetManyArgs, GetManyArgsAny, GetManyResponse, GetResponse, GetResponseInclude, GetResponseIncludeSelect, GetResponseNoInclude, GetRestRoutesArgs, GetRestRoutesOptions, GetRestRoutesResponse, MinimalDriver, PutArgs, PutEffect, RadsFeature, RadsHookDoc, RadsRequestContext, RadsUiSlotDefinition, RadsUiSlotName, RadsVitePluginOptions, Relation, RequiredFields, RestDriverOptions, RestFileUploadDriverOptions, Schema, SchemaValidators, TypeDefinition, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, ValidateStringDecoratorArgs, VerifyManyArgs, VerifyManyArgsAny, VerifyManyResponse, WhereJsonContains, cleanUndefinedAndNull, computed, createRadsDb, createRadsDbClient, diff, entity, field, getDriverInstance, handlePrecomputed, keepHistory, merge, precomputed, ui, validate };
|
|
431
|
+
export { Change, ComputedContext, ComputedContextGlobal, ComputedDecoratorArgs, CreateRadsArgsDrivers, CreateRadsDbArgs, CreateRadsDbArgsNormalized, CreateRadsDbClientArgs, DeepKeys, DeepPartial, DeepPartialWithNulls, Driver, DriverConstructor, EntityDecoratorArgs, EntityMethods, EnumDefinition, FieldDecoratorArgs, FieldDefinition, FileSystemNode, FileUploadArgs, FileUploadDriver, FileUploadResult, GenerateClientNormalizedOptions, GenerateClientOptions, GetAggArgs, GetAggArgsAgg, GetAggArgsAny, GetAggResponse, GetArgs, GetArgsAny, GetArgsInclude, GetManyArgs, GetManyArgsAny, GetManyResponse, GetResponse, GetResponseInclude, GetResponseIncludeSelect, GetResponseNoInclude, GetRestRoutesArgs, GetRestRoutesOptions, GetRestRoutesResponse, MinimalDriver, PutArgs, PutEffect, RadsFeature, RadsHookDoc, RadsRequestContext, RadsUiSlotDefinition, RadsUiSlotName, RadsVitePluginOptions, Relation, RequiredFields, RestDriverOptions, RestFileUploadDriverOptions, Schema, SchemaValidators, TypeDefinition, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, ValidateStringDecoratorArgs, VerifyManyArgs, VerifyManyArgsAny, VerifyManyResponse, WhereJsonContains, cleanUndefinedAndNull, computed, createRadsDb, createRadsDbClient, diff, entity, field, getDriverInstance, handlePrecomputed, keepHistory, merge, precomputed, ui, validate };
|
package/dist/index.mjs
CHANGED
|
@@ -680,7 +680,6 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
|
|
|
680
680
|
return docsToSave;
|
|
681
681
|
}
|
|
682
682
|
async function verifyMany(args, ctx) {
|
|
683
|
-
console.log("verMany");
|
|
684
683
|
if (driverInstance.verifyMany) {
|
|
685
684
|
return driverInstance.verifyMany(args, ctx);
|
|
686
685
|
}
|
|
@@ -733,10 +732,25 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
|
|
|
733
732
|
await afterPut(docArgsToSave, ctx, computedContext);
|
|
734
733
|
return { _logs, cursor, correctCount, incorrectCount, incorrectDocs };
|
|
735
734
|
}
|
|
735
|
+
function construct(key2) {
|
|
736
|
+
const type = schema[key2];
|
|
737
|
+
const result2 = {};
|
|
738
|
+
if (!type.fields)
|
|
739
|
+
return {};
|
|
740
|
+
if (type.fields.id && type.decorators.entity)
|
|
741
|
+
result2.id = v4();
|
|
742
|
+
for (const [fieldName, field] of Object.entries(type.fields)) {
|
|
743
|
+
if (field.defaultValue)
|
|
744
|
+
result2[fieldName] = field.defaultValue;
|
|
745
|
+
if (field.defaultValueClass)
|
|
746
|
+
result2[fieldName] = construct(field.defaultValueClass);
|
|
747
|
+
}
|
|
748
|
+
return result2;
|
|
749
|
+
}
|
|
736
750
|
const result = {
|
|
737
751
|
// No deleteMany / deleteAll on purpose - it's a dangerous operation, let them use driver instead
|
|
738
|
-
|
|
739
|
-
|
|
752
|
+
construct() {
|
|
753
|
+
return construct(key);
|
|
740
754
|
},
|
|
741
755
|
getMany,
|
|
742
756
|
putMany,
|