@forinda/kickjs-cli 8.15.0 → 8.16.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/agent-docs-DhiaLsBj.mjs +591 -0
- package/dist/agent-docs-DhiaLsBj.mjs.map +1 -0
- package/dist/agent-docs-lNvu1K1x.mjs +590 -0
- package/dist/{build-Czsf4CBN.mjs → build-BNHMWtNY.mjs} +2 -2
- package/dist/{build-gqxIH3D8.mjs → build-vY0bmwuH.mjs} +3 -3
- package/dist/{build-gqxIH3D8.mjs.map → build-vY0bmwuH.mjs.map} +1 -1
- package/dist/{builtins-6euI1-lN.mjs → builtins-CRRb7Lq1.mjs} +2 -2
- package/dist/{builtins-xahWxQLw.mjs → builtins-tE4nrAZ_.mjs} +59 -59
- package/dist/cli.mjs +2 -2
- package/dist/{config-DCM2vXUJ.mjs → config-mXO3F69m.mjs} +2 -2
- package/dist/{config-8jdSKLKJ.mjs → config-zWl1-NCq.mjs} +3 -3
- package/dist/{config-8jdSKLKJ.mjs.map → config-zWl1-NCq.mjs.map} +1 -1
- package/dist/{doctor-CwGU9orm.mjs → doctor-z92r35fo.mjs} +9 -9
- package/dist/{doctor-CwGU9orm.mjs.map → doctor-z92r35fo.mjs.map} +1 -1
- package/dist/{fullstack-9HywHQL-.mjs → fullstack-BqevN8LJ.mjs} +13 -13
- package/dist/{fullstack-9HywHQL-.mjs.map → fullstack-BqevN8LJ.mjs.map} +1 -1
- package/dist/{fullstack-BmIFnryN.mjs → fullstack-eMi-9BtZ.mjs} +9 -9
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/{plugin-DLZP4hZ0.mjs → plugin-BbbHEAzr.mjs} +2 -2
- package/dist/{plugin-BjmLRF7t.mjs → plugin-CH4X4T0O.mjs} +2 -2
- package/dist/project-Bp6SIRyt.mjs +132 -0
- package/dist/project-D96UoR0P.mjs +133 -0
- package/dist/project-D96UoR0P.mjs.map +1 -0
- package/dist/{project-root-Dk8r8FMi.mjs → project-root-Bw3CEPC7.mjs} +3 -3
- package/dist/{project-root-Dk8r8FMi.mjs.map → project-root-Bw3CEPC7.mjs.map} +1 -1
- package/dist/{project-root-8DH00M-b.mjs → project-root-DN0YbQE5.mjs} +2 -2
- package/dist/{rolldown-runtime-CRasMkPY.mjs → rolldown-runtime-CYy3EyO3.mjs} +1 -1
- package/dist/{run-plugins-R0bVf_nK.mjs → run-plugins-f7i7TlPV.mjs} +67 -67
- package/dist/run-plugins-f7i7TlPV.mjs.map +1 -0
- package/dist/{typegen-BZ8cQ1YM.mjs → typegen-Bq4Fis9G.mjs} +5 -5
- package/dist/{typegen-BZ8cQ1YM.mjs.map → typegen-Bq4Fis9G.mjs.map} +1 -1
- package/dist/{typegen-DNufBmjE.mjs → typegen-_x_Q5O0b.mjs} +4 -4
- package/dist/{types-DOcxTXlP.mjs → types-BLZecxnS.mjs} +1 -1
- package/package.json +2 -2
- package/templates/base/files/_dot_vscode/extensions.json +3 -0
- package/templates/base/files/kick.config.ts +4 -0
- package/templates/base/skills/add-adapter.txt +56 -0
- package/templates/base/skills/add-module.txt +53 -0
- package/templates/base/skills/add-plugin.txt +69 -0
- package/templates/base/skills/bootstrap-export.txt +21 -0
- package/templates/base/skills/cli-commands-cheatsheet.txt +46 -0
- package/templates/base/skills/cli-plugin.txt +61 -0
- package/templates/base/skills/context-contributor.txt +73 -0
- package/templates/base/skills/deny-list.txt +44 -0
- package/templates/base/skills/deploy.txt +99 -0
- package/templates/base/skills/docs-lookup.txt +40 -0
- package/templates/base/skills/env-wiring-check.txt +44 -0
- package/templates/base/skills/guard-vs-middleware-vs-contributor.txt +95 -0
- package/templates/base/skills/query-parsing-list-endpoint.txt +48 -0
- package/templates/base/skills/refresh-agent-docs.txt +27 -0
- package/templates/base/skills/route-flags.txt +73 -0
- package/templates/base/skills/thin-entry-file.txt +49 -0
- package/templates/base/skills/use-asset-manager.txt +61 -0
- package/templates/base/skills/write-controller-test.txt +63 -0
- package/templates/feature-views/feature.json +21 -0
- package/templates/feature-views/files/src/adapters/views.ts +5 -0
- package/templates/feature-views/files/src/views/home.kick +3 -0
- package/templates/feature-views/files/src/views/layouts/main.kick +13 -0
- package/templates/feature-views/files/src/views.ts +9 -0
- package/templates/feature-views/skills/views-forms.txt +68 -0
- package/templates/feature-views/skills/views.txt +49 -0
- package/templates/fullstack-root/files/_dot_vscode/extensions.json +3 -0
- package/dist/agent-docs-CrVQtJgn.mjs +0 -932
- package/dist/agent-docs-D7K6R5C3.mjs +0 -933
- package/dist/agent-docs-D7K6R5C3.mjs.map +0 -1
- package/dist/package-manager-9XxrErw1.mjs +0 -11
- package/dist/package-manager-Dwaolesm.mjs +0 -12
- package/dist/package-manager-Dwaolesm.mjs.map +0 -1
- package/dist/project-CFi3NvO9.mjs +0 -136
- package/dist/project-CFi3NvO9.mjs.map +0 -1
- package/dist/project-CO0D8B0V.mjs +0 -135
- package/dist/run-plugins-R0bVf_nK.mjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @forinda/kickjs-cli v8.
|
|
2
|
+
* @forinda/kickjs-cli v8.16.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Felix Orinda
|
|
5
5
|
*
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import{t as e}from"./rolldown-runtime-CRasMkPY.mjs";import{statSync as t}from"node:fs";import{basename as n,dirname as r,join as i,relative as a,resolve as o,sep as s}from"node:path";import{mkdir as c,readFile as l,readdir as u,stat as d,unlink as f,writeFile as p}from"node:fs/promises";import{parseSync as m}from"oxc-parser";import{globSync as h}from"glob";import{groupAssetKeys as g}from"@forinda/kickjs";const _=[`classes`,`tokens`,`injects`,`pluginsAndAdapters`,`contextKeys`,`routeFlags`,`routes`,`moduleMounts`,`globPatterns`];function v(e){if(!e||typeof e!=`object`)return!1;let t=e;return _.every(e=>Array.isArray(t[e]))}var y=class e{path;prev;next=/* @__PURE__ */ new Map;nextSig=/* @__PURE__ */ new Map;constructor(e,t){this.path=e,this.prev=t}static async load(t){let n=i(t,`scan.json`),r=/* @__PURE__ */ new Map;try{let e=await l(n,`utf-8`),t=JSON.parse(e);if(t.version===3&&t.files)for(let[e,n]of Object.entries(t.files))n&&typeof n.sig==`string`&&v(n.extract)&&r.set(e,n)}catch{}return new e(n,r)}static async signature(e){try{let t=await d(e);return`${t.mtimeMs}:${t.size}`}catch{return null}}get(e,t){let n=this.prev.get(e);return n&&n.sig===t?n.extract:null}set(e,t,n){this.next.set(e,n),this.nextSig.set(e,t)}cachedFiles(){return[...this.prev.keys()]}peek(e){return this.prev.get(e)?.extract??null}carry(e){let t=this.prev.get(e);return t?(this.next.set(e,t.extract),this.nextSig.set(e,t.sig),!0):!1}async save(){let e={};for(let[t,n]of this.next){let r=this.nextSig.get(t);r&&(e[t]={sig:r,extract:n})}let t={version:3,files:e};try{await c(r(this.path),{recursive:!0}),await p(this.path,JSON.stringify(t),`utf-8`)}catch{}}};let b=null;function ee(){return b??=new Set(L),b}const x=/* @__PURE__ */ new Set([`Get`,`Post`,`Put`,`Delete`,`Patch`]);function S(e){return typeof e==`object`&&!!e&&typeof e.type==`string`}function C(e,t){if(Array.isArray(e))for(let n of e)C(n,t);else if(S(e)){t(e);for(let n of Object.keys(e)){if(n===`type`)continue;let r=e[n];typeof r==`object`&&r&&C(r,t)}}}function w(e){if(!S(e))return null;if(e.type===`Literal`&&typeof e.value==`string`)return e.value;if(e.type===`TemplateLiteral`){let t=e.quasis,n=e.expressions;if(t?.length===1&&(n?.length??0)===0){let e=t[0].value?.cooked;return typeof e==`string`?e:null}}return null}function T(e){return S(e)&&e.type===`Identifier`?e.name:null}function E(e){return T(e.callee)}function D(e,t){if(!e||e.type!==`ObjectExpression`)return null;for(let n of e.properties??[]){if(n.type!==`Property`)continue;let e=n.key;if((T(e)??(e.type===`Literal`?String(e.value):w(e)))===t)return n.value}return null}function O(e){let t=e.arguments?.[0];return S(t)&&t.type===`ObjectExpression`?t:null}function k(e,t){let n=D(e,t);if(!S(n)||n.type!==`ArrayExpression`)return[];let r=[];for(let e of n.elements??[]){let t=w(e);t!==null&&r.push(t)}return r}function te(e,t){return a(t,e).split(s).join(`/`)}function ne(e){return(e.match(/:([a-zA-Z_]\w*)/g)??[]).map(e=>e.slice(1))}function re(e,t){for(let n of e.implements??[]){let e=n.expression??n;if(T(e)===t)return!0;if(e.type===`TSQualifiedName`||e.type===`MemberExpression`){let n=e.right??e.property;if(n&&T(n)===t)return!0}}return!1}function A(e){return e.decorators??[]}function j(e){let t=e.expression;if(!S(t)||t.type!==`CallExpression`)return null;let n=E(t);return n?{name:n,call:t}:null}function ie(e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Set;for(let i of e.body??[]){if(i.type===`ExportNamedDeclaration`&&!i.source)for(let e of i.specifiers??[]){let t=T(e.local);t&&t===T(e.exported)&&r.add(t)}if(i.type===`ImportDeclaration`){let e=w(i.source)??``;for(let n of i.specifiers??[]){let r=T(n.local);r&&t.set(r,{source:e})}continue}let e=i.type===`VariableDeclaration`?i:i.type===`ExportNamedDeclaration`&&S(i.declaration)?i.declaration:null;if(S(e)&&e.type===`VariableDeclaration`)for(let t of e.declarations??[]){let a=T(t.id);a&&n.add(a),a&&i!==e&&r.add(a)}}return{imports:t,topLevelConsts:n,exported:r}}function M(e,t){let n=t.imports.get(e);return n?{identifier:e,source:n.source}:t.topLevelConsts.has(e)?t.exported.has(e)?{identifier:e,source:``}:{identifier:e,source:null,unexported:!0}:{identifier:e,source:null}}function ae(e,t){let n=[];for(let r of e){let e=j(r),i=e?e.name:T(r.expression);if(!i||x.has(i))continue;let a=t.imports.get(i);n.push({identifier:i,source:a?a.source:t.topLevelConsts.has(i)?``:null})}return n}const N=/* @__PURE__ */ new Set([`bootstrap`,`createWebApp`,`Application`]);function oe(e,t){if(!N.has(e))return!1;let n=t.imports.get(e)?.source;return n===`@forinda/kickjs`||(n?.startsWith(`@forinda/kickjs/`)??!1)}function se(e,t){let n={refs:[],resolved:!1},r=P(e);if(!r||r.type!==`ArrayExpression`)return n;let i=[];for(let e of r.elements??[]){if(!S(e)||e.type!==`MemberExpression`||T(e.property)!==`registration`)return n;let r=e.object,a=T(r);if(!a&&S(r)&&r.type===`CallExpression`){let e=r.callee;S(e)&&e.type===`MemberExpression`&&T(e.property)===`with`&&(a=T(e.object))}if(!a)return n;let o=t.imports.get(a);i.push({identifier:a,source:o?o.source:t.topLevelConsts.has(a)?``:null})}return{refs:i,resolved:!0}}function P(e){let t=e.value??e;if(!S(t))return null;if(t.type===`ArrayExpression`)return t;let n=t.body;if(!S(n))return null;if(n.type!==`BlockStatement`)return n;let r=(n.body??[]).filter(e=>e.type===`ReturnStatement`);if(r.length!==1)return null;let i=r[0].argument;return S(i)?i:null}function F(e,t,n){let r=T(D(e,t));return r?M(r,n):null}function ce(e,t){for(let n of e){let e=j(n);if(!e||e.name!==`ApiQueryParams`)continue;let r=e.call.arguments?.[0],i=null;if(S(r)&&r.type===`ObjectExpression`)i=r;else{let e=T(r);if(e){let n=t.get(e);n&&n.type===`ObjectExpression`&&(i=n)}}return{filterable:k(i,`filterable`),sortable:k(i,`sortable`),searchable:k(i,`searchable`)}}return null}function I(e,t,n){let r;try{let n=m(t,e);if(n.errors.length>0)return null;r=n.program}catch{return null}let i=te(t,n),a=ie(r),o=[],s=[],c=[],l=[],u=[],d=[],f=/* @__PURE__ */ new Set,p=[],h=[],g=[],_=/* @__PURE__ */ new Set,v=/* @__PURE__ */ new Set,y=/* @__PURE__ */ new Map;C(r,e=>{if(e.type!==`VariableDeclarator`)return;let t=T(e.id),n=e.init;t&&S(n)&&y.set(n,t)});let b=/* @__PURE__ */ new Set,k=/* @__PURE__ */ new Map;for(let e of r.body??[]){let t=e.type===`VariableDeclaration`?e:e.type===`ExportNamedDeclaration`&&S(e.declaration)?e.declaration:null;if(S(t)&&t.type===`VariableDeclaration`)for(let e of t.declarations??[]){let t=T(e.id);t&&S(e.init)&&k.set(t,e.init)}}let M=[];for(let e of r.body??[])if(e.type===`ExportNamedDeclaration`&&S(e.declaration)){let t=e.declaration;t.type===`ClassDeclaration`&&M.push({cls:t,isDefault:!1})}else if(e.type===`ExportDefaultDeclaration`&&S(e.declaration)){let t=e.declaration;t.type===`ClassDeclaration`&&M.push({cls:t,isDefault:!0})}for(let{cls:e,isDefault:n}of M){let r=T(e.id);if(!r)continue;let a=null;for(let t of A(e)){let e=j(t);if(e&&ee().has(e.name)){a=e.name;break}}a?o.push({className:r,decorator:a,filePath:t,relativePath:i,isDefault:n}):re(e,`AppModule`)&&o.push({className:r,decorator:`Module`,filePath:t,relativePath:i,isDefault:n})}for(let e of r.body??[]){if(e.type!==`ExportNamedDeclaration`||!S(e.declaration))continue;let n=e.declaration;if(n.type===`VariableDeclaration`)for(let e of n.declarations??[]){let n=T(e.id),r=e.init;n&&S(r)&&r.type===`CallExpression`&&E(r)===`defineModule`&&(o.some(e=>e.className===n)||o.push({className:n,decorator:`Module`,filePath:t,relativePath:i,isDefault:!1}))}}C(r,n=>{if(n.type===`VariableDeclarator`){let e=n.init;if(S(e)&&e.type===`CallExpression`&&E(e)===`createToken`){let r=w(e.arguments?.[0]);r!==null&&(b.add(e),s.push({name:r,variable:T(n.id),filePath:t,relativePath:i}))}return}if(n.type!==`CallExpression`){if(n.type===`Decorator`){let e=j(n);if(e?.name===`Inject`){let n=w(e.call.arguments?.[0]);n!==null&&c.push({name:n,filePath:t,relativePath:i})}}return}let r=n.callee,a=E(n);if(a===`createToken`&&!b.has(n)){let e=w(n.arguments?.[0]);e!==null&&s.push({name:e,variable:null,filePath:t,relativePath:i})}else if(a===`defineAdapter`||a===`definePlugin`){let e=w(D(O(n),`name`));if(e!==null){let n=a===`definePlugin`?`plugin`:`adapter`,r=`${a}::${e}::${t}`;_.has(r)||(_.add(r),l.push({kind:n,name:e,filePath:t,relativePath:i}))}}else if(a===`defineRouteFlag`){let r=w(n.arguments?.[0]);if(r!==null&&!f.has(r)){f.add(r);let a=n.typeArguments,o=a?e.slice(a.start,a.end):null;d.push({name:r,valueType:o?o.slice(1,-1).trim():null,filePath:t,relativePath:i})}}else if(a===`defineContextDecorator`||a===`defineHttpContextDecorator`){let e=w(D(O(n),`key`));e!==null&&!v.has(e)&&(v.add(e),u.push({key:e,exportName:y.get(n)??null,filePath:t,relativePath:i}))}else if(S(r)&&r.type===`CallExpression`){let e=r.callee;if(S(e)&&e.type===`MemberExpression`&&T(e.property)===`withParams`){let r=T(e.object);if(r===`defineContextDecorator`||r===`defineHttpContextDecorator`){let e=w(D(O(n),`key`));e!==null&&!v.has(e)&&(v.add(e),u.push({key:e,exportName:y.get(n)??null,filePath:t,relativePath:i}))}}}else if(S(r)&&r.type===`MemberExpression`&&T(r.property)===`glob`){let e=r.object;S(e)&&e.type===`MetaProperty`&&C(n.arguments,e=>{let t=w(e);t!==null&&g.push(t)})}});let N=[];C(r,e=>{if(e.type===`ClassDeclaration`||e.type===`ClassExpression`){let t=T(e.id);t&&N.push({cls:e,className:t})}});for(let{cls:e,className:n}of N){let r=o.find(e=>e.className===n),s=e.body?.body;if(re(e,`AppAdapter`))for(let e of s??[]){if(e.type!==`PropertyDefinition`||T(e.key)!==`name`)continue;let n=w(e.value);if(n===null)continue;let r=`class::${n}::${t}`;_.has(r)||(_.add(r),l.push({kind:`adapter`,name:n,filePath:t,relativePath:i}));break}for(let o of s??[]){if(o.type!==`MethodDefinition`)continue;let s=T(o.key);if(!s)continue;if(s===`routes`){le(o.value,h);continue}if(!r)continue;let c=A(o),l=ce(c,k),u=[...ae(A(e),a),...ae(c,a)];for(let e of c){let o=j(e);if(!o||!x.has(o.name))continue;let c=o.call.arguments??[],d=w(c[0]),f=d&&d.length>0?d:`/`,m=S(c[1])&&c[1].type===`ObjectExpression`?c[1]:null;p.push({controller:n,method:s,httpMethod:o.name.toUpperCase(),path:f,pathParams:ne(f),queryFilterable:l?.filterable??null,querySortable:l?.sortable??null,querySearchable:l?.searchable??null,bodySchema:F(m,`body`,a),querySchema:F(m,`query`,a),paramsSchema:F(m,`params`,a),responseSchema:F(m,`response`,a),filePath:t,relativePath:i,controllerIsDefaultExport:r.isDefault,appliedDecorators:u,mountedPath:f})}}}C(r,e=>{if(e.type!==`Property`||T(e.key)!==`routes`)return;let t=e.value;S(t)&&(t.type===`FunctionExpression`||t.type===`ArrowFunctionExpression`)&&le(t,h)});let P=/* @__PURE__ */ new Set,I=/* @__PURE__ */ new Set;C(r,e=>{let t=e.type===`Property`&&T(e.key)===`contributors`,n=e.type===`MethodDefinition`&&T(e.key)===`contributors`;(t||n)&&I.add(e)});let L=e=>e.properties??e.body?.body??[];C(r,e=>{if(e.type!==`ObjectExpression`&&e.type!==`ClassDeclaration`)return;let t=L(e);if(t.map(e=>T(e.key)).includes(`routes`))for(let e of t)T(e.key)===`contributors`&&P.add(e)});let R=/* @__PURE__ */ new Set;C(r,e=>{let t=e.type===`CallExpression`?E(e):e.type===`NewExpression`?T(e.callee):null;if(t===null||!oe(t,a))return;let n=O(e);if(n)for(let e of n.properties??[])e.type===`Property`&&T(e.key)===`contributors`&&R.add(e)});let z=e=>{if(e.size===0)return null;let n=[],r=!0;for(let t of e){let e=se(t,a);e.resolved||(r=!1),n.push(...e.refs)}return{refs:n,resolved:r,filePath:t}},B=z(P),V=z(R);return{classes:o,tokens:s,injects:c,pluginsAndAdapters:l,contextKeys:u,routeFlags:d,routes:p,moduleMounts:h,globPatterns:/\.module\.[mc]?[tj]sx?$/.test(t)?g:[],moduleContributors:B,appContributors:V,hasNonDecoratorContributors:I.size>P.size+R.size}}function le(e,t){let n=[],r=[];C(e.body,e=>{if(e.type!==`Property`)return;let t=T(e.key);if(t===`path`){let t=w(e.value);t!==null&&n.push(t)}else if(t===`controller`){let t=T(e.value);t&&/^[A-Z]/.test(t)&&r.push(t)}});let i=Math.min(n.length,r.length);for(let e=0;e<i;e++)t.push({controller:r[e],mountPath:n[e]})}const L=[`Service`,`Controller`,`Repository`,`Injectable`,`Component`,`Module`],R=[`.ts`,`.tsx`,`.mts`,`.cts`],z=[`node_modules`,`.kickjs`,`dist`,`build`,`.test.`,`.spec.`,`.d.ts`],B=new RegExp(String.raw`@(${L.join(`|`)})\s*\([^)]*\)`+String.raw`(?:\s*@[A-Z]\w*(?:\s*\([^)]*\))?)*`+String.raw`\s*export\s+(default\s+)?(?:abstract\s+)?class\s+(\w+)`,`g`),V=new RegExp(String.raw`export\s+(default\s+)?(?:abstract\s+)?class\s+(\w+)`+String.raw`(?:\s+extends\s+\w+(?:<[^>]*>)?)?`+String.raw`\s+implements\s+[^{]*\bAppModule\b`,`g`),ue=/export\s+const\s+(\w+)\s*(?::\s*[^=]+)?=\s*defineModule\s*(?:<[^>]*>)?\s*\(/g,de=/(?:export\s+)?const\s+(\w+)\s*(?::\s*[^=]+)?=\s*createToken\s*(?:<[^>]*>)?\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g,fe=/createToken\s*(?:<[^>]*>)?\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g,pe=/@Inject\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g,H=/\b(defineAdapter|definePlugin)\s*(?:<[^>]*>)?\s*\(/g,U=/(?:(?:export\s+)?(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::[^=]+)?=\s*)?\b(?:defineContextDecorator|defineHttpContextDecorator)\s*(?:\.withParams\s*<(?:[^<>]|<[^<>]*>)*>\s*\(\s*\))?\s*(?:<(?:[^<>]|<[^<>]*>)*>)?\s*\(/g,me=new RegExp(String.raw`export\s+(?:default\s+)?(?:abstract\s+)?class\s+(\w+)`+String.raw`(?:\s+extends\s+\w+(?:<[^>]*>)?)?`+String.raw`\s+implements\s+[^{]*\bAppAdapter\b`,`g`),he=/\bname\s*(?::\s*[^=]+)?=\s*['"`]([^'"`]+)['"`]/,W=new RegExp(String.raw`@(${[`Get`,`Post`,`Put`,`Delete`,`Patch`].join(`|`)})\s*\(`,`g`);function G(e,t){let n=1;for(let r=t+1;r<e.length;r++){let t=e[r];if(t===`(`)n++;else if(t===`)`&&(n--,n===0))return r}return-1}function ge(e,t){let n=t;for(;n<e.length;){for(;n<e.length&&/\s/.test(e[n]);)n++;if(e[n]!==`@`)break;let t=e.slice(n).match(/^@([A-Z]\w*)/);if(!t)break;for(n+=t[0].length;n<e.length&&/\s/.test(e[n]);)n++;if(e[n]===`(`){let t=G(e,n);if(t<0)return null;n=t+1}}for(;n<e.length&&/\s/.test(e[n]);)n++;for(let t of[`public`,`private`,`protected`])if(e.slice(n,n+t.length)===t&&/\s/.test(e.charAt(n+t.length))){for(n+=t.length;n<e.length&&/\s/.test(e[n]);)n++;break}if(e.slice(n,n+5)===`async`&&/\s/.test(e.charAt(n+5)))for(n+=5;n<e.length&&/\s/.test(e[n]);)n++;let r=e.slice(n).match(/^([a-zA-Z_]\w*)\s*\(/);return r?{methodName:r[1],endPos:n+r[0].length}:null}function _e(e){return(e.match(/:([a-zA-Z_]\w*)/g)??[]).map(e=>e.slice(1))}function ve(e,t){let n=e.endsWith(`/`)?e.slice(0,-1):e;return!t||t===`/`?n||`/`:n+(t.startsWith(`/`)?t:`/`+t)||`/`}const ye=/\b(?:public\s+|private\s+|protected\s+)?routes\s*\([^)]*\)\s*(?::\s*[A-Za-z_][\w<>[\]\s,|]*\s*)?\{/g,be=/\bpath\s*:\s*['"`]([^'"`]*)['"`]/g,xe=/\bcontroller\s*:\s*([A-Z]\w*)\b/g,K=/\bimport\.meta\.glob\s*\(/g;function Se(e){let t=[];for(K.lastIndex=0;K.exec(e)!==null;){let n=K.lastIndex-1,r=G(e,n);if(r<0)continue;let i=e.slice(n+1,r),a=/['"`]([^'"`]+)['"`]/g,o;for(;(o=a.exec(i))!==null;)t.push(o[1])}return t}function Ce(e){let t=e.replace(/[.+^$()|[\]\\]/g,`\\$&`).replace(/\?/g,`.`).replace(/\*\*\//g,`___DOUBLESTAR_SLASH___`).replace(/\*\*/g,`___DOUBLESTAR___`).replace(/\*/g,`[^/]*`).replace(/___DOUBLESTAR_SLASH___/g,`(?:.+/)?`).replace(/___DOUBLESTAR___/g,`.*`);return RegExp(`^`+t+`$`)}function we(e,t){let n=e.startsWith(`./`)?e:`./`+e,r=!1;for(let e of t){let t=e.startsWith(`!`);Ce(t?e.slice(1):e).test(n)&&(r=!t)}return r}function Te(e){let t=[];ye.lastIndex=0;let n;for(;(n=ye.exec(e))!==null;){let r=e.indexOf(`{`,n.index+n[0].length-1);if(r<0)continue;let i=Ie(e,r);if(i<0)continue;let a=e.slice(r+1,i),o=[];be.lastIndex=0;let s;for(;(s=be.exec(a))!==null;)o.push(s[1]??``);let c=[];xe.lastIndex=0;let l;for(;(l=xe.exec(a))!==null;)c.push(l[1]);let u=Math.min(o.length,c.length);for(let e=0;e<u;e++)t.push({controller:c[e],mountPath:o[e]})}return t}function q(e,t){let n=new RegExp(String.raw`\b${t}\s*:\s*([A-Za-z_$][\w$]*)`,`g`).exec(e);return n?n[1]:null}function J(e,t){let n=Ee(e,t);return n===null?new RegExp(String.raw`(?:^|\n)\s*const\s+${t}\b`).test(e)?{identifier:t,source:null,unexported:!0}:{identifier:t,source:null}:{identifier:t,source:n}}function Ee(e,t){let n=new RegExp(String.raw`import\s*(?:type\s+)?\{[^}]*\b${t}\b[^}]*\}\s*from\s*['"\`]([^'"\`]+)['"\`]`).exec(e);if(n)return n[1];let r=new RegExp(String.raw`import\s+(?:type\s+)?${t}\s+from\s*['"\`]([^'"\`]+)['"\`]`).exec(e);if(r)return r[1];let i=new RegExp(String.raw`import\s*\*\s*as\s+${t}\s+from\s*['"\`]([^'"\`]+)['"\`]`).exec(e);return i?i[1]:new RegExp(String.raw`(?:^|\n)\s*export\s+const\s+${t}\b|export\s*\{[^}]*(?<!\bas\s+)\b${t}\b(?!\s+as\b)[^}]*\}(?!\s*from)`).test(e)?``:null}function De(e,t){let n=/@ApiQueryParams\s*\(\s*([\s\S]*?)\s*\)\s*$/.exec(e);if(!n){let n=/@ApiQueryParams\s*\(([\s\S]*?)\)/.exec(e);return n?Oe(n[1].trim(),t):null}return Oe(n[1].trim(),t)}function Oe(e,t){if(e.startsWith(`{`))return Ae(e);let n=/^([A-Za-z_]\w*)/.exec(e);if(n){let e=n[1],r=new RegExp(String.raw`const\s+${e}\s*(?::\s*[^=]+)?=\s*(\{[\s\S]*?\n\})`,`m`).exec(t);if(r)return Ae(r[1])}return{filterable:[],sortable:[],searchable:[]}}function ke(e,t){let n=new RegExp(String.raw`${t}\s*:\s*\[([\s\S]*?)\]`).exec(e);return n?Array.from(n[1].matchAll(/['"`]([^'"`]+)['"`]/g)).map(e=>e[1]):[]}function Ae(e){return{filterable:ke(e,`filterable`),sortable:ke(e,`sortable`),searchable:ke(e,`searchable`)}}async function je(e,t){let n=t.extensions??R,r=t.exclude??z,o=[],s;try{s=await u(e,{withFileTypes:!0,encoding:`utf-8`})}catch{return o}for(let c of s){let s=i(e,c.name),l=a(t.cwd,s);r.some(e=>l.includes(e))||(c.isDirectory()?o.push(...await je(s,t)):c.isFile()&&n.some(e=>c.name.endsWith(e))&&o.push(s))}return o}function Y(e,t){return a(t,e).split(s).join(`/`)}function Me(e,t,n){let r=[],i=Y(t,n);B.lastIndex=0;let a;for(;(a=B.exec(e))!==null;){let[,e,n,o]=a;r.push({className:o,decorator:e,filePath:t,relativePath:i,isDefault:!!n})}V.lastIndex=0;let o;for(;(o=V.exec(e))!==null;){let[,e,n]=o;r.some(e=>e.className===n&&e.filePath===t)||r.push({className:n,decorator:`Module`,filePath:t,relativePath:i,isDefault:!!e})}ue.lastIndex=0;let s;for(;(s=ue.exec(e))!==null;){let[,e]=s;r.some(n=>n.className===e&&n.filePath===t)||r.push({className:e,decorator:`Module`,filePath:t,relativePath:i,isDefault:!1})}return r}function Ne(e,t,n){let r=[],i=Y(t,n),a=/* @__PURE__ */ new Set;de.lastIndex=0;let o;for(;(o=de.exec(e))!==null;){let[e,n,s]=o;a.add(e),r.push({name:s,variable:n,filePath:t,relativePath:i})}for(fe.lastIndex=0;(o=fe.exec(e))!==null;)a.has(o[0])||r.push({name:o[1],variable:null,filePath:t,relativePath:i});return r}function Pe(e,t,n,r,i=/* @__PURE__ */ new Map){let a=[];if(r.length===0)return a;let o=Y(t,n),s=[];for(let t of r){let n=new RegExp(String.raw`class\s+${t.className}\b`).exec(e);n?.index!==void 0&&s.push({cls:t,start:n.index})}s.sort((e,t)=>e.start-t.start);for(let n=0;n<s.length;n++){let{cls:r,start:c}=s[n],l=n+1<s.length?s[n+1].start:e.length,u=e.slice(c,l);W.lastIndex=0;let d;for(;(d=W.exec(u))!==null;){let n=d[1],s=d.index,c=W.lastIndex-1,l=G(u,c);if(l<0)continue;let f=u.slice(c+1,l),p=f.match(/^\s*['"`]([^'"`]*)['"`]/),m=p&&p[1].length>0?p[1]:`/`,h=ge(u,l+1);if(!h)continue;let{methodName:g,endPos:_}=h;W.lastIndex=_;let v=De(u.slice(s,_),e),y=q(f,`body`),b=q(f,`query`),ee=q(f,`params`),x=q(f,`response`),S=i.get(r.className)??``,C=S?ve(S,m):m;a.push({controller:r.className,method:g,httpMethod:n.toUpperCase(),path:m,pathParams:_e(C),queryFilterable:v?.filterable??null,querySortable:v?.sortable??null,querySearchable:v?.searchable??null,bodySchema:y?J(e,y):null,querySchema:b?J(e,b):null,paramsSchema:ee?J(e,ee):null,responseSchema:x?J(e,x):null,filePath:t,relativePath:o,controllerIsDefaultExport:r.isDefault,mountedPath:C})}}return a}function Fe(e,t,n){let r=[],i=Y(t,n);pe.lastIndex=0;let a;for(;(a=pe.exec(e))!==null;)r.push({name:a[1],filePath:t,relativePath:i});return r}function Ie(e,t){let n=1;for(let r=t+1;r<e.length;r++){let t=e[r];if(t===`{`)n++;else if(t===`}`&&(n--,n===0))return r}return-1}function Le(e,t,n){let r=[],i=Y(t,n),a=/* @__PURE__ */ new Set;H.lastIndex=0;let o;for(;(o=H.exec(e))!==null;){let n=o[1],s=H.lastIndex-1,c=G(e,s);if(c<0)continue;let l=e.slice(s+1,c),u=/\bname\s*:\s*['"`]([^'"`]+)['"`]/.exec(l);if(!u)continue;let d=u[1],f=`${n}::${d}::${t}`;a.has(f)||(a.add(f),r.push({kind:n===`definePlugin`?`plugin`:`adapter`,name:d,filePath:t,relativePath:i}))}me.lastIndex=0;let s;for(;(s=me.exec(e))!==null;){let n=s.index,o=e.indexOf(`{`,n);if(o<0)continue;let c=Ie(e,o);if(c<0)continue;let l=e.slice(o+1,c),u=he.exec(l);if(!u)continue;let d=u[1],f=`class::${d}::${t}`;a.has(f)||(a.add(f),r.push({kind:`adapter`,name:d,filePath:t,relativePath:i}))}return r}function Re(e,t,n){let r=[],i=Y(t,n),a=/* @__PURE__ */ new Set;U.lastIndex=0;let o;for(;(o=U.exec(e))!==null;){let n=U.lastIndex-1,s=G(e,n);if(s<0)continue;let c=e.slice(n+1,s),l=/\bkey\s*:\s*['"`]([^'"`]+)['"`]/.exec(c);if(!l)continue;let u=l[1];a.has(u)||(a.add(u),r.push({key:u,exportName:o[1]??null,filePath:t,relativePath:i}))}return r}const ze=[`src/config/index.ts`,`src/config/env.ts`,`src/config.ts`,`src/env.ts`];async function Be(e,t){let n=t===`src/env.ts`?ze:[t];for(let t of n){let n=o(e,t),r;try{r=await l(n,`utf-8`)}catch{continue}if((/\bdefineEnv\s*\(/.test(r)||/\bfrom(Zod|Valibot|Yup)\s*\(/.test(r))&&/export\s+default\b/.test(r)&&!/export\s+default\s+loadEnvFromSchema\s*\(/.test(r))return{filePath:n,relativePath:Y(n,e)}}return null}function Ve(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=t.get(n.className)??[];e.push(n),t.set(n.className,e)}let n=[];for(let[e,r]of t)new Set(r.map(e=>e.filePath)).size>1&&n.push({className:e,classes:r});return n.sort((e,t)=>e.className.localeCompare(t.className)),n}const He=/* @__PURE__ */ new Set([`Controller`,`Service`,`Repository`,`Injectable`,`Component`,`Module`,`Middleware`,`ApiQueryParams`,`Public`,`Roles`,`Cron`,`Cacheable`,`CacheEvict`,`FileUpload`,`Asset`,`Builder`,`PostConstruct`,`PreDestroy`,`Value`,`Inject`,`Autowired`]);function X(e){return e.split(s).join(`/`).replace(/\.[mc]?[tj]sx?$/,``)}function Ue(e,t,n){let i=X(n);if(t===``)return i===X(e);if(t.startsWith(`.`)){let n=X(o(r(e),t));return i===n||i===`${n}/index`}let a=t.replace(/^[@~#]\//,``);if(a===t&&t.startsWith(`@`))return!1;let s=X(a);return i===s||i.endsWith(`/${s}`)}function We(e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map;for(let t of e)if(t)for(let{controller:e}of t.moduleMounts)n.set(e,(n.get(e)??0)+1);for(let r of e)if(r?.moduleContributors)for(let{controller:e}of r.moduleMounts){if((n.get(e)??0)>1){t.set(e,`ambiguous`);continue}let i=t.get(e);t.set(e,i===void 0?r.moduleContributors:`ambiguous`)}return t}function Ge(e,t,n,r=/* @__PURE__ */ new Map,i=[]){if(n){for(let t of e)t.contextKeys=null;return}let a=/* @__PURE__ */ new Map;for(let e of t){if(!e.exportName)continue;let t=a.get(e.exportName);t?t.push(e):a.set(e.exportName,[e])}for(let t of e){let e=t.appliedDecorators;if(!e){t.contextKeys=null;continue}let n=/* @__PURE__ */ new Set,o=!0,s=(e,t)=>{if(t.source===null)return null;let n=(a.get(t.identifier)??[]).filter(n=>Ue(e,t.source,n.filePath));return n.length===1?n[0].key:null};for(let r of e){if(He.has(r.identifier))continue;let e=s(t.filePath,r);if(e===null){o=!1;break}n.add(e)}if(o)for(let e of i){if(!e.resolved){o=!1;break}for(let t of e.refs){let r=s(e.filePath,t);if(r===null){o=!1;break}n.add(r)}if(!o)break}if(o){let e=r.get(t.controller);if(e===`ambiguous`)o=!1;else if(e){if(!e.resolved)o=!1;else for(let t of e.refs){let r=s(e.filePath,t);if(r===null){o=!1;break}n.add(r)}}}t.contextKeys=o?[...n].toSorted():null}}const Ke=/\bcontributors\s*(?::|\()/;function qe(e,t,n){return I(e,t,n)||{...Je(e,t,n),hasNonDecoratorContributors:Ke.test(e)}}function Je(e,t,n){let r=Me(e,t,n);return{classes:r,tokens:Ne(e,t,n),injects:Fe(e,t,n),pluginsAndAdapters:Le(e,t,n),routeFlags:[],contextKeys:Re(e,t,n),routes:Pe(e,t,n,r,/* @__PURE__ */ new Map),moduleMounts:Te(e),globPatterns:/\.module\.[mc]?[tj]sx?$/.test(t)?Se(e):[],hasNonDecoratorContributors:!1}}async function Ye(e,t,n){let r=n?await y.signature(e):null;if(n&&r){let t=n.get(e,r);if(t)return n.set(e,r,t),t}let i;try{i=await l(e,`utf-8`)}catch{return null}let a=qe(i,e,t);return n&&r&&n.set(e,r,a),a}async function Xe(e,t,n){let r=[],i=0,a=Array.from({length:Math.min(t,e.length)},async()=>{for(;;){let t=i++;if(t>=e.length)return;r[t]=await n(e[t],t)}});return await Promise.all(a),r}async function Z(e){let t=(await je(o(e.root),e)).toSorted(),n=e.cacheDir?await y.load(e.cacheDir):null,r=$e(t,await Xe(t,16,t=>Ye(t,e.cwd,n))),i=await Be(e.cwd,e.envFile??`src/env.ts`);return n&&await n.save(),{...r,env:i}}function Ze(e,t,n){let r=n.extensions??R,i=n.exclude??z;if(!e.startsWith(t+s)&&e!==t||!r.some(t=>e.endsWith(t)))return!1;let o=a(n.cwd,e);return!i.some(e=>o.includes(e))}async function Qe(e,t){if(!e.cacheDir)return Z(e);let n=o(e.root),r=await y.load(e.cacheDir),i=r.cachedFiles();if(i.length===0)return Z(e);let a=new Set(t.removed.map(t=>o(e.cwd,t))),s=t.changed.map(t=>o(e.cwd,t)).filter(t=>!a.has(t)&&Ze(t,n,e)),c=new Set(s),u=new Set(i);for(let e of c)u.add(e);for(let e of a)u.delete(e);let d=/* @__PURE__ */ new Map;await Xe(s,16,async t=>{if(!u.has(t))return;let n=await y.signature(t),i;try{i=await l(t,`utf-8`)}catch{u.delete(t);return}let a=qe(i,t,e.cwd);d.set(t,a),n&&r.set(t,n,a)});let f=[...u].toSorted(),p=$e(f,f.map(e=>d.get(e)||(r.carry(e),r.peek(e)))),m=await Be(e.cwd,e.envFile??`src/env.ts`);return await r.save(),{...p,env:m}}function $e(e,t){let n=[],r=[],i=[],a=[],o=[],c=[],l=[],u=/* @__PURE__ */ new Map;for(let e of t)if(e)for(let{controller:t,mountPath:n}of e.moduleMounts)u.has(t)||u.set(t,n);let d=/* @__PURE__ */ new Map;for(let s=0;s<e.length;s++){let f=t[s];if(f){n.push(...f.classes),i.push(...f.tokens),a.push(...f.injects),o.push(...f.pluginsAndAdapters),c.push(...f.contextKeys),l.push(...f.routeFlags),f.globPatterns.length>0&&d.set(e[s],f.globPatterns);for(let e of f.routes){let t=u.get(e.controller);if(t){let n=ve(t,e.path);r.push({...e,pathParams:_e(n),mountedPath:n})}else r.push({...e,mountedPath:e.mountedPath??e.path})}}}Ge(r,c,t.some(e=>e?.hasNonDecoratorContributors===!0),We(t),t.flatMap(e=>e?.appContributors?[e.appContributors]:[]));let f=[];for(let[e,t]of d){if(!/\.module\.[mc]?[tj]sx?$/.test(e)||t.length===0)continue;let r=e.replaceAll(s,`/`),i=r.slice(0,r.lastIndexOf(`/`));for(let a of n){if(a.decorator===`Module`)continue;let n=a.filePath.replaceAll(s,`/`);n.startsWith(i+`/`)&&n!==r&&(we(n.slice(i.length+1),t)||f.push({className:a.className,filePath:a.filePath,relativePath:a.relativePath,moduleFilePath:e,decorator:a.decorator}))}}n.sort((e,t)=>e.className===t.className?e.relativePath.localeCompare(t.relativePath):e.className.localeCompare(t.className)),i.sort((e,t)=>e.name.localeCompare(t.name)||e.relativePath.localeCompare(t.relativePath)),a.sort((e,t)=>e.name.localeCompare(t.name)||e.relativePath.localeCompare(t.relativePath)),r.sort((e,t)=>e.controller.localeCompare(t.controller)||e.method.localeCompare(t.method)),o.sort((e,t)=>e.name.localeCompare(t.name)||e.relativePath.localeCompare(t.relativePath)),c.sort((e,t)=>e.key.localeCompare(t.key)||e.relativePath.localeCompare(t.relativePath));let p=Ve(n);return f.sort((e,t)=>e.relativePath.localeCompare(t.relativePath)||e.className.localeCompare(t.className)),{classes:n,routes:r,tokens:i,injects:a,collisions:p,pluginsAndAdapters:o,contextKeys:c,routeFlags:l,orphanedClasses:f}}function et(e){let t=e.lastIndexOf(`.`);return t<=0?{stem:e,ext:``}:{stem:e.slice(0,t),ext:e.slice(t+1)}}function tt(e){let t=e.replaceAll(`\\`,`/`),{stem:n,ext:r}=et(t.slice(t.lastIndexOf(`/`)+1)),i=r||`ts`,a=n.lastIndexOf(`.`);return a>0?`./**/*.${n.slice(a+1)}.${i}`:`./**/*.${i}`}function nt(e){let t=/* @__PURE__ */ new Set;for(let n of e)t.add(tt(n.relativePath));return[...t].toSorted()}function rt(e,t){let n=0,r=null;for(let i=t;i<e.length;i++){let t=e[i];if(r){if(t===`\\`){i++;continue}t===r&&(r=null)}else if(t===`'`||t===`"`||t==="`")r=t;else if(t===`(`)n++;else if(t===`)`&&(n--,n===0))return i}return-1}function it(e,t,n,r){let i=null;for(let a=n;a<r;a++){let n=e[a];if(i){if(n===`\\`){a++;continue}n===i&&(i=null)}else if(n===`'`||n===`"`||n==="`")i=n;else if(n===t)return a}return-1}function at(e,t){let n=0,r=null;for(let i=t;i<e.length;i++){let t=e[i];if(r){if(t===`\\`){i++;continue}t===r&&(r=null)}else if(t===`'`||t===`"`||t==="`")r=t;else if(t===`[`)n++;else if(t===`]`&&(n--,n===0))return i}return-1}function ot(e){let t=/\bimport\.meta\.glob\s*\(/g,n=[],r;for(;(r=t.exec(e))!==null;){let t=e.indexOf(`(`,r.index);if(t<0)continue;let i=rt(e,t);i<0||n.push({start:r.index,open:t,close:i})}return n}function st(e,t){let n=ot(e);if(n.length===0)return null;let r=n.find(t=>/\beager\s*:\s*true\b/.test(e.slice(t.open,t.close+1)))??n[0],i=e.slice(r.start,r.close+1),a=new Set(Se(i).map(e=>e.startsWith(`!`)?e.slice(1):e)),o=t.filter(e=>!a.has(e));if(o.length===0)return null;let s=o.map(e=>`'${e}'`).join(`, `),c=it(e,`[`,r.open,r.close);if(c>=0){let t=at(e,c);if(t<0||t>r.close)return null;let n=e.slice(0,t);return n+(/[[,]\s*$/.test(n)?``:`, `)+s+e.slice(t)}let l=/(['"`])((?:\\.|(?!\1).)*)\1/,u=e.slice(r.open+1,r.close),d=l.exec(u);if(!d)return null;let f=r.open+1+d.index,p=f+d[0].length;return e.slice(0,f)+`[${d[0]}, ${s}]`+e.slice(p)}const Q="/* eslint-disable */\n// AUTO-GENERATED by `kick typegen`. DO NOT EDIT.\n// Re-run with `kick typegen` or rely on `kick dev` to refresh.\n",ct=/* @__PURE__ */ new Set([`Service`,`Repository`,`Injectable`,`Component`]);var lt=class extends Error{collisions;constructor(e){super(ut(e)),this.name=`TokenCollisionError`,this.collisions=e}};function ut(e){let t=[`kick typegen: token collision detected`];for(let n of e){t.push(``),t.push(` ${n.classes.length} classes named '${n.className}':`);for(let e of n.classes)t.push(` - ${e.relativePath}`)}return t.push(``),t.push(`Resolutions:`),t.push(` (a) Rename one of the classes`),t.push(` (b) Use createToken<T>('namespaced/Name') and import the token explicitly — see @forinda/kickjs`),t.push(` (c) Pass --allow-duplicates to namespace the registry keys automatically`),t.push(` (e.g. 'modules/users/UserService' instead of 'UserService')`),t.join(`
|
|
11
|
+
import{t as e}from"./rolldown-runtime-CYy3EyO3.mjs";import{statSync as t}from"node:fs";import{basename as n,dirname as r,join as i,relative as a,resolve as o,sep as s}from"node:path";import{mkdir as c,readFile as l,readdir as u,stat as d,unlink as f,writeFile as p}from"node:fs/promises";import{parseSync as m}from"oxc-parser";import{globSync as h}from"glob";import{groupAssetKeys as g}from"@forinda/kickjs";const _=[`classes`,`tokens`,`injects`,`pluginsAndAdapters`,`contextKeys`,`routeFlags`,`routes`,`moduleMounts`,`globPatterns`];function v(e){if(!e||typeof e!=`object`)return!1;let t=e;return _.every(e=>Array.isArray(t[e]))}var y=class e{path;prev;next=/* @__PURE__ */ new Map;nextSig=/* @__PURE__ */ new Map;constructor(e,t){this.path=e,this.prev=t}static async load(t){let n=i(t,`scan.json`),r=/* @__PURE__ */ new Map;try{let e=await l(n,`utf-8`),t=JSON.parse(e);if(t.version===3&&t.files)for(let[e,n]of Object.entries(t.files))n&&typeof n.sig==`string`&&v(n.extract)&&r.set(e,n)}catch{}return new e(n,r)}static async signature(e){try{let t=await d(e);return`${t.mtimeMs}:${t.size}`}catch{return null}}get(e,t){let n=this.prev.get(e);return n&&n.sig===t?n.extract:null}set(e,t,n){this.next.set(e,n),this.nextSig.set(e,t)}cachedFiles(){return[...this.prev.keys()]}peek(e){return this.prev.get(e)?.extract??null}carry(e){let t=this.prev.get(e);return t?(this.next.set(e,t.extract),this.nextSig.set(e,t.sig),!0):!1}async save(){let e={};for(let[t,n]of this.next){let r=this.nextSig.get(t);r&&(e[t]={sig:r,extract:n})}let t={version:3,files:e};try{await c(r(this.path),{recursive:!0}),await p(this.path,JSON.stringify(t),`utf-8`)}catch{}}};let b=null;function ee(){return b??=new Set(L),b}const x=/* @__PURE__ */ new Set([`Get`,`Post`,`Put`,`Delete`,`Patch`]);function S(e){return typeof e==`object`&&!!e&&typeof e.type==`string`}function C(e,t){if(Array.isArray(e))for(let n of e)C(n,t);else if(S(e)){t(e);for(let n of Object.keys(e)){if(n===`type`)continue;let r=e[n];typeof r==`object`&&r&&C(r,t)}}}function w(e){if(!S(e))return null;if(e.type===`Literal`&&typeof e.value==`string`)return e.value;if(e.type===`TemplateLiteral`){let t=e.quasis,n=e.expressions;if(t?.length===1&&(n?.length??0)===0){let e=t[0].value?.cooked;return typeof e==`string`?e:null}}return null}function T(e){return S(e)&&e.type===`Identifier`?e.name:null}function E(e){return T(e.callee)}function D(e,t){if(!e||e.type!==`ObjectExpression`)return null;for(let n of e.properties??[]){if(n.type!==`Property`)continue;let e=n.key;if((T(e)??(e.type===`Literal`?String(e.value):w(e)))===t)return n.value}return null}function O(e){let t=e.arguments?.[0];return S(t)&&t.type===`ObjectExpression`?t:null}function k(e,t){let n=D(e,t);if(!S(n)||n.type!==`ArrayExpression`)return[];let r=[];for(let e of n.elements??[]){let t=w(e);t!==null&&r.push(t)}return r}function te(e,t){return a(t,e).split(s).join(`/`)}function ne(e){return(e.match(/:([a-zA-Z_]\w*)/g)??[]).map(e=>e.slice(1))}function re(e,t){for(let n of e.implements??[]){let e=n.expression??n;if(T(e)===t)return!0;if(e.type===`TSQualifiedName`||e.type===`MemberExpression`){let n=e.right??e.property;if(n&&T(n)===t)return!0}}return!1}function A(e){return e.decorators??[]}function j(e){let t=e.expression;if(!S(t)||t.type!==`CallExpression`)return null;let n=E(t);return n?{name:n,call:t}:null}function ie(e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Set;for(let i of e.body??[]){if(i.type===`ExportNamedDeclaration`&&!i.source)for(let e of i.specifiers??[]){let t=T(e.local);t&&t===T(e.exported)&&r.add(t)}if(i.type===`ImportDeclaration`){let e=w(i.source)??``;for(let n of i.specifiers??[]){let r=T(n.local);r&&t.set(r,{source:e})}continue}let e=i.type===`VariableDeclaration`?i:i.type===`ExportNamedDeclaration`&&S(i.declaration)?i.declaration:null;if(S(e)&&e.type===`VariableDeclaration`)for(let t of e.declarations??[]){let a=T(t.id);a&&n.add(a),a&&i!==e&&r.add(a)}}return{imports:t,topLevelConsts:n,exported:r}}function M(e,t){let n=t.imports.get(e);return n?{identifier:e,source:n.source}:t.topLevelConsts.has(e)?t.exported.has(e)?{identifier:e,source:``}:{identifier:e,source:null,unexported:!0}:{identifier:e,source:null}}function ae(e,t){let n=[];for(let r of e){let e=j(r),i=e?e.name:T(r.expression);if(!i||x.has(i))continue;let a=t.imports.get(i);n.push({identifier:i,source:a?a.source:t.topLevelConsts.has(i)?``:null})}return n}const N=/* @__PURE__ */ new Set([`bootstrap`,`createWebApp`,`Application`]);function oe(e,t){if(!N.has(e))return!1;let n=t.imports.get(e)?.source;return n===`@forinda/kickjs`||(n?.startsWith(`@forinda/kickjs/`)??!1)}function se(e,t){let n={refs:[],resolved:!1},r=P(e);if(!r||r.type!==`ArrayExpression`)return n;let i=[];for(let e of r.elements??[]){if(!S(e)||e.type!==`MemberExpression`||T(e.property)!==`registration`)return n;let r=e.object,a=T(r);if(!a&&S(r)&&r.type===`CallExpression`){let e=r.callee;S(e)&&e.type===`MemberExpression`&&T(e.property)===`with`&&(a=T(e.object))}if(!a)return n;let o=t.imports.get(a);i.push({identifier:a,source:o?o.source:t.topLevelConsts.has(a)?``:null})}return{refs:i,resolved:!0}}function P(e){let t=e.value??e;if(!S(t))return null;if(t.type===`ArrayExpression`)return t;let n=t.body;if(!S(n))return null;if(n.type!==`BlockStatement`)return n;let r=(n.body??[]).filter(e=>e.type===`ReturnStatement`);if(r.length!==1)return null;let i=r[0].argument;return S(i)?i:null}function F(e,t,n){let r=T(D(e,t));return r?M(r,n):null}function ce(e,t){for(let n of e){let e=j(n);if(!e||e.name!==`ApiQueryParams`)continue;let r=e.call.arguments?.[0],i=null;if(S(r)&&r.type===`ObjectExpression`)i=r;else{let e=T(r);if(e){let n=t.get(e);n&&n.type===`ObjectExpression`&&(i=n)}}return{filterable:k(i,`filterable`),sortable:k(i,`sortable`),searchable:k(i,`searchable`)}}return null}function I(e,t,n){let r;try{let n=m(t,e);if(n.errors.length>0)return null;r=n.program}catch{return null}let i=te(t,n),a=ie(r),o=[],s=[],c=[],l=[],u=[],d=[],f=/* @__PURE__ */ new Set,p=[],h=[],g=[],_=/* @__PURE__ */ new Set,v=/* @__PURE__ */ new Set,y=/* @__PURE__ */ new Map;C(r,e=>{if(e.type!==`VariableDeclarator`)return;let t=T(e.id),n=e.init;t&&S(n)&&y.set(n,t)});let b=/* @__PURE__ */ new Set,k=/* @__PURE__ */ new Map;for(let e of r.body??[]){let t=e.type===`VariableDeclaration`?e:e.type===`ExportNamedDeclaration`&&S(e.declaration)?e.declaration:null;if(S(t)&&t.type===`VariableDeclaration`)for(let e of t.declarations??[]){let t=T(e.id);t&&S(e.init)&&k.set(t,e.init)}}let M=[];for(let e of r.body??[])if(e.type===`ExportNamedDeclaration`&&S(e.declaration)){let t=e.declaration;t.type===`ClassDeclaration`&&M.push({cls:t,isDefault:!1})}else if(e.type===`ExportDefaultDeclaration`&&S(e.declaration)){let t=e.declaration;t.type===`ClassDeclaration`&&M.push({cls:t,isDefault:!0})}for(let{cls:e,isDefault:n}of M){let r=T(e.id);if(!r)continue;let a=null;for(let t of A(e)){let e=j(t);if(e&&ee().has(e.name)){a=e.name;break}}a?o.push({className:r,decorator:a,filePath:t,relativePath:i,isDefault:n}):re(e,`AppModule`)&&o.push({className:r,decorator:`Module`,filePath:t,relativePath:i,isDefault:n})}for(let e of r.body??[]){if(e.type!==`ExportNamedDeclaration`||!S(e.declaration))continue;let n=e.declaration;if(n.type===`VariableDeclaration`)for(let e of n.declarations??[]){let n=T(e.id),r=e.init;n&&S(r)&&r.type===`CallExpression`&&E(r)===`defineModule`&&(o.some(e=>e.className===n)||o.push({className:n,decorator:`Module`,filePath:t,relativePath:i,isDefault:!1}))}}C(r,n=>{if(n.type===`VariableDeclarator`){let e=n.init;if(S(e)&&e.type===`CallExpression`&&E(e)===`createToken`){let r=w(e.arguments?.[0]);r!==null&&(b.add(e),s.push({name:r,variable:T(n.id),filePath:t,relativePath:i}))}return}if(n.type!==`CallExpression`){if(n.type===`Decorator`){let e=j(n);if(e?.name===`Inject`){let n=w(e.call.arguments?.[0]);n!==null&&c.push({name:n,filePath:t,relativePath:i})}}return}let r=n.callee,a=E(n);if(a===`createToken`&&!b.has(n)){let e=w(n.arguments?.[0]);e!==null&&s.push({name:e,variable:null,filePath:t,relativePath:i})}else if(a===`defineAdapter`||a===`definePlugin`){let e=w(D(O(n),`name`));if(e!==null){let n=a===`definePlugin`?`plugin`:`adapter`,r=`${a}::${e}::${t}`;_.has(r)||(_.add(r),l.push({kind:n,name:e,filePath:t,relativePath:i}))}}else if(a===`defineRouteFlag`){let r=w(n.arguments?.[0]);if(r!==null&&!f.has(r)){f.add(r);let a=n.typeArguments,o=a?e.slice(a.start,a.end):null;d.push({name:r,valueType:o?o.slice(1,-1).trim():null,filePath:t,relativePath:i})}}else if(a===`defineContextDecorator`||a===`defineHttpContextDecorator`){let e=w(D(O(n),`key`));e!==null&&!v.has(e)&&(v.add(e),u.push({key:e,exportName:y.get(n)??null,filePath:t,relativePath:i}))}else if(S(r)&&r.type===`CallExpression`){let e=r.callee;if(S(e)&&e.type===`MemberExpression`&&T(e.property)===`withParams`){let r=T(e.object);if(r===`defineContextDecorator`||r===`defineHttpContextDecorator`){let e=w(D(O(n),`key`));e!==null&&!v.has(e)&&(v.add(e),u.push({key:e,exportName:y.get(n)??null,filePath:t,relativePath:i}))}}}else if(S(r)&&r.type===`MemberExpression`&&T(r.property)===`glob`){let e=r.object;S(e)&&e.type===`MetaProperty`&&C(n.arguments,e=>{let t=w(e);t!==null&&g.push(t)})}});let N=[];C(r,e=>{if(e.type===`ClassDeclaration`||e.type===`ClassExpression`){let t=T(e.id);t&&N.push({cls:e,className:t})}});for(let{cls:e,className:n}of N){let r=o.find(e=>e.className===n),s=e.body?.body;if(re(e,`AppAdapter`))for(let e of s??[]){if(e.type!==`PropertyDefinition`||T(e.key)!==`name`)continue;let n=w(e.value);if(n===null)continue;let r=`class::${n}::${t}`;_.has(r)||(_.add(r),l.push({kind:`adapter`,name:n,filePath:t,relativePath:i}));break}for(let o of s??[]){if(o.type!==`MethodDefinition`)continue;let s=T(o.key);if(!s)continue;if(s===`routes`){le(o.value,h);continue}if(!r)continue;let c=A(o),l=ce(c,k),u=[...ae(A(e),a),...ae(c,a)];for(let e of c){let o=j(e);if(!o||!x.has(o.name))continue;let c=o.call.arguments??[],d=w(c[0]),f=d&&d.length>0?d:`/`,m=S(c[1])&&c[1].type===`ObjectExpression`?c[1]:null;p.push({controller:n,method:s,httpMethod:o.name.toUpperCase(),path:f,pathParams:ne(f),queryFilterable:l?.filterable??null,querySortable:l?.sortable??null,querySearchable:l?.searchable??null,bodySchema:F(m,`body`,a),querySchema:F(m,`query`,a),paramsSchema:F(m,`params`,a),responseSchema:F(m,`response`,a),filePath:t,relativePath:i,controllerIsDefaultExport:r.isDefault,appliedDecorators:u,mountedPath:f})}}}C(r,e=>{if(e.type!==`Property`||T(e.key)!==`routes`)return;let t=e.value;S(t)&&(t.type===`FunctionExpression`||t.type===`ArrowFunctionExpression`)&&le(t,h)});let P=/* @__PURE__ */ new Set,I=/* @__PURE__ */ new Set;C(r,e=>{let t=e.type===`Property`&&T(e.key)===`contributors`,n=e.type===`MethodDefinition`&&T(e.key)===`contributors`;(t||n)&&I.add(e)});let L=e=>e.properties??e.body?.body??[];C(r,e=>{if(e.type!==`ObjectExpression`&&e.type!==`ClassDeclaration`)return;let t=L(e);if(t.map(e=>T(e.key)).includes(`routes`))for(let e of t)T(e.key)===`contributors`&&P.add(e)});let R=/* @__PURE__ */ new Set;C(r,e=>{let t=e.type===`CallExpression`?E(e):e.type===`NewExpression`?T(e.callee):null;if(t===null||!oe(t,a))return;let n=O(e);if(n)for(let e of n.properties??[])e.type===`Property`&&T(e.key)===`contributors`&&R.add(e)});let z=e=>{if(e.size===0)return null;let n=[],r=!0;for(let t of e){let e=se(t,a);e.resolved||(r=!1),n.push(...e.refs)}return{refs:n,resolved:r,filePath:t}},B=z(P),V=z(R);return{classes:o,tokens:s,injects:c,pluginsAndAdapters:l,contextKeys:u,routeFlags:d,routes:p,moduleMounts:h,globPatterns:/\.module\.[mc]?[tj]sx?$/.test(t)?g:[],moduleContributors:B,appContributors:V,hasNonDecoratorContributors:I.size>P.size+R.size}}function le(e,t){let n=[],r=[];C(e.body,e=>{if(e.type!==`Property`)return;let t=T(e.key);if(t===`path`){let t=w(e.value);t!==null&&n.push(t)}else if(t===`controller`){let t=T(e.value);t&&/^[A-Z]/.test(t)&&r.push(t)}});let i=Math.min(n.length,r.length);for(let e=0;e<i;e++)t.push({controller:r[e],mountPath:n[e]})}const L=[`Service`,`Controller`,`Repository`,`Injectable`,`Component`,`Module`],R=[`.ts`,`.tsx`,`.mts`,`.cts`],z=[`node_modules`,`.kickjs`,`dist`,`build`,`.test.`,`.spec.`,`.d.ts`],B=new RegExp(String.raw`@(${L.join(`|`)})\s*\([^)]*\)`+String.raw`(?:\s*@[A-Z]\w*(?:\s*\([^)]*\))?)*`+String.raw`\s*export\s+(default\s+)?(?:abstract\s+)?class\s+(\w+)`,`g`),V=new RegExp(String.raw`export\s+(default\s+)?(?:abstract\s+)?class\s+(\w+)`+String.raw`(?:\s+extends\s+\w+(?:<[^>]*>)?)?`+String.raw`\s+implements\s+[^{]*\bAppModule\b`,`g`),ue=/export\s+const\s+(\w+)\s*(?::\s*[^=]+)?=\s*defineModule\s*(?:<[^>]*>)?\s*\(/g,de=/(?:export\s+)?const\s+(\w+)\s*(?::\s*[^=]+)?=\s*createToken\s*(?:<[^>]*>)?\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g,fe=/createToken\s*(?:<[^>]*>)?\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g,pe=/@Inject\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g,H=/\b(defineAdapter|definePlugin)\s*(?:<[^>]*>)?\s*\(/g,U=/(?:(?:export\s+)?(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::[^=]+)?=\s*)?\b(?:defineContextDecorator|defineHttpContextDecorator)\s*(?:\.withParams\s*<(?:[^<>]|<[^<>]*>)*>\s*\(\s*\))?\s*(?:<(?:[^<>]|<[^<>]*>)*>)?\s*\(/g,me=new RegExp(String.raw`export\s+(?:default\s+)?(?:abstract\s+)?class\s+(\w+)`+String.raw`(?:\s+extends\s+\w+(?:<[^>]*>)?)?`+String.raw`\s+implements\s+[^{]*\bAppAdapter\b`,`g`),he=/\bname\s*(?::\s*[^=]+)?=\s*['"`]([^'"`]+)['"`]/,W=new RegExp(String.raw`@(${[`Get`,`Post`,`Put`,`Delete`,`Patch`].join(`|`)})\s*\(`,`g`);function G(e,t){let n=1;for(let r=t+1;r<e.length;r++){let t=e[r];if(t===`(`)n++;else if(t===`)`&&(n--,n===0))return r}return-1}function ge(e,t){let n=t;for(;n<e.length;){for(;n<e.length&&/\s/.test(e[n]);)n++;if(e[n]!==`@`)break;let t=e.slice(n).match(/^@([A-Z]\w*)/);if(!t)break;for(n+=t[0].length;n<e.length&&/\s/.test(e[n]);)n++;if(e[n]===`(`){let t=G(e,n);if(t<0)return null;n=t+1}}for(;n<e.length&&/\s/.test(e[n]);)n++;for(let t of[`public`,`private`,`protected`])if(e.slice(n,n+t.length)===t&&/\s/.test(e.charAt(n+t.length))){for(n+=t.length;n<e.length&&/\s/.test(e[n]);)n++;break}if(e.slice(n,n+5)===`async`&&/\s/.test(e.charAt(n+5)))for(n+=5;n<e.length&&/\s/.test(e[n]);)n++;let r=e.slice(n).match(/^([a-zA-Z_]\w*)\s*\(/);return r?{methodName:r[1],endPos:n+r[0].length}:null}function _e(e){return(e.match(/:([a-zA-Z_]\w*)/g)??[]).map(e=>e.slice(1))}function ve(e,t){let n=e.endsWith(`/`)?e.slice(0,-1):e;return!t||t===`/`?n||`/`:n+(t.startsWith(`/`)?t:`/`+t)||`/`}const ye=/\b(?:public\s+|private\s+|protected\s+)?routes\s*\([^)]*\)\s*(?::\s*[A-Za-z_][\w<>[\]\s,|]*\s*)?\{/g,be=/\bpath\s*:\s*['"`]([^'"`]*)['"`]/g,xe=/\bcontroller\s*:\s*([A-Z]\w*)\b/g,K=/\bimport\.meta\.glob\s*\(/g;function Se(e){let t=[];for(K.lastIndex=0;K.exec(e)!==null;){let n=K.lastIndex-1,r=G(e,n);if(r<0)continue;let i=e.slice(n+1,r),a=/['"`]([^'"`]+)['"`]/g,o;for(;(o=a.exec(i))!==null;)t.push(o[1])}return t}function Ce(e){let t=e.replace(/[.+^$()|[\]\\]/g,`\\$&`).replace(/\?/g,`.`).replace(/\*\*\//g,`___DOUBLESTAR_SLASH___`).replace(/\*\*/g,`___DOUBLESTAR___`).replace(/\*/g,`[^/]*`).replace(/___DOUBLESTAR_SLASH___/g,`(?:.+/)?`).replace(/___DOUBLESTAR___/g,`.*`);return RegExp(`^`+t+`$`)}function we(e,t){let n=e.startsWith(`./`)?e:`./`+e,r=!1;for(let e of t){let t=e.startsWith(`!`);Ce(t?e.slice(1):e).test(n)&&(r=!t)}return r}function Te(e){let t=[];ye.lastIndex=0;let n;for(;(n=ye.exec(e))!==null;){let r=e.indexOf(`{`,n.index+n[0].length-1);if(r<0)continue;let i=Ie(e,r);if(i<0)continue;let a=e.slice(r+1,i),o=[];be.lastIndex=0;let s;for(;(s=be.exec(a))!==null;)o.push(s[1]??``);let c=[];xe.lastIndex=0;let l;for(;(l=xe.exec(a))!==null;)c.push(l[1]);let u=Math.min(o.length,c.length);for(let e=0;e<u;e++)t.push({controller:c[e],mountPath:o[e]})}return t}function q(e,t){let n=new RegExp(String.raw`\b${t}\s*:\s*([A-Za-z_$][\w$]*)`,`g`).exec(e);return n?n[1]:null}function J(e,t){let n=Ee(e,t);return n===null?new RegExp(String.raw`(?:^|\n)\s*const\s+${t}\b`).test(e)?{identifier:t,source:null,unexported:!0}:{identifier:t,source:null}:{identifier:t,source:n}}function Ee(e,t){let n=new RegExp(String.raw`import\s*(?:type\s+)?\{[^}]*\b${t}\b[^}]*\}\s*from\s*['"\`]([^'"\`]+)['"\`]`).exec(e);if(n)return n[1];let r=new RegExp(String.raw`import\s+(?:type\s+)?${t}\s+from\s*['"\`]([^'"\`]+)['"\`]`).exec(e);if(r)return r[1];let i=new RegExp(String.raw`import\s*\*\s*as\s+${t}\s+from\s*['"\`]([^'"\`]+)['"\`]`).exec(e);return i?i[1]:new RegExp(String.raw`(?:^|\n)\s*export\s+const\s+${t}\b|export\s*\{[^}]*(?<!\bas\s+)\b${t}\b(?!\s+as\b)[^}]*\}(?!\s*from)`).test(e)?``:null}function De(e,t){let n=/@ApiQueryParams\s*\(\s*([\s\S]*?)\s*\)\s*$/.exec(e);if(!n){let n=/@ApiQueryParams\s*\(([\s\S]*?)\)/.exec(e);return n?Oe(n[1].trim(),t):null}return Oe(n[1].trim(),t)}function Oe(e,t){if(e.startsWith(`{`))return Ae(e);let n=/^([A-Za-z_]\w*)/.exec(e);if(n){let e=n[1],r=new RegExp(String.raw`const\s+${e}\s*(?::\s*[^=]+)?=\s*(\{[\s\S]*?\n\})`,`m`).exec(t);if(r)return Ae(r[1])}return{filterable:[],sortable:[],searchable:[]}}function ke(e,t){let n=new RegExp(String.raw`${t}\s*:\s*\[([\s\S]*?)\]`).exec(e);return n?Array.from(n[1].matchAll(/['"`]([^'"`]+)['"`]/g)).map(e=>e[1]):[]}function Ae(e){return{filterable:ke(e,`filterable`),sortable:ke(e,`sortable`),searchable:ke(e,`searchable`)}}async function je(e,t){let n=t.extensions??R,r=t.exclude??z,o=[],s;try{s=await u(e,{withFileTypes:!0,encoding:`utf-8`})}catch{return o}for(let c of s){let s=i(e,c.name),l=a(t.cwd,s);r.some(e=>l.includes(e))||(c.isDirectory()?o.push(...await je(s,t)):c.isFile()&&n.some(e=>c.name.endsWith(e))&&o.push(s))}return o}function Y(e,t){return a(t,e).split(s).join(`/`)}function Me(e,t,n){let r=[],i=Y(t,n);B.lastIndex=0;let a;for(;(a=B.exec(e))!==null;){let[,e,n,o]=a;r.push({className:o,decorator:e,filePath:t,relativePath:i,isDefault:!!n})}V.lastIndex=0;let o;for(;(o=V.exec(e))!==null;){let[,e,n]=o;r.some(e=>e.className===n&&e.filePath===t)||r.push({className:n,decorator:`Module`,filePath:t,relativePath:i,isDefault:!!e})}ue.lastIndex=0;let s;for(;(s=ue.exec(e))!==null;){let[,e]=s;r.some(n=>n.className===e&&n.filePath===t)||r.push({className:e,decorator:`Module`,filePath:t,relativePath:i,isDefault:!1})}return r}function Ne(e,t,n){let r=[],i=Y(t,n),a=/* @__PURE__ */ new Set;de.lastIndex=0;let o;for(;(o=de.exec(e))!==null;){let[e,n,s]=o;a.add(e),r.push({name:s,variable:n,filePath:t,relativePath:i})}for(fe.lastIndex=0;(o=fe.exec(e))!==null;)a.has(o[0])||r.push({name:o[1],variable:null,filePath:t,relativePath:i});return r}function Pe(e,t,n,r,i=/* @__PURE__ */ new Map){let a=[];if(r.length===0)return a;let o=Y(t,n),s=[];for(let t of r){let n=new RegExp(String.raw`class\s+${t.className}\b`).exec(e);n?.index!==void 0&&s.push({cls:t,start:n.index})}s.sort((e,t)=>e.start-t.start);for(let n=0;n<s.length;n++){let{cls:r,start:c}=s[n],l=n+1<s.length?s[n+1].start:e.length,u=e.slice(c,l);W.lastIndex=0;let d;for(;(d=W.exec(u))!==null;){let n=d[1],s=d.index,c=W.lastIndex-1,l=G(u,c);if(l<0)continue;let f=u.slice(c+1,l),p=f.match(/^\s*['"`]([^'"`]*)['"`]/),m=p&&p[1].length>0?p[1]:`/`,h=ge(u,l+1);if(!h)continue;let{methodName:g,endPos:_}=h;W.lastIndex=_;let v=De(u.slice(s,_),e),y=q(f,`body`),b=q(f,`query`),ee=q(f,`params`),x=q(f,`response`),S=i.get(r.className)??``,C=S?ve(S,m):m;a.push({controller:r.className,method:g,httpMethod:n.toUpperCase(),path:m,pathParams:_e(C),queryFilterable:v?.filterable??null,querySortable:v?.sortable??null,querySearchable:v?.searchable??null,bodySchema:y?J(e,y):null,querySchema:b?J(e,b):null,paramsSchema:ee?J(e,ee):null,responseSchema:x?J(e,x):null,filePath:t,relativePath:o,controllerIsDefaultExport:r.isDefault,mountedPath:C})}}return a}function Fe(e,t,n){let r=[],i=Y(t,n);pe.lastIndex=0;let a;for(;(a=pe.exec(e))!==null;)r.push({name:a[1],filePath:t,relativePath:i});return r}function Ie(e,t){let n=1;for(let r=t+1;r<e.length;r++){let t=e[r];if(t===`{`)n++;else if(t===`}`&&(n--,n===0))return r}return-1}function Le(e,t,n){let r=[],i=Y(t,n),a=/* @__PURE__ */ new Set;H.lastIndex=0;let o;for(;(o=H.exec(e))!==null;){let n=o[1],s=H.lastIndex-1,c=G(e,s);if(c<0)continue;let l=e.slice(s+1,c),u=/\bname\s*:\s*['"`]([^'"`]+)['"`]/.exec(l);if(!u)continue;let d=u[1],f=`${n}::${d}::${t}`;a.has(f)||(a.add(f),r.push({kind:n===`definePlugin`?`plugin`:`adapter`,name:d,filePath:t,relativePath:i}))}me.lastIndex=0;let s;for(;(s=me.exec(e))!==null;){let n=s.index,o=e.indexOf(`{`,n);if(o<0)continue;let c=Ie(e,o);if(c<0)continue;let l=e.slice(o+1,c),u=he.exec(l);if(!u)continue;let d=u[1],f=`class::${d}::${t}`;a.has(f)||(a.add(f),r.push({kind:`adapter`,name:d,filePath:t,relativePath:i}))}return r}function Re(e,t,n){let r=[],i=Y(t,n),a=/* @__PURE__ */ new Set;U.lastIndex=0;let o;for(;(o=U.exec(e))!==null;){let n=U.lastIndex-1,s=G(e,n);if(s<0)continue;let c=e.slice(n+1,s),l=/\bkey\s*:\s*['"`]([^'"`]+)['"`]/.exec(c);if(!l)continue;let u=l[1];a.has(u)||(a.add(u),r.push({key:u,exportName:o[1]??null,filePath:t,relativePath:i}))}return r}const ze=[`src/config/index.ts`,`src/config/env.ts`,`src/config.ts`,`src/env.ts`];async function Be(e,t){let n=t===`src/env.ts`?ze:[t];for(let t of n){let n=o(e,t),r;try{r=await l(n,`utf-8`)}catch{continue}if((/\bdefineEnv\s*\(/.test(r)||/\bfrom(Zod|Valibot|Yup)\s*\(/.test(r))&&/export\s+default\b/.test(r)&&!/export\s+default\s+loadEnvFromSchema\s*\(/.test(r))return{filePath:n,relativePath:Y(n,e)}}return null}function Ve(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=t.get(n.className)??[];e.push(n),t.set(n.className,e)}let n=[];for(let[e,r]of t)new Set(r.map(e=>e.filePath)).size>1&&n.push({className:e,classes:r});return n.sort((e,t)=>e.className.localeCompare(t.className)),n}const He=/* @__PURE__ */ new Set([`Controller`,`Service`,`Repository`,`Injectable`,`Component`,`Module`,`Middleware`,`ApiQueryParams`,`Public`,`Roles`,`Cron`,`Cacheable`,`CacheEvict`,`FileUpload`,`Asset`,`Builder`,`PostConstruct`,`PreDestroy`,`Value`,`Inject`,`Autowired`]);function X(e){return e.split(s).join(`/`).replace(/\.[mc]?[tj]sx?$/,``)}function Ue(e,t,n){let i=X(n);if(t===``)return i===X(e);if(t.startsWith(`.`)){let n=X(o(r(e),t));return i===n||i===`${n}/index`}let a=t.replace(/^[@~#]\//,``);if(a===t&&t.startsWith(`@`))return!1;let s=X(a);return i===s||i.endsWith(`/${s}`)}function We(e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map;for(let t of e)if(t)for(let{controller:e}of t.moduleMounts)n.set(e,(n.get(e)??0)+1);for(let r of e)if(r?.moduleContributors)for(let{controller:e}of r.moduleMounts){if((n.get(e)??0)>1){t.set(e,`ambiguous`);continue}let i=t.get(e);t.set(e,i===void 0?r.moduleContributors:`ambiguous`)}return t}function Ge(e,t,n,r=/* @__PURE__ */ new Map,i=[]){if(n){for(let t of e)t.contextKeys=null;return}let a=/* @__PURE__ */ new Map;for(let e of t){if(!e.exportName)continue;let t=a.get(e.exportName);t?t.push(e):a.set(e.exportName,[e])}for(let t of e){let e=t.appliedDecorators;if(!e){t.contextKeys=null;continue}let n=/* @__PURE__ */ new Set,o=!0,s=(e,t)=>{if(t.source===null)return null;let n=(a.get(t.identifier)??[]).filter(n=>Ue(e,t.source,n.filePath));return n.length===1?n[0].key:null};for(let r of e){if(He.has(r.identifier))continue;let e=s(t.filePath,r);if(e===null){o=!1;break}n.add(e)}if(o)for(let e of i){if(!e.resolved){o=!1;break}for(let t of e.refs){let r=s(e.filePath,t);if(r===null){o=!1;break}n.add(r)}if(!o)break}if(o){let e=r.get(t.controller);if(e===`ambiguous`)o=!1;else if(e){if(!e.resolved)o=!1;else for(let t of e.refs){let r=s(e.filePath,t);if(r===null){o=!1;break}n.add(r)}}}t.contextKeys=o?[...n].toSorted():null}}const Ke=/\bcontributors\s*(?::|\()/;function qe(e,t,n){return I(e,t,n)||{...Je(e,t,n),hasNonDecoratorContributors:Ke.test(e)}}function Je(e,t,n){let r=Me(e,t,n);return{classes:r,tokens:Ne(e,t,n),injects:Fe(e,t,n),pluginsAndAdapters:Le(e,t,n),routeFlags:[],contextKeys:Re(e,t,n),routes:Pe(e,t,n,r,/* @__PURE__ */ new Map),moduleMounts:Te(e),globPatterns:/\.module\.[mc]?[tj]sx?$/.test(t)?Se(e):[],hasNonDecoratorContributors:!1}}async function Ye(e,t,n){let r=n?await y.signature(e):null;if(n&&r){let t=n.get(e,r);if(t)return n.set(e,r,t),t}let i;try{i=await l(e,`utf-8`)}catch{return null}let a=qe(i,e,t);return n&&r&&n.set(e,r,a),a}async function Xe(e,t,n){let r=[],i=0,a=Array.from({length:Math.min(t,e.length)},async()=>{for(;;){let t=i++;if(t>=e.length)return;r[t]=await n(e[t],t)}});return await Promise.all(a),r}async function Z(e){let t=(await je(o(e.root),e)).toSorted(),n=e.cacheDir?await y.load(e.cacheDir):null,r=$e(t,await Xe(t,16,t=>Ye(t,e.cwd,n))),i=await Be(e.cwd,e.envFile??`src/env.ts`);return n&&await n.save(),{...r,env:i}}function Ze(e,t,n){let r=n.extensions??R,i=n.exclude??z;if(!e.startsWith(t+s)&&e!==t||!r.some(t=>e.endsWith(t)))return!1;let o=a(n.cwd,e);return!i.some(e=>o.includes(e))}async function Qe(e,t){if(!e.cacheDir)return Z(e);let n=o(e.root),r=await y.load(e.cacheDir),i=r.cachedFiles();if(i.length===0)return Z(e);let a=new Set(t.removed.map(t=>o(e.cwd,t))),s=t.changed.map(t=>o(e.cwd,t)).filter(t=>!a.has(t)&&Ze(t,n,e)),c=new Set(s),u=new Set(i);for(let e of c)u.add(e);for(let e of a)u.delete(e);let d=/* @__PURE__ */ new Map;await Xe(s,16,async t=>{if(!u.has(t))return;let n=await y.signature(t),i;try{i=await l(t,`utf-8`)}catch{u.delete(t);return}let a=qe(i,t,e.cwd);d.set(t,a),n&&r.set(t,n,a)});let f=[...u].toSorted(),p=$e(f,f.map(e=>d.get(e)||(r.carry(e),r.peek(e)))),m=await Be(e.cwd,e.envFile??`src/env.ts`);return await r.save(),{...p,env:m}}function $e(e,t){let n=[],r=[],i=[],a=[],o=[],c=[],l=[],u=/* @__PURE__ */ new Map;for(let e of t)if(e)for(let{controller:t,mountPath:n}of e.moduleMounts)u.has(t)||u.set(t,n);let d=/* @__PURE__ */ new Map;for(let s=0;s<e.length;s++){let f=t[s];if(f){n.push(...f.classes),i.push(...f.tokens),a.push(...f.injects),o.push(...f.pluginsAndAdapters),c.push(...f.contextKeys),l.push(...f.routeFlags),f.globPatterns.length>0&&d.set(e[s],f.globPatterns);for(let e of f.routes){let t=u.get(e.controller);if(t){let n=ve(t,e.path);r.push({...e,pathParams:_e(n),mountedPath:n})}else r.push({...e,mountedPath:e.mountedPath??e.path})}}}Ge(r,c,t.some(e=>e?.hasNonDecoratorContributors===!0),We(t),t.flatMap(e=>e?.appContributors?[e.appContributors]:[]));let f=[];for(let[e,t]of d){if(!/\.module\.[mc]?[tj]sx?$/.test(e)||t.length===0)continue;let r=e.replaceAll(s,`/`),i=r.slice(0,r.lastIndexOf(`/`));for(let a of n){if(a.decorator===`Module`)continue;let n=a.filePath.replaceAll(s,`/`);n.startsWith(i+`/`)&&n!==r&&(we(n.slice(i.length+1),t)||f.push({className:a.className,filePath:a.filePath,relativePath:a.relativePath,moduleFilePath:e,decorator:a.decorator}))}}n.sort((e,t)=>e.className===t.className?e.relativePath.localeCompare(t.relativePath):e.className.localeCompare(t.className)),i.sort((e,t)=>e.name.localeCompare(t.name)||e.relativePath.localeCompare(t.relativePath)),a.sort((e,t)=>e.name.localeCompare(t.name)||e.relativePath.localeCompare(t.relativePath)),r.sort((e,t)=>e.controller.localeCompare(t.controller)||e.method.localeCompare(t.method)),o.sort((e,t)=>e.name.localeCompare(t.name)||e.relativePath.localeCompare(t.relativePath)),c.sort((e,t)=>e.key.localeCompare(t.key)||e.relativePath.localeCompare(t.relativePath));let p=Ve(n);return f.sort((e,t)=>e.relativePath.localeCompare(t.relativePath)||e.className.localeCompare(t.className)),{classes:n,routes:r,tokens:i,injects:a,collisions:p,pluginsAndAdapters:o,contextKeys:c,routeFlags:l,orphanedClasses:f}}function et(e){let t=e.lastIndexOf(`.`);return t<=0?{stem:e,ext:``}:{stem:e.slice(0,t),ext:e.slice(t+1)}}function tt(e){let t=e.replaceAll(`\\`,`/`),{stem:n,ext:r}=et(t.slice(t.lastIndexOf(`/`)+1)),i=r||`ts`,a=n.lastIndexOf(`.`);return a>0?`./**/*.${n.slice(a+1)}.${i}`:`./**/*.${i}`}function nt(e){let t=/* @__PURE__ */ new Set;for(let n of e)t.add(tt(n.relativePath));return[...t].toSorted()}function rt(e,t){let n=0,r=null;for(let i=t;i<e.length;i++){let t=e[i];if(r){if(t===`\\`){i++;continue}t===r&&(r=null)}else if(t===`'`||t===`"`||t==="`")r=t;else if(t===`(`)n++;else if(t===`)`&&(n--,n===0))return i}return-1}function it(e,t,n,r){let i=null;for(let a=n;a<r;a++){let n=e[a];if(i){if(n===`\\`){a++;continue}n===i&&(i=null)}else if(n===`'`||n===`"`||n==="`")i=n;else if(n===t)return a}return-1}function at(e,t){let n=0,r=null;for(let i=t;i<e.length;i++){let t=e[i];if(r){if(t===`\\`){i++;continue}t===r&&(r=null)}else if(t===`'`||t===`"`||t==="`")r=t;else if(t===`[`)n++;else if(t===`]`&&(n--,n===0))return i}return-1}function ot(e){let t=/\bimport\.meta\.glob\s*\(/g,n=[],r;for(;(r=t.exec(e))!==null;){let t=e.indexOf(`(`,r.index);if(t<0)continue;let i=rt(e,t);i<0||n.push({start:r.index,open:t,close:i})}return n}function st(e,t){let n=ot(e);if(n.length===0)return null;let r=n.find(t=>/\beager\s*:\s*true\b/.test(e.slice(t.open,t.close+1)))??n[0],i=e.slice(r.start,r.close+1),a=new Set(Se(i).map(e=>e.startsWith(`!`)?e.slice(1):e)),o=t.filter(e=>!a.has(e));if(o.length===0)return null;let s=o.map(e=>`'${e}'`).join(`, `),c=it(e,`[`,r.open,r.close);if(c>=0){let t=at(e,c);if(t<0||t>r.close)return null;let n=e.slice(0,t);return n+(/[[,]\s*$/.test(n)?``:`, `)+s+e.slice(t)}let l=/(['"`])((?:\\.|(?!\1).)*)\1/,u=e.slice(r.open+1,r.close),d=l.exec(u);if(!d)return null;let f=r.open+1+d.index,p=f+d[0].length;return e.slice(0,f)+`[${d[0]}, ${s}]`+e.slice(p)}const Q="/* eslint-disable */\n// AUTO-GENERATED by `kick typegen`. DO NOT EDIT.\n// Re-run with `kick typegen` or rely on `kick dev` to refresh.\n",ct=/* @__PURE__ */ new Set([`Service`,`Repository`,`Injectable`,`Component`]);var lt=class extends Error{collisions;constructor(e){super(ut(e)),this.name=`TokenCollisionError`,this.collisions=e}};function ut(e){let t=[`kick typegen: token collision detected`];for(let n of e){t.push(``),t.push(` ${n.classes.length} classes named '${n.className}':`);for(let e of n.classes)t.push(` - ${e.relativePath}`)}return t.push(``),t.push(`Resolutions:`),t.push(` (a) Rename one of the classes`),t.push(` (b) Use createToken<T>('namespaced/Name') and import the token explicitly — see @forinda/kickjs`),t.push(` (c) Pass --allow-duplicates to namespace the registry keys automatically`),t.push(` (e.g. 'modules/users/UserService' instead of 'UserService')`),t.join(`
|
|
12
12
|
`)}function dt(e,t){let n=r(t),i=a(n,e).split(s).join(`/`);return i=i.replace(/\.(ts|tsx|mts|cts)$/i,``),i.startsWith(`.`)||(i=`./`+i),i}function ft(e){let t=e.relativePath.replace(/^src\//,``).replace(/\.(ts|tsx|mts|cts)$/i,``).split(`/`);t.pop();let n=t.join(`/`);return n?`${n}/${e.className}`:e.className}function pt(e,t,n){let r=/* @__PURE__ */ new Set,i=[];for(let a of e){if(!ct.has(a.decorator))continue;let e=n.has(a.className)?ft(a):a.className;if(r.has(e))continue;r.add(e);let o=dt(a.filePath,t),s=a.isDefault?`import('${o}').default`:`import('${o}').${a.className}`;i.push(` '${e}': ${s}`)}let a=i.length?i.join(`
|
|
13
13
|
`):" // (no services discovered yet — run `kick g service <name>` to add one)";return`${Q}
|
|
14
14
|
declare module '@forinda/kickjs' {
|
|
@@ -99,8 +99,8 @@ ${At(n,` `)}
|
|
|
99
99
|
|
|
100
100
|
export {}
|
|
101
101
|
`}const kt=Symbol(`asset-leaf`);function At(e,t){let n=Object.keys(e).toSorted(),r=[];for(let i of n){let n=e[i],a=jt(i)?i:JSON.stringify(i);n===kt?r.push(`${t}${a}: () => string`):(r.push(`${t}${a}: {`),r.push(At(n,`${t} `)),r.push(`${t}}`))}return r.join(`
|
|
102
|
-
`)}function jt(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function Mt(e){try{return t(e).isDirectory()}catch{return!1}}var Nt=/* @__PURE__ */ e({runTypegen:()=>Ft,sweepStaleTypegen:()=>zt,watchTypegen:()=>Rt,writeTypegenArtifacts:()=>$});function Pt(e){let t=e.cwd??process.cwd();return{cwd:t,srcDir:o(t,e.srcDir??`src`),outDir:o(t,e.outDir??`.kickjs/types`),silent:e.silent??!1,allowDuplicates:e.allowDuplicates??!1,schemaValidator:e.schemaValidator??!1,envFile:e.envFile??`src/env.ts`}}async function Ft(e={}){let{cwd:t,srcDir:n,outDir:r,silent:i,allowDuplicates:a,envFile:s}=Pt(e),c=Date.now(),l={root:n,cwd:t,cacheDir:e.noCache?void 0:o(t,`.kickjs`,`cache`),envFile:s===!1?void 0:s},u=e.changedFiles?await Qe(l,e.changedFiles):await Z(l);if(u.collisions.length>0&&!a)throw new lt(u.collisions);let d=Dt(e.assetMap,t),f=[],p=[];if(e.runPlugins!==!1){try{let{runAllPluginTypegens:n}=await import(`./builtins-
|
|
102
|
+
`)}function jt(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function Mt(e){try{return t(e).isDirectory()}catch{return!1}}var Nt=/* @__PURE__ */ e({runTypegen:()=>Ft,sweepStaleTypegen:()=>zt,watchTypegen:()=>Rt,writeTypegenArtifacts:()=>$});function Pt(e){let t=e.cwd??process.cwd();return{cwd:t,srcDir:o(t,e.srcDir??`src`),outDir:o(t,e.outDir??`.kickjs/types`),silent:e.silent??!1,allowDuplicates:e.allowDuplicates??!1,schemaValidator:e.schemaValidator??!1,envFile:e.envFile??`src/env.ts`}}async function Ft(e={}){let{cwd:t,srcDir:n,outDir:r,silent:i,allowDuplicates:a,envFile:s}=Pt(e),c=Date.now(),l={root:n,cwd:t,cacheDir:e.noCache?void 0:o(t,`.kickjs`,`cache`),envFile:s===!1?void 0:s},u=e.changedFiles?await Qe(l,e.changedFiles):await Z(l);if(u.collisions.length>0&&!a)throw new lt(u.collisions);let d=Dt(e.assetMap,t),f=[],p=[];if(e.runPlugins!==!1){try{let{runAllPluginTypegens:n}=await import(`./builtins-tE4nrAZ_.mjs`).then(e=>e.n),{loadKickConfig:r}=await import(`./config-mXO3F69m.mjs`).then(e=>e.n);f=await n({cwd:t,config:await r(t),silent:!0,changedFiles:e.changedFiles})}catch(e){if(!i){let t=e instanceof Error?e.message:String(e);console.warn(` kick typegen: plugin pipeline failed (${t}) — continuing`)}}p.push(...await $(r,f,i))}let m=Tt(u.tokens),h=Lt(u,d.count,p),g=Date.now()-c;if(!i){let e=r.replace(t+`/`,``),n=h.resolvedCollisions>0?`, ${h.resolvedCollisions} collisions namespaced`:``,i=h.envWritten?`, env typed`:``,a=h.pluginEntries>0?`, ${h.pluginEntries} plugins/adapters`:``,o=h.assetEntries>0?`, ${h.assetEntries} assets`:``;if(console.log(` kick typegen → ${h.serviceTokens} services, ${h.routeEntries} routes, ${h.moduleTokens} modules${a}${o}${i}${n} → ${e} (${g}ms)`),m.length>0){console.warn(` kick typegen: ${m.length} token(s) don't match the <scope>/<area>/<key> convention:`);for(let e of m){let t=e.variable?` [${e.variable}]`:``;console.warn(` '${e.token}' (${e.filePath})${t} — ${e.reason}`),e.suggestion&&console.warn(` → suggestion: ${e.suggestion}`)}}}return u.orphanedClasses.length>0&&await It(u.orphanedClasses,{fix:e.fix??!1,silent:i}),{scan:u,result:h,tokenWarnings:m}}async function It(e,{fix:t,silent:n}){let r=/* @__PURE__ */ new Map;for(let t of e){let e=r.get(t.moduleFilePath)??[];e.push(t),r.set(t.moduleFilePath,e)}if(t){let e=0,t=[];for(let[i,a]of r){let r=nt(a);try{let a=await l(i,`utf-8`),o=st(a,r);o&&o!==a?(await p(i,o),e++,n||console.log(` kick typegen --fix: patched ${i}\n + ${r.join(`, `)}`)):t.push(i)}catch{t.push(i)}}if(!n&&(e>0&&console.log(` kick typegen --fix: updated ${e} module glob(s) — re-run typegen to pick up the now-loaded classes.`),t.length>0)){console.warn(` kick typegen --fix: could not auto-patch ${t.length} module(s) (no import.meta.glob() call found) — add the patterns by hand:`);for(let e of t){let t=r.get(e)??[];console.warn(` ${e}: ${nt(t).join(`, `)}`)}}}else if(!n){console.warn(` kick typegen: ${e.length} decorated class(es) not matched by any module's import.meta.glob():`);for(let[e,t]of r){for(let e of t)console.warn(` @${e.decorator} ${e.className} (${e.relativePath})`);let n=nt(t);console.warn(` → add to import.meta.glob([...]) in ${e}:`),console.warn(` ${n.map(e=>`'${e}'`).join(`, `)}`)}console.warn(" → or run `kick typegen --fix` to apply these automatically.")}}function Lt(e,t,n){let r=new Set(e.collisions.map(e=>e.className)),i=e.classes.filter(e=>ct.has(e.decorator)),a=_t(e.classes,e.tokens,e.injects,r);return{registryEntries:i.length,serviceTokens:new Set(a).size,moduleTokens:vt(e.classes).length,routeEntries:e.routes.length,pluginEntries:new Set(e.pluginsAndAdapters.map(e=>e.name)).size,assetEntries:t,envWritten:e.env!==null,written:n,resolvedCollisions:e.collisions.length}}async function $(e,t,n){await c(e,{recursive:!0}),await p(i(r(e),`.gitignore`),`# Auto-generated by kick typegen
|
|
103
103
|
*
|
|
104
|
-
`,`utf-8`);let a=t.filter(e=>e.outFile).map(e=>e.outFile);return await zt(e,a,t,n),a}async function Rt(e={}){let t=Pt(e),{srcDir:n,silent:r,cwd:i}=t,a={...t,allowDuplicates:!0,runPlugins:!1,noCache:e.noCache},o=process.env.KICKJS_WATCH_POLLING===`1`||process.env.KICKJS_WATCH_POLLING===`true`,[{runAllPluginTypegens:s},{loadKickConfig:c}]=await Promise.all([import(`./builtins-
|
|
104
|
+
`,`utf-8`);let a=t.filter(e=>e.outFile).map(e=>e.outFile);return await zt(e,a,t,n),a}async function Rt(e={}){let t=Pt(e),{srcDir:n,silent:r,cwd:i}=t,a={...t,allowDuplicates:!0,runPlugins:!1,noCache:e.noCache},o=process.env.KICKJS_WATCH_POLLING===`1`||process.env.KICKJS_WATCH_POLLING===`true`,[{runAllPluginTypegens:s},{loadKickConfig:c}]=await Promise.all([import(`./builtins-tE4nrAZ_.mjs`).then(e=>e.n),import(`./config-mXO3F69m.mjs`).then(e=>e.n)]),l=await c(i),u=async()=>{try{await Ft({...a})}catch(e){if(r)return;if(e instanceof lt)console.error(`
|
|
105
105
|
`+e.message+`
|
|
106
106
|
`);else{let t=e instanceof Error?e.message:String(e);console.error(` kick typegen failed: ${t}`)}}},d=async()=>{try{let e=await s({cwd:i,config:l,silent:!0,watch:!0});await $(t.outDir,e,!0)}catch{}};await u(),await d();let{watch:f}=await import(`node:fs`),p=null,m=e=>{e&&/\.(ts|tsx|mts|cts)$/.test(e)&&(e.includes(`.kickjs`)||e.endsWith(`.d.ts`)||(p&&clearTimeout(p),p=setTimeout(()=>{u().then(d)},100)))};if(o){r||console.log(` kick typegen: polling mode (KICKJS_WATCH_POLLING)`);let e=setInterval(()=>{u().then(d)},2e3);return()=>clearInterval(e)}let h;try{h=f(n,{recursive:!0},(e,t)=>{m(t)})}catch(e){r||console.warn(` kick typegen: watch mode unavailable (${e?.message??e}). Falling back to polling.`);let t=setInterval(()=>{u().then(d)},2e3);return()=>clearInterval(t)}return()=>{p&&clearTimeout(p),h.close()}}async function zt(e,t,r,i){let a=/* @__PURE__ */ new Set;for(let e of t)a.add(n(e));for(let e of r)e.outFile&&a.add(n(e.outFile));let s;try{s=await u(e)}catch{return[]}let c=[];for(let t of s){if(!Bt.has(t)||a.has(t))continue;let n=o(e,t);try{if(!(await d(n)).isFile())continue;await f(n),c.push(t)}catch{}}return c.length>0&&!i&&console.log(` kick typegen: swept ${c.length} stale file(s): ${c.join(`, `)}`),c}const Bt=/* @__PURE__ */ new Set([`assets.d.ts`,`env.ts`,`routes.ts`,`registry.d.ts`,`services.d.ts`,`modules.d.ts`,`plugins.d.ts`,`augmentations.d.ts`,`index.d.ts`,`kick__augmentations.d.ts`]);export{w as C,S,j as _,Dt as a,D as b,vt as c,Ct as d,pt as f,Qe as g,Z as h,$ as i,_t as l,gt as m,Nt as n,Ot as o,St as p,Rt as r,lt as s,Ft as t,ht as u,A as v,C as w,T as x,O as y};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forinda/kickjs-cli",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.16.0",
|
|
4
4
|
"description": "CLI for KickJS — project scaffolding, DDD module generation, dev/build/start",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kickjs",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"oxfmt": "^0.72.0",
|
|
42
42
|
"picocolors": "^1.1.1",
|
|
43
43
|
"pluralize": "^8.0.0",
|
|
44
|
-
"@forinda/kickjs": "10.
|
|
44
|
+
"@forinda/kickjs": "10.13.0",
|
|
45
45
|
"@forinda/kickjs-cli-kit": "0.1.3",
|
|
46
46
|
"@forinda/kickjs-db": "8.11.2"
|
|
47
47
|
},
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { defineConfig } from '@forinda/kickjs-cli'
|
|
2
|
+
// @kick:imports
|
|
2
3
|
|
|
3
4
|
export default defineConfig({
|
|
4
5
|
pattern: '{{template}}',
|
|
@@ -10,6 +11,9 @@ export default defineConfig({
|
|
|
10
11
|
// Pinned so `kick add` and other dep-installing commands always use the
|
|
11
12
|
// project's intended package manager, regardless of which lockfile exists.
|
|
12
13
|
packageManager: '{{packageManager}}',
|
|
14
|
+
plugins: [
|
|
15
|
+
// @kick:config-plugin
|
|
16
|
+
],
|
|
13
17
|
modules: {
|
|
14
18
|
dir: 'src/modules',
|
|
15
19
|
// @kick:repo
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kickjs-add-adapter
|
|
3
|
+
description: Use when wiring a single-concern lifecycle integration (Swagger, DevTools, Sentry, Redis client).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
**Steps**:
|
|
7
|
+
1. `kick g adapter <name>` to scaffold the boilerplate, OR install via `kick add <package>` for first-party adapters.
|
|
8
|
+
2. The generated file uses `defineAdapter()` — never `class implements AppAdapter`.
|
|
9
|
+
3. Add the adapter instance (note the parens) to `src/adapters/index.ts` — don't inline in `src/index.ts`.
|
|
10
|
+
4. Pick the right hook and middleware phase deliberately.
|
|
11
|
+
5. Verify with `kick dev` that the adapter's lifecycle logs fire.
|
|
12
|
+
|
|
13
|
+
**Canonical shape** — factory closure owns instance state:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
export const RedisAdapter = defineAdapter<RedisConfig>({
|
|
17
|
+
name: 'RedisAdapter',
|
|
18
|
+
defaults: { url: 'redis://localhost' },
|
|
19
|
+
build: (config) => {
|
|
20
|
+
const client = createClient(config.url)
|
|
21
|
+
return {
|
|
22
|
+
beforeStart: ({ container }) => {
|
|
23
|
+
container.registerInstance(REDIS_CLIENT, client)
|
|
24
|
+
},
|
|
25
|
+
afterStart: () => client.connect(),
|
|
26
|
+
shutdown: () => client.quit(),
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
// In src/adapters/index.ts:
|
|
32
|
+
export const adapters = [RedisAdapter({ url: getEnv('REDIS_URL') })] // <-- note parens
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Lifecycle hook decision tree**:
|
|
36
|
+
- `beforeMount` — register early routes that should bypass middleware (health, docs UI).
|
|
37
|
+
- `beforeStart` — DI ready, server not listening yet. **Use this for `container.registerInstance(...)` calls** so they work under `createTestApp` too.
|
|
38
|
+
- `afterStart` — server has `ctx.server` available. Only use for things that need a listening server (Socket.IO upgrades, port logging). **Doesn't fire under `createTestApp`.**
|
|
39
|
+
- `shutdown` — runs concurrently via `Promise.allSettled`, so one failure doesn't block siblings (but errors are swallowed — log inside).
|
|
40
|
+
|
|
41
|
+
**Middleware phases** (see `MiddlewarePhase` JSDoc):
|
|
42
|
+
`beforeGlobal` | `afterGlobal` (default) | `beforeRoutes` | `afterRoutes` (fires only on fall-through — matched routes that respond skip it).
|
|
43
|
+
|
|
44
|
+
**Multi-instance** — `.scoped('cache', { url: ... })` makes `name` become `RedisAdapter:cache`. **Deferred config** — `.async({ inject, useFactory })` for config that depends on DI-resolved services.
|
|
45
|
+
|
|
46
|
+
**Red flags**:
|
|
47
|
+
- `bootstrap({ adapters: [MyAdapter] })` — passed the factory, not the instance. Call it: `MyAdapter()`.
|
|
48
|
+
- Inlining the adapter list directly in `src/index.ts` — entry file should stay thin.
|
|
49
|
+
- Returning a plain object instead of going through `defineAdapter()` — type inference for `config` will be wrong.
|
|
50
|
+
- Using `.async()` for an adapter that returns `middleware()` / `contributors()` / `beforeMount()` / `onRouteMount()` — those hooks have already run by the time `.async()` resolves and are silently skipped.
|
|
51
|
+
- Cross-adapter ordering via array position when it's load-bearing — use `dependsOn: ['OtelAdapter']`; cycles throw `MountCycleError` at boot.
|
|
52
|
+
- Using an adapter when the integration ships **modules + DI bindings + middleware** together → that's a plugin. Promote to `definePlugin()` (see `add-plugin` skill).
|
|
53
|
+
|
|
54
|
+
**Nuances**:
|
|
55
|
+
- `AdapterContext.server` is `undefined` outside `afterStart`.
|
|
56
|
+
- `shutdown` errors are swallowed by `Promise.allSettled` — wrap in try/catch and log if you care.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kickjs-add-module
|
|
3
|
+
description: Use when the user asks to add a new feature module (controller + service + repo + DTOs).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
**Trigger phrases**: "add a users module", "scaffold tasks", "new feature for X".
|
|
7
|
+
|
|
8
|
+
**Steps**:
|
|
9
|
+
1. Run `kick g module <name>` (use plural form if the project pluralizes — check `kick.config.ts`).
|
|
10
|
+
2. Verify the new folder under `src/modules/<name>/` contains `<name>.module.ts` (filename suffix is mandatory for Vite HMR).
|
|
11
|
+
3. Confirm the module appears in `src/modules/index.ts` exports — generator does this automatically; verify if you bypassed it.
|
|
12
|
+
4. Open `<name>.dto.ts` and tighten the Zod schemas to real fields (the generator emits placeholders).
|
|
13
|
+
5. Run `kick typecheck` and `{{pm}} run test` before claiming done.
|
|
14
|
+
|
|
15
|
+
**Canonical module shape** — `defineModule` factory, never `class implements AppModule`:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
export const TodosModule = defineModule({
|
|
19
|
+
name: 'TodosModule',
|
|
20
|
+
build: () => ({
|
|
21
|
+
register(container) {
|
|
22
|
+
container.registerFactory(TODO_REPO, () => createTodoRepository())
|
|
23
|
+
},
|
|
24
|
+
routes() {
|
|
25
|
+
return { path: '/todos', controller: TodosController }
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
})
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The module file MUST include `import.meta.glob([...], { eager: true })` for every `@Controller` / `@Service` / `@Repository` / `@Component` class — without it, decorators never fire and DI silently resolves to `undefined` (or routes vanish). Use **recursive** patterns (`./**/*.controller.ts`) so the glob keeps working when you nest files into sub-folders (`controllers/`, `presentation/`, …). If you reorganise and a class stops loading, `kick typegen` flags it as orphaned and `kick typegen --fix` patches the glob for you.
|
|
32
|
+
|
|
33
|
+
**Multiple route sets / versioning** — `routes()` may return an array with per-entry `version` override:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
routes() {
|
|
37
|
+
return [
|
|
38
|
+
{ path: '/todos', controller: TodosController }, // /api/v1/todos
|
|
39
|
+
{ path: '/todos', version: 2, controller: TodosV2Controller }, // /api/v2/todos
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Conditional / per-tenant mounting** — use `bootstrap({ setup(registry) { registry.mount(...) } })`, not the static `modules` array.
|
|
45
|
+
|
|
46
|
+
**Composition** — `defineModules().mount(TodosModule()).mount(UsersModule())` (fluent) or `AppModuleEntry[]` (array form).
|
|
47
|
+
|
|
48
|
+
**Red flags** (stop and ask):
|
|
49
|
+
- File created as `<name>.ts` instead of `<name>.module.ts` — Vite plugin's `*.module.[tj]sx?` glob doesn't pick it up; every save becomes a full restart.
|
|
50
|
+
- `@Controller('/path')` with a path argument — `@Controller()` takes no arguments; the prefix goes in the module's `routes().path`.
|
|
51
|
+
- `TodosModule` instead of `TodosModule()` for a module that takes config — refused, since the bare name would silently select the defaults. A module with no config accepts either, but prefer the invoked form for consistency.
|
|
52
|
+
- `routes()` returning `router: …` when a `controller:` would do — controller form is required for OpenAPI/Swagger introspection.
|
|
53
|
+
- Module not registered in `src/modules/index.ts`.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kickjs-add-plugin
|
|
3
|
+
description: Use when scaffolding a feature that bundles modules + DI + middleware + adapters together (auth, monitoring suite, multi-tenant scaffolding).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
**When plugin > adapter**: a plugin is the right answer when the integration ships **more than one** of: a module, a DI binding, middleware, or another adapter. If you have a single hook (`beforeStart`) and no other contributions, use `defineAdapter` instead.
|
|
7
|
+
|
|
8
|
+
**Canonical shape**:
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { definePlugin } from '@forinda/kickjs'
|
|
12
|
+
|
|
13
|
+
export const AuthPlugin = definePlugin({
|
|
14
|
+
name: 'AuthPlugin',
|
|
15
|
+
defaults: { tokenTtl: '1h' },
|
|
16
|
+
build: (config, { name }) => ({
|
|
17
|
+
modules: () => [AuthModule()],
|
|
18
|
+
adapters: () => [JwtAdapter({ ttl: config.tokenTtl })],
|
|
19
|
+
middleware: () => [requestIdMiddleware()],
|
|
20
|
+
register(container) {
|
|
21
|
+
container.registerFactory(TOKEN_SIGNER, () => createSigner(config))
|
|
22
|
+
},
|
|
23
|
+
contributors() {
|
|
24
|
+
return [LoadCurrentUser.registration]
|
|
25
|
+
},
|
|
26
|
+
onReady({ server }) {
|
|
27
|
+
log.info(`AuthPlugin listening on port ${server.address().port}`)
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
// In bootstrap:
|
|
33
|
+
bootstrap({ plugins: [AuthPlugin({ tokenTtl: getEnv('TOKEN_TTL') })] }) // <-- parens
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**Inline plugin literal** — the canonical answer for one-off DI bindings. There's no top-level `register:` on `bootstrap` itself:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
bootstrap({
|
|
40
|
+
plugins: [{ name: 'vector-store', register(c) { c.registerInstance(VECTOR_STORE, store) } }],
|
|
41
|
+
})
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Execution order** (memorize):
|
|
45
|
+
plugin `register()` → plugin `middleware()` → plugin `modules()` + user modules → plugin `adapters()` + user adapters → server listens → plugin `onReady()`.
|
|
46
|
+
|
|
47
|
+
**Static vs dynamic modules**: `modules()` returning an array is introspectable (Swagger, DevTools see it). `setup(registry)` is imperative — pick the latter when the module set depends on resolved config.
|
|
48
|
+
|
|
49
|
+
**Multi-instance** — `.scoped('users', { url })`; derive unique DI tokens from `ctx.name` inside `build`:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
build: (config, { name }) => ({
|
|
53
|
+
register(c) {
|
|
54
|
+
c.registerInstance(createToken(`cache/${name}`), client)
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**Precedence**: plugin contributors land at `'adapter'` precedence — beat global, lose to module/class/method same-key.
|
|
60
|
+
|
|
61
|
+
**Red flags**:
|
|
62
|
+
- `bootstrap({ plugins: [AuthPlugin] })` — passed factory. Call it: `AuthPlugin()`.
|
|
63
|
+
- Reaching for a plugin when an adapter would do (no modules, no DI bindings, no contributors) — overkill; use `defineAdapter()`.
|
|
64
|
+
- `.async()` plugin that depends on `modules()` / `middleware()` / `adapters()` / `contributors()` — those are dropped. `.async()` only resolves `register()` + `onReady()`.
|
|
65
|
+
- Confusing CLI plugins (`defineCliPlugin` from `@forinda/kickjs-cli`) with runtime plugins (`definePlugin` from `@forinda/kickjs`) — different surfaces, different registration sites.
|
|
66
|
+
- `dependsOn: ['SomePlugin']` referring to a plugin not in the boot list — throws `MissingMountDepError` at boot.
|
|
67
|
+
|
|
68
|
+
**Nuances**:
|
|
69
|
+
- `definition` is `Object.freeze`'d metadata; useful for version checks (`compare(AuthPlugin.definition.version, '1.2.0')`) — not mountable.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kickjs-bootstrap-export
|
|
3
|
+
description: Use when HMR is silently doing full restarts on every save, or createTestApp can't find the app handle.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
**Check** `src/index.ts`'s last line:
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
// CORRECT — Vite plugin + createTestApp import the named `app` symbol
|
|
10
|
+
export const app = await bootstrap({ ... })
|
|
11
|
+
|
|
12
|
+
// WRONG — HMR degrades to full restart, createTestApp loses the handle
|
|
13
|
+
await bootstrap({ ... })
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The Vite plugin imports the named `app` symbol via `virtual:kickjs/app`; testing helpers do too. Without the export, both fall back to slower paths (full restart on save, mock handle in tests) **without warning**.
|
|
17
|
+
|
|
18
|
+
**Red flags**:
|
|
19
|
+
- A bare `await bootstrap(...)` with no `export` — fix by adding `export const app =`.
|
|
20
|
+
- Re-assigning `app` later in the file (`app = somethingElse`) — Vite imports by reference at module-load time; reassignments don't propagate.
|
|
21
|
+
- Multiple files calling `bootstrap()` — only the entry should. Tests use `createTestApp` instead.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kickjs-cli-commands-cheatsheet
|
|
3
|
+
description: Use as a quick reference for the most common kick CLI workflows — scaffolding, dev/build/start, generation, inspection.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
**Top commands**:
|
|
7
|
+
- `kick new <name>` — start a new project (prompts for template / repo / pm).
|
|
8
|
+
- `kick dev` — local dev server with Vite HMR.
|
|
9
|
+
- `kick build` — production bundle via Vite.
|
|
10
|
+
- `kick start` — run the built artifact (`NODE_ENV=production` auto-set).
|
|
11
|
+
- `kick g module <name>` — add a feature module; structure follows `pattern` in `kick.config.ts`.
|
|
12
|
+
- `kick g scaffold <Name> <field:type>...` — full CRUD module from field definitions.
|
|
13
|
+
- `kick g guard <name>` / `kick g middleware <name>` / `kick g contributor <name>` — the three "before the handler" shapes. A guard is a middleware by convention, NOT a separate primitive.
|
|
14
|
+
- `kick add <pkg>` — install optional packages (auto-resolves peer deps + package manager).
|
|
15
|
+
- `kick g --list` — list every available generator (built-ins + plugin-shipped).
|
|
16
|
+
- `kick info` — environment / version dump for bug reports.
|
|
17
|
+
- `kick inspect` — introspect a running app: routes, middleware, adapters, DI graph.
|
|
18
|
+
|
|
19
|
+
**Useful flag combos**:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
kick new my-api --yes # CI-safe: minimal + inmemory, no prompts
|
|
23
|
+
kick new my-api -t rest --pm {{pm}} --no-git --install # Fully scriptable REST scaffold
|
|
24
|
+
kick new . --yes --force # Scaffold into current dir, clear existing files
|
|
25
|
+
kick g scaffold Post title:string body:text:optional # Shell-safe optional field syntax
|
|
26
|
+
kick g agents -f --only skills # Refresh just the skills after upgrade
|
|
27
|
+
kick add queue:bullmq # Package + peer deps (bullmq + ioredis) in one shot
|
|
28
|
+
kick inspect --port 4000 --json # Machine-readable route/adapter dump
|
|
29
|
+
kick g config --force --repo postgres # Drop a kick.config.ts into a legacy project
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Lesser-known, high-value**:
|
|
33
|
+
- `kick inspect --watch` — live route/middleware/adapter table that re-renders on hot reload; faster than re-curling `/_debug`.
|
|
34
|
+
- `kick g agents -f` — regenerates `CLAUDE.md` (root) and `.agents/AGENTS.md` / `GEMINI.md` / `COPILOT.md` + every `.agents/skills/<slug>/SKILL.md` from the current CLI templates.
|
|
35
|
+
- `kick dev:debug` — same flags as `kick dev` but opens a Node inspector port for IDE attach.
|
|
36
|
+
- `kick list --all` (alias `kick ls --all`) — full optional-package catalog at this CLI version.
|
|
37
|
+
- `kick typegen --watch` — standalone typegen watcher when `kick dev` isn't running.
|
|
38
|
+
- `kick check` — preflight gate (typecheck + lint + format) before commit.
|
|
39
|
+
- `kick codemod` — automated AST-level migration between framework versions.
|
|
40
|
+
|
|
41
|
+
**Red flags**:
|
|
42
|
+
- Using globally-installed `@forinda/kickjs-cli` while contributing to the monorepo — `pnpm link --global` from `packages/cli` so generators match the framework.
|
|
43
|
+
- Writing `"name:type?"` for optional scaffold fields — `?` is a shell glob in bash/zsh; use `name:type:optional`.
|
|
44
|
+
- Running `kick new <name> --yes` in a non-empty directory expecting it to wipe — `--yes` aborts without `--force`; pair them when destruction is intended.
|
|
45
|
+
- Skipping `kick g config` on a legacy project then wondering why generators ignore `modules.dir` / `modules.repo`.
|
|
46
|
+
- Editing `kick.config.ts` with deprecated top-level `modulesDir` / `defaultRepo` / `schemaDir` / `pluralize` instead of the nested `modules` block.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kickjs-cli-plugin
|
|
3
|
+
description: Use when adding a kick <name> command, a kick g <name> generator, or a typegen emitter to this project or a package it ships.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
A CLI plugin contributes commands, generators and typegen emitters to the
|
|
7
|
+
`kick` CLI. Every built-in command ships as one, so the contract is the same
|
|
8
|
+
one the framework uses.
|
|
9
|
+
|
|
10
|
+
**Steps**:
|
|
11
|
+
1. Write the plugin. All four contribution kinds are optional:
|
|
12
|
+
```ts
|
|
13
|
+
// kick-tool.ts
|
|
14
|
+
import { defineCliPlugin } from '@forinda/kickjs-cli'
|
|
15
|
+
|
|
16
|
+
export const toolPlugin = (options: { watch?: boolean } = {}) =>
|
|
17
|
+
defineCliPlugin({
|
|
18
|
+
// Stable id, unique across plugins — it names the plugin in conflict errors.
|
|
19
|
+
name: 'my-tool',
|
|
20
|
+
// Declarative: same shape as kick.config.ts `commands`.
|
|
21
|
+
commands: [{ name: 'db:migrate', description: 'Apply migrations', steps: 'node ./scripts/migrate.js' }],
|
|
22
|
+
// Programmatic: full commander API, when you need options or subcommands.
|
|
23
|
+
register(program, ctx) {
|
|
24
|
+
program
|
|
25
|
+
.command('my-tool')
|
|
26
|
+
.description('Do the thing')
|
|
27
|
+
.option('--watch', 'Watch mode')
|
|
28
|
+
.action(async () => {
|
|
29
|
+
ctx.log(`running in ${ctx.projectRoot}`)
|
|
30
|
+
// ctx.config is the loaded kick.config.ts
|
|
31
|
+
})
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
2. Register it in `kick.config.ts`:
|
|
36
|
+
```ts
|
|
37
|
+
import { toolPlugin } from './kick-tool'
|
|
38
|
+
|
|
39
|
+
export default defineConfig({ plugins: [toolPlugin()] })
|
|
40
|
+
```
|
|
41
|
+
3. Check it is loaded, per contribution kind: `kick --help` lists a command,
|
|
42
|
+
`kick g --list` lists a generator, `kick typegen` runs an emitter. A
|
|
43
|
+
plugin that fails to load takes the whole CLI down with a conflict error,
|
|
44
|
+
so silence here means the config never referenced it.
|
|
45
|
+
|
|
46
|
+
**Which kind to use**: `commands` for a shell one-liner, `register` for
|
|
47
|
+
options / subcommands / async work, `generators` (`defineGenerator`) for
|
|
48
|
+
`kick g <name>` scaffolders, `typegens` for a file under `.kickjs/types/`.
|
|
49
|
+
|
|
50
|
+
**Red flags**:
|
|
51
|
+
- Confusing this with a runtime plugin: `defineCliPlugin` (from
|
|
52
|
+
`@forinda/kickjs-cli`) extends the CLI; `definePlugin` (from
|
|
53
|
+
`@forinda/kickjs`) hooks the running app. They share nothing.
|
|
54
|
+
- Claiming a command name a built-in owns (`build:netlify`, `typegen`,
|
|
55
|
+
`generate`) — duplicate declarative names are a startup conflict, and
|
|
56
|
+
`register` has no conflict detection at all, so it silently loses. Namespace
|
|
57
|
+
your own (`my-tool:build`).
|
|
58
|
+
- Doing real work inside `register` — it runs at CLI startup for every
|
|
59
|
+
command, so it must only register. Put the work in the action.
|
|
60
|
+
- Importing heavy dependencies at module scope. `await import()` them inside
|
|
61
|
+
the action, so an unrelated `kick dev` does not pay for them.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kickjs-context-contributor
|
|
3
|
+
description: Use when a middleware's only job is to set ctx values consumed elsewhere — replace with defineHttpContextDecorator (HTTP) or defineContextDecorator (transport-agnostic).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
**Pattern** (HTTP — most common):
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { defineHttpContextDecorator, type RequestContext } from '@forinda/kickjs'
|
|
10
|
+
|
|
11
|
+
// Augment ContextMeta — required for ctx.get('tenant') to be typed
|
|
12
|
+
declare module '@forinda/kickjs' {
|
|
13
|
+
interface ContextMeta {
|
|
14
|
+
tenant: { id: string; name: string }
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// The `declare module` block above is all you need for typed `ctx.get`.
|
|
19
|
+
|
|
20
|
+
const LoadTenant = defineHttpContextDecorator({
|
|
21
|
+
key: 'tenant',
|
|
22
|
+
deps: { repo: TENANT_REPO }, // typed DI
|
|
23
|
+
resolve: (ctx, { repo }) => repo.findById(ctx.req.headers['x-tenant-id'] as string),
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
const LoadProject = defineHttpContextDecorator({
|
|
27
|
+
key: 'project',
|
|
28
|
+
dependsOn: ['tenant'], // typo'd key = tsc error
|
|
29
|
+
resolve: (ctx) => projectsRepo.find(ctx.get('tenant')!.id, ctx.params.id),
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
@LoadTenant
|
|
33
|
+
@LoadProject
|
|
34
|
+
@Get('/projects/:id')
|
|
35
|
+
getProject(ctx: RequestContext) {
|
|
36
|
+
return ctx.get('project')
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Use `defineContextDecorator` (no Http prefix) only when the contributor must run across HTTP, WebSocket, queue, and cron transports — `Ctx` defaults to the smaller `ExecutionContext` surface (`get` / `set` / `requestId` only, no `req`).
|
|
41
|
+
|
|
42
|
+
**Five precedence levels** (high → low):
|
|
43
|
+
**method > class > module > adapter > global**
|
|
44
|
+
|
|
45
|
+
Same-key collisions WITHIN a precedence level throw `DuplicateContributorError`. Across levels, the higher precedence silently overrides — a feature, not a bug, but debug it by giving resolvers distinguishable return values.
|
|
46
|
+
|
|
47
|
+
**Boot-time validation**:
|
|
48
|
+
- Cycles in `dependsOn` → `ContributorCycleError`.
|
|
49
|
+
- `dependsOn` referring to an unknown key → `MissingContributorError`.
|
|
50
|
+
- Both errors fail boot, not first request.
|
|
51
|
+
|
|
52
|
+
**Critical rules — all stem from the same shared-via-ALS instance model**:
|
|
53
|
+
- Every per-request stage (middleware → contributors → handler) gets its OWN `RequestContext` instance, but they all read/write the SAME `AsyncLocalStorage`-backed bag.
|
|
54
|
+
- **`resolve` and `onError` must RETURN the value** — the runner writes it via `ctx.set(key, value)`. Direct property assignment (`ctx.tenant = …`) sticks to one instance only and the handler instance never sees it.
|
|
55
|
+
- `ctx.set('tenant', x)` then `ctx.get('tenant')` works across instances. `ctx.req.headers[...]` works (the underlying node request is shared). Note it is a node `IncomingMessage` on Fastify and a web-backed request on h3, not an `express.Request`.
|
|
56
|
+
- Services with no `ctx` reference: `getRequestValue('tenant')` returns `MetaValue<'tenant'> | undefined` (typed via the augmented `ContextMeta`). For `requestId` use `getRequestStore()`.
|
|
57
|
+
- **No `setRequestValue` — writes flow through `ctx.set` or a contributor's return value.** Avoids "spooky action at a distance" where any service can pollute the per-request bag.
|
|
58
|
+
|
|
59
|
+
**Error matrix**:
|
|
60
|
+
- `optional: true` — `resolve` throws → key left unset; downstream sees `ctx.get(key) === undefined`.
|
|
61
|
+
- `optional: false` (default) + `onError` — return a fallback value to write; return `undefined` to skip; throw to forward to the request error handler.
|
|
62
|
+
- `optional: false` + no `onError` — throw propagates straight to the request error handler.
|
|
63
|
+
|
|
64
|
+
**Don't use this for**: response short-circuit, stream mutation, or pre-route-matching work — keep `@Middleware()` for those.
|
|
65
|
+
|
|
66
|
+
**Red flags**:
|
|
67
|
+
- `ctx.get('key')!` — the non-null assertion compiles even when the producing decorator isn't on the route. Use `ctx.require('key')`.
|
|
68
|
+
- `contributors: [LoadX]` at a module / adapter / bootstrap site — those take registrations: `LoadX.registration` or `LoadX.with({ ... }).registration`.
|
|
69
|
+
- A `paramDefaults` value that every call site overrides (`action: 'settings:read'`) — drop it and let the compiler require the field at each site.
|
|
70
|
+
- `defineContextDecorator<'k', Deps, Params>(spec)` positional form for a parameterised contributor — use `.withParams<Params>()(spec)` or `deps` inference is lost.
|
|
71
|
+
- `ctx.tenant = x` instead of returning the value from `resolve` — sticks to one instance only.
|
|
72
|
+
- Plugin / adapter authors using bare keys (`'state'`) instead of namespaced (`'@my-plugin/state'`) — collides with adopter keys.
|
|
73
|
+
- `getRequestValue<string>('traceId')` — generic is the **key** type, not value type.
|