rads-db 3.0.13 → 3.0.18
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 +11 -2
- package/dist/index.d.ts +8 -5
- package/dist/index.mjs +11 -2
- package/features/softDelete.cjs +1 -3
- package/features/softDelete.mjs +1 -1
- package/integrations/restEndpointsDev.cjs +12 -5
- package/integrations/restEndpointsDev.mjs +14 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -983,10 +983,19 @@ function generateMethods(schema, validators, options) {
|
|
|
983
983
|
const db = {
|
|
984
984
|
_schema: schema,
|
|
985
985
|
_radsUiSlots: getRadsUiSlots(opts.features),
|
|
986
|
-
uploadFile(args) {
|
|
986
|
+
async uploadFile(args) {
|
|
987
|
+
for (const f of opts.features) {
|
|
988
|
+
const result2 = await f.beforeUploadFile?.(args);
|
|
989
|
+
if (result2)
|
|
990
|
+
return result2;
|
|
991
|
+
}
|
|
987
992
|
if (!opts.fileUploadDriver)
|
|
988
993
|
throw new Error(`Missing configuration. Please specify "fileUploadDriver" argument in "createRads()".`);
|
|
989
|
-
|
|
994
|
+
const result = await opts.fileUploadDriver.uploadFile(args);
|
|
995
|
+
for (const f of opts.features) {
|
|
996
|
+
await f.afterUploadFile?.(result, args);
|
|
997
|
+
}
|
|
998
|
+
return result;
|
|
990
999
|
}
|
|
991
1000
|
};
|
|
992
1001
|
const effects = {};
|
package/dist/index.d.ts
CHANGED
|
@@ -99,7 +99,7 @@ interface ValidateNumberDecoratorArgs {
|
|
|
99
99
|
}
|
|
100
100
|
interface ValidateStringDecoratorArgs {
|
|
101
101
|
preset?: 'text' | 'html' | 'markdown' | 'alpha' | 'alphanum' | 'number' | 'decimalNumber' | 'email' | 'icon' | 'imageUrl' | 'fileUrl' | 'absoluteUrl' | 'relativeUrl' | 'phoneNumber' | 'datetime' | 'date' | 'time' | 'timeInterval' | 'duration';
|
|
102
|
-
regex?: RegExp;
|
|
102
|
+
regex?: RegExp | string;
|
|
103
103
|
minLength?: number;
|
|
104
104
|
maxLength?: number;
|
|
105
105
|
}
|
|
@@ -207,12 +207,13 @@ interface TypeDefinition {
|
|
|
207
207
|
handle?: string;
|
|
208
208
|
handlePlural?: string;
|
|
209
209
|
}
|
|
210
|
+
interface FileUploadResult {
|
|
211
|
+
url: string;
|
|
212
|
+
}
|
|
210
213
|
interface FileUploadDriver {
|
|
211
214
|
driverName: string;
|
|
212
215
|
client?: any;
|
|
213
|
-
uploadFile(args: FileUploadArgs, ctx?: RadsRequestContext): Promise<
|
|
214
|
-
url: string;
|
|
215
|
-
}>;
|
|
216
|
+
uploadFile(args: FileUploadArgs, ctx?: RadsRequestContext): Promise<FileUploadResult>;
|
|
216
217
|
}
|
|
217
218
|
interface GetRestRoutesOptions {
|
|
218
219
|
/** Instance of RadsDb */
|
|
@@ -366,6 +367,8 @@ interface RadsFeature {
|
|
|
366
367
|
oldDoc: any;
|
|
367
368
|
doc: any;
|
|
368
369
|
}[], ctx: RadsRequestContext, computedContext: ComputedContext) => void;
|
|
370
|
+
beforeUploadFile?: (args: FileUploadArgs) => MaybePromise<any>;
|
|
371
|
+
afterUploadFile?: (result: FileUploadResult, args: FileUploadArgs) => MaybePromise<void>;
|
|
369
372
|
}
|
|
370
373
|
|
|
371
374
|
declare function entity<T>(meta?: EntityDecoratorArgs): (classConstructor: new () => T, _ctx?: ClassDecoratorContext<any>) => void;
|
|
@@ -389,4 +392,4 @@ declare function createRadsDb(args?: CreateRadsDbArgs): RadsDb;
|
|
|
389
392
|
*/
|
|
390
393
|
declare function createRadsDbClient(args?: CreateRadsDbClientArgs): RadsDb;
|
|
391
394
|
|
|
392
|
-
export { Change, ComputedContext, ComputedContextGlobal, ComputedDecoratorArgs, CreateRadsArgsDrivers, CreateRadsDbArgs, CreateRadsDbArgsNormalized, CreateRadsDbClientArgs, DeepPartial, Driver, DriverConstructor, EntityDecoratorArgs, EntityMethods, EnumDefinition, FieldDecoratorArgs, FieldDefinition, FileSystemNode, FileUploadArgs, FileUploadDriver, GenerateClientNormalizedOptions, GenerateClientOptions, GetAggArgs, GetAggArgsAgg, GetAggArgsAny, GetAggResponse, GetArgs, GetArgsAny, GetArgsInclude, GetManyArgs, GetManyArgsAny, GetManyResponse, GetResponse, GetResponseInclude, GetResponseIncludeSelect, GetResponseNoInclude, GetRestRoutesArgs, GetRestRoutesOptions, GetRestRoutesResponse, MinimalDriver, PutArgs, PutEffect, RadsFeature, RadsRequestContext, RadsUiSlotDefinition, RadsUiSlotName, RadsVitePluginOptions, Relation, RequiredFields, RestDriverOptions, RestFileUploadDriverOptions, Schema, SchemaValidators, TypeDefinition, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, ValidateStringDecoratorArgs, VerifyManyArgs, VerifyManyArgsAny, VerifyManyResponse, computed, createRadsDb, createRadsDbClient, entity, field, getDriverInstance, precomputed, ui, validate };
|
|
395
|
+
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, RadsRequestContext, RadsUiSlotDefinition, RadsUiSlotName, RadsVitePluginOptions, Relation, RequiredFields, RestDriverOptions, RestFileUploadDriverOptions, Schema, SchemaValidators, TypeDefinition, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, ValidateStringDecoratorArgs, VerifyManyArgs, VerifyManyArgsAny, VerifyManyResponse, computed, createRadsDb, createRadsDbClient, entity, field, getDriverInstance, precomputed, ui, validate };
|
package/dist/index.mjs
CHANGED
|
@@ -975,10 +975,19 @@ function generateMethods(schema, validators, options) {
|
|
|
975
975
|
const db = {
|
|
976
976
|
_schema: schema,
|
|
977
977
|
_radsUiSlots: getRadsUiSlots(opts.features),
|
|
978
|
-
uploadFile(args) {
|
|
978
|
+
async uploadFile(args) {
|
|
979
|
+
for (const f of opts.features) {
|
|
980
|
+
const result2 = await f.beforeUploadFile?.(args);
|
|
981
|
+
if (result2)
|
|
982
|
+
return result2;
|
|
983
|
+
}
|
|
979
984
|
if (!opts.fileUploadDriver)
|
|
980
985
|
throw new Error(`Missing configuration. Please specify "fileUploadDriver" argument in "createRads()".`);
|
|
981
|
-
|
|
986
|
+
const result = await opts.fileUploadDriver.uploadFile(args);
|
|
987
|
+
for (const f of opts.features) {
|
|
988
|
+
await f.afterUploadFile?.(result, args);
|
|
989
|
+
}
|
|
990
|
+
return result;
|
|
982
991
|
}
|
|
983
992
|
};
|
|
984
993
|
const effects = {};
|
package/features/softDelete.cjs
CHANGED
|
@@ -11,9 +11,7 @@ var _default = () => {
|
|
|
11
11
|
if (!context.schema[context.typeName]?.fields?.isDeleted) return;
|
|
12
12
|
if (args.where.isDeleted || args.where.isDeleted_in) return;
|
|
13
13
|
args.where._and = [...(args.where._and || []), {
|
|
14
|
-
|
|
15
|
-
isDeleted: true
|
|
16
|
-
}
|
|
14
|
+
isDeleted: false
|
|
17
15
|
}];
|
|
18
16
|
}
|
|
19
17
|
};
|
package/features/softDelete.mjs
CHANGED
|
@@ -7,8 +7,10 @@ module.exports = void 0;
|
|
|
7
7
|
var _promises = _interopRequireDefault(require("node:fs/promises"));
|
|
8
8
|
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
9
9
|
var _klaw = _interopRequireDefault(require("klaw"));
|
|
10
|
+
var _ignore = _interopRequireDefault(require("ignore"));
|
|
10
11
|
var _restEndpointsDevLint = _interopRequireDefault(require("./restEndpointsDev/restEndpointsDevLint.cjs"));
|
|
11
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
let gitignore;
|
|
12
14
|
const root = _nodePath.default.resolve(".");
|
|
13
15
|
var _default = {
|
|
14
16
|
lint: _restEndpointsDevLint.default.lint,
|
|
@@ -91,17 +93,16 @@ function sanitizeFilepath(filepath) {
|
|
|
91
93
|
if (!result.startsWith(root)) throw new Error("Invalid path");
|
|
92
94
|
}
|
|
93
95
|
async function readdirRecursive(dir, options) {
|
|
96
|
+
await initGitignore();
|
|
94
97
|
options = {
|
|
95
98
|
...options
|
|
96
99
|
};
|
|
97
100
|
const klawIterator = await (0, _klaw.default)(dir, {
|
|
98
|
-
depthLimit: options.recursive ? 15 : 0,
|
|
101
|
+
depthLimit: options.recursive ? options.depthLimit ?? 15 : 0,
|
|
99
102
|
preserveSymlinks: true,
|
|
100
103
|
filter: p => {
|
|
101
104
|
const rp = _nodePath.default.relative(".", p);
|
|
102
|
-
|
|
103
|
-
if (rp.startsWith("node_modules")) return false;
|
|
104
|
-
return true;
|
|
105
|
+
return !gitignore.ignores(rp);
|
|
105
106
|
}
|
|
106
107
|
});
|
|
107
108
|
const results = [];
|
|
@@ -110,10 +111,16 @@ async function readdirRecursive(dir, options) {
|
|
|
110
111
|
const rp = _nodePath.default.relative(dir, file.path).replaceAll("\\", "/");
|
|
111
112
|
if (!rp) continue;
|
|
112
113
|
results.push({
|
|
113
|
-
path: rp
|
|
114
|
+
path: `./${rp}`,
|
|
114
115
|
type: file.stats.isDirectory() ? "tree" : "blob",
|
|
115
116
|
size: file.stats.size
|
|
116
117
|
});
|
|
117
118
|
}
|
|
118
119
|
return results;
|
|
120
|
+
}
|
|
121
|
+
async function initGitignore() {
|
|
122
|
+
if (gitignore) return;
|
|
123
|
+
const gitignoreStr = await _promises.default.readFile("./.gitignore", "utf-8");
|
|
124
|
+
gitignore = (0, _ignore.default)().add(["node_modules", ".git"]);
|
|
125
|
+
if (gitignoreStr) gitignore = gitignore.add(gitignoreStr.split("\n").filter(x => x));
|
|
119
126
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import klaw from "klaw";
|
|
4
|
+
import ignore from "ignore";
|
|
4
5
|
import restEndpointsDevLint from "./restEndpointsDev/restEndpointsDevLint.mjs";
|
|
6
|
+
let gitignore;
|
|
5
7
|
const root = path.resolve(".");
|
|
6
8
|
export default {
|
|
7
9
|
lint: restEndpointsDevLint.lint,
|
|
@@ -83,17 +85,14 @@ function sanitizeFilepath(filepath) {
|
|
|
83
85
|
throw new Error("Invalid path");
|
|
84
86
|
}
|
|
85
87
|
async function readdirRecursive(dir, options) {
|
|
88
|
+
await initGitignore();
|
|
86
89
|
options = { ...options };
|
|
87
90
|
const klawIterator = await klaw(dir, {
|
|
88
|
-
depthLimit: options.recursive ? 15 : 0,
|
|
91
|
+
depthLimit: options.recursive ? options.depthLimit ?? 15 : 0,
|
|
89
92
|
preserveSymlinks: true,
|
|
90
93
|
filter: (p) => {
|
|
91
94
|
const rp = path.relative(".", p);
|
|
92
|
-
|
|
93
|
-
return false;
|
|
94
|
-
if (rp.startsWith("node_modules"))
|
|
95
|
-
return false;
|
|
96
|
-
return true;
|
|
95
|
+
return !gitignore.ignores(rp);
|
|
97
96
|
}
|
|
98
97
|
});
|
|
99
98
|
const results = [];
|
|
@@ -104,10 +103,18 @@ async function readdirRecursive(dir, options) {
|
|
|
104
103
|
if (!rp)
|
|
105
104
|
continue;
|
|
106
105
|
results.push({
|
|
107
|
-
path: rp
|
|
106
|
+
path: `./${rp}`,
|
|
108
107
|
type: file.stats.isDirectory() ? "tree" : "blob",
|
|
109
108
|
size: file.stats.size
|
|
110
109
|
});
|
|
111
110
|
}
|
|
112
111
|
return results;
|
|
113
112
|
}
|
|
113
|
+
async function initGitignore() {
|
|
114
|
+
if (gitignore)
|
|
115
|
+
return;
|
|
116
|
+
const gitignoreStr = await fs.readFile("./.gitignore", "utf-8");
|
|
117
|
+
gitignore = ignore().add(["node_modules", ".git"]);
|
|
118
|
+
if (gitignoreStr)
|
|
119
|
+
gitignore = gitignore.add(gitignoreStr.split("\n").filter((x) => x));
|
|
120
|
+
}
|