fexapi 0.1.3 → 0.1.4

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
@@ -73,6 +73,16 @@ Generates:
73
73
  - `fexapi/generated.api.json`
74
74
  - `fexapi/migrations/schema.json`
75
75
 
76
+ ### 3a) Format schema (optional)
77
+
78
+ Auto-format your schema to use readable multi-line field formatting:
79
+
80
+ ```bash
81
+ npx fexapi format
82
+ ```
83
+
84
+ This rewrites `fexapi/schema.fexapi` with each field on its own indented line for better readability.
85
+
76
86
  ### 4) Start server
77
87
 
78
88
  ```bash
@@ -6,6 +6,9 @@ export declare const parseInitOptions: (initArgs: string[]) => {
6
6
  export declare const parseGenerateOptions: (generateArgs: string[]) => {
7
7
  error?: string;
8
8
  };
9
+ export declare const parseFormatOptions: (formatArgs: string[]) => {
10
+ error?: string;
11
+ };
9
12
  export declare const parseServeOptions: (serveArgs: string[]) => {
10
13
  host: string;
11
14
  port?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../src/cli/args.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,GAC3B,UAAU,MAAM,EAAE,KACjB;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAWtC,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,cAAc,MAAM,EAAE,KACrB;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAQlB,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,WAAW,MAAM,EAAE,KAClB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAkDxE,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,SAAS,MAAM,EAAE,KAEf;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAE,GAC3E;IAAE,KAAK,EAAE,MAAM,CAAA;CAwDlB,CAAC"}
1
+ {"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../src/cli/args.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,GAC3B,UAAU,MAAM,EAAE,KACjB;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAWtC,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,cAAc,MAAM,EAAE,KACrB;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAQlB,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,YAAY,MAAM,EAAE,KACnB;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAQlB,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,WAAW,MAAM,EAAE,KAClB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAkDxE,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,SAAS,MAAM,EAAE,KAEf;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAE,GAC3E;IAAE,KAAK,EAAE,MAAM,CAAA;CAwDlB,CAAC"}
package/dist/cli/args.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseDevOptions = exports.parseServeOptions = exports.parseGenerateOptions = exports.parseInitOptions = void 0;
3
+ exports.parseDevOptions = exports.parseServeOptions = exports.parseFormatOptions = exports.parseGenerateOptions = exports.parseInitOptions = void 0;
4
4
  const parseInitOptions = (initArgs) => {
5
5
  const validFlags = new Set(["--force"]);
6
6
  const invalidFlags = initArgs.filter((value) => value.startsWith("-") && !validFlags.has(value));
@@ -18,6 +18,14 @@ const parseGenerateOptions = (generateArgs) => {
18
18
  return {};
19
19
  };
20
20
  exports.parseGenerateOptions = parseGenerateOptions;
21
+ const parseFormatOptions = (formatArgs) => {
22
+ const invalidFlags = formatArgs.filter((value) => value.startsWith("-"));
23
+ if (invalidFlags.length > 0) {
24
+ return { error: `Unknown option(s): ${invalidFlags.join(", ")}` };
25
+ }
26
+ return {};
27
+ };
28
+ exports.parseFormatOptions = parseFormatOptions;
21
29
  const parseServeOptions = (serveArgs) => {
22
30
  const getFlagValue = (flagName) => {
23
31
  const index = serveArgs.indexOf(flagName);
@@ -1 +1 @@
1
- {"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../src/cli/help.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,YAgDrB,CAAC"}
1
+ {"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../src/cli/help.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,YAkDrB,CAAC"}
package/dist/cli/help.js CHANGED
@@ -7,6 +7,7 @@ const printHelp = () => {
7
7
  console.log("Usage:");
8
8
  console.log(" fexapi init [--force]");
9
9
  console.log(" fexapi generate");
10
+ console.log(" fexapi format");
10
11
  console.log(" fexapi dev [--watch] [--host <host>] [--port <number>] [--log]");
11
12
  console.log(" fexapi serve [--host <host>] [--port <number>] [--log]");
12
13
  console.log(" fexapi run [--host <host>] [--port <number>] [--log]");
@@ -17,6 +18,7 @@ const printHelp = () => {
17
18
  console.log(" fexapi init");
18
19
  console.log(" fexapi init --force");
19
20
  console.log(" fexapi generate");
21
+ console.log(" fexapi format");
20
22
  console.log(" fexapi dev --watch");
21
23
  console.log(" fexapi dev --watch --log");
22
24
  console.log(" fexapi serve --log");
@@ -0,0 +1,2 @@
1
+ export declare const formatSchema: () => number;
2
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/commands/format.ts"],"names":[],"mappings":"AAmCA,eAAO,MAAM,YAAY,QAAO,MAuC/B,CAAC"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatSchema = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ const schema_1 = require("../schema");
7
+ const paths_1 = require("../project/paths");
8
+ const formatSchemaToMultiline = (schemaText) => {
9
+ const parsed = (0, schema_1.parseFexapiSchema)(schemaText);
10
+ if (parsed.errors.length > 0 ||
11
+ !parsed.schema ||
12
+ parsed.schema.routes.length === 0) {
13
+ return schemaText;
14
+ }
15
+ const lines = [];
16
+ lines.push("# Server");
17
+ lines.push(`port: ${parsed.schema.port}`);
18
+ lines.push("");
19
+ lines.push("# Routes");
20
+ for (const route of parsed.schema.routes) {
21
+ lines.push(`${route.method} ${route.path}:`);
22
+ for (const field of route.fields) {
23
+ lines.push(` ${field.name}:${field.type}`);
24
+ }
25
+ lines.push("");
26
+ }
27
+ return lines.join("\n").trimEnd() + "\n";
28
+ };
29
+ const formatSchema = () => {
30
+ const projectRoot = (0, paths_1.resolveProjectRoot)();
31
+ if (!projectRoot) {
32
+ console.error("Could not find package.json in this directory or parent directories.");
33
+ return 1;
34
+ }
35
+ const schemaPath = (0, node_path_1.join)(projectRoot, "fexapi", "schema.fexapi");
36
+ if (!(0, node_fs_1.existsSync)(schemaPath)) {
37
+ console.error(`Schema file not found: ${schemaPath}`);
38
+ console.error("Run `fexapi init` first.");
39
+ return 1;
40
+ }
41
+ const schemaText = (0, node_fs_1.readFileSync)(schemaPath, "utf-8");
42
+ const parsed = (0, schema_1.parseFexapiSchema)(schemaText);
43
+ if (parsed.errors.length > 0 || !parsed.schema) {
44
+ console.error("Failed to parse schema.fexapi");
45
+ for (const error of parsed.errors) {
46
+ console.error(`- ${error}`);
47
+ }
48
+ return 1;
49
+ }
50
+ const formatted = formatSchemaToMultiline(schemaText);
51
+ (0, node_fs_1.writeFileSync)(schemaPath, formatted, "utf-8");
52
+ console.log(`Formatted ${schemaPath}`);
53
+ console.log(`Routes: ${parsed.schema.routes.length} | Port: ${parsed.schema.port}`);
54
+ return 0;
55
+ };
56
+ exports.formatSchema = formatSchema;
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const args_1 = require("./cli/args");
5
5
  const dev_1 = require("./commands/dev");
6
6
  const help_1 = require("./cli/help");
7
+ const format_1 = require("./commands/format");
7
8
  const generate_1 = require("./commands/generate");
8
9
  const init_1 = require("./commands/init");
9
10
  const serve_1 = require("./commands/serve");
@@ -41,6 +42,21 @@ const main = async () => {
41
42
  }
42
43
  process.exit((0, generate_1.generateFromSchema)());
43
44
  }
45
+ else if (firstArg === "format") {
46
+ if (restArgs.includes("--help") || restArgs.includes("-h")) {
47
+ console.log("Usage: fexapi format");
48
+ console.log("Reformats fexapi/schema.fexapi to use readable multi-line field formatting.");
49
+ process.exit(0);
50
+ }
51
+ const formatOptions = (0, args_1.parseFormatOptions)(restArgs);
52
+ if (formatOptions.error) {
53
+ console.error(formatOptions.error);
54
+ console.log("");
55
+ console.log("Usage: fexapi format");
56
+ process.exit(1);
57
+ }
58
+ process.exit((0, format_1.formatSchema)());
59
+ }
44
60
  else if (firstArg === "dev") {
45
61
  if (restArgs.includes("--help") || restArgs.includes("-h")) {
46
62
  console.log("Usage: fexapi dev [--watch] [--host <host>] [--port <number>] [--log]");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fexapi",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Mock API generation CLI tool for local development and testing",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",