api-core-lib 12.0.87 → 12.0.88

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.
Files changed (2) hide show
  1. package/dist/cli.cjs +109 -0
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -456,10 +456,119 @@ import type { ${schemasToImport.join(", ")} } from './types';
456
456
  const allPathParams = /* @__PURE__ */ new Set();
457
457
  Object.values(module2.actions).forEach((action) => action.pathParams.forEach((param) => allPathParams.add(param)));
458
458
  const pathParamsType = allPathParams.size > 0 ? `{ ${[...allPathParams].map((p) => `${p}?: string | number`).join("; ")} }` : "Record<string, never>";
459
+ let endpointsContent = `// This file is auto-generated. Do not edit directly.
460
+
461
+ `;
462
+ endpointsContent += `import type { QueryOptions } from 'api-core-lib';
463
+ `;
464
+ const endpointTypesToImport = /* @__PURE__ */ new Set();
465
+ Object.values(module2.actions).forEach((action) => {
466
+ if (action.inputType !== "undefined" && action.inputType !== "QueryOptions") {
467
+ endpointTypesToImport.add(action.inputType);
468
+ }
469
+ });
470
+ if (endpointTypesToImport.size > 0) {
471
+ endpointsContent += `import type { ${[...endpointTypesToImport].join(", ")} } from './types';
472
+
473
+ `;
474
+ }
475
+ endpointsContent += `export const ${camelCaseModuleName}Endpoints = {
476
+ `;
477
+ for (const action of Object.values(module2.actions)) {
478
+ const params = [];
479
+ if (action.pathParams.length > 0) {
480
+ params.push(`params: { ${action.pathParams.map((p) => `${p}: string | number`).join("; ")} }`);
481
+ }
482
+ if (action.inputType !== "undefined" && action.inputType !== "QueryOptions") {
483
+ params.push(`body: ${action.inputType}`);
484
+ }
485
+ if (action.hasQuery) {
486
+ params.push(`query?: QueryOptions`);
487
+ }
488
+ endpointsContent += ` /**
489
+ * ${action.method} ${module2.baseEndpoint}${action.path}
490
+ * ${action.description}
491
+ */
492
+ `;
493
+ endpointsContent += ` ${action.name}: (${params.join(", ")}) => ({
494
+ `;
495
+ endpointsContent += ` action: '${action.name}' as const,
496
+ `;
497
+ if (action.pathParams.length > 0) endpointsContent += ` pathParams: params,
498
+ `;
499
+ if (action.inputType !== "undefined" && action.inputType !== "QueryOptions") endpointsContent += ` input: body,
500
+ `;
501
+ if (action.hasQuery) endpointsContent += ` input: query,
502
+ `;
503
+ endpointsContent += ` }),
504
+
505
+ `;
506
+ }
507
+ endpointsContent += `};
508
+ `;
509
+ import_fs.default.writeFileSync(import_path.default.join(moduleOutputPath, `${camelCaseModuleName}.endpoints.ts`), endpointsContent);
459
510
  console.log(import_chalk.default.gray(` \u2713 ${camelCaseModuleName}.endpoints.ts (Type-Safe Endpoints)`));
511
+ const hookContent = `// This file is auto-generated. Do not edit directly.
512
+
513
+ import { useApiModule, UseApiModuleOptions } from 'api-core-lib/client';
514
+ import { apiClient } from '@/lib/api-core/clientApi'; // Assuming a fixed path
515
+ import { ${module2.moduleName} as TModuleType } from './config';
516
+ import { ${module2.moduleName} } from './config';
517
+
518
+ type ModulePathParams = ${pathParamsType};
519
+
520
+ type ${moduleBaseName}ApiOptions = Omit<UseApiModuleOptions, 'pathParams'> & {
521
+ pathParams?: ModulePathParams;
522
+ };
523
+
524
+ /**
525
+ * Custom hook for interacting with the ${moduleBaseName} API module.
526
+ */
527
+ export const use${moduleBaseName}Api = (options: ${moduleBaseName}ApiOptions = {}) => {
528
+ return useApiModule<typeof TModuleType['actions']>(apiClient, ${module2.moduleName}, options);
529
+ };
530
+ `;
531
+ import_fs.default.writeFileSync(import_path.default.join(moduleOutputPath, `use${moduleBaseName}.ts`), hookContent);
460
532
  console.log(import_chalk.default.gray(` \u2713 use${moduleBaseName}.ts (Custom Hook)`));
533
+ const providerContent = `// This file is auto-generated. Do not edit directly.
534
+ 'use client';
535
+
536
+ import React from 'react';
537
+ import { ApiModuleProvider } from 'api-core-lib/client';
538
+ import { use${moduleBaseName}Api } from './use${moduleBaseName}';
539
+
540
+ type Options = Parameters<typeof use${moduleBaseName}Api>[0];
541
+
542
+ interface ${moduleBaseName}ProviderProps {
543
+ children: React.ReactNode;
544
+ options?: Options;
545
+ }
546
+
547
+ /**
548
+ * A dedicated React Provider that initializes and provides the ${moduleBaseName} API context.
549
+ */
550
+ export function ${moduleBaseName}Provider({ children, options = {} }: ${moduleBaseName}ProviderProps) {
551
+ const api = use${moduleBaseName}Api(options);
552
+ return <ApiModuleProvider value={api}>{children}</ApiModuleProvider>;
553
+ }
554
+ `;
461
555
  const providerFileName = `${moduleBaseName}.provider.tsx`;
556
+ import_fs.default.writeFileSync(import_path.default.join(moduleOutputPath, providerFileName), providerContent);
462
557
  console.log(import_chalk.default.gray(` \u2713 ${providerFileName} (React Provider)`));
558
+ const serverContent = `// This file is auto-generated. For server-side use only.
559
+
560
+ import { createServerApi } from 'api-core-lib/server';
561
+ import { serverApiClient } from '@/lib/api-core/serverApi'; // Assuming a fixed path
562
+ import { ${module2.moduleName} } from './config';
563
+
564
+ /**
565
+ * Creates a server-side instance of the ${moduleBaseName} API for pre-fetching data in RSC.
566
+ */
567
+ export const create${moduleBaseName}ServerApi = () => {
568
+ return createServerApi(serverApiClient, ${module2.moduleName});
569
+ };
570
+ `;
571
+ import_fs.default.writeFileSync(import_path.default.join(moduleOutputPath, `${camelCaseModuleName}.server.ts`), serverContent);
463
572
  console.log(import_chalk.default.gray(` \u2713 ${camelCaseModuleName}.server.ts (Server-Side Helper)`));
464
573
  const newExports = [
465
574
  `
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-core-lib",
3
- "version": "12.0.87",
3
+ "version": "12.0.88",
4
4
  "description": "A flexible and powerful API client library for modern web applications.",
5
5
  "type": "module",
6
6
  "exports": {