klaim 1.0.4 → 1.0.5

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 @@
1
+ "use strict";var g=Object.defineProperty;var w=(n,t,e)=>t in n?g(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var a=(n,t,e)=>w(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function m(n){return n.trim().replace(/^\/|\/$/g,"")}function d(n){return n.replace(/([-_][a-z])/gi,t=>t.toUpperCase().replace("-","").replace("_","")).replace(/(^\w)/,t=>t.toLowerCase())}var f=(n=>(n.GET="GET",n.POST="POST",n.PUT="PUT",n.DELETE="DELETE",n.PATCH="PATCH",n.OPTIONS="OPTIONS",n))(f||{});class h{constructor(t,e,r,i="GET"){a(this,"api","undefined");a(this,"name");a(this,"url");a(this,"method");a(this,"headers");a(this,"arguments",new Set);this.name=d(t),this.name!==t&&console.warn(`Route name "${t}" has been camelCased to "${this.name}"`),this.url=m(e),this.headers=r||{},this.method=i,this.detectArguments()}static createRoute(t,e,r,i){const s=new h(t,e,r,i);return o.i.registerRoute(s),s}static get(t,e,r={}){return this.createRoute(t,e,r,"GET")}static post(t,e,r){return this.createRoute(t,e,r,"POST")}static put(t,e,r){return this.createRoute(t,e,r,"PUT")}static delete(t,e,r){return this.createRoute(t,e,r,"DELETE")}static patch(t,e,r){return this.createRoute(t,e,r,"PATCH")}static options(t,e,r){return this.createRoute(t,e,r,"OPTIONS")}detectArguments(){const t=this.url.match(/\[([^\]]+)]/g);t&&t.forEach(e=>{const r=e.replace(/\[|]/g,"");this.arguments.add(r)})}}const l={};async function A(n,t,e={},r={}){const i=T(`${n.url}/${t.url}`,t,e),s={};return r&&t.method!==f.GET&&(s.body=JSON.stringify(r)),s.headers={"Content-Type":"application/json",...n.headers,...t.headers},s.method=t.method,await(await fetch(i,s)).json()}function T(n,t,e){let r=n;return t.arguments.forEach(i=>{if(e[i]===void 0)throw new Error(`Argument ${i} is missing`);r=r.replace(`[${i}]`,e[i])}),r}const c=class c{constructor(){a(this,"_apis",new Map);a(this,"_currentApi",null)}static get i(){return c._instance||(c._instance=new c),c._instance}registerApi(t){this._apis.set(t.name,t),l[t.name]={}}setCurrent(t){const e=this._apis.get(t);if(!e)throw new Error(`API ${t} not found`);this._currentApi=e}clearCurrent(){this._currentApi=null}registerRoute(t){if(!this._currentApi)throw new Error("No current API set, use Route only inside Api.create callback");t.api=this._currentApi.name,this._currentApi.routes.set(t.name,t),this.addToKlaimRoute(t.api,t)}getApi(t){return this._apis.get(t)}getRoute(t,e){const r=this._apis.get(t);if(!r)throw new Error(`API ${t} not found`);return r.routes.get(e)}addToKlaimRoute(t,e){l[t][e.name]=async(r={},i={})=>{const s=c.i._apis.get(t);if(!s)throw new Error(`API ${e.api} not found`);return A(s,e,r,i)}}};a(c,"_instance");let o=c;class p{constructor(t,e,r){a(this,"name");a(this,"url");a(this,"headers");a(this,"routes",new Map);this.name=t,this.url=m(e),this.headers=r||{}}static create(t,e,r,i={}){const s=d(t);s!==t&&console.warn(`API name "${t}" has been camelCased to "${s}"`);const u=new p(s,e,i);return o.i.registerApi(u),o.i.setCurrent(s),r(),o.i.clearCurrent(),u}}exports.Api=p;exports.Klaim=l;exports.Registry=o;exports.Route=h;
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "homepage": "https://github.com/antharuu/klaim#readme",
22
22
  "type": "module",
23
- "version": "1.0.4",
23
+ "version": "1.0.5",
24
24
  "main": "dist/klaim.cjs.js",
25
25
  "module": "dist/klaim.es.js",
26
26
  "types": "dist/index.d.ts",
package/tsconfig.json CHANGED
@@ -1,15 +1,20 @@
1
1
  {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "module": "ESNext",
5
- "lib": ["ESNext", "DOM"],
6
- "declaration": true,
7
- "outDir": "dist",
8
- "strict": true,
9
- "moduleResolution": "node",
10
- "esModuleInterop": true,
11
- "skipLibCheck": true,
12
- "forceConsistentCasingInFileNames": true
13
- },
14
- "include": ["src"]
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "lib": [
6
+ "ESNext",
7
+ "DOM"
8
+ ],
9
+ "declaration": true,
10
+ "outDir": "dist",
11
+ "strict": true,
12
+ "moduleResolution": "node",
13
+ "esModuleInterop": true,
14
+ "skipLibCheck": true,
15
+ "forceConsistentCasingInFileNames": true
16
+ },
17
+ "include": [
18
+ "src"
19
+ ]
15
20
  }
package/vite.config.ts CHANGED
@@ -1,12 +1,14 @@
1
- import { defineConfig } from 'vite';
2
- import { configDefaults } from 'vitest/config';
1
+ import {defineConfig} from 'vite';
2
+ import {configDefaults} from 'vitest/config';
3
+ import * as path from 'path'; // Utilisation de l'importation compatible
3
4
 
4
5
  export default defineConfig({
5
6
  build: {
6
7
  lib: {
7
- entry: 'src/index.ts',
8
+ entry: path.resolve(__dirname, 'src/index.ts'),
8
9
  name: 'klaim',
9
- fileName: format => `klaim.${format}.js`
10
+ fileName: format => `klaim.${format}.js`,
11
+ formats: ['es', 'cjs']
10
12
  },
11
13
  rollupOptions: {
12
14
  external: [],
package/dist/klaim.umd.js DELETED
@@ -1 +0,0 @@
1
- (function(i,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(i=typeof globalThis<"u"?globalThis:i||self,a(i.klaim={}))})(this,function(i){"use strict";var A=Object.defineProperty;var E=(i,a,l)=>a in i?A(i,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):i[a]=l;var o=(i,a,l)=>E(i,typeof a!="symbol"?a+"":a,l);function a(r){return r.trim().replace(/^\/|\/$/g,"")}function l(r){return r.replace(/([-_][a-z])/gi,e=>e.toUpperCase().replace("-","").replace("_","")).replace(/(^\w)/,e=>e.toLowerCase())}var T=(r=>(r.GET="GET",r.POST="POST",r.PUT="PUT",r.DELETE="DELETE",r.PATCH="PATCH",r.OPTIONS="OPTIONS",r))(T||{});class p{constructor(e,t,n,c="GET"){o(this,"api","undefined");o(this,"name");o(this,"url");o(this,"method");o(this,"headers");o(this,"arguments",new Set);this.name=l(e),this.name!==e&&console.warn(`Route name "${e}" has been camelCased to "${this.name}"`),this.url=a(t),this.headers=n||{},this.method=c,this.detectArguments()}static createRoute(e,t,n,c){const s=new p(e,t,n,c);return h.i.registerRoute(s),s}static get(e,t,n={}){return this.createRoute(e,t,n,"GET")}static post(e,t,n){return this.createRoute(e,t,n,"POST")}static put(e,t,n){return this.createRoute(e,t,n,"PUT")}static delete(e,t,n){return this.createRoute(e,t,n,"DELETE")}static patch(e,t,n){return this.createRoute(e,t,n,"PATCH")}static options(e,t,n){return this.createRoute(e,t,n,"OPTIONS")}detectArguments(){const e=this.url.match(/\[([^\]]+)]/g);e&&e.forEach(t=>{const n=t.replace(/\[|]/g,"");this.arguments.add(n)})}}const d={};async function g(r,e,t={},n={}){const c=w(`${r.url}/${e.url}`,e,t),s={};return n&&e.method!==T.GET&&(s.body=JSON.stringify(n)),s.headers={"Content-Type":"application/json",...r.headers,...e.headers},s.method=e.method,await(await fetch(c,s)).json()}function w(r,e,t){let n=r;return e.arguments.forEach(c=>{if(t[c]===void 0)throw new Error(`Argument ${c} is missing`);n=n.replace(`[${c}]`,t[c])}),n}const u=class u{constructor(){o(this,"_apis",new Map);o(this,"_currentApi",null)}static get i(){return u._instance||(u._instance=new u),u._instance}registerApi(e){this._apis.set(e.name,e),d[e.name]={}}setCurrent(e){const t=this._apis.get(e);if(!t)throw new Error(`API ${e} not found`);this._currentApi=t}clearCurrent(){this._currentApi=null}registerRoute(e){if(!this._currentApi)throw new Error("No current API set, use Route only inside Api.create callback");e.api=this._currentApi.name,this._currentApi.routes.set(e.name,e),this.addToKlaimRoute(e.api,e)}getApi(e){return this._apis.get(e)}getRoute(e,t){const n=this._apis.get(e);if(!n)throw new Error(`API ${e} not found`);return n.routes.get(t)}addToKlaimRoute(e,t){d[e][t.name]=async(n={},c={})=>{const s=u.i._apis.get(e);if(!s)throw new Error(`API ${t.api} not found`);return g(s,t,n,c)}}};o(u,"_instance");let h=u;class f{constructor(e,t,n){o(this,"name");o(this,"url");o(this,"headers");o(this,"routes",new Map);this.name=e,this.url=a(t),this.headers=n||{}}static create(e,t,n,c={}){const s=l(e);s!==e&&console.warn(`API name "${e}" has been camelCased to "${s}"`);const m=new f(s,t,c);return h.i.registerApi(m),h.i.setCurrent(s),n(),h.i.clearCurrent(),m}}i.Api=f,i.Klaim=d,i.Registry=h,i.Route=p,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});