@m5kdev/backend 0.4.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.
Files changed (38) hide show
  1. package/dist/src/modules/ai/ai.prompts.d.ts +5 -0
  2. package/dist/src/modules/ai/ai.prompts.js +16 -0
  3. package/dist/src/modules/ai/ai.service.d.ts +26 -12
  4. package/dist/src/modules/ai/ai.service.js +105 -15
  5. package/dist/src/modules/auth/auth.dto.d.ts +2 -2
  6. package/dist/src/modules/auth/auth.lib.d.ts +3 -3
  7. package/dist/src/modules/auth/auth.repository.d.ts +2 -2
  8. package/dist/src/modules/auth/auth.repository.js +1 -1
  9. package/dist/src/modules/auth/auth.service.d.ts +3 -3
  10. package/dist/src/modules/auth/auth.service.js +1 -1
  11. package/dist/src/modules/auth/auth.trpc.d.ts +6 -6
  12. package/dist/src/modules/auth/auth.trpc.js +1 -1
  13. package/dist/src/modules/base/base.abstract.d.ts +3 -2
  14. package/dist/src/modules/base/base.abstract.js +10 -1
  15. package/dist/src/modules/base/base.procedure.d.ts +112 -0
  16. package/dist/src/modules/base/base.procedure.js +289 -0
  17. package/dist/src/modules/base/base.repository.d.ts +1 -0
  18. package/dist/src/modules/base/base.repository.js +12 -2
  19. package/dist/src/modules/base/base.service.d.ts +17 -5
  20. package/dist/src/modules/base/base.service.js +7 -0
  21. package/dist/src/modules/base/base.service.test.d.ts +1 -0
  22. package/dist/src/modules/base/base.service.test.js +415 -0
  23. package/dist/src/modules/connect/connect.repository.d.ts +3 -3
  24. package/dist/src/modules/connect/connect.service.d.ts +4 -4
  25. package/dist/src/modules/connect/connect.trpc.d.ts +2 -2
  26. package/dist/src/modules/recurrence/recurrence.service.d.ts +29 -8
  27. package/dist/src/modules/recurrence/recurrence.service.js +3 -4
  28. package/dist/src/modules/recurrence/recurrence.trpc.d.ts +3 -3
  29. package/dist/src/modules/recurrence/recurrence.trpc.js +1 -1
  30. package/dist/src/modules/tag/tag.db.js +1 -1
  31. package/dist/src/modules/tag/tag.repository.js +27 -26
  32. package/dist/src/modules/tag/tag.service.d.ts +86 -15
  33. package/dist/src/modules/tag/tag.service.js +20 -12
  34. package/dist/src/modules/tag/tag.trpc.d.ts +3 -3
  35. package/dist/src/types.d.ts +5 -5
  36. package/dist/src/utils/trpc.d.ts +6 -6
  37. package/dist/tsconfig.tsbuildinfo +1 -1
  38. package/package.json +6 -5
@@ -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
  }
@@ -11,11 +11,11 @@ export declare function createTagTRPC({ router, privateProcedure: procedure }: T
11
11
  page?: number | undefined;
12
12
  limit?: number | undefined;
13
13
  sort?: string | undefined;
14
- order?: "desc" | "asc" | undefined;
14
+ order?: "asc" | "desc" | undefined;
15
15
  filters?: {
16
16
  columnId: string;
17
17
  type: "string" | "number" | "boolean" | "date" | "enum";
18
- method: "intersect" | "contains" | "equals" | "starts_with" | "ends_with" | "greater_than" | "less_than" | "on" | "between" | "before" | "after" | "oneOf" | "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: "intersect" | "contains" | "equals" | "starts_with" | "ends_with" | "greater_than" | "less_than" | "on" | "between" | "before" | "after" | "oneOf" | "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;
@@ -147,8 +147,8 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(trpcM
147
147
  listAdminWaitlist: import("@trpc/server").TRPCQueryProcedure<{
148
148
  input: void;
149
149
  output: {
150
- name: string | null;
151
150
  id: string;
151
+ name: string | null;
152
152
  email: string | null;
153
153
  createdAt: Date;
154
154
  updatedAt: Date | null;
@@ -161,8 +161,8 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(trpcM
161
161
  email: string;
162
162
  };
163
163
  output: {
164
- name: string | null;
165
164
  id: string;
165
+ name: string | null;
166
166
  email: string | null;
167
167
  createdAt: Date;
168
168
  updatedAt: Date | null;
@@ -192,8 +192,8 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(trpcM
192
192
  id: string;
193
193
  };
194
194
  output: {
195
- name: string | null;
196
195
  id: string;
196
+ name: string | null;
197
197
  email: string | null;
198
198
  createdAt: Date;
199
199
  updatedAt: Date | null;
@@ -206,8 +206,8 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(trpcM
206
206
  id: string;
207
207
  };
208
208
  output: {
209
- name: string | null;
210
209
  id: string;
210
+ name: string | null;
211
211
  email: string | null;
212
212
  createdAt: Date;
213
213
  updatedAt: Date | null;
@@ -220,8 +220,8 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(trpcM
220
220
  email: string;
221
221
  };
222
222
  output: {
223
- name: string | null;
224
223
  id: string;
224
+ name: string | null;
225
225
  email: string | null;
226
226
  createdAt: Date;
227
227
  updatedAt: Date | null;
@@ -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
21
  expiresAt: Date;
23
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;
@@ -30,15 +30,14 @@ export declare function createAuthContext(auth: BetterAuth): ({ req }: CreateExp
30
30
  activeTeamRole: string | null;
31
31
  };
32
32
  user: {
33
- email: string;
33
+ id: string;
34
34
  name: string;
35
- role: string | null;
35
+ email: string;
36
+ emailVerified: boolean;
36
37
  image: string | null;
37
- metadata: Record<string, unknown>;
38
- id: string;
39
38
  createdAt: Date;
40
39
  updatedAt: Date;
41
- emailVerified: boolean;
40
+ role: string | null;
42
41
  banned: boolean | null;
43
42
  banReason: string | null;
44
43
  banExpires: Date | null;
@@ -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
  };