@ishaanbarde/medium-common 1.0.0
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.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/package.json +15 -0
- package/tsconfig.json +45 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Blog Zod Schema
|
|
4
|
+
* Validates data before saving into database for blog table
|
|
5
|
+
*/
|
|
6
|
+
export declare const blogSchema: z.ZodObject<{
|
|
7
|
+
title: z.ZodString;
|
|
8
|
+
content: z.ZodOptional<z.ZodString>;
|
|
9
|
+
published: z.ZodDefault<z.ZodBoolean>;
|
|
10
|
+
authorId: z.ZodNumber;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
export type BlogInput = z.infer<typeof blogSchema>;
|
|
13
|
+
/**
|
|
14
|
+
* Validates blog data
|
|
15
|
+
* Returns the data on success and errors on failure
|
|
16
|
+
* @param data
|
|
17
|
+
*/
|
|
18
|
+
export declare function validateBlog(data: any): {
|
|
19
|
+
title: string;
|
|
20
|
+
content?: string | undefined;
|
|
21
|
+
published: boolean;
|
|
22
|
+
authorId: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Update Blogs Schema
|
|
26
|
+
* Requires at least one of the above fields to be provided
|
|
27
|
+
*/
|
|
28
|
+
export declare const updateBlogSchema: z.ZodObject<{
|
|
29
|
+
title: z.ZodOptional<z.ZodString>;
|
|
30
|
+
content: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
31
|
+
published: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
32
|
+
authorId: z.ZodOptional<z.ZodNumber>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB;;;GAGG;AACH,eAAO,MAAM,UAAU;;;;;iBAKrB,CAAC;AAEH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAEnD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,GAAG;;;;;EAOrC;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;iBAIzB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Blog Zod Schema
|
|
4
|
+
* Validates data before saving into database for blog table
|
|
5
|
+
*/
|
|
6
|
+
export const blogSchema = z.object({
|
|
7
|
+
title: z.string().min(1, "Title is required"),
|
|
8
|
+
content: z.string().optional(),
|
|
9
|
+
published: z.boolean().default(false),
|
|
10
|
+
authorId: z.number().int().positive("Required UserId for creation"),
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Validates blog data
|
|
14
|
+
* Returns the data on success and errors on failure
|
|
15
|
+
* @param data
|
|
16
|
+
*/
|
|
17
|
+
export function validateBlog(data) {
|
|
18
|
+
const result = blogSchema.safeParse(data);
|
|
19
|
+
if (!result.success) {
|
|
20
|
+
throw result.error;
|
|
21
|
+
}
|
|
22
|
+
return result.data;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Update Blogs Schema
|
|
26
|
+
* Requires at least one of the above fields to be provided
|
|
27
|
+
*/
|
|
28
|
+
export const updateBlogSchema = blogSchema
|
|
29
|
+
.partial()
|
|
30
|
+
.refine((data) => Object.keys(data).length > 0, {
|
|
31
|
+
message: "At least one field must be provided",
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,mBAAmB,CAAC;IAC7C,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9B,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IACrC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,8BAA8B,CAAC;CACpE,CAAC,CAAC;AAIH;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAS;IACpC,MAAM,MAAM,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAE1C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,MAAM,CAAC,KAAK,CAAC;IACrB,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU;KACvC,OAAO,EAAE;KACT,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;IAC9C,OAAO,EAAE,qCAAqC;CAC/C,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ishaanbarde/medium-common",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"zod": "^4.4.3"
|
|
14
|
+
}
|
|
15
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Visit https://aka.ms/tsconfig to read more about this file
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
// File Layout
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
|
|
8
|
+
// Environment Settings
|
|
9
|
+
// See also https://aka.ms/tsconfig/module
|
|
10
|
+
"module": "ESNext",
|
|
11
|
+
"moduleResolution": "Bundler",
|
|
12
|
+
"target": "esnext",
|
|
13
|
+
"types": [],
|
|
14
|
+
// For nodejs:
|
|
15
|
+
// "lib": ["esnext"],
|
|
16
|
+
// "types": ["node"],
|
|
17
|
+
// and npm install -D @types/node
|
|
18
|
+
|
|
19
|
+
// Other Outputs
|
|
20
|
+
"sourceMap": true,
|
|
21
|
+
"declaration": true,
|
|
22
|
+
"declarationMap": true,
|
|
23
|
+
|
|
24
|
+
// Stricter Typechecking Options
|
|
25
|
+
"noUncheckedIndexedAccess": true,
|
|
26
|
+
"exactOptionalPropertyTypes": true,
|
|
27
|
+
|
|
28
|
+
// Style Options
|
|
29
|
+
// "noImplicitReturns": true,
|
|
30
|
+
// "noImplicitOverride": true,
|
|
31
|
+
// "noUnusedLocals": true,
|
|
32
|
+
// "noUnusedParameters": true,
|
|
33
|
+
// "noFallthroughCasesInSwitch": true,
|
|
34
|
+
// "noPropertyAccessFromIndexSignature": true,
|
|
35
|
+
|
|
36
|
+
// Recommended Options
|
|
37
|
+
"strict": true,
|
|
38
|
+
"jsx": "react-jsx",
|
|
39
|
+
"verbatimModuleSyntax": true,
|
|
40
|
+
"isolatedModules": true,
|
|
41
|
+
"noUncheckedSideEffectImports": true,
|
|
42
|
+
"moduleDetection": "force",
|
|
43
|
+
"skipLibCheck": true
|
|
44
|
+
}
|
|
45
|
+
}
|