suparisma 0.0.2 → 0.0.3

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.
@@ -17,22 +17,22 @@ const config_1 = require("../config");
17
17
  *
18
18
  * @example
19
19
  * // The generated index allows imports like:
20
- * import useSuparisma from './hooks/generated';
20
+ * import useSuparisma from './your-output-dir'; // e.g., from './suparisma/generated'
21
21
  * // or
22
- * import { useSuparismaUser } from './hooks/generated';
22
+ * import { useSuparismaUser } from './your-output-dir';
23
23
  */
24
24
  function generateMainIndexFile(modelInfos) {
25
25
  // Import statements for hooks
26
26
  const imports = modelInfos
27
- .map((info) => `import { ${config_1.HOOK_NAME_PREFIX}${info.modelName} } from './${config_1.HOOK_NAME_PREFIX}${info.modelName}';`)
27
+ .map((info) => `import { ${config_1.HOOK_NAME_PREFIX}${info.modelName} } from './hooks/${config_1.HOOK_NAME_PREFIX}${info.modelName}';`)
28
28
  .join('\n');
29
29
  // Import all required types
30
30
  const typeImports = modelInfos
31
- .map((info) => `import type { Use${info.modelName}Options, ${info.modelName}HookApi } from './${info.modelName}Types';`)
31
+ .map((info) => `import type { Use${info.modelName}Options, ${info.modelName}HookApi } from './types/${info.modelName}Types';`)
32
32
  .join('\n');
33
33
  // Model-specific type exports
34
34
  const modelTypeExports = modelInfos
35
- .map((info) => `export type { ${info.modelName}WithRelations, ${info.modelName}CreateInput, ${info.modelName}UpdateInput, ${info.modelName}WhereInput, ${info.modelName}WhereUniqueInput, ${info.modelName}OrderByInput, ${info.modelName}HookApi, Use${info.modelName}Options } from './${info.modelName}Types';`)
35
+ .map((info) => `export type { ${info.modelName}WithRelations, ${info.modelName}CreateInput, ${info.modelName}UpdateInput, ${info.modelName}WhereInput, ${info.modelName}WhereUniqueInput, ${info.modelName}OrderByInput, ${info.modelName}HookApi, Use${info.modelName}Options } from './types/${info.modelName}Types';`)
36
36
  .join('\n');
37
37
  // Create hook interface properties
38
38
  const hookProperties = modelInfos
@@ -48,7 +48,7 @@ function generateMainIndexFile(modelInfos) {
48
48
 
49
49
  ${imports}
50
50
  ${typeImports}
51
- export type { SuparismaOptions, SearchQuery, SearchState, FilterOperators } from './core';
51
+ export type { SuparismaOptions, SearchQuery, SearchState, FilterOperators } from './utils/core';
52
52
  ${modelTypeExports}
53
53
 
54
54
  /**
@@ -69,7 +69,7 @@ ${hookProperties}
69
69
  *
70
70
  * @example
71
71
  * // Get hooks for different models
72
- * import useSuparisma from './hooks/generated';
72
+ * import useSuparisma from './your-output-dir'; // e.g., from './suparisma/generated'
73
73
  *
74
74
  * // Access user model with all hook methods
75
75
  * const users = useSuparisma.user();
@@ -94,7 +94,12 @@ ${hookAssignments}
94
94
 
95
95
  export default useSuparisma;
96
96
  `;
97
+ // Output to OUTPUT_DIR (root of generated files)
97
98
  const outputPath = path_1.default.join(config_1.OUTPUT_DIR, 'index.ts');
99
+ // Ensure the main output directory exists (it should have been created by other generators for subdirs too)
100
+ if (!fs_1.default.existsSync(config_1.OUTPUT_DIR)) {
101
+ fs_1.default.mkdirSync(config_1.OUTPUT_DIR, { recursive: true });
102
+ }
98
103
  fs_1.default.writeFileSync(outputPath, content);
99
104
  console.log(`Generated main module file at ${outputPath}`);
100
105
  }
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.generateSupabaseClientFile = generateSupabaseClientFile;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
- const config_1 = require("../config"); // Assuming OUTPUT_DIR is defined in config.ts
9
+ const config_1 = require("../config"); // Ensure this is UTILS_DIR
10
10
  function generateSupabaseClientFile() {
11
11
  const supabaseClientContent = `// THIS FILE IS AUTO-GENERATED - DO NOT EDIT DIRECTLY
12
12
 
@@ -19,10 +19,10 @@ export const supabase = createClient(
19
19
  process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
20
20
  );
21
21
  `;
22
- const outputPath = path_1.default.join(config_1.OUTPUT_DIR, 'supabase-client-generated.ts');
23
- // Ensure the output directory exists
24
- if (!fs_1.default.existsSync(config_1.OUTPUT_DIR)) {
25
- fs_1.default.mkdirSync(config_1.OUTPUT_DIR, { recursive: true });
22
+ // Output to the UTILS_DIR
23
+ const outputPath = path_1.default.join(config_1.UTILS_DIR, 'supabase-client.ts');
24
+ if (!fs_1.default.existsSync(config_1.UTILS_DIR)) {
25
+ fs_1.default.mkdirSync(config_1.UTILS_DIR, { recursive: true });
26
26
  }
27
27
  fs_1.default.writeFileSync(outputPath, supabaseClientContent);
28
28
  console.log(`🚀 Generated Supabase client file at: ${outputPath}`);
@@ -38,6 +38,9 @@ function generateModelTypesFile(model) {
38
38
  });
39
39
  // Extract searchable fields from annotations
40
40
  const searchFields = model.searchFields?.map((field) => field.name) || [];
41
+ // Find the actual field names for createdAt and updatedAt
42
+ const createdAtField = model.fields.find(field => field.isCreatedAt)?.name || 'createdAt';
43
+ const updatedAtField = model.fields.find(field => field.isUpdatedAt)?.name || 'updatedAt';
41
44
  // Create a manual property list for WithRelations interface
42
45
  const withRelationsProps = model.fields
43
46
  .filter((field) => !relationObjectFields.includes(field.name) && !foreignKeyFields.includes(field.name))
@@ -90,7 +93,7 @@ function generateModelTypesFile(model) {
90
93
  // Edit the generator script instead
91
94
 
92
95
  import type { ${modelName} } from '@prisma/client';
93
- import type { ModelResult, SuparismaOptions, SearchQuery, SearchState } from './core';
96
+ import type { ModelResult, SuparismaOptions, SearchQuery, SearchState } from '../utils/core';
94
97
 
95
98
  /**
96
99
  * Extended ${modelName} type that includes relation fields.
@@ -288,6 +291,18 @@ export interface ${modelName}HookApi {
288
291
  */
289
292
  loading: boolean;
290
293
 
294
+ /**
295
+ * The current count of records matching the filter criteria.
296
+ * This automatically updates with the data, including realtime updates.
297
+ * It always reflects the current length of the data array, respecting any filters.
298
+ *
299
+ * @example
300
+ * // Display the count in the UI
301
+ * const { count } = ${modelName.toLowerCase()};
302
+ * return <div>Total records: {count}</div>;
303
+ */
304
+ count: number;
305
+
291
306
  ${searchFields.length > 0
292
307
  ? `/**
293
308
  * Search functionality for ${modelName} records.
@@ -507,26 +522,6 @@ ${createInputProps
507
522
  create: ${modelName}CreateInput;
508
523
  }) => ${modelName}SingleResult;
509
524
 
510
- /**
511
- * Count the number of ${modelName} records matching the filter criteria.
512
- *
513
- * @param params - Optional filter parameters
514
- * @returns A promise with the count of matching records
515
- *
516
- * @example
517
- * // Count all ${modelName.toLowerCase()} records
518
- * const count = await ${modelName.toLowerCase()}.count();
519
- *
520
- * @example
521
- * // Count active ${modelName.toLowerCase()} records
522
- * const activeCount = await ${modelName.toLowerCase()}.count({
523
- * where: { active: true }
524
- * });
525
- */
526
- count: (params?: {
527
- where?: ${modelName}WhereInput;
528
- }) => Promise<number>;
529
-
530
525
  /**
531
526
  * Manually refresh the data with current filter settings.
532
527
  * Useful after external operations or when realtime is disabled.
@@ -552,7 +547,10 @@ ${createInputProps
552
547
  skip?: number;
553
548
  }) => ${modelName}ManyResult;
554
549
  }`;
555
- const outputPath = path_1.default.join(config_1.OUTPUT_DIR, `${modelName}Types.ts`);
550
+ const outputPath = path_1.default.join(config_1.TYPES_DIR, `${modelName}Types.ts`);
551
+ if (!fs_1.default.existsSync(config_1.TYPES_DIR)) {
552
+ fs_1.default.mkdirSync(config_1.TYPES_DIR, { recursive: true });
553
+ }
556
554
  fs_1.default.writeFileSync(outputPath, typeContent);
557
555
  console.log(`Generated type definitions for ${modelName} at ${outputPath}`);
558
556
  return {
@@ -562,5 +560,7 @@ ${createInputProps
562
560
  hasUpdatedAt: model.fields.some((field) => field.isUpdatedAt),
563
561
  searchFields,
564
562
  defaultValues: Object.keys(defaultValues).length > 0 ? defaultValues : undefined,
563
+ createdAtField,
564
+ updatedAtField
565
565
  };
566
566
  }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });