suparisma 0.0.1

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 (43) hide show
  1. package/.gitattributes +2 -0
  2. package/LICENSE +21 -0
  3. package/README.md +4 -0
  4. package/dist/config.js +7 -0
  5. package/dist/generated/supabase-client-generated.js +7 -0
  6. package/dist/generators/coreGenerator.js +1430 -0
  7. package/dist/generators/hookGenerator.js +108 -0
  8. package/dist/generators/indexGenerator.js +100 -0
  9. package/dist/generators/supabaseClientGenerator.js +29 -0
  10. package/dist/generators/typeGenerator.js +566 -0
  11. package/dist/hooks/generated/UserTypes.js +2 -0
  12. package/dist/hooks/generated/core.js +1089 -0
  13. package/dist/hooks/generated/index.js +33 -0
  14. package/dist/hooks/generated/useSuparismaUser.js +60 -0
  15. package/dist/index.js +259 -0
  16. package/dist/parser.js +117 -0
  17. package/dist/types.js +2 -0
  18. package/package.json +28 -0
  19. package/prisma/schema.prisma +22 -0
  20. package/src/config.ts +7 -0
  21. package/src/generated/hooks/useSuparismaUser.ts +77 -0
  22. package/src/generated/index.ts +50 -0
  23. package/src/generated/types/UserTypes.ts +400 -0
  24. package/src/generated/utils/core.ts +1413 -0
  25. package/src/generated/utils/supabase-client.ts +7 -0
  26. package/src/generators/coreGenerator.ts +1426 -0
  27. package/src/generators/hookGenerator.ts +110 -0
  28. package/src/generators/indexGenerator.ts +117 -0
  29. package/src/generators/supabaseClientGenerator.ts +24 -0
  30. package/src/generators/typeGenerator.ts +587 -0
  31. package/src/index.ts +339 -0
  32. package/src/parser.ts +134 -0
  33. package/src/suparisma/generated/UserTypes.ts +400 -0
  34. package/src/suparisma/generated/core.ts +1413 -0
  35. package/src/suparisma/generated/hooks/useSuparismaUser.ts +77 -0
  36. package/src/suparisma/generated/index.ts +50 -0
  37. package/src/suparisma/generated/supabase-client-generated.ts +9 -0
  38. package/src/suparisma/generated/types/UserTypes.ts +400 -0
  39. package/src/suparisma/generated/useSuparismaUser.ts +77 -0
  40. package/src/suparisma/generated/utils/core.ts +1413 -0
  41. package/src/suparisma/generated/utils/supabase-client.ts +7 -0
  42. package/src/types.ts +57 -0
  43. package/tsconfig.json +20 -0
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateModelHookFile = generateModelHookFile;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const config_1 = require("../config");
10
+ /**
11
+ * Generate model-specific hook for a model
12
+ *
13
+ * This generates a standalone hook file for each model that uses the core
14
+ * hook factory to create a type-safe hook for that model.
15
+ *
16
+ * @param modelInfo - Processed model information with metadata
17
+ */
18
+ function generateModelHookFile(modelInfo) {
19
+ const { modelName, tableName, hasCreatedAt, hasUpdatedAt, searchFields, defaultValues } = modelInfo;
20
+ // Configure search fields if available
21
+ const searchConfig = searchFields && searchFields.length > 0
22
+ ? `,\n // Configure search for fields with @enableSearch annotation\n searchFields: ${JSON.stringify(searchFields)}`
23
+ : '';
24
+ // Add default values config if available
25
+ const defaultValuesConfig = defaultValues
26
+ ? `,\n // Default values from schema\n defaultValues: ${JSON.stringify(defaultValues)}`
27
+ : '';
28
+ // Generate the hook content
29
+ const hookContent = `// THIS FILE IS AUTO-GENERATED - DO NOT EDIT DIRECTLY
30
+ // Edit the generator script instead: scripts/generate-realtime-hooks.ts
31
+
32
+ import { createSuparismaHook } from './core';
33
+ import type {
34
+ ${modelName}WithRelations,
35
+ ${modelName}CreateInput,
36
+ ${modelName}UpdateInput,
37
+ ${modelName}WhereInput,
38
+ ${modelName}WhereUniqueInput,
39
+ ${modelName}OrderByInput,
40
+ ${modelName}HookApi,
41
+ Use${modelName}Options
42
+ } from './${modelName}Types';
43
+
44
+ /**
45
+ * A Prisma-like hook for interacting with ${modelName} records with real-time capabilities.
46
+ *
47
+ * This hook provides CRUD operations, real-time updates, and search functionality.
48
+ *
49
+ * @param options - Optional configuration options for the hook
50
+ * @returns An object with data state and methods for interacting with ${modelName} records
51
+ *
52
+ * @example
53
+ * // Basic usage - get all ${modelName} records with realtime updates
54
+ * const ${modelName.toLowerCase()} = ${config_1.HOOK_NAME_PREFIX}${modelName}();
55
+ * const { data, loading, error } = ${modelName.toLowerCase()};
56
+ *
57
+ * @example
58
+ * // With filtering and ordering
59
+ * const ${modelName.toLowerCase()} = ${config_1.HOOK_NAME_PREFIX}${modelName}({
60
+ * where: { active: true },
61
+ * orderBy: { created_at: 'desc' },
62
+ * limit: 10
63
+ * });
64
+ *
65
+ * @example
66
+ * // Create a new record
67
+ * const result = await ${modelName.toLowerCase()}.create({
68
+ * name: "Example Name",
69
+ * // other fields...
70
+ * });
71
+ *
72
+ * @example
73
+ * // Update a record
74
+ * const result = await ${modelName.toLowerCase()}.update({
75
+ * where: { id: "123" },
76
+ * data: { name: "Updated Name" }
77
+ * });
78
+ *
79
+ * @example
80
+ * // Delete a record
81
+ * const result = await ${modelName.toLowerCase()}.delete({ id: "123" });
82
+ *
83
+ * @example
84
+ * // Find records with specific criteria
85
+ * const result = await ${modelName.toLowerCase()}.findMany({
86
+ * where: { // filters },
87
+ * orderBy: { // ordering },
88
+ * take: 20 // limit
89
+ * });
90
+ */
91
+ export const ${config_1.HOOK_NAME_PREFIX}${modelName} = createSuparismaHook<
92
+ ${modelName}WithRelations,
93
+ ${modelName}WithRelations,
94
+ ${modelName}CreateInput,
95
+ ${modelName}UpdateInput,
96
+ ${modelName}WhereInput,
97
+ ${modelName}WhereUniqueInput,
98
+ ${modelName}OrderByInput
99
+ >({
100
+ tableName: '${tableName}',
101
+ hasCreatedAt: ${hasCreatedAt},
102
+ hasUpdatedAt: ${hasUpdatedAt}${searchConfig}${defaultValuesConfig}
103
+ }) as (options?: Use${modelName}Options) => ${modelName}HookApi;
104
+ `;
105
+ const outputPath = path_1.default.join(config_1.OUTPUT_DIR, `${config_1.HOOK_NAME_PREFIX}${modelName}.ts`);
106
+ fs_1.default.writeFileSync(outputPath, hookContent);
107
+ console.log(`Generated hook for ${modelName} at ${outputPath}`);
108
+ }
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateMainIndexFile = generateMainIndexFile;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const config_1 = require("../config");
10
+ /**
11
+ * Generate main index file to export all hooks and types.
12
+ *
13
+ * This creates a central module file that exports all generated hooks
14
+ * and their associated types, allowing for clean imports in the user's code.
15
+ *
16
+ * @param modelInfos - Array of processed model information
17
+ *
18
+ * @example
19
+ * // The generated index allows imports like:
20
+ * import useSuparisma from './hooks/generated';
21
+ * // or
22
+ * import { useSuparismaUser } from './hooks/generated';
23
+ */
24
+ function generateMainIndexFile(modelInfos) {
25
+ // Import statements for hooks
26
+ const imports = modelInfos
27
+ .map((info) => `import { ${config_1.HOOK_NAME_PREFIX}${info.modelName} } from './${config_1.HOOK_NAME_PREFIX}${info.modelName}';`)
28
+ .join('\n');
29
+ // Import all required types
30
+ const typeImports = modelInfos
31
+ .map((info) => `import type { Use${info.modelName}Options, ${info.modelName}HookApi } from './${info.modelName}Types';`)
32
+ .join('\n');
33
+ // Model-specific type exports
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';`)
36
+ .join('\n');
37
+ // Create hook interface properties
38
+ const hookProperties = modelInfos
39
+ .map((info) => ` ${info.modelName.charAt(0).toLowerCase() + info.modelName.slice(1)}: (options?: Use${info.modelName}Options) => ${info.modelName}HookApi;`)
40
+ .join('\n');
41
+ // Generate hook assignments
42
+ const hookAssignments = modelInfos
43
+ .map((info) => ` ${info.modelName.charAt(0).toLowerCase() + info.modelName.slice(1)}: ${config_1.HOOK_NAME_PREFIX}${info.modelName},`)
44
+ .join('\n');
45
+ // Generated content with all necessary imports
46
+ const content = `// THIS FILE IS AUTO-GENERATED - DO NOT EDIT DIRECTLY
47
+ // Edit the generator script instead: scripts/generate-realtime-hooks.ts
48
+
49
+ ${imports}
50
+ ${typeImports}
51
+ export type { SuparismaOptions, SearchQuery, SearchState, FilterOperators } from './core';
52
+ ${modelTypeExports}
53
+
54
+ /**
55
+ * Interface for all Suparisma hooks with dot notation access.
56
+ * This provides IntelliSense for all available models.
57
+ *
58
+ * @example
59
+ * // Access hooks for different models
60
+ * const users = useSuparisma.user();
61
+ * const posts = useSuparisma.post();
62
+ */
63
+ export interface SuparismaHooks {
64
+ ${hookProperties}
65
+ }
66
+
67
+ /**
68
+ * Main Suparisma hook object with dot notation access to all model hooks.
69
+ *
70
+ * @example
71
+ * // Get hooks for different models
72
+ * import useSuparisma from './hooks/generated';
73
+ *
74
+ * // Access user model with all hook methods
75
+ * const users = useSuparisma.user();
76
+ * const { data, loading, error } = users;
77
+ *
78
+ * // Create a new record
79
+ * await users.create({ name: "John" });
80
+ *
81
+ * // Delete a record
82
+ * await users.delete({ id: "123" });
83
+ *
84
+ * @example
85
+ * // Use with filtering and options
86
+ * const admins = useSuparisma.user({
87
+ * where: { role: 'admin' },
88
+ * orderBy: { created_at: 'desc' }
89
+ * });
90
+ */
91
+ const useSuparisma: SuparismaHooks = {
92
+ ${hookAssignments}
93
+ };
94
+
95
+ export default useSuparisma;
96
+ `;
97
+ const outputPath = path_1.default.join(config_1.OUTPUT_DIR, 'index.ts');
98
+ fs_1.default.writeFileSync(outputPath, content);
99
+ console.log(`Generated main module file at ${outputPath}`);
100
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateSupabaseClientFile = generateSupabaseClientFile;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const config_1 = require("../config"); // Assuming OUTPUT_DIR is defined in config.ts
10
+ function generateSupabaseClientFile() {
11
+ const supabaseClientContent = `// THIS FILE IS AUTO-GENERATED - DO NOT EDIT DIRECTLY
12
+
13
+ import { createClient } from '@supabase/supabase-js';
14
+
15
+ console.log(\`NEXT_PUBLIC_SUPABASE_URL: \${process.env.NEXT_PUBLIC_SUPABASE_URL}\`);
16
+ console.log(\`NEXT_PUBLIC_SUPABASE_ANON_KEY: \${process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY}\`);
17
+ export const supabase = createClient(
18
+ process.env.NEXT_PUBLIC_SUPABASE_URL!,
19
+ process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
20
+ );
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 });
26
+ }
27
+ fs_1.default.writeFileSync(outputPath, supabaseClientContent);
28
+ console.log(`🚀 Generated Supabase client file at: ${outputPath}`);
29
+ }