resora 0.1.8 → 0.1.10

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/bin/index.mjs CHANGED
@@ -1,11 +1,11 @@
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{Command as u,Kernel as d}from"@h3ravel/musket";let f=o.resolve(process.cwd(),`node_modules/resora/stubs`);t(f)||(f=o.resolve(process.cwd(),`stubs`));const p=()=>({stubsDir:f,preferredCase:`camel`,paginatedExtras:[`meta`,`links`],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`},resourcesDir:`src/resources`,stubs:{config:`resora.config.stub`,resource:`resource.stub`,collection:`resource.collection.stub`}}),m=(e={})=>{let t=p();return Object.assign(t,e,{stubs:Object.assign(t.stubs,e.stubs||{})})};var h=class{command;config={};constructor(e={}){this.config=m(e);let n=l(import.meta.url),r=[c(process.cwd(),`resora.config.ts`),c(process.cwd(),`resora.config.js`),c(process.cwd(),`resora.config.cjs`)];for(let e of r)if(t(e))try{let{default:t}=n(e);Object.assign(this.config,t);break}catch(t){console.error(`Error loading config file at ${e}:`,t)}}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));let s=r.replace(/(Resource|Collection)$/,``)+`Resource`,l=`/**
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{Command as l,Kernel as u}from"@h3ravel/musket";let d=o.resolve(process.cwd(),`node_modules/resora/stubs`);t(d)||(d=o.resolve(process.cwd(),`stubs`));const f=()=>({stubsDir:d,preferredCase:`camel`,paginatedExtras:[`meta`,`links`],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`},resourcesDir:`src/resources`,stubs:{config:`resora.config.stub`,resource:`resource.stub`,collection:`resource.collection.stub`}}),p=(e={})=>{let t=f();return Object.assign(t,e,{stubs:Object.assign(t.stubs,e.stubs||{})})};var m=class{command;config={};constructor(e={}){this.config=p(e)}async loadConfig(e={}){this.config=p(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}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));let s=r.replace(/(Resource|Collection)$/,``)+`Resource`,l=`/**
3
3
  * The resource that this collection collects.
4
4
  */
5
5
  collects = ${s}
6
- `,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}}},g=class extends u{signature=`init
6
+ `,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}}},h=class extends l{signature=`init
7
7
  {--force : Force overwrite if config file already exists (existing file will be backed up) }
8
- `;description=`Initialize Resora`;async handle(){this.app.command=this,this.app.init(),this.success(`Resora initialized`)}},_=class extends u{signature=`#create:
8
+ `;description=`Initialize Resora`;async handle(){this.app.command=this,this.app.init(),this.success(`Resora initialized`)}},g=class extends l{signature=`#create:
9
9
  {resource : Generates a new resource file.
10
10
  | {name : Name of the resource to create}
11
11
  | {--c|collection : Make a resource collection}
@@ -19,11 +19,11 @@ import{copyFileSync as e,existsSync as t,mkdirSync as n,readFileSync as r,rmSync
19
19
  | {prefix : prefix of the resources to create, "Admin" will create AdminResource, AdminCollection}
20
20
  | {--force : Create the resource or collection file even if it already exists.}
21
21
  }
22
- `;description=`Create a new resource or resource collection file`;async handle(){this.app.command=this;let e=``,t=this.dictionary.name||this.dictionary.baseCommand;if([`resource`,`collection`].includes(t)&&!this.argument(`name`))return void this.error(`Error: Name argument is required.`);if(t===`all`&&!this.argument(`prefix`))return void this.error(`Error: Prefix argument is required.`);switch(t){case`resource`:({path:e}=this.app.makeResource(this.argument(`name`),this.options()));break;case`collection`:({path:e}=this.app.makeResource(this.argument(`name`)+`Collection`,this.options()));break;case`all`:{let t=this.app.makeResource(this.argument(`prefix`),{force:this.option(`force`)}),n=this.app.makeResource(this.argument(`prefix`)+`Collection`,{collection:!0,force:this.option(`force`)});e=`${t.path}, ${n.path}`;break}default:this.fail(`Unknown action: ${t}`)}this.success(`Created: ${e}`)}},v=String.raw`
22
+ `;description=`Create a new resource or resource collection file`;async handle(){this.app.command=this;let e=``,t=this.dictionary.name||this.dictionary.baseCommand;if([`resource`,`collection`].includes(t)&&!this.argument(`name`))return void this.error(`Error: Name argument is required.`);if(t===`all`&&!this.argument(`prefix`))return void this.error(`Error: Prefix argument is required.`);switch(t){case`resource`:({path:e}=this.app.makeResource(this.argument(`name`),this.options()));break;case`collection`:({path:e}=this.app.makeResource(this.argument(`name`)+`Collection`,this.options()));break;case`all`:{let t=this.app.makeResource(this.argument(`prefix`),{force:this.option(`force`)}),n=this.app.makeResource(this.argument(`prefix`)+`Collection`,{collection:!0,force:this.option(`force`)});e=`${t.path}, ${n.path}`;break}default:this.fail(`Unknown action: ${t}`)}this.success(`Created: ${e}`)}},_=String.raw`
23
23
  _____
24
24
  | __ \
25
25
  | |__) |___ ___ ___ _ __ __ _
26
26
  | _ // _ \/ __|/ _ \| '__/ _, |
27
27
  | | \ \ __/\__ \ (_) | | | (_| |
28
28
  |_| \_\___||___/\___/|_| \__,_|
29
- `;const y=new h;await d.init(y,{logo:v,name:`Resora CLI`,baseCommands:[_,g],exceptionHandler(e){throw e}});export{};
29
+ `;const v=new m;await u.init(await v.loadConfig(),{logo:_,name:`Resora CLI`,baseCommands:[g,h],exceptionHandler(e){throw e}});export{};
package/dist/index.cjs CHANGED
@@ -29,7 +29,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
29
29
  let fs = require("fs");
30
30
  let path = require("path");
31
31
  path = __toESM(path);
32
- let module$1 = require("module");
33
32
  let _h3ravel_musket = require("@h3ravel/musket");
34
33
 
35
34
  //#region src/ApiResource.ts
@@ -94,19 +93,22 @@ var CliApp = class {
94
93
  config = {};
95
94
  constructor(config = {}) {
96
95
  this.config = defineConfig(config);
97
- const require = (0, module$1.createRequire)(require("url").pathToFileURL(__filename).href);
96
+ }
97
+ async loadConfig(config = {}) {
98
+ this.config = defineConfig(config);
98
99
  const possibleConfigPaths = [
99
100
  (0, path.join)(process.cwd(), "resora.config.ts"),
100
101
  (0, path.join)(process.cwd(), "resora.config.js"),
101
102
  (0, path.join)(process.cwd(), "resora.config.cjs")
102
103
  ];
103
104
  for (const configPath of possibleConfigPaths) if ((0, fs.existsSync)(configPath)) try {
104
- const { default: userConfig } = require(configPath);
105
+ const { default: userConfig } = await import(configPath);
105
106
  Object.assign(this.config, userConfig);
106
107
  break;
107
108
  } catch (e) {
108
109
  console.error(`Error loading config file at ${configPath}:`, e);
109
110
  }
111
+ return this;
110
112
  }
111
113
  /**
112
114
  * Initialize Resora by creating a default config file in the current directory
package/dist/index.d.cts CHANGED
@@ -229,6 +229,7 @@ declare class CliApp {
229
229
  command: Command;
230
230
  protected config: Config;
231
231
  constructor(config?: Partial<Config>);
232
+ loadConfig(config?: Partial<Config>): Promise<this>;
232
233
  /**
233
234
  * Initialize Resora by creating a default config file in the current directory
234
235
  *
package/dist/index.d.mts CHANGED
@@ -229,6 +229,7 @@ declare class CliApp {
229
229
  command: Command;
230
230
  protected config: Config;
231
231
  constructor(config?: Partial<Config>);
232
+ loadConfig(config?: Partial<Config>): Promise<this>;
232
233
  /**
233
234
  * Initialize Resora by creating a default config file in the current directory
234
235
  *
package/dist/index.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
2
2
  import path, { dirname, join } from "path";
3
- import { createRequire } from "module";
4
3
  import { Command } from "@h3ravel/musket";
5
4
 
6
5
  //#region src/ApiResource.ts
@@ -65,19 +64,22 @@ var CliApp = class {
65
64
  config = {};
66
65
  constructor(config = {}) {
67
66
  this.config = defineConfig(config);
68
- const require = createRequire(import.meta.url);
67
+ }
68
+ async loadConfig(config = {}) {
69
+ this.config = defineConfig(config);
69
70
  const possibleConfigPaths = [
70
71
  join(process.cwd(), "resora.config.ts"),
71
72
  join(process.cwd(), "resora.config.js"),
72
73
  join(process.cwd(), "resora.config.cjs")
73
74
  ];
74
75
  for (const configPath of possibleConfigPaths) if (existsSync(configPath)) try {
75
- const { default: userConfig } = require(configPath);
76
+ const { default: userConfig } = await import(configPath);
76
77
  Object.assign(this.config, userConfig);
77
78
  break;
78
79
  } catch (e) {
79
80
  console.error(`Error loading config file at ${configPath}:`, e);
80
81
  }
82
+ return this;
81
83
  }
82
84
  /**
83
85
  * Initialize Resora by creating a default config file in the current directory
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resora",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "A structured API response layer for Node.js and TypeScript with automatic JSON responses, collection support, and pagination handling.",
5
5
  "keywords": [
6
6
  "api",