@m5kdev/backend 0.5.0 → 0.6.0

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,5 +1,5 @@
1
- import type { RecurrenceService } from "./recurrence.service";
2
1
  import { type TRPCMethods } from "../../utils/trpc";
2
+ import type { RecurrenceService } from "./recurrence.service";
3
3
  export declare function createRecurrenceTRPC({ router, privateProcedure: procedure }: TRPCMethods, recurrenceService: RecurrenceService): import("@trpc/server").TRPCBuiltRouter<{
4
4
  ctx: import("../auth/auth.lib").Context;
5
5
  meta: any;
@@ -15,7 +15,7 @@ export declare function createRecurrenceTRPC({ router, privateProcedure: procedu
15
15
  filters?: {
16
16
  columnId: string;
17
17
  type: "string" | "number" | "boolean" | "date" | "enum";
18
- method: "contains" | "equals" | "starts_with" | "ends_with" | "greater_than" | "less_than" | "on" | "between" | "before" | "after" | "oneOf" | "intersect" | "isEmpty" | "isNotEmpty" | "is_null" | "is_not_null";
18
+ method: "on" | "contains" | "equals" | "starts_with" | "ends_with" | "greater_than" | "less_than" | "between" | "before" | "after" | "oneOf" | "intersect" | "isEmpty" | "isNotEmpty" | "is_null" | "is_not_null";
19
19
  value: string | number | boolean | string[];
20
20
  valueTo?: string | undefined;
21
21
  endColumnId?: string | undefined;
@@ -20,7 +20,7 @@ const deleteRecurrenceOutputSchema = zod_1.z.object({ id: zod_1.z.string() });
20
20
  function createRecurrenceTRPC({ router, privateProcedure: procedure }, recurrenceService) {
21
21
  return router({
22
22
  list: procedure
23
- .input(query_schema_1.querySchema.optional())
23
+ .input(query_schema_1.querySchema.default({}))
24
24
  .output(listRecurrenceOutputSchema)
25
25
  .query(async ({ ctx, input }) => {
26
26
  return (0, trpc_1.handleTRPCResult)(await recurrenceService.list(input, ctx));
@@ -122,34 +122,35 @@ class TagRepository extends base_repository_1.BaseTableRepository {
122
122
  });
123
123
  }
124
124
  async listTaggings(input, tx) {
125
- return this.throwableAsync(async () => {
126
- const db = tx ?? this.orm;
127
- const filters = [(0, drizzle_orm_1.eq)(this.schema.taggings.resourceType, input.resourceType)];
128
- if (input.resourceIds?.length) {
129
- filters.push((0, drizzle_orm_1.inArray)(this.schema.taggings.resourceId, input.resourceIds));
130
- }
131
- const rows = await db
132
- .select()
133
- .from(this.schema.taggings)
134
- .where((0, drizzle_orm_1.and)(...filters));
135
- return (0, neverthrow_1.ok)(rows);
136
- });
125
+ const db = tx ?? this.orm;
126
+ const filters = [(0, drizzle_orm_1.eq)(this.schema.taggings.resourceType, input.resourceType)];
127
+ if (input.resourceIds?.length) {
128
+ filters.push((0, drizzle_orm_1.inArray)(this.schema.taggings.resourceId, input.resourceIds));
129
+ }
130
+ const rows = await this.throwableQuery(() => db
131
+ .select()
132
+ .from(this.schema.taggings)
133
+ .where((0, drizzle_orm_1.and)(...filters)));
134
+ if (rows.isErr())
135
+ return (0, neverthrow_1.err)(rows.error);
136
+ return (0, neverthrow_1.ok)(rows.value);
137
137
  }
138
138
  async list(input, tx) {
139
- return this.throwableAsync(async () => {
140
- const db = tx ?? this.orm;
141
- const conditions = this.getConditionBuilder(this.table);
142
- conditions.push((0, drizzle_orm_1.isNull)(this.table.deletedAt));
143
- conditions.applyFilters(input);
144
- if (input?.assignableTo) {
145
- conditions.push(this.helpers.arrayContains(this.table.assignableTo, [input.assignableTo]));
146
- }
147
- const whereClause = conditions.join();
148
- const rowsQuery = this.withSortingAndPagination(db.select().from(this.table).where(whereClause), input || {});
149
- const countQuery = db.select({ count: (0, drizzle_orm_1.count)() }).from(this.table).where(whereClause);
150
- const [rows, [totalResult]] = await Promise.all([rowsQuery, countQuery]);
151
- return (0, neverthrow_1.ok)({ rows, total: totalResult?.count ?? 0 });
152
- });
139
+ const db = tx ?? this.orm;
140
+ const conditions = this.getConditionBuilder(this.table);
141
+ conditions.push((0, drizzle_orm_1.isNull)(this.table.deletedAt));
142
+ conditions.applyFilters(input);
143
+ if (input?.assignableTo) {
144
+ conditions.push(this.helpers.arrayContains(this.table.assignableTo, [input.assignableTo]));
145
+ }
146
+ const whereClause = conditions.join();
147
+ const rowsQuery = this.withSortingAndPagination(db.select().from(this.table).where(whereClause), input || {});
148
+ const countQuery = db.select({ count: (0, drizzle_orm_1.count)() }).from(this.table).where(whereClause);
149
+ const countResult = await this.throwableQuery(() => Promise.all([rowsQuery, countQuery]));
150
+ if (countResult.isErr())
151
+ return (0, neverthrow_1.err)(countResult.error);
152
+ const [rows, [totalResult]] = countResult.value;
153
+ return (0, neverthrow_1.ok)({ rows, total: totalResult?.count ?? 0 });
153
154
  }
154
155
  }
155
156
  exports.TagRepository = TagRepository;
@@ -1,8 +1,6 @@
1
- import type { TagCreateSchema, TagDeleteSchema, TagLinkSchema, TagListInputSchema, TagListOutputSchema, TagListSchema, TagSchema, TagUpdateSchema } from "@m5kdev/commons/modules/tag/tag.schema";
2
- import type { User } from "../auth/auth.lib";
1
+ import type { TagDeleteSchema, TagLinkSchema, TagListInputSchema, TagListOutputSchema, TagListSchema, TagSchema } from "@m5kdev/commons/modules/tag/tag.schema";
3
2
  import type { ServerResultAsync } from "../base/base.dto";
4
3
  import { BaseService } from "../base/base.service";
5
- import type { TaggingSelectOutputResult, TagSelectOutputResult } from "./tag.dto";
6
4
  import type { TagRepository } from "./tag.repository";
7
5
  export declare class TagService extends BaseService<{
8
6
  tag: TagRepository;
@@ -18,20 +16,93 @@ export declare class TagService extends BaseService<{
18
16
  resourceType: string;
19
17
  resourceId: string;
20
18
  }[]>>;
21
- create(data: TagCreateSchema, { user }: {
22
- user: User;
23
- }): Promise<TagSelectOutputResult>;
24
- update(data: TagUpdateSchema, { user }: {
25
- user: User;
26
- }): Promise<TagSelectOutputResult>;
27
- link(data: TagLinkSchema, { user }: {
28
- user: User;
29
- }): Promise<TaggingSelectOutputResult>;
19
+ readonly create: import("../base/base.procedure").ServiceProcedure<{
20
+ name: string;
21
+ color: string;
22
+ assignableTo: string[];
23
+ organizationId?: string | undefined;
24
+ teamId?: string | undefined;
25
+ resourceType?: string | undefined;
26
+ resourceId?: string | undefined;
27
+ }, {
28
+ user?: import("../auth/auth.lib").User | null;
29
+ session?: import("../auth/auth.lib").Session | null;
30
+ } & Record<string, unknown> & import("../auth/auth.lib").Context, {
31
+ id: string;
32
+ createdAt: Date;
33
+ updatedAt: Date | null;
34
+ deletedAt: Date | null;
35
+ userId: string;
36
+ organizationId: string | null;
37
+ teamId: string | null;
38
+ name: string;
39
+ color: string | null;
40
+ type: string | null;
41
+ isEnabled: boolean;
42
+ parentId: string | null;
43
+ assignableTo: string[];
44
+ }>;
45
+ readonly update: import("../base/base.procedure").ServiceProcedure<{
46
+ id: string;
47
+ name?: string | undefined;
48
+ color?: string | undefined;
49
+ assignableTo?: string[] | undefined;
50
+ }, {
51
+ user?: import("../auth/auth.lib").User | null;
52
+ session?: import("../auth/auth.lib").Session | null;
53
+ } & Record<string, unknown> & import("../auth/auth.lib").Context, {
54
+ id: string;
55
+ createdAt: Date;
56
+ updatedAt: Date | null;
57
+ deletedAt: Date | null;
58
+ userId: string;
59
+ organizationId: string | null;
60
+ teamId: string | null;
61
+ name: string;
62
+ color: string | null;
63
+ type: string | null;
64
+ isEnabled: boolean;
65
+ parentId: string | null;
66
+ assignableTo: string[];
67
+ }>;
68
+ readonly link: import("../base/base.procedure").ServiceProcedure<{
69
+ tagId: string;
70
+ resourceType: string;
71
+ resourceId: string;
72
+ }, {
73
+ user?: import("../auth/auth.lib").User | null;
74
+ session?: import("../auth/auth.lib").Session | null;
75
+ } & Record<string, unknown> & import("../auth/auth.lib").Context, {
76
+ id: string;
77
+ createdAt: Date;
78
+ tagId: string;
79
+ resourceType: string;
80
+ resourceId: string;
81
+ }>;
30
82
  linkBulk(data: TagLinkSchema[]): ServerResultAsync<TagSchema[]>;
31
83
  set(data: TagLinkSchema[]): ServerResultAsync<TagSchema[]>;
32
- unlink(data: TagLinkSchema, { user }: {
33
- user: User;
34
- }): Promise<TagSelectOutputResult>;
84
+ readonly unlink: import("../base/base.procedure").ServiceProcedure<{
85
+ tagId: string;
86
+ resourceType: string;
87
+ resourceId: string;
88
+ }, {
89
+ user?: import("../auth/auth.lib").User | null;
90
+ session?: import("../auth/auth.lib").Session | null;
91
+ } & Record<string, unknown> & import("../auth/auth.lib").Context, {
92
+ id: string;
93
+ createdAt: Date;
94
+ updatedAt: Date | null;
95
+ deletedAt: Date | null;
96
+ userId: string;
97
+ organizationId: string | null;
98
+ teamId: string | null;
99
+ name: string;
100
+ color: string | null;
101
+ type: string | null;
102
+ isEnabled: boolean;
103
+ parentId: string | null;
104
+ assignableTo: string[];
105
+ }>;
35
106
  delete(data: TagDeleteSchema): ServerResultAsync<{
36
107
  id: string;
37
108
  }>;
@@ -9,24 +9,32 @@ class TagService extends base_service_1.BaseService {
9
9
  async listTaggings(input) {
10
10
  return this.repository.tag.listTaggings(input);
11
11
  }
12
- async create(data, { user }) {
13
- return this.repository.tag.create({ ...data, userId: user.id });
14
- }
15
- async update(data, { user }) {
16
- return this.repository.tag.update({ ...data, userId: user.id });
17
- }
18
- async link(data, { user }) {
19
- return this.repository.tag.link({ ...data, userId: user.id });
20
- }
12
+ create = this.procedure("create")
13
+ .requireAuth()
14
+ .handle(({ input, ctx }) => {
15
+ return this.repository.tag.create({ ...input, userId: ctx.user.id });
16
+ });
17
+ update = this.procedure("update")
18
+ .requireAuth()
19
+ .handle(({ input, ctx }) => {
20
+ return this.repository.tag.update({ ...input, userId: ctx.user.id });
21
+ });
22
+ link = this.procedure("link")
23
+ .requireAuth()
24
+ .handle(({ input, ctx }) => {
25
+ return this.repository.tag.link({ ...input, userId: ctx.user.id });
26
+ });
21
27
  async linkBulk(data) {
22
28
  return this.repository.tag.linkBulk(data);
23
29
  }
24
30
  async set(data) {
25
31
  return this.repository.tag.set(data);
26
32
  }
27
- async unlink(data, { user }) {
28
- return this.repository.tag.unlink({ ...data, userId: user.id });
29
- }
33
+ unlink = this.procedure("unlink")
34
+ .requireAuth()
35
+ .handle(({ input, ctx }) => {
36
+ return this.repository.tag.unlink({ ...input, userId: ctx.user.id });
37
+ });
30
38
  async delete(data) {
31
39
  return this.repository.tag.softDeleteById(data.id);
32
40
  }
@@ -15,7 +15,7 @@ export declare function createTagTRPC({ router, privateProcedure: procedure }: T
15
15
  filters?: {
16
16
  columnId: string;
17
17
  type: "string" | "number" | "boolean" | "date" | "enum";
18
- method: "contains" | "equals" | "starts_with" | "ends_with" | "greater_than" | "less_than" | "on" | "between" | "before" | "after" | "oneOf" | "intersect" | "isEmpty" | "isNotEmpty" | "is_null" | "is_not_null";
18
+ method: "on" | "contains" | "equals" | "starts_with" | "ends_with" | "greater_than" | "less_than" | "between" | "before" | "after" | "oneOf" | "intersect" | "isEmpty" | "isNotEmpty" | "is_null" | "is_not_null";
19
19
  value: string | number | boolean | string[];
20
20
  valueTo?: string | undefined;
21
21
  endColumnId?: string | undefined;
@@ -48,7 +48,7 @@ export declare function createTagTRPC({ router, privateProcedure: procedure }: T
48
48
  resourceIds?: {
49
49
  columnId: string;
50
50
  type: "string" | "number" | "boolean" | "date" | "enum";
51
- method: "contains" | "equals" | "starts_with" | "ends_with" | "greater_than" | "less_than" | "on" | "between" | "before" | "after" | "oneOf" | "intersect" | "isEmpty" | "isNotEmpty" | "is_null" | "is_not_null";
51
+ method: "on" | "contains" | "equals" | "starts_with" | "ends_with" | "greater_than" | "less_than" | "between" | "before" | "after" | "oneOf" | "intersect" | "isEmpty" | "isNotEmpty" | "is_null" | "is_not_null";
52
52
  value: string | number | boolean | string[];
53
53
  valueTo?: string | undefined;
54
54
  endColumnId?: string | undefined;
@@ -58,10 +58,10 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(trpcM
58
58
  input: void;
59
59
  output: {
60
60
  id: string;
61
- status: string;
62
61
  createdAt: Date;
63
62
  updatedAt: Date | null;
64
63
  expiresAt: Date | null;
64
+ status: string;
65
65
  claimUserId: string | null;
66
66
  claimedAt: Date | null;
67
67
  claimedEmail: string | null;
@@ -76,11 +76,11 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(trpcM
76
76
  output: {
77
77
  id: string;
78
78
  email: string;
79
- url: string;
80
79
  createdAt: Date;
81
- userId: string;
82
80
  expiresAt: Date | null;
81
+ userId: string;
83
82
  claimId: string;
83
+ url: string;
84
84
  };
85
85
  meta: any;
86
86
  }>;
@@ -91,11 +91,11 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(trpcM
91
91
  output: {
92
92
  id: string;
93
93
  email: string;
94
- url: string;
95
94
  createdAt: Date;
96
- userId: string;
97
95
  expiresAt: Date | null;
96
+ userId: string;
98
97
  claimId: string;
98
+ url: string;
99
99
  }[];
100
100
  meta: any;
101
101
  }>;
@@ -148,11 +148,11 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(trpcM
148
148
  input: void;
149
149
  output: {
150
150
  id: string;
151
- email: string | null;
152
151
  name: string | null;
153
- status: string;
152
+ email: string | null;
154
153
  createdAt: Date;
155
154
  updatedAt: Date | null;
155
+ status: string;
156
156
  }[];
157
157
  meta: any;
158
158
  }>;
@@ -162,11 +162,11 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(trpcM
162
162
  };
163
163
  output: {
164
164
  id: string;
165
- email: string | null;
166
165
  name: string | null;
167
- status: string;
166
+ email: string | null;
168
167
  createdAt: Date;
169
168
  updatedAt: Date | null;
169
+ status: string;
170
170
  };
171
171
  meta: any;
172
172
  }>;
@@ -193,11 +193,11 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(trpcM
193
193
  };
194
194
  output: {
195
195
  id: string;
196
- email: string | null;
197
196
  name: string | null;
198
- status: string;
197
+ email: string | null;
199
198
  createdAt: Date;
200
199
  updatedAt: Date | null;
200
+ status: string;
201
201
  };
202
202
  meta: any;
203
203
  }>;
@@ -207,11 +207,11 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(trpcM
207
207
  };
208
208
  output: {
209
209
  id: string;
210
- email: string | null;
211
210
  name: string | null;
212
- status: string;
211
+ email: string | null;
213
212
  createdAt: Date;
214
213
  updatedAt: Date | null;
214
+ status: string;
215
215
  };
216
216
  meta: any;
217
217
  }>;
@@ -221,11 +221,11 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(trpcM
221
221
  };
222
222
  output: {
223
223
  id: string;
224
- email: string | null;
225
224
  name: string | null;
226
- status: string;
225
+ email: string | null;
227
226
  createdAt: Date;
228
227
  updatedAt: Date | null;
228
+ status: string;
229
229
  };
230
230
  meta: any;
231
231
  }>;
@@ -18,11 +18,11 @@ export declare function createAuthContext(auth: BetterAuth): ({ req }: CreateExp
18
18
  id: string;
19
19
  createdAt: Date;
20
20
  updatedAt: Date;
21
- userId: string;
22
- token: string;
23
21
  expiresAt: Date;
22
+ token: string;
24
23
  ipAddress: string | null;
25
24
  userAgent: string | null;
25
+ userId: string;
26
26
  impersonatedBy: string | null;
27
27
  activeOrganizationId: string | null;
28
28
  activeOrganizationRole: string | null;
@@ -31,9 +31,8 @@ export declare function createAuthContext(auth: BetterAuth): ({ req }: CreateExp
31
31
  };
32
32
  user: {
33
33
  id: string;
34
- email: string;
35
34
  name: string;
36
- metadata: Record<string, unknown>;
35
+ email: string;
37
36
  emailVerified: boolean;
38
37
  image: string | null;
39
38
  createdAt: Date;
@@ -47,6 +46,7 @@ export declare function createAuthContext(auth: BetterAuth): ({ req }: CreateExp
47
46
  paymentPlanTier: string | null;
48
47
  paymentPlanExpiresAt: Date | null;
49
48
  preferences: string | null;
49
+ metadata: Record<string, unknown>;
50
50
  onboarding: number | null;
51
51
  flags: string | null;
52
52
  };