resora 0.1.9 → 0.1.11

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
@@ -2,9 +2,9 @@
2
2
 
3
3
  [![NPM Downloads](https://img.shields.io/npm/dt/resora.svg)](https://www.npmjs.com/package/resora)
4
4
  [![npm version](https://img.shields.io/npm/v/resora.svg)](https://www.npmjs.com/package/resora)
5
- [![License](https://img.shields.io/npm/l/resora.svg)](https://github.com/toneflix/resora/blob/main/LICENSE)
6
- [![CI](https://github.com/toneflix/resora/actions/workflows/ci.yml/badge.svg)](https://github.com/toneflix/resora/actions/workflows/ci.yml)
7
- [![Deploy Docs](https://github.com/toneflix/resora/actions/workflows/deploy-docs.yml/badge.svg)](https://github.com/toneflix/resora/actions/workflows/deploy-docs.yml)
5
+ [![License](https://img.shields.io/npm/l/resora.svg)](https://github.com/arcstack-hq/resora/blob/main/LICENSE)
6
+ [![CI](https://github.com/arcstack-hq/resora/actions/workflows/ci.yml/badge.svg)](https://github.com/arcstack-hq/resora/actions/workflows/ci.yml)
7
+ [![Deploy Docs](https://github.com/arcstack-hq/resora/actions/workflows/deploy-docs.yml/badge.svg)](https://github.com/arcstack-hq/resora/actions/workflows/deploy-docs.yml)
8
8
 
9
9
  Resora is a structured API response layer for Node.js and TypeScript backends.
10
10
 
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)}async loadConfig(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)}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=`/**
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(await y.loadConfig(),{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
@@ -97,14 +96,13 @@ var CliApp = class {
97
96
  }
98
97
  async loadConfig(config = {}) {
99
98
  this.config = defineConfig(config);
100
- const require = (0, module$1.createRequire)(require("url").pathToFileURL(__filename).href);
101
99
  const possibleConfigPaths = [
102
100
  (0, path.join)(process.cwd(), "resora.config.ts"),
103
101
  (0, path.join)(process.cwd(), "resora.config.js"),
104
102
  (0, path.join)(process.cwd(), "resora.config.cjs")
105
103
  ];
106
104
  for (const configPath of possibleConfigPaths) if ((0, fs.existsSync)(configPath)) try {
107
- const { default: userConfig } = require(configPath);
105
+ const { default: userConfig } = await import(configPath);
108
106
  Object.assign(this.config, userConfig);
109
107
  break;
110
108
  } catch (e) {
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
@@ -68,14 +67,13 @@ var CliApp = class {
68
67
  }
69
68
  async loadConfig(config = {}) {
70
69
  this.config = defineConfig(config);
71
- const require = createRequire(import.meta.url);
72
70
  const possibleConfigPaths = [
73
71
  join(process.cwd(), "resora.config.ts"),
74
72
  join(process.cwd(), "resora.config.js"),
75
73
  join(process.cwd(), "resora.config.cjs")
76
74
  ];
77
75
  for (const configPath of possibleConfigPaths) if (existsSync(configPath)) try {
78
- const { default: userConfig } = require(configPath);
76
+ const { default: userConfig } = await import(configPath);
79
77
  Object.assign(this.config, userConfig);
80
78
  break;
81
79
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resora",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
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",
@@ -14,13 +14,13 @@
14
14
  "json",
15
15
  "response"
16
16
  ],
17
- "homepage": "https://toneflix.github.io/resora",
17
+ "homepage": "https://arcstack-hq.github.io/resora",
18
18
  "bugs": {
19
- "url": "https://github.com/toneflix/resora/issues"
19
+ "url": "https://github.com/arcstack-hq/resora/issues"
20
20
  },
21
21
  "repository": {
22
22
  "type": "git",
23
- "url": "git+https://github.com/toneflix/resora.git"
23
+ "url": "git+https://github.com/arcstack-hq/resora.git"
24
24
  },
25
25
  "license": "MIT",
26
26
  "author": "3m1n1nce <3m1n1nce@toneflix.net>",