@cravery/core 0.0.4 → 0.0.5

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.
@@ -1,115 +1,140 @@
1
- import { z } from "zod";
2
- import type {
3
- Firestore,
4
- Transaction,
5
- WriteBatch,
6
- } from "firebase-admin/firestore";
7
-
8
- export const SortDirectionSchema = z.enum(["asc", "desc"]);
9
- export type SortDirection = z.infer<typeof SortDirectionSchema>;
10
-
11
- export interface OrderBy {
12
- field: string;
13
- direction: SortDirection;
14
- }
15
-
16
- export interface QueryOptions {
17
- limit?: number;
18
- offset?: number;
19
- orderBy?: OrderBy;
20
- }
21
-
22
- export interface PaginatedResult<T> {
23
- data: T[];
24
- total: number;
25
- hasMore: boolean;
26
- }
27
-
28
- export interface CursorPaginatedResult<T> {
29
- data: T[];
30
- nextCursor: string | null;
31
- hasMore: boolean;
32
- }
33
-
34
- export type WhereOp =
35
- | "<"
36
- | "<="
37
- | "=="
38
- | "!="
39
- | ">="
40
- | ">"
41
- | "array-contains"
42
- | "array-contains-any"
43
- | "in"
44
- | "not-in";
45
-
46
- export interface WhereClause {
47
- field: string;
48
- op: WhereOp;
49
- value: unknown;
50
- }
51
-
52
- export type TransactionCallback<R> = (transaction: Transaction) => Promise<R>;
53
-
54
- export interface RepositoryConfig {
55
- enableTimestamps?: boolean;
56
- enableSoftDelete?: boolean;
57
- validateOnWrite?: boolean;
58
- }
59
-
60
- export interface IRepository<T extends { id: string }> {
61
- // Read operations
62
- findById(id: string): Promise<T | null>;
63
- findByIds(ids: string[]): Promise<T[]>;
64
- findAll(options?: QueryOptions): Promise<T[]>;
65
- findWhere(clauses: WhereClause[], options?: QueryOptions): Promise<T[]>;
66
- findPaginated(
67
- clauses?: WhereClause[],
68
- options?: QueryOptions,
69
- ): Promise<PaginatedResult<T>>;
70
- findPaginatedCursor(
71
- clauses?: WhereClause[],
72
- options?: QueryOptions & { cursor?: string },
73
- ): Promise<CursorPaginatedResult<T>>;
74
- exists(id: string): Promise<boolean>;
75
- count(clauses?: WhereClause[]): Promise<number>;
76
-
77
- // Write operations (timestamps are auto-added by the repository)
78
- create(data: Omit<T, "id" | "createdAt" | "updatedAt" | "deletedAt">, id?: string): Promise<T>;
79
- update(id: string, data: Partial<Omit<T, "id" | "createdAt" | "updatedAt" | "deletedAt">>): Promise<T>;
80
- delete(id: string): Promise<void>;
81
-
82
- // Batch operations
83
- createMany(items: Omit<T, "id" | "createdAt" | "updatedAt" | "deletedAt">[]): Promise<T[]>;
84
- updateMany(updates: Array<{ id: string; data: Partial<Omit<T, "id" | "createdAt" | "updatedAt" | "deletedAt">> }>): Promise<void>;
85
- deleteMany(ids: string[]): Promise<void>;
86
-
87
- // Field operations
88
- increment(id: string, field: keyof T, value?: number): Promise<void>;
89
- decrement(id: string, field: keyof T, value?: number): Promise<void>;
90
-
91
- // Transaction support
92
- runTransaction<R>(callback: TransactionCallback<R>): Promise<R>;
93
- getFirestore(): Firestore;
94
- batch(): WriteBatch;
95
-
96
- // Batch operations (for cross-repository atomic writes)
97
- createInBatch(batch: WriteBatch, data: Omit<T, "id" | "createdAt" | "updatedAt" | "deletedAt">, id?: string): T;
98
- setInBatch(batch: WriteBatch, id: string, data: Partial<Omit<T, "id" | "createdAt" | "updatedAt" | "deletedAt">>): void;
99
- updateInBatch(batch: WriteBatch, id: string, data: Partial<Omit<T, "id" | "createdAt" | "updatedAt" | "deletedAt">>): void;
100
- deleteInBatch(batch: WriteBatch, id: string): void;
101
- }
102
-
103
- export interface IRTDBRepository<T extends { id: string }> {
104
- get(id: string): Promise<T | null>;
105
- getAll(): Promise<T[]>;
106
-
107
- set(id: string, data: T): Promise<void>;
108
- update(id: string, data: Partial<T>): Promise<void>;
109
- remove(id: string): Promise<void>;
110
-
111
- increment(id: string, field: string, delta?: number): Promise<void>;
112
- decrement(id: string, field: string, delta?: number): Promise<void>;
113
-
114
- multiUpdate(updates: Record<string, unknown>): Promise<void>;
115
- }
1
+ import { z } from "zod";
2
+ import type {
3
+ Firestore,
4
+ Transaction,
5
+ WriteBatch,
6
+ } from "firebase-admin/firestore";
7
+
8
+ export const SortDirectionSchema = z.enum(["asc", "desc"]);
9
+ export type SortDirection = z.infer<typeof SortDirectionSchema>;
10
+
11
+ export interface OrderBy {
12
+ field: string;
13
+ direction: SortDirection;
14
+ }
15
+
16
+ export interface QueryOptions {
17
+ limit?: number;
18
+ offset?: number;
19
+ orderBy?: OrderBy;
20
+ }
21
+
22
+ export interface PaginatedResult<T> {
23
+ data: T[];
24
+ total: number;
25
+ hasMore: boolean;
26
+ }
27
+
28
+ export interface CursorPaginatedResult<T> {
29
+ data: T[];
30
+ nextCursor: string | null;
31
+ hasMore: boolean;
32
+ }
33
+
34
+ export type WhereOp =
35
+ | "<"
36
+ | "<="
37
+ | "=="
38
+ | "!="
39
+ | ">="
40
+ | ">"
41
+ | "array-contains"
42
+ | "array-contains-any"
43
+ | "in"
44
+ | "not-in";
45
+
46
+ export interface WhereClause {
47
+ field: string;
48
+ op: WhereOp;
49
+ value: unknown;
50
+ }
51
+
52
+ export type TransactionCallback<R> = (transaction: Transaction) => Promise<R>;
53
+
54
+ export interface RepositoryConfig {
55
+ enableTimestamps?: boolean;
56
+ enableSoftDelete?: boolean;
57
+ validateOnWrite?: boolean;
58
+ }
59
+
60
+ export interface IRepository<T extends { id: string }> {
61
+ // Read operations
62
+ findById(id: string): Promise<T | null>;
63
+ findByIds(ids: string[]): Promise<T[]>;
64
+ findAll(options?: QueryOptions): Promise<T[]>;
65
+ findWhere(clauses: WhereClause[], options?: QueryOptions): Promise<T[]>;
66
+ findPaginated(
67
+ clauses?: WhereClause[],
68
+ options?: QueryOptions,
69
+ ): Promise<PaginatedResult<T>>;
70
+ findPaginatedCursor(
71
+ clauses?: WhereClause[],
72
+ options?: QueryOptions & { cursor?: string },
73
+ ): Promise<CursorPaginatedResult<T>>;
74
+ exists(id: string): Promise<boolean>;
75
+ count(clauses?: WhereClause[]): Promise<number>;
76
+
77
+ // Write operations (timestamps are auto-added by the repository)
78
+ create(
79
+ data: Omit<T, "id" | "createdAt" | "updatedAt" | "deletedAt">,
80
+ id?: string,
81
+ ): Promise<T>;
82
+ update(
83
+ id: string,
84
+ data: Partial<Omit<T, "id" | "createdAt" | "updatedAt" | "deletedAt">>,
85
+ ): Promise<T>;
86
+ delete(id: string): Promise<void>;
87
+
88
+ // Batch operations
89
+ createMany(
90
+ items: Omit<T, "id" | "createdAt" | "updatedAt" | "deletedAt">[],
91
+ ): Promise<T[]>;
92
+ updateMany(
93
+ updates: Array<{
94
+ id: string;
95
+ data: Partial<Omit<T, "id" | "createdAt" | "updatedAt" | "deletedAt">>;
96
+ }>,
97
+ ): Promise<void>;
98
+ deleteMany(ids: string[]): Promise<void>;
99
+
100
+ // Field operations
101
+ increment(id: string, field: keyof T, value?: number): Promise<void>;
102
+ decrement(id: string, field: keyof T, value?: number): Promise<void>;
103
+
104
+ // Transaction support
105
+ runTransaction<R>(callback: TransactionCallback<R>): Promise<R>;
106
+ getFirestore(): Firestore;
107
+ batch(): WriteBatch;
108
+
109
+ // Batch operations (for cross-repository atomic writes)
110
+ createInBatch(
111
+ batch: WriteBatch,
112
+ data: Omit<T, "id" | "createdAt" | "updatedAt" | "deletedAt">,
113
+ id?: string,
114
+ ): T;
115
+ setInBatch(
116
+ batch: WriteBatch,
117
+ id: string,
118
+ data: Partial<Omit<T, "id" | "createdAt" | "updatedAt" | "deletedAt">>,
119
+ ): void;
120
+ updateInBatch(
121
+ batch: WriteBatch,
122
+ id: string,
123
+ data: Partial<Omit<T, "id" | "createdAt" | "updatedAt" | "deletedAt">>,
124
+ ): void;
125
+ deleteInBatch(batch: WriteBatch, id: string): void;
126
+ }
127
+
128
+ export interface IRTDBRepository<T extends { id: string }> {
129
+ get(id: string): Promise<T | null>;
130
+ getAll(): Promise<T[]>;
131
+
132
+ set(id: string, data: T): Promise<void>;
133
+ update(id: string, data: Partial<T>): Promise<void>;
134
+ remove(id: string): Promise<void>;
135
+
136
+ increment(id: string, field: string, delta?: number): Promise<void>;
137
+ decrement(id: string, field: string, delta?: number): Promise<void>;
138
+
139
+ multiUpdate(updates: Record<string, unknown>): Promise<void>;
140
+ }
@@ -1,85 +1,44 @@
1
- import { z } from "zod";
2
- import { Timestamp } from "firebase-admin/firestore";
3
- import { AllergenSchema } from "../enums/allergen";
4
- import { DietaryTagSchema } from "../enums/dietary_tag";
5
- import { CuisineSchema } from "../enums/cuisine";
6
- import { SpicinessSchema } from "../enums/spiciness";
7
- import { LocaleSchema } from "../enums/locale";
8
- import { TemperatureUnitSchema } from "../enums/temperature_unit";
9
-
10
- export const MEASUREMENT_SYSTEM_VALUES = ["metric", "imperial"] as const;
11
- export const MeasurementSystemSchema = z.enum(MEASUREMENT_SYSTEM_VALUES);
12
- export type MeasurementSystem = (typeof MEASUREMENT_SYSTEM_VALUES)[number];
13
-
14
- export const THEME_VALUES = ["light", "dark", "system"] as const;
15
- export const ThemeSchema = z.enum(THEME_VALUES);
16
- export type Theme = (typeof THEME_VALUES)[number];
17
-
18
- export const NotificationSettingsSchema = z.object({
19
- email: z.boolean(),
20
- push: z.boolean(),
21
- marketing: z.boolean(),
22
- weeklyDigest: z.boolean(),
23
- });
24
- export type NotificationSettings = z.infer<typeof NotificationSettingsSchema>;
25
-
26
- export const PrivacySettingsSchema = z.object({
27
- showAllergensOnProfile: z.boolean(),
28
- showDietaryTagsOnProfile: z.boolean(),
29
- allowRecipeRecommendations: z.boolean(),
30
- });
31
- export type PrivacySettings = z.infer<typeof PrivacySettingsSchema>;
32
-
33
- export const SettingsSchema = z.object({
34
- id: z.string(),
35
-
36
- // Dietary preferences
37
- allergens: z.array(AllergenSchema),
38
- dietaryTags: z.array(DietaryTagSchema),
39
- cuisinePreferences: z.array(CuisineSchema),
40
- spicinessPreference: SpicinessSchema.optional(),
41
- excludedIngredients: z.array(z.string()),
42
-
43
- // App preferences
44
- locale: LocaleSchema,
45
- temperatureUnit: TemperatureUnitSchema,
46
- measurementSystem: MeasurementSystemSchema,
47
- theme: ThemeSchema,
48
-
49
- // Notifications
50
- notifications: NotificationSettingsSchema,
51
-
52
- // Privacy
53
- privacy: PrivacySettingsSchema,
54
-
55
- // Timestamps
56
- createdAt: z.custom<Timestamp>(),
57
- updatedAt: z.custom<Timestamp>(),
58
- });
59
-
60
- export type Settings = z.infer<typeof SettingsSchema>;
61
-
62
- export type SettingsInput = Omit<Settings, "id" | "createdAt" | "updatedAt">;
63
-
64
- export const createDefaultSettings = (): SettingsInput => ({
65
- allergens: [],
66
- dietaryTags: [],
67
- cuisinePreferences: [],
68
- spicinessPreference: undefined,
69
- excludedIngredients: [],
70
- locale: "en",
71
- temperatureUnit: "celsius",
72
- measurementSystem: "metric",
73
- theme: "system",
74
- notifications: {
75
- email: true,
76
- push: true,
77
- marketing: false,
78
- weeklyDigest: true,
79
- },
80
- privacy: {
81
- showAllergensOnProfile: false,
82
- showDietaryTagsOnProfile: false,
83
- allowRecipeRecommendations: true,
84
- },
85
- });
1
+ import { z } from "zod";
2
+ import { Timestamp } from "firebase-admin/firestore";
3
+ import { AllergenSchema } from "../enums/allergen";
4
+ import { DietaryTagSchema } from "../enums/dietary_tag";
5
+ import { CuisineSchema } from "../enums/cuisine";
6
+ import { SpicinessSchema } from "../enums/spiciness";
7
+ import { LocaleSchema } from "../enums/locale";
8
+ import { TemperatureUnitSchema } from "../enums/temperature_unit";
9
+
10
+ export const MEASUREMENT_SYSTEM_VALUES = ["metric", "imperial"] as const;
11
+ export const MeasurementSystemSchema = z.enum(MEASUREMENT_SYSTEM_VALUES);
12
+ export type MeasurementSystem = (typeof MEASUREMENT_SYSTEM_VALUES)[number];
13
+
14
+ export const THEME_VALUES = ["light", "dark", "system"] as const;
15
+ export const ThemeSchema = z.enum(THEME_VALUES);
16
+ export type Theme = (typeof THEME_VALUES)[number];
17
+
18
+ export const NotificationSettingsSchema = z.object({
19
+ email: z.boolean(),
20
+ push: z.boolean(),
21
+ marketing: z.boolean(),
22
+ weeklyDigest: z.boolean(),
23
+ });
24
+ export type NotificationSettings = z.infer<typeof NotificationSettingsSchema>;
25
+
26
+ export const SettingsSchema = z.object({
27
+ id: z.string(),
28
+ allergens: z.array(AllergenSchema),
29
+ dietaryTags: z.array(DietaryTagSchema),
30
+ cuisines: z.array(CuisineSchema),
31
+ spiciness: SpicinessSchema.optional(),
32
+ excludedIngredients: z.array(z.string()),
33
+ locale: LocaleSchema,
34
+ temperatureUnit: TemperatureUnitSchema,
35
+ measurementSystem: MeasurementSystemSchema,
36
+ theme: ThemeSchema,
37
+ notifications: NotificationSettingsSchema,
38
+ createdAt: z.custom<Timestamp>(),
39
+ updatedAt: z.custom<Timestamp>(),
40
+ });
41
+
42
+ export type Settings = z.infer<typeof SettingsSchema>;
43
+
44
+ export type SettingsInput = Omit<Settings, "id" | "createdAt" | "updatedAt">;
package/src/types/user.ts CHANGED
@@ -15,4 +15,7 @@ export const UserSchema = z.object({
15
15
  });
16
16
  export type User = z.infer<typeof UserSchema>;
17
17
 
18
- export type UserInput = Omit<User, "id" | "createdAt" | "updatedAt" | "deletedAt">;
18
+ export type UserInput = Omit<
19
+ User,
20
+ "id" | "createdAt" | "updatedAt" | "deletedAt"
21
+ >;