rads-db 3.0.81 → 3.0.83
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 +6 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +6 -4
- package/fileUploadDrivers/restApi.cjs +2 -2
- package/fileUploadDrivers/restApi.mjs +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -879,9 +879,9 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
|
|
|
879
879
|
await afterPut(docArgsToSave, ctx, computedContext);
|
|
880
880
|
return { _logs, cursor, correctCount, incorrectCount, incorrectDocs };
|
|
881
881
|
}
|
|
882
|
-
function construct(key2) {
|
|
882
|
+
function construct(key2, defaultValues) {
|
|
883
883
|
const type = schema[key2];
|
|
884
|
-
|
|
884
|
+
let result2 = {};
|
|
885
885
|
if (!type.fields)
|
|
886
886
|
return {};
|
|
887
887
|
if (type.fields.id && type.decorators.entity)
|
|
@@ -892,12 +892,14 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
|
|
|
892
892
|
if (field.defaultValueClass)
|
|
893
893
|
result2[fieldName] = construct(field.defaultValueClass);
|
|
894
894
|
}
|
|
895
|
+
if (defaultValues)
|
|
896
|
+
result2 = merge(result2, defaultValues);
|
|
895
897
|
return result2;
|
|
896
898
|
}
|
|
897
899
|
const result = {
|
|
898
900
|
// No deleteMany / deleteAll on purpose - it's a dangerous operation, let them use driver instead
|
|
899
|
-
construct() {
|
|
900
|
-
return construct(key);
|
|
901
|
+
construct(defaultValues) {
|
|
902
|
+
return construct(key, defaultValues);
|
|
901
903
|
},
|
|
902
904
|
getMany,
|
|
903
905
|
putMany,
|
package/dist/index.d.ts
CHANGED
|
@@ -110,7 +110,7 @@ type DeepKeys<T> = T extends object ? {
|
|
|
110
110
|
}[(string | number) & keyof T] : never;
|
|
111
111
|
interface EntityMethods<E, EN extends keyof EntityMeta> {
|
|
112
112
|
/** Returns object with with random UUID as `id` and prefilled default values */
|
|
113
|
-
construct(): E;
|
|
113
|
+
construct(defaultValues?: DeepPartial<E>): E;
|
|
114
114
|
/** Used to access underlying mechanism of storage directly.
|
|
115
115
|
* Warning: bypasses all rads features - schema won't be validated, default values won't be filled, etc. */
|
|
116
116
|
driver: Driver;
|
package/dist/index.mjs
CHANGED
|
@@ -872,9 +872,9 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
|
|
|
872
872
|
await afterPut(docArgsToSave, ctx, computedContext);
|
|
873
873
|
return { _logs, cursor, correctCount, incorrectCount, incorrectDocs };
|
|
874
874
|
}
|
|
875
|
-
function construct(key2) {
|
|
875
|
+
function construct(key2, defaultValues) {
|
|
876
876
|
const type = schema[key2];
|
|
877
|
-
|
|
877
|
+
let result2 = {};
|
|
878
878
|
if (!type.fields)
|
|
879
879
|
return {};
|
|
880
880
|
if (type.fields.id && type.decorators.entity)
|
|
@@ -885,12 +885,14 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
|
|
|
885
885
|
if (field.defaultValueClass)
|
|
886
886
|
result2[fieldName] = construct(field.defaultValueClass);
|
|
887
887
|
}
|
|
888
|
+
if (defaultValues)
|
|
889
|
+
result2 = merge(result2, defaultValues);
|
|
888
890
|
return result2;
|
|
889
891
|
}
|
|
890
892
|
const result = {
|
|
891
893
|
// No deleteMany / deleteAll on purpose - it's a dangerous operation, let them use driver instead
|
|
892
|
-
construct() {
|
|
893
|
-
return construct(key);
|
|
894
|
+
construct(defaultValues) {
|
|
895
|
+
return construct(key, defaultValues);
|
|
894
896
|
},
|
|
895
897
|
getMany,
|
|
896
898
|
putMany,
|
|
@@ -43,7 +43,7 @@ async function getJsonBody(args) {
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
async function blobToDataUrl(blob) {
|
|
46
|
-
if (FileReader) {
|
|
46
|
+
if (globalThis.FileReader) {
|
|
47
47
|
return new Promise((resolve, reject) => {
|
|
48
48
|
const a = new FileReader();
|
|
49
49
|
a.onload = function (e) {
|
|
@@ -55,7 +55,7 @@ async function blobToDataUrl(blob) {
|
|
|
55
55
|
a.readAsDataURL(blob);
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
-
if (Buffer) {
|
|
58
|
+
if (globalThis.Buffer) {
|
|
59
59
|
const buf = await blob.arrayBuffer();
|
|
60
60
|
const b64string = Buffer.from(buf).toString("base64");
|
|
61
61
|
return `data:${blob.type};base64,${b64string}`;
|
|
@@ -31,7 +31,7 @@ async function getJsonBody(args) {
|
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
async function blobToDataUrl(blob) {
|
|
34
|
-
if (FileReader) {
|
|
34
|
+
if (globalThis.FileReader) {
|
|
35
35
|
return new Promise((resolve, reject) => {
|
|
36
36
|
const a = new FileReader();
|
|
37
37
|
a.onload = function(e) {
|
|
@@ -43,7 +43,7 @@ async function blobToDataUrl(blob) {
|
|
|
43
43
|
a.readAsDataURL(blob);
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
if (Buffer) {
|
|
46
|
+
if (globalThis.Buffer) {
|
|
47
47
|
const buf = await blob.arrayBuffer();
|
|
48
48
|
const b64string = Buffer.from(buf).toString("base64");
|
|
49
49
|
return `data:${blob.type};base64,${b64string}`;
|