fexapi 0.2.3 → 0.2.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.
@@ -1 +1 @@
1
- {"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../src/cli/help.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,YA8DrB,CAAC"}
1
+ {"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../src/cli/help.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,SAAS,YAiErB,CAAC"}
package/dist/cli/help.js CHANGED
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.printHelp = void 0;
4
4
  const ui_1 = require("./ui");
5
5
  const printHelp = () => {
6
+ const version = (0, ui_1.getCliVersion)();
6
7
  (0, ui_1.printBanner)();
8
+ console.log(ui_1.ui.dim(`version ${version}`));
7
9
  (0, ui_1.printSpacer)();
8
10
  console.log(ui_1.ui.bold("Usage"));
9
11
  console.log(` ${(0, ui_1.formatCommand)("fexapi init [--force]")}`);
@@ -13,6 +15,7 @@ const printHelp = () => {
13
15
  console.log(` ${(0, ui_1.formatCommand)("fexapi serve [--host <host>] [--port <number>] [--log]")}`);
14
16
  console.log(` ${(0, ui_1.formatCommand)("fexapi run [--host <host>] [--port <number>] [--log]")}`);
15
17
  console.log(` ${(0, ui_1.formatCommand)("fexapi [--host <host>] [--port <number>] [--log]")}`);
18
+ console.log(` ${(0, ui_1.formatCommand)("fexapi --version")}`);
16
19
  console.log(` ${(0, ui_1.formatCommand)("fexapi --help")}`);
17
20
  (0, ui_1.printSpacer)();
18
21
  console.log(ui_1.ui.bold("Examples"));
package/dist/cli/ui.d.ts CHANGED
@@ -32,5 +32,6 @@ export declare const logWarn: (message: string) => void;
32
32
  export declare const logError: (message: string) => void;
33
33
  export declare const logStep: (message: string) => void;
34
34
  export declare const formatCommand: (command: string) => string;
35
+ export declare const getCliVersion: () => string;
35
36
  export {};
36
37
  //# sour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M,gBAAgB,GAAI,OAAO,MAAM,KAAG,IAkBhD,CAAC;AAEF,eAAO,MAAM,WAAW,QAAO,IAO9B,CAAC;AAEF,eAAO,MAAM,WAAW,QAAO,IAE9B,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,SAAS,MAAM,KAAG,IAEzC,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,SAAS,MAAM,KAAG,IAE5C,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,SAAS,MAAM,KAAG,IAEzC,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,SAAS,MAAM,KAAG,IAE1C,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,SAAS,MAAM,KAAG,IAEzC,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,KAAG,MAE/C,CAAC;AAEF,eAAO,MAAM,aAAa,QAAO,MAyBhC,CAAC"}
package/dist/cli/ui.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatCommand = exports.logStep = exports.logError = exports.logWarn = exports.logSuccess = exports.logInfo = exports.printSpacer = exports.printBanner = exports.printGroupHeader = exports.printSummaryCard = exports.formatDuration = exports.nowMs = exports.startSpinner = exports.ui = void 0;
3
+ exports.getCliVersion = exports.formatCommand = exports.logStep = exports.logError = exports.logWarn = exports.logSuccess = exports.logInfo = exports.printSpacer = exports.printBanner = exports.printGroupHeader = exports.printSummaryCard = exports.formatDuration = exports.nowMs = exports.startSpinner = exports.ui = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
4
6
  const shouldUseColor = () => {
5
7
  return Boolean(process.stdout.isTTY);
6
8
  };
@@ -26,7 +28,7 @@ exports.ui = {
26
28
  white: (text) => paint("97", text),
27
29
  };
28
30
  const SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
29
- const ANSI_REGEX = /\u001b\[[0-9;]*m/g;
31
+ const ANSI_REGEX = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
30
32
  const stripAnsi = (text) => text.replace(ANSI_REGEX, "");
31
33
  const visibleLength = (text) => stripAnsi(text).length;
32
34
  const getTerminalWidth = () => {
@@ -208,3 +210,25 @@ const formatCommand = (command) => {
208
210
  return exports.ui.bold(command);
209
211
  };
210
212
  exports.formatCommand = formatCommand;
213
+ const getCliVersion = () => {
214
+ const packageCandidates = [
215
+ (0, node_path_1.join)(__dirname, "..", "..", "package.json"),
216
+ (0, node_path_1.join)(__dirname, "..", "package.json"),
217
+ ];
218
+ for (const packagePath of packageCandidates) {
219
+ if (!(0, node_fs_1.existsSync)(packagePath)) {
220
+ continue;
221
+ }
222
+ try {
223
+ const packageJson = JSON.parse((0, node_fs_1.readFileSync)(packagePath, "utf-8"));
224
+ if (packageJson.version) {
225
+ return packageJson.version;
226
+ }
227
+ }
228
+ catch {
229
+ continue;
230
+ }
231
+ }
232
+ return "unknown";
233
+ };
234
+ exports.getCliVersion = getCliVersion;
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AA4OA,eAAO,MAAM,iBAAiB,GAAU,YAErC;IACD,KAAK,EAAE,OAAO,CAAC;CAChB,KAAG,OAAO,CAAC,MAAM,CA+KjB,CAAC"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAgOA,eAAO,MAAM,iBAAiB,GAAU,YAErC;IACD,KAAK,EAAE,OAAO,CAAC;CAChB,KAAG,OAAO,CAAC,MAAM,CA8KjB,CAAC"}
@@ -92,21 +92,12 @@ const askInitWizardQuestions = async () => {
92
92
  questionInterface.close();
93
93
  }
94
94
  };
95
- const getRuntimeConfigTemplate = ({ port, cors, includeSampleRoutes, }) => {
96
- const routeSection = includeSampleRoutes
97
- ? [
98
- " routes: {",
99
- ' "/users": { count: 10, schema: "user" },',
100
- ' "/posts": { count: 20, schema: "post" },',
101
- " },",
102
- ]
103
- : [];
95
+ const getRuntimeConfigTemplate = ({ port, cors, }) => {
104
96
  return [
105
97
  "module.exports = {",
106
98
  ` port: ${port},`,
107
99
  ` cors: ${cors},`,
108
100
  " delay: 0,",
109
- ...routeSection,
110
101
  "};",
111
102
  ].join("\n");
112
103
  };
@@ -183,7 +174,6 @@ const initializeProject = async ({ force, }) => {
183
174
  (0, node_fs_1.writeFileSync)(runtimeConfigPath, `${getRuntimeConfigTemplate({
184
175
  port: wizardAnswers.port,
185
176
  cors: wizardAnswers.cors,
186
- includeSampleRoutes: wizardAnswers.generateSampleSchemas,
187
177
  })}\n`, "utf-8");
188
178
  }
189
179
  let userSchemaStatus = "skipped";
@@ -35,7 +35,7 @@ const createProjectServer = ({ host, port, logEnabled = false, }) => {
35
35
  const more = overlappingPaths.length > 5
36
36
  ? ` (+${overlappingPaths.length - 5} more)`
37
37
  : "";
38
- (0, ui_1.logWarn)(`Config routes override generated schema routes for: ${sample}${more}. Remove or edit fexapi.config.js routes if you want schema.fexapi changes to appear.`);
38
+ (0, ui_1.logInfo)(`Both schema and config define: ${sample}${more}. Schema routes take precedence; remove duplicates in fexapi.config.js to keep behavior clear.`);
39
39
  }
40
40
  if (Object.keys(schemaDefinitions).length > 0) {
41
41
  (0, ui_1.logInfo)(`Loaded custom schemas from fexapi/schemas (${Object.keys(schemaDefinitions).length})`);
package/dist/index.js CHANGED
@@ -12,6 +12,12 @@ const serve_1 = require("./commands/serve");
12
12
  const args = process.argv.slice(2);
13
13
  const [firstArg, ...restArgs] = args;
14
14
  const main = async () => {
15
+ if (firstArg === "--version" || firstArg === "-v" || firstArg === "version") {
16
+ (0, ui_1.printBanner)();
17
+ (0, ui_1.printSpacer)();
18
+ console.log((0, ui_1.getCliVersion)());
19
+ process.exit(0);
20
+ }
15
21
  if (firstArg === "init") {
16
22
  if (restArgs.includes("--help") || restArgs.includes("-h")) {
17
23
  (0, ui_1.printBanner)();
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,KAAK,EACV,mBAAmB,EACnB,uBAAuB,EAExB,MAAM,gBAAgB,CAAC;AAGxB,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,aAAa,CAAC,EAAE,mBAAmB,CAAC;IACpC,iBAAiB,CAAC,EAAE,uBAAuB,CAAC;IAC5C,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB,CAAC;AAgMF,eAAO,MAAM,WAAW,GAAI,0EAOzB,aAAkB,wFAwJpB,CAAC"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,KAAK,EACV,mBAAmB,EACnB,uBAAuB,EAExB,MAAM,gBAAgB,CAAC;AAGxB,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,aAAa,CAAC,EAAE,mBAAmB,CAAC;IACpC,iBAAiB,CAAC,EAAE,uBAAuB,CAAC;IAC5C,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB,CAAC;AAgMF,eAAO,MAAM,WAAW,GAAI,0EAOzB,aAAkB,wFA0JpB,CAAC"}
package/dist/server.js CHANGED
@@ -191,17 +191,6 @@ const startServer = ({ host = DEFAULT_HOST, port = DEFAULT_PORT, apiSpec, runtim
191
191
  response.end();
192
192
  return;
193
193
  }
194
- if (request.method === "GET") {
195
- const configuredRoute = configuredRoutes[pathname];
196
- if (configuredRoute) {
197
- const count = getCountOverrideFromUrl(request.url) ?? configuredRoute.count;
198
- const payloadKey = toCollectionKey(pathname);
199
- sendJson(response, 200, {
200
- [payloadKey]: Array.from({ length: count }, () => createRecordFromSchemaName(configuredRoute.schema, schemaDefinitions)),
201
- }, { cors: corsEnabled, delay: responseDelay });
202
- return;
203
- }
204
- }
205
194
  if (apiSpec) {
206
195
  const matchedRoute = apiSpec.routes.find((route) => route.method === request.method && route.path === pathname);
207
196
  if (matchedRoute) {
@@ -228,7 +217,9 @@ const startServer = ({ host = DEFAULT_HOST, port = DEFAULT_PORT, apiSpec, runtim
228
217
  requestBody = JSON.parse(raw);
229
218
  }
230
219
  }
231
- catch { }
220
+ catch {
221
+ requestBody = {};
222
+ }
232
223
  const generatedRecord = createRecordFromRoute(matchedRoute);
233
224
  const merged = { ...generatedRecord, ...requestBody };
234
225
  const statusCode = method === "POST" ? 201 : 200;
@@ -240,6 +231,17 @@ const startServer = ({ host = DEFAULT_HOST, port = DEFAULT_PORT, apiSpec, runtim
240
231
  return;
241
232
  }
242
233
  }
234
+ if (request.method === "GET") {
235
+ const configuredRoute = configuredRoutes[pathname];
236
+ if (configuredRoute) {
237
+ const count = getCountOverrideFromUrl(request.url) ?? configuredRoute.count;
238
+ const payloadKey = toCollectionKey(pathname);
239
+ sendJson(response, 200, {
240
+ [payloadKey]: Array.from({ length: count }, () => createRecordFromSchemaName(configuredRoute.schema, schemaDefinitions)),
241
+ }, { cors: corsEnabled, delay: responseDelay });
242
+ return;
243
+ }
244
+ }
243
245
  sendJson(response, 404, {
244
246
  message: "Route not found",
245
247
  availableRoutes,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fexapi",
3
- "version": "0.2.3",
3
+ "version": "0.2.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",