resora 0.2.17 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -174,6 +174,23 @@ It works with:
174
174
 
175
175
  Adapters can be added without changing application logic.
176
176
 
177
+ ## Plugin System
178
+
179
+ Resora exposes a first-class plugin registry for opt-in integrations and lifecycle extensions.
180
+
181
+ ```ts
182
+ import { registerPlugin } from 'resora';
183
+ import { clearRouterExpressPlugin } from '@resora/plugin-clear-router';
184
+
185
+ registerPlugin(clearRouterExpressPlugin);
186
+ ```
187
+
188
+ Plugins can:
189
+
190
+ - hook into serialization and response dispatch
191
+ - inject framework integrations without core changes
192
+ - register reusable transformation utilities
193
+
177
194
  ## Conditional Rendering Example
178
195
 
179
196
  ```ts
package/bin/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import{copyFileSync as e,existsSync as t,mkdirSync as n,readFileSync as r,rmSync as i,writeFileSync as a}from"fs";import o,{dirname as s,join as c}from"path";import{createRequire as l}from"module";import{pathToFileURL as u}from"url";import{Command as d,Kernel as f}from"@h3ravel/musket";let p={first:`first`,last:`last`,prev:`prev`,next:`next`},m={previous:`previous`,next:`next`};const h=e=>{p={...p,...e}},g=e=>{m={...m,...e}};let _=o.resolve(process.cwd(),`node_modules/resora/stubs`);t(_)||(_=o.resolve(process.cwd(),`stubs`));const v=()=>({stubsDir:_,preferredCase:`camel`,responseStructure:{wrap:!0,rootKey:`data`},paginatedExtras:[`meta`,`links`],baseUrl:``,pageName:`page`,paginatedLinks:{first:`first`,last:`last`,prev:`prev`,next:`next`},paginatedMeta:{to:`to`,from:`from`,links:`links`,path:`path`,total:`total`,per_page:`per_page`,last_page:`last_page`,current_page:`current_page`},cursorMeta:{previous:`previous`,next:`next`},resourcesDir:`src/resources`,stubs:{config:`resora.config.stub`,resource:`resource.stub`,collection:`resource.collection.stub`}}),y=e=>{let t=v();return Object.assign(t,e,{stubs:Object.assign(t.stubs,e.stubs||{})},{cursorMeta:Object.assign(t.cursorMeta,e.cursorMeta||{})},{paginatedMeta:e.paginatedMeta||t.paginatedMeta},{paginatedLinks:Object.assign(t.paginatedLinks,e.paginatedLinks||{})},{responseStructure:Object.assign(t.responseStructure,e.responseStructure||{})})};let b=!1,x;const S=e=>{e.preferredCase!==`camel`&&e.preferredCase,e.responseStructure,e.paginatedExtras,h(e.paginatedLinks),e.paginatedMeta,g(e.cursorMeta),e.baseUrl,e.pageName},C=async e=>await import(`${u(e).href}?resora_runtime=${Date.now()}`),w=e=>{S(y((e?.default??e)||{})),b=!0},T=()=>{let e=l(import.meta.url),n=[o.join(process.cwd(),`resora.config.cjs`)];for(let r of n)if(t(r))try{return w(e(r)),!0}catch{continue}return!1};(async()=>{if(!b){if(x)return await x;T()||(x=(async()=>{let e=[o.join(process.cwd(),`resora.config.js`),o.join(process.cwd(),`resora.config.ts`)];for(let n of e)if(t(n))try{w(await C(n));return}catch{continue}b=!0})(),await x)}})();var E=class{command;config={};constructor(e={}){this.config=y(e)}async loadConfig(e={}){this.config=y(e);let n=[c(process.cwd(),`resora.config.ts`),c(process.cwd(),`resora.config.js`),c(process.cwd(),`resora.config.cjs`)];for(let e of n)if(t(e))try{let{default:t}=await import(e);Object.assign(this.config,t);break}catch(t){console.error(`Error loading config file at ${e}:`,t)}return this}getConfig(){return this.config}init(){let n=c(process.cwd(),`resora.config.js`),i=c(this.config.stubsDir,this.config.stubs.config);return t(n)&&!this.command.option(`force`)&&(this.command.error(`Error: ${n} already exists.`),process.exit(1)),this.ensureDirectory(n),t(n)&&this.command.option(`force`)&&e(n,n.replace(/\.js$/,`.backup.${Date.now()}.js`)),a(n,r(i,`utf-8`)),{path:n}}ensureDirectory(e){let r=s(e);t(r)||n(r,{recursive:!0})}generateFile(e,n,o,s){t(n)&&!s?.force?(this.command.error(`Error: ${n} already exists.`),process.exit(1)):t(n)&&s?.force&&i(n);let c=r(e,`utf-8`);for(let[e,t]of Object.entries(o))c=c.replace(RegExp(`{{${e}}}`,`g`),t);return this.ensureDirectory(n),a(n,c),n}makeResource(e,n){let r=e;n?.collection&&!e.endsWith(`Collection`)&&!e.endsWith(`Resource`)?r+=`Collection`:!n?.collection&&!e.endsWith(`Resource`)&&!e.endsWith(`Collection`)&&(r+=`Resource`);let i=`${r}.ts`,a=c(this.config.resourcesDir,i),o=c(this.config.stubsDir,n?.collection||e.endsWith(`Collection`)?this.config.stubs.collection:this.config.stubs.resource);t(o)||(this.command.error(`Error: Stub file ${o} not found.`),process.exit(1)),r=r.split(`/`).pop()?.split(`.`).shift();let s=r.replace(/(Resource|Collection)$/,``)+`Resource`,l=[`/**`,` * The resource that this collection collects.`,` */`,`collects = ${s}`].join(`
3
- `),u=`import ${s} from './${s}'\n`,d=(!!n?.collection||e.endsWith(`Collection`))&&t(c(this.config.resourcesDir,`${s}.ts`)),f=this.generateFile(o,a,{ResourceName:r,CollectionResourceName:r.replace(/(Resource|Collection)$/,``)+`Resource`,"collects = Resource":d?l:``,"import = Resource":d?u:``},n);return{name:r,path:f}}},D=class extends d{signature=`init
2
+ import{copyFileSync as e,existsSync as t,mkdirSync as n,readFileSync as r,rmSync as i,writeFileSync as a}from"fs";import o,{dirname as s,join as c}from"path";import{AsyncLocalStorage as l}from"node:async_hooks";import{createRequire as u}from"module";import{pathToFileURL as d}from"url";import{Command as f,Kernel as p}from"@h3ravel/musket";let m={first:`first`,last:`last`,prev:`prev`,next:`next`},h={previous:`previous`,next:`next`};const g=e=>{m={...m,...e}},_=e=>{h={...h,...e}};new l;let v=o.resolve(process.cwd(),`node_modules/resora/stubs`);t(v)||(v=o.resolve(process.cwd(),`stubs`));const y=()=>({stubsDir:v,preferredCase:`camel`,responseStructure:{wrap:!0,rootKey:`data`},paginatedExtras:[`meta`,`links`],baseUrl:``,pageName:`page`,paginatedLinks:{first:`first`,last:`last`,prev:`prev`,next:`next`},paginatedMeta:{to:`to`,from:`from`,links:`links`,path:`path`,total:`total`,per_page:`per_page`,last_page:`last_page`,current_page:`current_page`},cursorMeta:{previous:`previous`,next:`next`},resourcesDir:`src/resources`,stubs:{config:`resora.config.stub`,resource:`resource.stub`,collection:`resource.collection.stub`}}),b=e=>{let t=y();return Object.assign(t,e,{stubs:Object.assign(t.stubs,e.stubs||{})},{cursorMeta:Object.assign(t.cursorMeta,e.cursorMeta||{})},{paginatedMeta:e.paginatedMeta||t.paginatedMeta},{paginatedLinks:Object.assign(t.paginatedLinks,e.paginatedLinks||{})},{responseStructure:Object.assign(t.responseStructure,e.responseStructure||{})})};let x=!1,S;const C=e=>{e.preferredCase!==`camel`&&e.preferredCase,e.responseStructure,e.paginatedExtras,g(e.paginatedLinks),e.paginatedMeta,_(e.cursorMeta),e.baseUrl,e.pageName},w=async e=>await import(`${d(e).href}?resora_runtime=${Date.now()}`),T=e=>{C(b((e?.default??e)||{})),x=!0},E=()=>{let e=u(import.meta.url),n=[o.join(process.cwd(),`resora.config.cjs`)];for(let r of n)if(t(r))try{return T(e(r)),!0}catch{continue}return!1};(async()=>{if(!x){if(S)return await S;E()||(S=(async()=>{let e=[o.join(process.cwd(),`resora.config.js`),o.join(process.cwd(),`resora.config.ts`)];for(let n of e)if(t(n))try{T(await w(n));return}catch{continue}x=!0})(),await S)}})();var D=class{command;config={};constructor(e={}){this.config=b(e)}async loadConfig(e={}){this.config=b(e);let n=[c(process.cwd(),`resora.config.ts`),c(process.cwd(),`resora.config.js`),c(process.cwd(),`resora.config.cjs`)];for(let e of n)if(t(e))try{let{default:t}=await import(e);Object.assign(this.config,t);break}catch(t){console.error(`Error loading config file at ${e}:`,t)}return this}getConfig(){return this.config}init(){let n=c(process.cwd(),`resora.config.js`),i=c(this.config.stubsDir,this.config.stubs.config);return t(n)&&!this.command.option(`force`)&&(this.command.error(`Error: ${n} already exists.`),process.exit(1)),this.ensureDirectory(n),t(n)&&this.command.option(`force`)&&e(n,n.replace(/\.js$/,`.backup.${Date.now()}.js`)),a(n,r(i,`utf-8`)),{path:n}}ensureDirectory(e){let r=s(e);t(r)||n(r,{recursive:!0})}generateFile(e,n,o,s){t(n)&&!s?.force?(this.command.error(`Error: ${n} already exists.`),process.exit(1)):t(n)&&s?.force&&i(n);let c=r(e,`utf-8`);for(let[e,t]of Object.entries(o))c=c.replace(RegExp(`{{${e}}}`,`g`),t);return this.ensureDirectory(n),a(n,c),n}makeResource(e,n){let r=e;n?.collection&&!e.endsWith(`Collection`)&&!e.endsWith(`Resource`)?r+=`Collection`:!n?.collection&&!e.endsWith(`Resource`)&&!e.endsWith(`Collection`)&&(r+=`Resource`);let i=`${r}.ts`,a=c(this.config.resourcesDir,i),o=c(this.config.stubsDir,n?.collection||e.endsWith(`Collection`)?this.config.stubs.collection:this.config.stubs.resource);t(o)||(this.command.error(`Error: Stub file ${o} not found.`),process.exit(1)),r=r.split(`/`).pop()?.split(`.`).shift();let s=r.replace(/(Resource|Collection)$/,``)+`Resource`,l=[`/**`,` * The resource that this collection collects.`,` */`,`collects = ${s}`].join(`
3
+ `),u=`import ${s} from './${s}'\n`,d=(!!n?.collection||e.endsWith(`Collection`))&&t(c(this.config.resourcesDir,`${s}.ts`)),f=this.generateFile(o,a,{ResourceName:r,CollectionResourceName:r.replace(/(Resource|Collection)$/,``)+`Resource`,"collects = Resource":d?l:``,"import = Resource":d?u:``},n);return{name:r,path:f}}},O=class extends f{signature=`init
4
4
  {--force : Force overwrite if config file already exists (existing file will be backed up) }
5
- `;description=`Initialize Resora`;async handle(){this.app.command=this,this.app.init(),this.success(`Resora initialized`)}},O=class extends d{signature=`#create:
5
+ `;description=`Initialize Resora`;async handle(){this.app.command=this,this.app.init(),this.success(`Resora initialized`)}},k=class extends f{signature=`#create:
6
6
  {resource : Generates a new resource file.
7
7
  | {name : Name of the resource to create}
8
8
  | {--c|collection : Make a resource collection}
@@ -16,11 +16,11 @@ import{copyFileSync as e,existsSync as t,mkdirSync as n,readFileSync as r,rmSync
16
16
  | {prefix : prefix of the resources to create, "Admin" will create AdminResource, AdminCollection}
17
17
  | {--force : Create the resource or collection file even if it already exists.}
18
18
  }
19
- `;description=`Create a new resource or resource collection file`;async handle(){this.app.command=this;let e=``,t=this.argument(`name`)||this.argument(`prefix`),n=this.dictionary.name||this.dictionary.baseCommand;if([`resource`,`collection`].includes(n)&&!t)return void this.error(`Error: Name argument is required.`);if(n===`all`&&!t)return void this.error(`Error: Prefix argument is required.`);switch(n){case`resource`:({path:e}=this.app.makeResource(t,this.options()));break;case`collection`:({path:e}=this.app.makeResource(t+`Collection`,this.options()));break;case`all`:{let n=this.app.makeResource(t,{force:this.option(`force`)}),r=this.app.makeResource(t+`Collection`,{collection:!0,force:this.option(`force`)});e=`${n.path}, ${r.path}`;break}default:this.fail(`Unknown action: ${n}`)}this.success(`Created: ${e}`)}},k=String.raw`
19
+ `;description=`Create a new resource or resource collection file`;async handle(){this.app.command=this;let e=``,t=this.argument(`name`)||this.argument(`prefix`),n=this.dictionary.name||this.dictionary.baseCommand;if([`resource`,`collection`].includes(n)&&!t)return void this.error(`Error: Name argument is required.`);if(n===`all`&&!t)return void this.error(`Error: Prefix argument is required.`);switch(n){case`resource`:({path:e}=this.app.makeResource(t,this.options()));break;case`collection`:({path:e}=this.app.makeResource(t+`Collection`,this.options()));break;case`all`:{let n=this.app.makeResource(t,{force:this.option(`force`)}),r=this.app.makeResource(t+`Collection`,{collection:!0,force:this.option(`force`)});e=`${n.path}, ${r.path}`;break}default:this.fail(`Unknown action: ${n}`)}this.success(`Created: ${e}`)}},A=String.raw`
20
20
  _____
21
21
  | __ \
22
22
  | |__) |___ ___ ___ _ __ __ _
23
23
  | _ // _ \/ __|/ _ \| '__/ _, |
24
24
  | | \ \ __/\__ \ (_) | | | (_| |
25
25
  |_| \_\___||___/\___/|_| \__,_|
26
- `;const A=new E;await f.init(await A.loadConfig(),{logo:k,name:`Resora CLI`,baseCommands:[O,D,...A.getConfig().extraCommands||[]],exceptionHandler(e){throw e}});export{};
26
+ `;const j=new D;await p.init(await j.loadConfig(),{logo:A,name:`Resora CLI`,baseCommands:[k,O,...j.getConfig().extraCommands||[]],exceptionHandler(e){throw e}});export{};