suparisma 0.0.1 → 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.
Files changed (38) hide show
  1. package/README.md +156 -3
  2. package/dist/config.js +12 -3
  3. package/dist/generators/coreGenerator.js +122 -40
  4. package/dist/generators/hookGenerator.js +16 -7
  5. package/dist/generators/indexGenerator.js +12 -7
  6. package/dist/generators/supabaseClientGenerator.js +5 -5
  7. package/dist/generators/typeGenerator.js +22 -22
  8. package/dist/index.js +103 -25
  9. package/{src/suparisma/generated/useSuparismaUser.ts → dist/suparisma/generated/hooks/useSuparismaUser.js} +19 -35
  10. package/dist/suparisma/generated/index.js +33 -0
  11. package/dist/suparisma/generated/types/UserTypes.js +4 -0
  12. package/dist/suparisma/generated/utils/core.js +1090 -0
  13. package/dist/suparisma/generated/utils/supabase-client.js +8 -0
  14. package/package.json +12 -2
  15. package/prisma/schema.prisma +19 -3
  16. package/tsconfig.json +1 -1
  17. package/src/config.ts +0 -7
  18. package/src/generated/hooks/useSuparismaUser.ts +0 -77
  19. package/src/generated/index.ts +0 -50
  20. package/src/generated/types/UserTypes.ts +0 -400
  21. package/src/generated/utils/core.ts +0 -1413
  22. package/src/generated/utils/supabase-client.ts +0 -7
  23. package/src/generators/coreGenerator.ts +0 -1426
  24. package/src/generators/hookGenerator.ts +0 -110
  25. package/src/generators/indexGenerator.ts +0 -117
  26. package/src/generators/supabaseClientGenerator.ts +0 -24
  27. package/src/generators/typeGenerator.ts +0 -587
  28. package/src/index.ts +0 -339
  29. package/src/parser.ts +0 -134
  30. package/src/suparisma/generated/UserTypes.ts +0 -400
  31. package/src/suparisma/generated/core.ts +0 -1413
  32. package/src/suparisma/generated/hooks/useSuparismaUser.ts +0 -77
  33. package/src/suparisma/generated/index.ts +0 -50
  34. package/src/suparisma/generated/supabase-client-generated.ts +0 -9
  35. package/src/suparisma/generated/types/UserTypes.ts +0 -400
  36. package/src/suparisma/generated/utils/core.ts +0 -1413
  37. package/src/suparisma/generated/utils/supabase-client.ts +0 -7
  38. package/src/types.ts +0 -57
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ // THIS FILE IS AUTO-GENERATED - DO NOT EDIT DIRECTLY
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.supabase = void 0;
5
+ const supabase_js_1 = require("@supabase/supabase-js");
6
+ console.log(`NEXT_PUBLIC_SUPABASE_URL: ${process.env.NEXT_PUBLIC_SUPABASE_URL}`);
7
+ console.log(`NEXT_PUBLIC_SUPABASE_ANON_KEY: ${process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY}`);
8
+ exports.supabase = (0, supabase_js_1.createClient)(process.env.NEXT_PUBLIC_SUPABASE_URL, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suparisma",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Opinionated typesafe React realtime CRUD hooks generator for all your Supabase tables, powered by Prisma.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -8,8 +8,18 @@
8
8
  "start": "node dist/index.js",
9
9
  "test": "jest",
10
10
  "generate-prisma-types": "prisma generate",
11
- "generate-hooks": "ts-node --transpile-only src/index.ts"
11
+ "generate-hooks-dev": "npx prisma generate && npx prisma db push && ts-node --transpile-only src/index.ts generate",
12
+ "run-next-example": "cd src/examples/with-next && npm run dev"
12
13
  },
14
+ "keywords": [
15
+ "react",
16
+ "hooks",
17
+ "supabase",
18
+ "prisma",
19
+ "typescript",
20
+ "nextjs",
21
+ "realtime"
22
+ ],
13
23
  "dependencies": {
14
24
  "@supabase/supabase-js": "^2.49.4",
15
25
  "dotenv": "^16.5.0",
@@ -1,4 +1,4 @@
1
- // This is your Prisma schema file,
1
+ // This is a sample Prisma schema file,
2
2
  // learn more about it in the docs: https://pris.ly/d/prisma-schema
3
3
 
4
4
  // Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
@@ -13,10 +13,26 @@ datasource db {
13
13
  url = env("DATABASE_URL")
14
14
  }
15
15
 
16
- model User {
16
+ enum SomeEnum {
17
+ ONE
18
+ TWO
19
+ THREE
20
+ }
21
+
22
+ // Realtime is enabled by default for all models
23
+ model Thing {
17
24
  id String @id @default(uuid())
18
- email String @unique
19
25
  name String?
26
+ someEnum SomeEnum @default(ONE)
27
+ someNumber Int?
20
28
  createdAt DateTime @default(now())
21
29
  updatedAt DateTime @updatedAt
22
30
  }
31
+
32
+ // @disableRealtime
33
+ model AuditLog {
34
+ id String @id @default(uuid())
35
+ action String
36
+ details String?
37
+ createdAt DateTime @default(now())
38
+ }
package/tsconfig.json CHANGED
@@ -16,5 +16,5 @@
16
16
  "jsx": "preserve"
17
17
  },
18
18
  "include": ["src/**/*", "../src/app/**/*.ts"],
19
- "exclude": ["node_modules", "**/*.spec.ts"]
19
+ "exclude": ["node_modules", "**/*.spec.ts", "src/examples/**/*"]
20
20
  }
package/src/config.ts DELETED
@@ -1,7 +0,0 @@
1
- // Configuration
2
- export const PRISMA_SCHEMA_PATH = process.env.SUPARISMA_PRISMA_SCHEMA_PATH || 'prisma/schema.prisma';
3
- export const OUTPUT_DIR = process.env.SUPARISMA_OUTPUT_DIR || 'src/suparisma/generated';
4
- export const TYPES_DIR = `${OUTPUT_DIR}/types`;
5
- export const HOOKS_DIR = `${OUTPUT_DIR}/hooks`;
6
- export const UTILS_DIR = `${OUTPUT_DIR}/utils`;
7
- export const HOOK_NAME_PREFIX = 'useSuparisma';
@@ -1,77 +0,0 @@
1
- // THIS FILE IS AUTO-GENERATED - DO NOT EDIT DIRECTLY
2
- // Edit the generator script instead: scripts/generate-realtime-hooks.ts
3
-
4
- import { createSuparismaHook } from '../utils/core';
5
- import type {
6
- UserWithRelations,
7
- UserCreateInput,
8
- UserUpdateInput,
9
- UserWhereInput,
10
- UserWhereUniqueInput,
11
- UserOrderByInput,
12
- UserHookApi,
13
- UseUserOptions
14
- } from '../types/UserTypes';
15
-
16
- /**
17
- * A Prisma-like hook for interacting with User records with real-time capabilities.
18
- *
19
- * This hook provides CRUD operations, real-time updates, and search functionality.
20
- *
21
- * @param options - Optional configuration options for the hook
22
- * @returns An object with data state and methods for interacting with User records
23
- *
24
- * @example
25
- * // Basic usage - get all User records with realtime updates
26
- * const user = useSuparismaUser();
27
- * const { data, loading, error } = user;
28
- *
29
- * @example
30
- * // With filtering and ordering
31
- * const user = useSuparismaUser({
32
- * where: { active: true },
33
- * orderBy: { created_at: 'desc' },
34
- * limit: 10
35
- * });
36
- *
37
- * @example
38
- * // Create a new record
39
- * const result = await user.create({
40
- * name: "Example Name",
41
- * // other fields...
42
- * });
43
- *
44
- * @example
45
- * // Update a record
46
- * const result = await user.update({
47
- * where: { id: "123" },
48
- * data: { name: "Updated Name" }
49
- * });
50
- *
51
- * @example
52
- * // Delete a record
53
- * const result = await user.delete({ id: "123" });
54
- *
55
- * @example
56
- * // Find records with specific criteria
57
- * const result = await user.findMany({
58
- * where: { // filters },
59
- * orderBy: { // ordering },
60
- * take: 20 // limit
61
- * });
62
- */
63
- export const useSuparismaUser = createSuparismaHook<
64
- UserWithRelations,
65
- UserWithRelations,
66
- UserCreateInput,
67
- UserUpdateInput,
68
- UserWhereInput,
69
- UserWhereUniqueInput,
70
- UserOrderByInput
71
- >({
72
- tableName: 'User',
73
- hasCreatedAt: true,
74
- hasUpdatedAt: true,
75
- // Default values from schema
76
- defaultValues: {"id":"uuid(","createdAt":"now("}
77
- }) as (options?: UseUserOptions) => UserHookApi;
@@ -1,50 +0,0 @@
1
- // THIS FILE IS AUTO-GENERATED - DO NOT EDIT DIRECTLY
2
- // Edit the generator script instead: scripts/generate-realtime-hooks.ts
3
-
4
- import { useSuparismaUser } from './hooks/useSuparismaUser';
5
- import type { UseUserOptions, UserHookApi } from './types/UserTypes';
6
- export type { SuparismaOptions, SearchQuery, SearchState, FilterOperators } from './utils/core';
7
- export type { UserWithRelations, UserCreateInput, UserUpdateInput, UserWhereInput, UserWhereUniqueInput, UserOrderByInput, UserHookApi, UseUserOptions } from './types/UserTypes';
8
-
9
- /**
10
- * Interface for all Suparisma hooks with dot notation access.
11
- * This provides IntelliSense for all available models.
12
- *
13
- * @example
14
- * // Access hooks for different models
15
- * const users = useSuparisma.user();
16
- * const posts = useSuparisma.post();
17
- */
18
- export interface SuparismaHooks {
19
- user: (options?: UseUserOptions) => UserHookApi;
20
- }
21
-
22
- /**
23
- * Main Suparisma hook object with dot notation access to all model hooks.
24
- *
25
- * @example
26
- * // Get hooks for different models
27
- * import useSuparisma from './generated';
28
- *
29
- * // Access user model with all hook methods
30
- * const users = useSuparisma.user();
31
- * const { data, loading, error } = users;
32
- *
33
- * // Create a new record
34
- * await users.create({ name: "John" });
35
- *
36
- * // Delete a record
37
- * await users.delete({ id: "123" });
38
- *
39
- * @example
40
- * // Use with filtering and options
41
- * const admins = useSuparisma.user({
42
- * where: { role: 'admin' },
43
- * orderBy: { created_at: 'desc' }
44
- * });
45
- */
46
- const useSuparisma: SuparismaHooks = {
47
- user: useSuparismaUser,
48
- };
49
-
50
- export default useSuparisma;
@@ -1,400 +0,0 @@
1
- // THIS FILE IS AUTO-GENERATED - DO NOT EDIT DIRECTLY
2
- // Edit the generator script instead
3
-
4
- import type { User } from '@prisma/client';
5
- import type { ModelResult, SuparismaOptions, SearchQuery, SearchState } from '../utils/core';
6
-
7
- /**
8
- * Extended User type that includes relation fields.
9
- * This represents the complete shape of User records returned from the database.
10
- */
11
- export interface UserWithRelations {
12
- id: string;
13
- email: string;
14
- name?: string;
15
- createdAt: string;
16
- updatedAt: string;
17
- }
18
-
19
- /**
20
- * Input type for creating a new User record.
21
- * Fields with default values are optional and will be filled automatically if not provided.
22
- *
23
- * @example
24
- * // Create a minimal user
25
- * user.create({
26
- * // Required fields only
27
- * email: string,
28
- * });
29
- *
30
- * @example
31
- * // Create with optional fields
32
- * user.create({
33
- * // All fields including optional ones
34
- * id?: string,
35
- * email: string,
36
- * name?: string,
37
- * });
38
- */
39
- export interface UserCreateInput {
40
- id?: string;
41
- email: string;
42
- name?: string;
43
- }
44
-
45
- /**
46
- * Input type for updating an existing User record.
47
- * All fields are optional since you only need to specify the fields you want to change.
48
- *
49
- * @example
50
- * // Update a user's fields
51
- * user.update({
52
- * where: { id: "123" },
53
- * data: {
54
- * id?: string,
55
- * email: string,
56
- * }
57
- * });
58
- */
59
- export type UserUpdateInput = Partial<UserCreateInput>;
60
-
61
- /**
62
- * Filter type for querying User records.
63
- * You can filter by any field in the model using equality or advanced filter operators.
64
- *
65
- * @example
66
- * // Basic filtering
67
- * user.findMany({
68
- * where: {
69
- * id: "value",
70
- * email: "value"
71
- * }
72
- * });
73
- *
74
- * @example
75
- * // Advanced filtering
76
- * user.findMany({
77
- * where: {
78
- * // Use advanced operators
79
- * id: { contains: "partial" }
80
- * }
81
- * });
82
- */
83
- export type UserWhereInput = Partial<UserWithRelations>;
84
-
85
- /**
86
- * Unique identifier for finding a specific User record.
87
- * Usually uses the ID field but can be any field marked as @unique in the schema.
88
- *
89
- * @example
90
- * // Find by ID
91
- * user.findUnique({ id: "123" });
92
- *
93
- * @example
94
- * // Delete by ID
95
- * user.delete({ id: "123" });
96
- */
97
- export type UserWhereUniqueInput = {
98
- id: string;
99
- };
100
-
101
- /**
102
- * Sort options for User queries.
103
- * Specify the field to sort by and the direction ('asc' or 'desc').
104
- *
105
- * @example
106
- * // Sort by creation date, newest first
107
- * user.findMany({
108
- * orderBy: { created_at: 'desc' }
109
- * });
110
- *
111
- * @example
112
- * // Sort alphabetically
113
- * user.findMany({
114
- * orderBy: { name: 'asc' }
115
- * });
116
- */
117
- export type UserOrderByInput = {
118
- [key in keyof UserWithRelations]?: 'asc' | 'desc';
119
- };
120
-
121
- /**
122
- * Result type for operations that return a single User record.
123
- */
124
- export type UserSingleResult = ModelResult<UserWithRelations>;
125
-
126
- /**
127
- * Result type for operations that return multiple User records.
128
- */
129
- export type UserManyResult = ModelResult<UserWithRelations[]>;
130
-
131
- /**
132
- * Configuration options for the User hook.
133
- */
134
- export type UseUserOptions = SuparismaOptions<UserWhereInput, UserOrderByInput>;
135
-
136
- /**
137
- * The complete API for interacting with User records.
138
- * This interface defines all available operations and state properties.
139
- */
140
- export interface UserHookApi {
141
- /**
142
- * Current array of User records.
143
- * This is automatically updated when:
144
- * - The initial data is loaded
145
- * - Mutations are performed (create, update, delete)
146
- * - Real-time updates are received from other clients
147
- * - The refresh method is called
148
- *
149
- * @example
150
- * // Render a list of user records
151
- * const { data } = user;
152
- * return (
153
- * <ul>
154
- * {data.map(item => (
155
- * <li key={item.id}>{item.name}</li>
156
- * ))}
157
- * </ul>
158
- * );
159
- */
160
- data: UserWithRelations[];
161
-
162
- /**
163
- * Error object if the last operation failed, null otherwise.
164
- *
165
- * @example
166
- * // Handle potential errors
167
- * const { error } = user;
168
- * if (error) {
169
- * return <div>Error: {error.message}</div>;
170
- * }
171
- */
172
- error: Error | null;
173
-
174
- /**
175
- * Boolean indicating if an operation is in progress.
176
- *
177
- * @example
178
- * // Show loading state
179
- * const { loading } = user;
180
- * if (loading) {
181
- * return <div>Loading...</div>;
182
- * }
183
- */
184
- loading: boolean;
185
-
186
-
187
-
188
- /**
189
- * Find a single User record by its unique identifier.
190
- *
191
- * @param where - The unique identifier to find the record by
192
- * @returns A promise with the found record or error
193
- *
194
- * @example
195
- * // Find user by ID
196
- * const result = await user.findUnique({ id: "123" });
197
- * if (result.data) {
198
- * console.log("Found user:", result.data);
199
- * }
200
- */
201
- findUnique: (where: UserWhereUniqueInput) => UserSingleResult;
202
-
203
- /**
204
- * Find multiple User records matching the filter criteria.
205
- * Supports filtering, sorting, and pagination.
206
- *
207
- * @param params - Optional query parameters
208
- * @returns A promise with the matching records or error
209
- *
210
- * @example
211
- * // Get all user records
212
- * const result = await user.findMany();
213
- *
214
- * @example
215
- * // Filter and sort records
216
- * const result = await user.findMany({
217
- * where: { active: true },
218
- * orderBy: { created_at: 'desc' },
219
- * take: 10,
220
- * skip: 0
221
- * });
222
- */
223
- findMany: (params?: {
224
- where?: UserWhereInput;
225
- orderBy?: UserOrderByInput;
226
- take?: number;
227
- skip?: number;
228
- }) => UserManyResult;
229
-
230
- /**
231
- * Find the first User record matching the filter criteria.
232
- *
233
- * @param params - Optional query parameters
234
- * @returns A promise with the first matching record or error
235
- *
236
- * @example
237
- * // Find the first active user
238
- * const result = await user.findFirst({
239
- * where: { active: true }
240
- * });
241
- *
242
- * @example
243
- * // Find the oldest user
244
- * const result = await user.findFirst({
245
- * orderBy: { created_at: 'asc' }
246
- * });
247
- */
248
- findFirst: (params?: {
249
- where?: UserWhereInput;
250
- orderBy?: UserOrderByInput;
251
- }) => UserSingleResult;
252
-
253
- /**
254
- * Create a new User record.
255
- * Fields with default values are optional and will use their defaults if not provided.
256
- *
257
- * @param data - The data for the new record
258
- * @returns A promise with the created record or error
259
- *
260
- * @example
261
- * // Create a new user
262
- * const result = await user.create({
263
- * email: "value"
264
- * });
265
- *
266
- * @example
267
- * // Create with custom ID (overriding default)
268
- * const result = await user.create({
269
- * id: "custom-id",
270
- * email: "value"
271
- * });
272
- */
273
- create: (data: UserCreateInput) => UserSingleResult;
274
-
275
- /**
276
- * Update an existing User record.
277
- *
278
- * @param params - Object with the record identifier and fields to update
279
- * @returns A promise with the updated record or error
280
- *
281
- * @example
282
- * // Update a user's fields
283
- * const result = await user.update({
284
- * where: { id: "123" },
285
- * data: {
286
- * id?: "updated value",
287
- * email: "updated value"
288
- * }
289
- * });
290
- */
291
- update: (params: {
292
- where: UserWhereUniqueInput;
293
- data: UserUpdateInput;
294
- }) => UserSingleResult;
295
-
296
- /**
297
- * Delete a User record by its unique identifier.
298
- *
299
- * @param where - The unique identifier of the record to delete
300
- * @returns A promise with the deleted record or error
301
- *
302
- * @example
303
- * // Delete a user by ID
304
- * const result = await user.delete({ id: "123" });
305
- * if (result.data) {
306
- * console.log("Deleted user:", result.data);
307
- * }
308
- */
309
- delete: (where: UserWhereUniqueInput) => UserSingleResult;
310
-
311
- /**
312
- * Delete multiple User records matching the filter criteria.
313
- *
314
- * @param params - Optional filter parameters
315
- * @returns A promise with the count of deleted records or error
316
- *
317
- * @example
318
- * // Delete all inactive user records
319
- * const result = await user.deleteMany({
320
- * where: { active: false }
321
- * });
322
- * console.log(`Deleted ${result.count} records`);
323
- *
324
- * @example
325
- * // Delete all user records (use with caution!)
326
- * const result = await user.deleteMany();
327
- */
328
- deleteMany: (params?: {
329
- where?: UserWhereInput;
330
- }) => Promise<{ count: number; error: Error | null }>;
331
-
332
- /**
333
- * Create a record if it doesn't exist, or update it if it does.
334
- *
335
- * @param params - Object with the identifier, update data, and create data
336
- * @returns A promise with the created or updated record or error
337
- *
338
- * @example
339
- * // Upsert a user by ID
340
- * const result = await user.upsert({
341
- * where: { id: "123" },
342
- * update: { name: "Updated Name" },
343
- * create: {
344
- * id: "123",
345
- * name: "New Name",
346
- * email: "value"
347
- * }
348
- * });
349
- */
350
- upsert: (params: {
351
- where: UserWhereUniqueInput;
352
- update: UserUpdateInput;
353
- create: UserCreateInput;
354
- }) => UserSingleResult;
355
-
356
- /**
357
- * Count the number of User records matching the filter criteria.
358
- *
359
- * @param params - Optional filter parameters
360
- * @returns A promise with the count of matching records
361
- *
362
- * @example
363
- * // Count all user records
364
- * const count = await user.count();
365
- *
366
- * @example
367
- * // Count active user records
368
- * const activeCount = await user.count({
369
- * where: { active: true }
370
- * });
371
- */
372
- count: (params?: {
373
- where?: UserWhereInput;
374
- }) => Promise<number>;
375
-
376
- /**
377
- * Manually refresh the data with current filter settings.
378
- * Useful after external operations or when realtime is disabled.
379
- *
380
- * @param params - Optional override parameters for this specific refresh
381
- * @returns A promise with the refreshed data or error
382
- *
383
- * @example
384
- * // Refresh with current filter settings
385
- * await user.refresh();
386
- *
387
- * @example
388
- * // Refresh with different filters for this call only
389
- * await user.refresh({
390
- * where: { active: true },
391
- * orderBy: { name: 'asc' }
392
- * });
393
- */
394
- refresh: (params?: {
395
- where?: UserWhereInput;
396
- orderBy?: UserOrderByInput;
397
- take?: number;
398
- skip?: number;
399
- }) => UserManyResult;
400
- }