@hedystia/types 1.10.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.
@@ -0,0 +1,21 @@
1
+ interface RouteInfo {
2
+ method: string;
3
+ path: string;
4
+ params?: unknown;
5
+ query?: unknown;
6
+ headers?: unknown;
7
+ body?: unknown;
8
+ response?: unknown;
9
+ data?: unknown;
10
+ error?: unknown;
11
+ }
12
+ type TypeGeneratorOptions = {
13
+ includeSubscriptions?: boolean;
14
+ includeWebSocket?: boolean;
15
+ };
16
+
17
+ declare function schemaToTypeString(schema: any): string;
18
+
19
+ declare function generateTypes(routes: RouteInfo[], filePath: string): Promise<void>;
20
+
21
+ export { type RouteInfo, type TypeGeneratorOptions, generateTypes, schemaToTypeString };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var u=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var g=(e,n)=>{for(var o in n)u(e,o,{get:n[o],enumerable:!0})},b=(e,n,o,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of T(n))!S.call(e,r)&&r!==o&&u(e,r,{get:()=>n[r],enumerable:!(a=l(n,r))||a.enumerable});return e};var h=e=>b(u({},"__esModule",{value:!0}),e);var x={};g(x,{generateTypes:()=>j,schemaToTypeString:()=>i});module.exports=h(x);var d=require("fs/promises");var t=require("@hedystia/validations");function i(e){if(!e)return"any";if(e instanceof t.StringSchemaType)return"string";if(e instanceof t.NumberSchemaType)return"number";if(e instanceof t.BooleanSchemaType)return"boolean";if(e instanceof t.NullSchemaType)return"null";if(e instanceof t.AnySchemaType)return"any";if(e instanceof t.OptionalSchema){let n=e.innerSchema;return`${i(n)} | undefined`}if(e instanceof t.ArraySchema){let n=e.innerSchema,o=i(n);return o.includes("|")||o.includes("{")?`(${o})[]`:`${o}[]`}if(e instanceof t.UnionSchema){let n=e.schemas||[];return n.length===0?"any":n.map(o=>i(o)).join(" | ")}if(e instanceof t.LiteralSchema){let n=e.value;return typeof n=="string"?`'${n}'`:String(n)}if(e instanceof t.InstanceOfSchema){let n=e.classConstructor;return n?n.name:"object"}if(e instanceof t.ObjectSchemaType){let n=e.definition;if(!n||Object.keys(n).length===0)return"{}";let o=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/;return`{${Object.entries(n).map(([r,p])=>{let c=o.test(r)?r:`"${r}"`,y=p instanceof t.OptionalSchema,f=y?"?":"",s=i(p);return y&&(s=s.replace(" | undefined","")),`${c}${f}:${s}`}).join(";")}}`}return"any"}async function j(e,n){let a=`// Automatic Hedystia type generation
2
+ export type AppRoutes=[${e.map(r=>{let p=i(r.response),c=i(r.params),y=i(r.query),f=i(r.body),s=i(r.headers),m=i(r.data),$=i(r.error);return`{method:"${r.method}";path:"${r.path}";params:${c};query:${y};body:${f};headers:${s};response:${p};data:${m};error:${$}}`}).join(",")}];`;await(0,d.writeFile)(n,a,"utf8")}0&&(module.exports={generateTypes,schemaToTypeString});
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@hedystia/types",
3
+ "version": "1.10.0",
4
+ "description": "Type definition generator for multiple frameworks",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": "./dist/index.js"
9
+ },
10
+ "private": false,
11
+ "license": "MIT",
12
+ "scripts": {
13
+ "build": "tsup",
14
+ "dev": "bun --watch --no-clear-screen run src/index.ts"
15
+ },
16
+ "dependencies": {
17
+ "@hedystia/validations": "^1.10.0"
18
+ },
19
+ "devDependencies": {
20
+ "@standard-schema/spec": "^1.0.0",
21
+ "@types/bun": "^1.3.3",
22
+ "tsup": "^8.3.5"
23
+ },
24
+ "peerDependencies": {
25
+ "@hedystia/validations": ">= 1.10.0",
26
+ "typescript": ">= 5.0.0"
27
+ },
28
+ "peerDependenciesMeta": {
29
+ "typescript": {
30
+ "optional": true
31
+ }
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/Hedystia/Framework"
36
+ },
37
+ "author": {
38
+ "name": "Zastinian",
39
+ "email": "contact@zastinian.com",
40
+ "url": "https://github.com/Zastinian"
41
+ },
42
+ "type": "commonjs"
43
+ }