rads-db 3.0.34 → 3.0.37
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 +15 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +16 -2
- package/features/eventSourcing.cjs +1 -1
- package/features/eventSourcing.mjs +1 -1
- package/integrations/node.cjs +3 -1
- package/integrations/node.mjs +1 -1
- package/package.json +5 -4
package/dist/index.cjs
CHANGED
|
@@ -22,7 +22,14 @@ function generateValidators(schema) {
|
|
|
22
22
|
const result = {};
|
|
23
23
|
for (const key in zodSchemas) {
|
|
24
24
|
result[key] = (value) => {
|
|
25
|
-
|
|
25
|
+
try {
|
|
26
|
+
value = zodSchemas[key].parse(value);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (error instanceof zod.ZodError)
|
|
29
|
+
throw new ValidationError(error);
|
|
30
|
+
else
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
26
33
|
fillDefaultValues(schema, key, value);
|
|
27
34
|
return value;
|
|
28
35
|
};
|
|
@@ -100,6 +107,13 @@ function getFieldZodSchemaBase(zodSchemas, schema, field, shouldBeLazy) {
|
|
|
100
107
|
}
|
|
101
108
|
throw new Error(`Unknown type: ${field.type}`);
|
|
102
109
|
}
|
|
110
|
+
class ValidationError extends Error {
|
|
111
|
+
constructor(error) {
|
|
112
|
+
super(error.errors[0].message);
|
|
113
|
+
this.message = error.errors[0].message;
|
|
114
|
+
this.issues = error.errors;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
103
117
|
|
|
104
118
|
const operatorFns = {
|
|
105
119
|
eq: (x, w) => x === w,
|
package/dist/index.d.ts
CHANGED
|
@@ -64,7 +64,7 @@ type GetResponseNoInclude<E, EN extends keyof EntityMeta> = {
|
|
|
64
64
|
[K in keyof E]: K extends keyof EntityMeta[EN]['relations'] ? E[K] extends any[] ? RelationData<EN, K>[] : RelationData<EN, K> : E[K];
|
|
65
65
|
};
|
|
66
66
|
type DeepPartial<T> = {
|
|
67
|
-
[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] | null;
|
|
67
|
+
[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;
|
|
68
68
|
};
|
|
69
69
|
type Relation<T extends {
|
|
70
70
|
id: any;
|
|
@@ -209,7 +209,7 @@ interface TypeDefinition {
|
|
|
209
209
|
handle?: string;
|
|
210
210
|
handlePlural?: string;
|
|
211
211
|
isExtending?: string;
|
|
212
|
-
keepHistoryFields
|
|
212
|
+
keepHistoryFields?: string[];
|
|
213
213
|
}
|
|
214
214
|
interface FileUploadResult {
|
|
215
215
|
url: string;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
1
|
+
import { z, ZodError } from 'zod';
|
|
2
2
|
import _ from 'lodash';
|
|
3
3
|
import { v4 } from 'uuid';
|
|
4
4
|
import createMerge from '@fastify/deepmerge';
|
|
@@ -14,7 +14,14 @@ function generateValidators(schema) {
|
|
|
14
14
|
const result = {};
|
|
15
15
|
for (const key in zodSchemas) {
|
|
16
16
|
result[key] = (value) => {
|
|
17
|
-
|
|
17
|
+
try {
|
|
18
|
+
value = zodSchemas[key].parse(value);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
if (error instanceof ZodError)
|
|
21
|
+
throw new ValidationError(error);
|
|
22
|
+
else
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
18
25
|
fillDefaultValues(schema, key, value);
|
|
19
26
|
return value;
|
|
20
27
|
};
|
|
@@ -92,6 +99,13 @@ function getFieldZodSchemaBase(zodSchemas, schema, field, shouldBeLazy) {
|
|
|
92
99
|
}
|
|
93
100
|
throw new Error(`Unknown type: ${field.type}`);
|
|
94
101
|
}
|
|
102
|
+
class ValidationError extends Error {
|
|
103
|
+
constructor(error) {
|
|
104
|
+
super(error.errors[0].message);
|
|
105
|
+
this.message = error.errors[0].message;
|
|
106
|
+
this.issues = error.errors;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
95
109
|
|
|
96
110
|
const operatorFns = {
|
|
97
111
|
eq: (x, w) => x === w,
|
|
@@ -101,7 +101,7 @@ function verifyEventSourcingSetup(schema, effects) {
|
|
|
101
101
|
function keepHistory(keepHistoryFields, originalChange, changeEvent) {
|
|
102
102
|
if (keepHistoryFields && originalChange) {
|
|
103
103
|
keepHistoryFields.forEach(prop => {
|
|
104
|
-
if (!changeEvent.change[prop] && originalChange[prop]) {
|
|
104
|
+
if (!changeEvent.change[prop] && originalChange[prop] !== void 0) {
|
|
105
105
|
changeEvent.change[prop] = originalChange[prop];
|
|
106
106
|
}
|
|
107
107
|
});
|
|
@@ -89,7 +89,7 @@ function verifyEventSourcingSetup(schema, effects) {
|
|
|
89
89
|
function keepHistory(keepHistoryFields, originalChange, changeEvent) {
|
|
90
90
|
if (keepHistoryFields && originalChange) {
|
|
91
91
|
keepHistoryFields.forEach((prop) => {
|
|
92
|
-
if (!changeEvent.change[prop] && originalChange[prop]) {
|
|
92
|
+
if (!changeEvent.change[prop] && originalChange[prop] !== void 0) {
|
|
93
93
|
changeEvent.change[prop] = originalChange[prop];
|
|
94
94
|
}
|
|
95
95
|
});
|
package/integrations/node.cjs
CHANGED
|
@@ -52,7 +52,9 @@ async function getSchema(normalizedOptions) {
|
|
|
52
52
|
} = normalizedOptions;
|
|
53
53
|
let schema;
|
|
54
54
|
if (entitiesDir) {
|
|
55
|
-
if (!_nodeFs.default.existsSync(entitiesDir)) await _promises.default.mkdir(entitiesDir
|
|
55
|
+
if (!_nodeFs.default.existsSync(entitiesDir)) await _promises.default.mkdir(entitiesDir, {
|
|
56
|
+
recursive: true
|
|
57
|
+
});
|
|
56
58
|
const response = await _promises.default.readdir(entitiesDir, {
|
|
57
59
|
withFileTypes: true
|
|
58
60
|
});
|
package/integrations/node.mjs
CHANGED
|
@@ -49,7 +49,7 @@ export async function getSchema(normalizedOptions) {
|
|
|
49
49
|
let schema;
|
|
50
50
|
if (entitiesDir) {
|
|
51
51
|
if (!fs2.existsSync(entitiesDir))
|
|
52
|
-
await fs.mkdir(entitiesDir);
|
|
52
|
+
await fs.mkdir(entitiesDir, { recursive: true });
|
|
53
53
|
const response = await fs.readdir(entitiesDir, { withFileTypes: true });
|
|
54
54
|
const entities = {};
|
|
55
55
|
for (const file of response) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rads-db",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.37",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"drivers",
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"author": "",
|
|
47
47
|
"license": "ISC",
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@supabase/supabase-js": ">=2",
|
|
50
49
|
"@azure/cosmos": ">=3",
|
|
51
50
|
"@azure/storage-blob": ">=12",
|
|
51
|
+
"@supabase/supabase-js": ">=2",
|
|
52
52
|
"dexie": ">=3",
|
|
53
53
|
"h3": ">=1.6.0",
|
|
54
54
|
"typescript": ">=5.0.0"
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
},
|
|
73
73
|
"packageManager": "pnpm@8.6.1",
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@supabase/supabase-js": "^2.39.0",
|
|
76
75
|
"@azure/cosmos": "^3.17.3",
|
|
76
|
+
"@supabase/supabase-js": "^2.39.0",
|
|
77
77
|
"@types/eslint": "^8.44.8",
|
|
78
78
|
"@types/klaw": "^3.0.3",
|
|
79
79
|
"@types/lodash": "4.14.191",
|
|
@@ -87,6 +87,7 @@
|
|
|
87
87
|
"rads-db": "link:.",
|
|
88
88
|
"simple-git-hooks": "^2.8.1",
|
|
89
89
|
"symlink-dir": "^5.1.1",
|
|
90
|
+
"ts-node": "^10.9.2",
|
|
90
91
|
"tsup": "^6.7.0",
|
|
91
92
|
"unbuild": "^1.2.1",
|
|
92
93
|
"vite": "^4.0.0",
|
|
@@ -105,7 +106,7 @@
|
|
|
105
106
|
"scripts": {
|
|
106
107
|
"test": "vitest --run && vitest typecheck --run",
|
|
107
108
|
"link-rads-db": "symlink-dir ./test/_rads-db ./node_modules/_rads-db",
|
|
108
|
-
"generate-test-schema": "
|
|
109
|
+
"generate-test-schema": "ts-node ./src/integrations/cli -d './test/entities'",
|
|
109
110
|
"dev": "pnpm install && pnpm link-rads-db && pnpm build && pnpm generate-test-schema && vitest --ui --test-timeout 300000",
|
|
110
111
|
"lint": "cross-env NODE_ENV=production eslint src/**/*.* test/**/*.*",
|
|
111
112
|
"dev-typecheck": "pnpm install && pnpm build && pnpm generate-test-schema && pnpm link-rads-db && vitest typecheck --ui",
|