rads-db 0.1.42 → 0.1.44
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 +44 -8
- package/dist/index.d.ts +7 -4
- package/dist/index.mjs +43 -8
- package/fileUploadDrivers/restApi.cjs +1 -3
- package/fileUploadDrivers/restApi.mjs +0 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
const zod = require('zod');
|
|
4
4
|
const _ = require('lodash');
|
|
5
|
+
const createMerge = require('@fastify/deepmerge');
|
|
5
6
|
const uuid = require('uuid');
|
|
6
7
|
const _radsDb = require('_rads-db');
|
|
7
8
|
|
|
8
9
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
9
10
|
|
|
10
11
|
const ___default = /*#__PURE__*/_interopDefaultCompat(_);
|
|
12
|
+
const createMerge__default = /*#__PURE__*/_interopDefaultCompat(createMerge);
|
|
11
13
|
|
|
12
14
|
function generateValidators(schema) {
|
|
13
15
|
const zodSchemas = {};
|
|
@@ -60,7 +62,7 @@ function getFieldZodSchema(zodSchemas, schema, field, shouldBeLazy) {
|
|
|
60
62
|
if (field.isArray)
|
|
61
63
|
fieldSchema = fieldSchema.array();
|
|
62
64
|
if (!field.isRequired)
|
|
63
|
-
fieldSchema = fieldSchema.optional();
|
|
65
|
+
fieldSchema = fieldSchema.optional().nullable();
|
|
64
66
|
if (field.defaultValue !== void 0)
|
|
65
67
|
fieldSchema = fieldSchema.default(field.defaultValue);
|
|
66
68
|
if (field.defaultValueCopyFrom !== void 0)
|
|
@@ -96,13 +98,40 @@ function getFieldZodSchemaBase(zodSchemas, schema, field, shouldBeLazy) {
|
|
|
96
98
|
throw new Error(`Unknown type: ${field.type}`);
|
|
97
99
|
}
|
|
98
100
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
101
|
+
const mergeFn = createMerge__default({
|
|
102
|
+
mergeArray(options) {
|
|
103
|
+
const clone = options.clone;
|
|
104
|
+
return function(target, source) {
|
|
105
|
+
return clone(source);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
function merge(target, source) {
|
|
110
|
+
cleanUndefined(source);
|
|
111
|
+
const result = mergeFn(target, source);
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
function cleanUndefined(obj) {
|
|
115
|
+
if (!obj || !___default.isPlainObject(obj))
|
|
116
|
+
return;
|
|
117
|
+
cleanUndefinedInner(obj);
|
|
118
|
+
}
|
|
119
|
+
function cleanUndefinedInner(obj) {
|
|
120
|
+
for (const key in obj) {
|
|
121
|
+
if (obj[key] === void 0)
|
|
122
|
+
delete obj[key];
|
|
123
|
+
if (___default.isPlainObject(obj[key]))
|
|
124
|
+
cleanUndefinedInner(obj[key]);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function cleanUndefinedAndNull(obj) {
|
|
129
|
+
for (const key in obj) {
|
|
130
|
+
if (obj[key] == null)
|
|
131
|
+
delete obj[key];
|
|
132
|
+
if (___default.isPlainObject(obj[key]))
|
|
133
|
+
cleanUndefinedAndNull(obj[key]);
|
|
134
|
+
}
|
|
106
135
|
}
|
|
107
136
|
|
|
108
137
|
const operatorFns = {
|
|
@@ -586,6 +615,8 @@ function generateMethods(schema, validators, options) {
|
|
|
586
615
|
uploadFile(args) {
|
|
587
616
|
if (!opts.fileUploadDriver)
|
|
588
617
|
throw new Error(`Missing configuration. Please specify "fileUploadDriver" argument in "createRads()".`);
|
|
618
|
+
if (!args.containerName)
|
|
619
|
+
args.containerName = "files";
|
|
589
620
|
return opts.fileUploadDriver.uploadFile(args);
|
|
590
621
|
}
|
|
591
622
|
};
|
|
@@ -612,6 +643,7 @@ function generateMethods(schema, validators, options) {
|
|
|
612
643
|
db
|
|
613
644
|
};
|
|
614
645
|
const driverInstance = getDriverInstance(schema, key, opts.driver, drivers);
|
|
646
|
+
const mustCleanNulls = driverInstance.driverName !== "restApi";
|
|
615
647
|
db[handle] = {
|
|
616
648
|
getAgg: async (args, ctx) => {
|
|
617
649
|
if (!args?.agg)
|
|
@@ -652,6 +684,8 @@ function generateMethods(schema, validators, options) {
|
|
|
652
684
|
const oldDoc = await driverInstance.get({ where: { id: doc.id } });
|
|
653
685
|
if (oldDoc)
|
|
654
686
|
doc = merge(oldDoc, doc);
|
|
687
|
+
if (mustCleanNulls)
|
|
688
|
+
cleanUndefinedAndNull(doc);
|
|
655
689
|
doc = validators[key](doc);
|
|
656
690
|
const docArgsToSave = [{ doc, oldDoc }];
|
|
657
691
|
await fillDenormFieldsBeforePut(computedContext, docArgsToSave);
|
|
@@ -674,6 +708,8 @@ function generateMethods(schema, validators, options) {
|
|
|
674
708
|
const docArgsToSave = docs.map((doc) => {
|
|
675
709
|
const oldDoc = oldDocsById[doc.id];
|
|
676
710
|
doc = merge(oldDoc, doc);
|
|
711
|
+
if (mustCleanNulls)
|
|
712
|
+
cleanUndefinedAndNull(doc);
|
|
677
713
|
doc = validators[key](doc);
|
|
678
714
|
return { oldDoc, doc };
|
|
679
715
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -51,12 +51,15 @@ type GetResponseNoInclude<E, EN extends keyof EntityMeta> = {
|
|
|
51
51
|
type DeepPartial<T> = {
|
|
52
52
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
53
53
|
};
|
|
54
|
+
type DeepPartialNullable<T> = {
|
|
55
|
+
[K in keyof T]?: DeepPartialNullable<T[K]> | null;
|
|
56
|
+
};
|
|
54
57
|
type Relation<T extends {
|
|
55
58
|
id: any;
|
|
56
59
|
}, K extends Exclude<keyof T, 'id'> = never> = Pick<T, K | 'id'> & DeepPartial<T>;
|
|
57
60
|
type PutArgs<T> = {
|
|
58
61
|
id: string;
|
|
59
|
-
} &
|
|
62
|
+
} & DeepPartialNullable<T>;
|
|
60
63
|
interface EntityMethods<E, EN extends keyof EntityMeta, W> {
|
|
61
64
|
get<A extends GetArgs<E, EN, W>>(args: A): MaybePromise$1<GetResponse<E, EN, A>>;
|
|
62
65
|
getMany<A extends GetManyArgs<E, EN, W>>(args?: A): MaybePromise$1<GetManyResponse<E, EN, A>>;
|
|
@@ -78,7 +81,7 @@ interface ValidateNumberDecoratorArgs {
|
|
|
78
81
|
max?: number;
|
|
79
82
|
}
|
|
80
83
|
interface ValidateStringDecoratorArgs {
|
|
81
|
-
preset?: 'number' | 'decimalNumber' | 'email' | 'icon' | 'imageUrl' | 'fileUrl' | 'absoluteUrl' | 'relativeUrl' | 'phoneNumber' | 'datetime' | 'date' | 'time' | 'timeInterval' | 'duration';
|
|
84
|
+
preset?: 'text' | 'html' | 'markdown' | 'alpha' | 'alphanum' | 'number' | 'decimalNumber' | 'email' | 'icon' | 'imageUrl' | 'fileUrl' | 'absoluteUrl' | 'relativeUrl' | 'phoneNumber' | 'datetime' | 'date' | 'time' | 'timeInterval' | 'duration';
|
|
82
85
|
regex?: RegExp;
|
|
83
86
|
minLength?: number;
|
|
84
87
|
maxLength?: number;
|
|
@@ -159,8 +162,8 @@ interface FileUploadDriver {
|
|
|
159
162
|
}
|
|
160
163
|
interface FileUploadArgs {
|
|
161
164
|
blob: Blob;
|
|
165
|
+
fileName: string;
|
|
162
166
|
containerName?: string;
|
|
163
|
-
fileName?: string;
|
|
164
167
|
options?: any;
|
|
165
168
|
}
|
|
166
169
|
interface MinimalDriver {
|
|
@@ -263,4 +266,4 @@ declare function computed(meta?: ComputedDecoratorArgs): (a: any, b?: ClassField
|
|
|
263
266
|
declare function createRads(args?: CreateRadsArgs): RadsDb;
|
|
264
267
|
declare function getRestRoutes(db: RadsDb, prefix?: string): Record<string, Record<string, Function>>;
|
|
265
268
|
|
|
266
|
-
export { AzureCosmosDriverOptions, AzureStorageBlobUploadDriverOptions, Change, ComputedContext, ComputedDecoratorArgs, CreateRadsArgs, DeepPartial, Driver, DriverConstructor, DriverOptions, EntityDecoratorArgs, EntityMethods, FieldDecoratorArgs, FieldDefinition, FileUploadArgs, FileUploadDriver, GenerateClientNormalizedOptions, GenerateClientOptions, GetAggArgs, GetAggArgsAgg, GetAggArgsAny, GetAggResponse, GetArgs, GetArgsAny, GetArgsInclude, GetManyArgs, GetManyArgsAny, GetManyResponse, GetResponse, GetResponseInclude, GetResponseIncludeSelect, GetResponseNoInclude, MemoryDriverOptions, MemoryFileUploadDriverOptions, MinimalDriver, PutArgs, PutEffect, RadsRequestContext, Relation, RestDriverOptions, RestFileUploadDriverOptions, Schema, SchemaValidators, TypeDefinition, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, ValidateStringDecoratorArgs, computed, createRads, entity, field, getRestRoutes, precomputed, ui, validate };
|
|
269
|
+
export { AzureCosmosDriverOptions, AzureStorageBlobUploadDriverOptions, Change, ComputedContext, ComputedDecoratorArgs, CreateRadsArgs, DeepPartial, DeepPartialNullable, Driver, DriverConstructor, DriverOptions, EntityDecoratorArgs, EntityMethods, FieldDecoratorArgs, FieldDefinition, FileUploadArgs, FileUploadDriver, GenerateClientNormalizedOptions, GenerateClientOptions, GetAggArgs, GetAggArgsAgg, GetAggArgsAny, GetAggResponse, GetArgs, GetArgsAny, GetArgsInclude, GetManyArgs, GetManyArgsAny, GetManyResponse, GetResponse, GetResponseInclude, GetResponseIncludeSelect, GetResponseNoInclude, MemoryDriverOptions, MemoryFileUploadDriverOptions, MinimalDriver, PutArgs, PutEffect, RadsRequestContext, Relation, RestDriverOptions, RestFileUploadDriverOptions, Schema, SchemaValidators, TypeDefinition, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, ValidateStringDecoratorArgs, computed, createRads, entity, field, getRestRoutes, precomputed, ui, validate };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import _ from 'lodash';
|
|
3
|
+
import createMerge from '@fastify/deepmerge';
|
|
3
4
|
import { v4 } from 'uuid';
|
|
4
5
|
import { schema } from '_rads-db';
|
|
5
6
|
|
|
@@ -54,7 +55,7 @@ function getFieldZodSchema(zodSchemas, schema, field, shouldBeLazy) {
|
|
|
54
55
|
if (field.isArray)
|
|
55
56
|
fieldSchema = fieldSchema.array();
|
|
56
57
|
if (!field.isRequired)
|
|
57
|
-
fieldSchema = fieldSchema.optional();
|
|
58
|
+
fieldSchema = fieldSchema.optional().nullable();
|
|
58
59
|
if (field.defaultValue !== void 0)
|
|
59
60
|
fieldSchema = fieldSchema.default(field.defaultValue);
|
|
60
61
|
if (field.defaultValueCopyFrom !== void 0)
|
|
@@ -90,13 +91,40 @@ function getFieldZodSchemaBase(zodSchemas, schema, field, shouldBeLazy) {
|
|
|
90
91
|
throw new Error(`Unknown type: ${field.type}`);
|
|
91
92
|
}
|
|
92
93
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
94
|
+
const mergeFn = createMerge({
|
|
95
|
+
mergeArray(options) {
|
|
96
|
+
const clone = options.clone;
|
|
97
|
+
return function(target, source) {
|
|
98
|
+
return clone(source);
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
function merge(target, source) {
|
|
103
|
+
cleanUndefined(source);
|
|
104
|
+
const result = mergeFn(target, source);
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
function cleanUndefined(obj) {
|
|
108
|
+
if (!obj || !_.isPlainObject(obj))
|
|
109
|
+
return;
|
|
110
|
+
cleanUndefinedInner(obj);
|
|
111
|
+
}
|
|
112
|
+
function cleanUndefinedInner(obj) {
|
|
113
|
+
for (const key in obj) {
|
|
114
|
+
if (obj[key] === void 0)
|
|
115
|
+
delete obj[key];
|
|
116
|
+
if (_.isPlainObject(obj[key]))
|
|
117
|
+
cleanUndefinedInner(obj[key]);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function cleanUndefinedAndNull(obj) {
|
|
122
|
+
for (const key in obj) {
|
|
123
|
+
if (obj[key] == null)
|
|
124
|
+
delete obj[key];
|
|
125
|
+
if (_.isPlainObject(obj[key]))
|
|
126
|
+
cleanUndefinedAndNull(obj[key]);
|
|
127
|
+
}
|
|
100
128
|
}
|
|
101
129
|
|
|
102
130
|
const operatorFns = {
|
|
@@ -580,6 +608,8 @@ function generateMethods(schema, validators, options) {
|
|
|
580
608
|
uploadFile(args) {
|
|
581
609
|
if (!opts.fileUploadDriver)
|
|
582
610
|
throw new Error(`Missing configuration. Please specify "fileUploadDriver" argument in "createRads()".`);
|
|
611
|
+
if (!args.containerName)
|
|
612
|
+
args.containerName = "files";
|
|
583
613
|
return opts.fileUploadDriver.uploadFile(args);
|
|
584
614
|
}
|
|
585
615
|
};
|
|
@@ -606,6 +636,7 @@ function generateMethods(schema, validators, options) {
|
|
|
606
636
|
db
|
|
607
637
|
};
|
|
608
638
|
const driverInstance = getDriverInstance(schema, key, opts.driver, drivers);
|
|
639
|
+
const mustCleanNulls = driverInstance.driverName !== "restApi";
|
|
609
640
|
db[handle] = {
|
|
610
641
|
getAgg: async (args, ctx) => {
|
|
611
642
|
if (!args?.agg)
|
|
@@ -646,6 +677,8 @@ function generateMethods(schema, validators, options) {
|
|
|
646
677
|
const oldDoc = await driverInstance.get({ where: { id: doc.id } });
|
|
647
678
|
if (oldDoc)
|
|
648
679
|
doc = merge(oldDoc, doc);
|
|
680
|
+
if (mustCleanNulls)
|
|
681
|
+
cleanUndefinedAndNull(doc);
|
|
649
682
|
doc = validators[key](doc);
|
|
650
683
|
const docArgsToSave = [{ doc, oldDoc }];
|
|
651
684
|
await fillDenormFieldsBeforePut(computedContext, docArgsToSave);
|
|
@@ -668,6 +701,8 @@ function generateMethods(schema, validators, options) {
|
|
|
668
701
|
const docArgsToSave = docs.map((doc) => {
|
|
669
702
|
const oldDoc = oldDocsById[doc.id];
|
|
670
703
|
doc = merge(oldDoc, doc);
|
|
704
|
+
if (mustCleanNulls)
|
|
705
|
+
cleanUndefinedAndNull(doc);
|
|
671
706
|
doc = validators[key](doc);
|
|
672
707
|
return { oldDoc, doc };
|
|
673
708
|
});
|
|
@@ -4,8 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
module.exports = void 0;
|
|
7
|
-
var _formData = _interopRequireDefault(require("form-data"));
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
7
|
var _default = options => {
|
|
10
8
|
options = {
|
|
11
9
|
baseUrl: "/api",
|
|
@@ -17,7 +15,7 @@ var _default = options => {
|
|
|
17
15
|
const driver = {
|
|
18
16
|
driverName: "restApi",
|
|
19
17
|
async uploadFile(args) {
|
|
20
|
-
const form = new
|
|
18
|
+
const form = new FormData();
|
|
21
19
|
form.append("containerName", args.containerName || "");
|
|
22
20
|
form.append("blob", args.blob, args.fileName);
|
|
23
21
|
const response = await fetch(`${options.baseUrl}/uploadFile`, {
|
package/package.json
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"require": "./integrations/*.cjs"
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
-
"version": "0.1.
|
|
37
|
+
"version": "0.1.44",
|
|
38
38
|
"description": "Say goodbye to boilerplate code and hello to efficient and elegant syntax.",
|
|
39
39
|
"keywords": [],
|
|
40
40
|
"author": "",
|
|
@@ -74,9 +74,9 @@
|
|
|
74
74
|
"vitest": "^0.31.0"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
+
"@fastify/deepmerge": "^1.3.0",
|
|
77
78
|
"@nuxt/kit": "^3.5.1",
|
|
78
79
|
"dataloader": "^2.2.2",
|
|
79
|
-
"form-data": "^4.0.0",
|
|
80
80
|
"lodash": "^4.17.21",
|
|
81
81
|
"pluralize": "^8.0.0",
|
|
82
82
|
"uuid": ">=8",
|