rads-db 0.1.40 → 0.1.43
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 +25 -3
- package/dist/index.mjs +43 -9
- 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
|
+
cleanNull(result);
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
function cleanNull(obj) {
|
|
116
|
+
for (const key in obj) {
|
|
117
|
+
if (obj[key] === null)
|
|
118
|
+
delete obj[key];
|
|
119
|
+
if (___default.isPlainObject(obj[key]))
|
|
120
|
+
cleanNull(obj[key]);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function cleanUndefined(obj) {
|
|
124
|
+
if (!obj || !___default.isPlainObject(obj))
|
|
125
|
+
return;
|
|
126
|
+
cleanUndefinedInner(obj);
|
|
127
|
+
}
|
|
128
|
+
function cleanUndefinedInner(obj) {
|
|
129
|
+
for (const key in obj) {
|
|
130
|
+
if (obj[key] === void 0)
|
|
131
|
+
delete obj[key];
|
|
132
|
+
if (___default.isPlainObject(obj[key]))
|
|
133
|
+
cleanUndefinedInner(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
|
};
|
|
@@ -803,6 +834,10 @@ function ui(args) {
|
|
|
803
834
|
return function(classConstructor, _ctx) {
|
|
804
835
|
};
|
|
805
836
|
}
|
|
837
|
+
function validate(args) {
|
|
838
|
+
return function(classConstructor, _ctx) {
|
|
839
|
+
};
|
|
840
|
+
}
|
|
806
841
|
function field(meta) {
|
|
807
842
|
return function(a, b) {
|
|
808
843
|
};
|
|
@@ -848,3 +883,4 @@ exports.field = field;
|
|
|
848
883
|
exports.getRestRoutes = getRestRoutes;
|
|
849
884
|
exports.precomputed = precomputed;
|
|
850
885
|
exports.ui = ui;
|
|
886
|
+
exports.validate = validate;
|
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>>;
|
|
@@ -67,6 +70,22 @@ interface EntityMethods<E, EN extends keyof EntityMeta, W> {
|
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
type MaybePromise<T> = Promise<T> | T;
|
|
73
|
+
type ValidateFieldDecoratorArgs<T> = T extends string ? ValidateStringDecoratorArgs : T extends number ? ValidateNumberDecoratorArgs : ValidateAnyDecoratorArgs;
|
|
74
|
+
interface ValidateEntityDecoratorArgs {
|
|
75
|
+
}
|
|
76
|
+
interface ValidateAnyDecoratorArgs {
|
|
77
|
+
}
|
|
78
|
+
interface ValidateNumberDecoratorArgs {
|
|
79
|
+
isWhole?: boolean;
|
|
80
|
+
min?: number;
|
|
81
|
+
max?: number;
|
|
82
|
+
}
|
|
83
|
+
interface ValidateStringDecoratorArgs {
|
|
84
|
+
preset?: 'text' | 'html' | 'markdown' | 'alpha' | 'alphanum' | 'number' | 'decimalNumber' | 'email' | 'icon' | 'imageUrl' | 'fileUrl' | 'absoluteUrl' | 'relativeUrl' | 'phoneNumber' | 'datetime' | 'date' | 'time' | 'timeInterval' | 'duration';
|
|
85
|
+
regex?: RegExp;
|
|
86
|
+
minLength?: number;
|
|
87
|
+
maxLength?: number;
|
|
88
|
+
}
|
|
70
89
|
interface UiFieldDecoratorArgs {
|
|
71
90
|
/** User-friendly name of the entity (singular).
|
|
72
91
|
* Used as editor field label and column name in exports.
|
|
@@ -76,6 +95,8 @@ interface UiFieldDecoratorArgs {
|
|
|
76
95
|
icon?: string;
|
|
77
96
|
/** Free text - hint to display under editor field in UI */
|
|
78
97
|
hint?: string;
|
|
98
|
+
/** TODO: Preferred component to display or edit this value */
|
|
99
|
+
component?: string;
|
|
79
100
|
}
|
|
80
101
|
interface UiDecoratorArgs<T = any> {
|
|
81
102
|
/** User-friendly name of the entity (singular).
|
|
@@ -141,8 +162,8 @@ interface FileUploadDriver {
|
|
|
141
162
|
}
|
|
142
163
|
interface FileUploadArgs {
|
|
143
164
|
blob: Blob;
|
|
165
|
+
fileName: string;
|
|
144
166
|
containerName?: string;
|
|
145
|
-
fileName?: string;
|
|
146
167
|
options?: any;
|
|
147
168
|
}
|
|
148
169
|
interface MinimalDriver {
|
|
@@ -237,6 +258,7 @@ interface RadsRequestContext {
|
|
|
237
258
|
|
|
238
259
|
declare function entity<T>(meta?: EntityDecoratorArgs): (classConstructor: new () => T, _ctx?: ClassDecoratorContext<any>) => void;
|
|
239
260
|
declare function ui<T>(args: T extends new () => any ? UiDecoratorArgs<InstanceType<T>> : UiFieldDecoratorArgs): (classConstructor: T, _ctx?: ClassDecoratorContext | ClassFieldDecoratorContext) => void;
|
|
261
|
+
declare function validate<T, C, F>(args: T extends new () => any ? ValidateEntityDecoratorArgs : ValidateFieldDecoratorArgs<F>): (classConstructor: T, _ctx?: ClassDecoratorContext | ClassFieldDecoratorContext<C, F>) => void;
|
|
240
262
|
declare function field(meta?: FieldDecoratorArgs): (a: any, b?: ClassFieldDecoratorContext) => void;
|
|
241
263
|
declare function precomputed(meta?: ComputedDecoratorArgs): (a: any, b?: ClassFieldDecoratorContext | ClassDecoratorContext) => void;
|
|
242
264
|
declare function computed(meta?: ComputedDecoratorArgs): (a: any, b?: ClassFieldDecoratorContext | ClassDecoratorContext) => void;
|
|
@@ -244,4 +266,4 @@ declare function computed(meta?: ComputedDecoratorArgs): (a: any, b?: ClassField
|
|
|
244
266
|
declare function createRads(args?: CreateRadsArgs): RadsDb;
|
|
245
267
|
declare function getRestRoutes(db: RadsDb, prefix?: string): Record<string, Record<string, Function>>;
|
|
246
268
|
|
|
247
|
-
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, computed, createRads, entity, field, getRestRoutes, precomputed, ui };
|
|
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
|
+
cleanNull(result);
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
function cleanNull(obj) {
|
|
109
|
+
for (const key in obj) {
|
|
110
|
+
if (obj[key] === null)
|
|
111
|
+
delete obj[key];
|
|
112
|
+
if (_.isPlainObject(obj[key]))
|
|
113
|
+
cleanNull(obj[key]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function cleanUndefined(obj) {
|
|
117
|
+
if (!obj || !_.isPlainObject(obj))
|
|
118
|
+
return;
|
|
119
|
+
cleanUndefinedInner(obj);
|
|
120
|
+
}
|
|
121
|
+
function cleanUndefinedInner(obj) {
|
|
122
|
+
for (const key in obj) {
|
|
123
|
+
if (obj[key] === void 0)
|
|
124
|
+
delete obj[key];
|
|
125
|
+
if (_.isPlainObject(obj[key]))
|
|
126
|
+
cleanUndefinedInner(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
|
};
|
|
@@ -797,6 +827,10 @@ function ui(args) {
|
|
|
797
827
|
return function(classConstructor, _ctx) {
|
|
798
828
|
};
|
|
799
829
|
}
|
|
830
|
+
function validate(args) {
|
|
831
|
+
return function(classConstructor, _ctx) {
|
|
832
|
+
};
|
|
833
|
+
}
|
|
800
834
|
function field(meta) {
|
|
801
835
|
return function(a, b) {
|
|
802
836
|
};
|
|
@@ -835,4 +869,4 @@ function getRestRoutes(db, prefix = "/") {
|
|
|
835
869
|
return routes;
|
|
836
870
|
}
|
|
837
871
|
|
|
838
|
-
export { computed, createRads, entity, field, getRestRoutes, precomputed, ui };
|
|
872
|
+
export { computed, createRads, entity, field, getRestRoutes, precomputed, ui, validate };
|
|
@@ -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.43",
|
|
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",
|