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