@m5kdev/backend 0.5.0 → 0.7.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 (53) hide show
  1. package/dist/src/modules/ai/ai.service.d.ts +11 -13
  2. package/dist/src/modules/ai/ai.service.js +6 -6
  3. package/dist/src/modules/ai/ai.trpc.d.ts +1 -1
  4. package/dist/src/modules/auth/auth.lib.d.ts +8 -12
  5. package/dist/src/modules/auth/auth.lib.js +2 -2
  6. package/dist/src/modules/auth/auth.service.d.ts +17 -47
  7. package/dist/src/modules/auth/auth.service.js +79 -66
  8. package/dist/src/modules/auth/auth.trpc.d.ts +16 -16
  9. package/dist/src/modules/base/base.abstract.d.ts +3 -2
  10. package/dist/src/modules/base/base.abstract.js +10 -1
  11. package/dist/src/modules/base/base.actor.d.ts +68 -0
  12. package/dist/src/modules/base/base.actor.js +99 -0
  13. package/dist/src/modules/base/base.actor.test.d.ts +1 -0
  14. package/dist/src/modules/base/base.actor.test.js +58 -0
  15. package/dist/src/modules/base/base.grants.d.ts +3 -7
  16. package/dist/src/modules/base/base.grants.js +22 -10
  17. package/dist/src/modules/base/base.grants.test.js +16 -45
  18. package/dist/src/modules/base/base.procedure.d.ts +109 -0
  19. package/dist/src/modules/base/base.procedure.js +301 -0
  20. package/dist/src/modules/base/base.repository.d.ts +1 -0
  21. package/dist/src/modules/base/base.repository.js +12 -2
  22. package/dist/src/modules/base/base.service.d.ts +23 -23
  23. package/dist/src/modules/base/base.service.js +26 -12
  24. package/dist/src/modules/base/base.service.test.d.ts +1 -0
  25. package/dist/src/modules/base/base.service.test.js +443 -0
  26. package/dist/src/modules/billing/billing.service.d.ts +4 -25
  27. package/dist/src/modules/billing/billing.service.js +6 -6
  28. package/dist/src/modules/billing/billing.trpc.d.ts +2 -2
  29. package/dist/src/modules/billing/billing.trpc.js +4 -6
  30. package/dist/src/modules/connect/connect.repository.d.ts +3 -3
  31. package/dist/src/modules/connect/connect.service.d.ts +21 -13
  32. package/dist/src/modules/connect/connect.service.js +10 -8
  33. package/dist/src/modules/connect/connect.trpc.d.ts +2 -2
  34. package/dist/src/modules/recurrence/recurrence.service.d.ts +59 -8
  35. package/dist/src/modules/recurrence/recurrence.service.js +16 -14
  36. package/dist/src/modules/recurrence/recurrence.trpc.d.ts +3 -3
  37. package/dist/src/modules/recurrence/recurrence.trpc.js +1 -1
  38. package/dist/src/modules/social/social.service.d.ts +3 -4
  39. package/dist/src/modules/social/social.service.js +3 -3
  40. package/dist/src/modules/tag/tag.repository.js +27 -26
  41. package/dist/src/modules/tag/tag.service.d.ts +90 -15
  42. package/dist/src/modules/tag/tag.service.js +20 -12
  43. package/dist/src/modules/tag/tag.trpc.d.ts +3 -3
  44. package/dist/src/modules/workflow/workflow.service.d.ts +48 -8
  45. package/dist/src/modules/workflow/workflow.service.js +6 -6
  46. package/dist/src/modules/workflow/workflow.trpc.d.ts +2 -2
  47. package/dist/src/types.d.ts +19 -19
  48. package/dist/src/utils/trpc.d.ts +31 -41
  49. package/dist/src/utils/trpc.js +95 -0
  50. package/dist/src/utils/trpc.test.d.ts +1 -0
  51. package/dist/src/utils/trpc.test.js +154 -0
  52. package/dist/tsconfig.tsbuildinfo +1 -1
  53. package/package.json +3 -3
@@ -1,7 +1,7 @@
1
1
  import { type TRPCMethods } from "../../utils/trpc";
2
2
  import type { ConnectService } from "./connect.service";
3
3
  export declare function createConnectTRPC({ router, privateProcedure: procedure }: TRPCMethods, connectService: ConnectService): import("@trpc/server").TRPCBuiltRouter<{
4
- ctx: import("../auth/auth.lib").Context;
4
+ ctx: import("../../utils/trpc").Context;
5
5
  meta: any;
6
6
  errorShape: import("@trpc/server").TRPCDefaultErrorShape;
7
7
  transformer: true;
@@ -12,10 +12,10 @@ export declare function createConnectTRPC({ router, privateProcedure: procedure
12
12
  inactive?: boolean | undefined;
13
13
  };
14
14
  output: {
15
- provider: string;
16
15
  id: string;
17
16
  createdAt: Date;
18
17
  userId: string;
18
+ provider: string;
19
19
  accountType: string;
20
20
  providerAccountId: string;
21
21
  updatedAt?: Date | null | undefined;
@@ -1,6 +1,4 @@
1
- import type { CreateRecurrenceSchema, DeleteRecurrenceRulesSchema, DeleteRecurrenceSchema, UpdateRecurrenceRulesSchema, UpdateRecurrenceSchema } from "@m5kdev/commons/modules/recurrence/recurrence.schema";
2
- import type { QueryInput } from "@m5kdev/commons/modules/schemas/query.schema";
3
- import type { Context, User } from "../auth/auth.lib";
1
+ import type { DeleteRecurrenceRulesSchema, DeleteRecurrenceSchema, UpdateRecurrenceRulesSchema, UpdateRecurrenceSchema } from "@m5kdev/commons/modules/recurrence/recurrence.schema";
4
2
  import type { ServerResultAsync } from "../base/base.dto";
5
3
  import { BaseService } from "../base/base.service";
6
4
  import type { CreateWithRulesResult, RecurrenceRepository, RecurrenceRulesRepository } from "./recurrence.repository";
@@ -8,13 +6,66 @@ export declare class RecurrenceService extends BaseService<{
8
6
  recurrence: RecurrenceRepository;
9
7
  recurrenceRules: RecurrenceRulesRepository;
10
8
  }, Record<string, never>> {
11
- create(data: CreateRecurrenceSchema, ctx: Context): ServerResultAsync<CreateWithRulesResult>;
12
- list(query?: QueryInput, ctx?: {
13
- user?: User;
14
- }): ServerResultAsync<{
15
- rows: CreateWithRulesResult["recurrence"][];
9
+ readonly list: import("../base/base.procedure").ServiceProcedure<{
10
+ page?: number | undefined;
11
+ limit?: number | undefined;
12
+ sort?: string | undefined;
13
+ order?: "asc" | "desc" | undefined;
14
+ filters?: {
15
+ columnId: string;
16
+ type: "string" | "number" | "boolean" | "date" | "enum";
17
+ method: "on" | "contains" | "equals" | "starts_with" | "ends_with" | "greater_than" | "less_than" | "between" | "before" | "after" | "oneOf" | "intersect" | "isEmpty" | "isNotEmpty" | "is_null" | "is_not_null";
18
+ value: string | number | boolean | string[];
19
+ valueTo?: string | undefined;
20
+ endColumnId?: string | undefined;
21
+ }[] | undefined;
22
+ }, {
23
+ actor?: import("../base/base.actor").AuthenticatedActor | null;
24
+ } & Record<string, unknown> & {
25
+ actor: import("../base/base.actor").UserActor;
26
+ }, {
27
+ rows: {
28
+ id: string;
29
+ name: string | null;
30
+ createdAt: Date;
31
+ updatedAt: Date;
32
+ metadata: Record<string, any> | null;
33
+ userId: string | null;
34
+ organizationId: string | null;
35
+ teamId: string | null;
36
+ enabled: boolean;
37
+ kind: string | null;
38
+ }[];
16
39
  total: number;
17
40
  }>;
41
+ readonly create: import("../base/base.procedure").ServiceProcedure<{
42
+ name: string;
43
+ kind: string;
44
+ enabled: boolean;
45
+ recurrenceRules: {
46
+ interval: number;
47
+ freq: number;
48
+ bysetpos?: number | number[] | null | undefined;
49
+ bymonth?: number | number[] | null | undefined;
50
+ bymonthday?: number | number[] | null | undefined;
51
+ byyearday?: number | number[] | null | undefined;
52
+ byweekno?: number | number[] | null | undefined;
53
+ byweekday?: number | number[] | null | undefined;
54
+ byhour?: number | number[] | null | undefined;
55
+ byminute?: number | number[] | null | undefined;
56
+ bysecond?: number | number[] | null | undefined;
57
+ dtstart?: Date | null | undefined;
58
+ wkst?: number | null | undefined;
59
+ count?: number | null | undefined;
60
+ until?: Date | null | undefined;
61
+ tzid?: string | null | undefined;
62
+ }[];
63
+ metadata?: Record<string, unknown> | null | undefined;
64
+ }, {
65
+ actor?: import("../base/base.actor").AuthenticatedActor | null;
66
+ } & Record<string, unknown> & {
67
+ actor: import("../base/base.actor").UserActor;
68
+ }, CreateWithRulesResult>;
18
69
  findById(id: string): ServerResultAsync<CreateWithRulesResult["recurrence"] | null>;
19
70
  update(data: UpdateRecurrenceSchema & {
20
71
  id: string;
@@ -31,23 +31,25 @@ function mapRuleToInsert(rule) {
31
31
  return out;
32
32
  }
33
33
  class RecurrenceService extends base_service_1.BaseService {
34
- async create(data, ctx) {
34
+ list = this.procedure("list")
35
+ .addContextFilter(["user"])
36
+ .handle(({ input }) => this.repository.recurrence.queryList(input));
37
+ create = this.procedure("create")
38
+ .requireAuth()
39
+ .handle(({ input, ctx }) => {
40
+ const { actor } = ctx;
35
41
  const recurrenceData = {
36
- name: data.name,
37
- kind: data.kind,
38
- enabled: data.enabled,
39
- metadata: data.metadata ?? null,
40
- userId: ctx.user?.id ?? null,
41
- organizationId: ctx.session.activeOrganizationId ?? null,
42
- teamId: ctx.session.activeTeamId ?? null,
42
+ name: input.name,
43
+ kind: input.kind,
44
+ enabled: input.enabled,
45
+ metadata: input.metadata ?? null,
46
+ userId: actor.userId,
47
+ organizationId: actor.organizationId,
48
+ teamId: actor.teamId,
43
49
  };
44
- const rulesData = data.recurrenceRules.map(mapRuleToInsert);
50
+ const rulesData = input.recurrenceRules.map(mapRuleToInsert);
45
51
  return this.repository.recurrence.createWithRules(recurrenceData, rulesData);
46
- }
47
- async list(query, ctx) {
48
- const queryWithUser = ctx?.user ? this.addUserFilter(ctx.user.id, query, "userId") : query;
49
- return this.repository.recurrence.queryList(queryWithUser);
50
- }
52
+ });
51
53
  async findById(id) {
52
54
  const result = await this.repository.recurrence.findById(id);
53
55
  if (result.isErr())
@@ -1,7 +1,7 @@
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
- ctx: import("../auth/auth.lib").Context;
4
+ ctx: import("../../utils/trpc").Context;
5
5
  meta: any;
6
6
  errorShape: import("@trpc/server").TRPCDefaultErrorShape;
7
7
  transformer: true;
@@ -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));
@@ -1,3 +1,4 @@
1
+ import type { RequiredServiceActor } from "../base/base.actor";
1
2
  import type { ServerResultAsync } from "../base/base.dto";
2
3
  import { BaseService } from "../base/base.service";
3
4
  import type { ConnectRepository } from "../connect/connect.repository";
@@ -19,10 +20,8 @@ export declare class SocialService extends BaseService<{
19
20
  file: FileService;
20
21
  }, providers: SocialProvider[]);
21
22
  getProvider(id: string): SocialProvider | null;
22
- postToProvider(providerId: string, input: SocialPostInput, { user }: {
23
- user: {
24
- id: string;
25
- };
23
+ postToProvider(providerId: string, input: SocialPostInput, { actor }: {
24
+ actor: RequiredServiceActor<"user">;
26
25
  }): ServerResultAsync<SocialPostResult>;
27
26
  private ensureFreshConnection;
28
27
  }
@@ -12,14 +12,14 @@ class SocialService extends base_service_1.BaseService {
12
12
  getProvider(id) {
13
13
  return this.providers.get(id) ?? null;
14
14
  }
15
- async postToProvider(providerId, input, { user }) {
15
+ async postToProvider(providerId, input, { actor }) {
16
16
  return this.throwableAsync(async () => {
17
17
  const provider = this.getProvider(providerId);
18
18
  if (!provider) {
19
19
  return this.error("BAD_REQUEST", `Unknown provider: ${providerId}`);
20
20
  }
21
21
  const connectionResult = await this.repository.connect.list({
22
- userId: user.id,
22
+ userId: actor.userId,
23
23
  providers: [providerId],
24
24
  });
25
25
  if (connectionResult.isErr()) {
@@ -46,7 +46,7 @@ class SocialService extends base_service_1.BaseService {
46
46
  const result = await provider.post({
47
47
  deps: { fileService: this.service.file },
48
48
  context: {
49
- userId: user.id,
49
+ userId: actor.userId,
50
50
  connection: connection.value,
51
51
  accessToken,
52
52
  },
@@ -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,97 @@ 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
+ actor?: import("../base/base.actor").AuthenticatedActor | null;
29
+ } & Record<string, unknown> & {
30
+ actor: import("../base/base.actor").UserActor;
31
+ }, {
32
+ id: string;
33
+ createdAt: Date;
34
+ updatedAt: Date | null;
35
+ deletedAt: Date | null;
36
+ userId: string;
37
+ organizationId: string | null;
38
+ teamId: string | null;
39
+ name: string;
40
+ color: string | null;
41
+ type: string | null;
42
+ isEnabled: boolean;
43
+ parentId: string | null;
44
+ assignableTo: string[];
45
+ }>;
46
+ readonly update: import("../base/base.procedure").ServiceProcedure<{
47
+ id: string;
48
+ name?: string | undefined;
49
+ color?: string | undefined;
50
+ assignableTo?: string[] | undefined;
51
+ }, {
52
+ actor?: import("../base/base.actor").AuthenticatedActor | null;
53
+ } & Record<string, unknown> & {
54
+ actor: import("../base/base.actor").UserActor;
55
+ }, {
56
+ id: string;
57
+ createdAt: Date;
58
+ updatedAt: Date | null;
59
+ deletedAt: Date | null;
60
+ userId: string;
61
+ organizationId: string | null;
62
+ teamId: string | null;
63
+ name: string;
64
+ color: string | null;
65
+ type: string | null;
66
+ isEnabled: boolean;
67
+ parentId: string | null;
68
+ assignableTo: string[];
69
+ }>;
70
+ readonly link: import("../base/base.procedure").ServiceProcedure<{
71
+ tagId: string;
72
+ resourceType: string;
73
+ resourceId: string;
74
+ }, {
75
+ actor?: import("../base/base.actor").AuthenticatedActor | null;
76
+ } & Record<string, unknown> & {
77
+ actor: import("../base/base.actor").UserActor;
78
+ }, {
79
+ id: string;
80
+ createdAt: Date;
81
+ tagId: string;
82
+ resourceType: string;
83
+ resourceId: string;
84
+ }>;
30
85
  linkBulk(data: TagLinkSchema[]): ServerResultAsync<TagSchema[]>;
31
86
  set(data: TagLinkSchema[]): ServerResultAsync<TagSchema[]>;
32
- unlink(data: TagLinkSchema, { user }: {
33
- user: User;
34
- }): Promise<TagSelectOutputResult>;
87
+ readonly unlink: import("../base/base.procedure").ServiceProcedure<{
88
+ tagId: string;
89
+ resourceType: string;
90
+ resourceId: string;
91
+ }, {
92
+ actor?: import("../base/base.actor").AuthenticatedActor | null;
93
+ } & Record<string, unknown> & {
94
+ actor: import("../base/base.actor").UserActor;
95
+ }, {
96
+ id: string;
97
+ createdAt: Date;
98
+ updatedAt: Date | null;
99
+ deletedAt: Date | null;
100
+ userId: string;
101
+ organizationId: string | null;
102
+ teamId: string | null;
103
+ name: string;
104
+ color: string | null;
105
+ type: string | null;
106
+ isEnabled: boolean;
107
+ parentId: string | null;
108
+ assignableTo: string[];
109
+ }>;
35
110
  delete(data: TagDeleteSchema): ServerResultAsync<{
36
111
  id: string;
37
112
  }>;
@@ -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.actor.userId });
16
+ });
17
+ update = this.procedure("update")
18
+ .requireAuth()
19
+ .handle(({ input, ctx }) => {
20
+ return this.repository.tag.update({ ...input, userId: ctx.actor.userId });
21
+ });
22
+ link = this.procedure("link")
23
+ .requireAuth()
24
+ .handle(({ input, ctx }) => {
25
+ return this.repository.tag.link({ ...input, userId: ctx.actor.userId });
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.actor.userId });
37
+ });
30
38
  async delete(data) {
31
39
  return this.repository.tag.softDeleteById(data.id);
32
40
  }
@@ -1,7 +1,7 @@
1
1
  import { type TRPCMethods } from "../../utils/trpc";
2
2
  import type { TagService } from "./tag.service";
3
3
  export declare function createTagTRPC({ router, privateProcedure: procedure }: TRPCMethods, tagService: TagService): import("@trpc/server").TRPCBuiltRouter<{
4
- ctx: import("../auth/auth.lib").Context;
4
+ ctx: import("../../utils/trpc").Context;
5
5
  meta: any;
6
6
  errorShape: import("@trpc/server").TRPCDefaultErrorShape;
7
7
  transformer: true;
@@ -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;
@@ -1,18 +1,58 @@
1
- import type { WorkflowListInputSchema, WorkflowListOutputSchema, WorkflowReadInputSchema, WorkflowReadOutputSchema } from "@m5kdev/commons/modules/workflow/workflow.schema";
1
+ import type { WorkflowReadOutputSchema } from "@m5kdev/commons/modules/workflow/workflow.schema";
2
2
  import type { Job } from "bullmq";
3
- import type { User } from "../auth/auth.lib";
4
3
  import type { ServerResultAsync } from "../base/base.dto";
5
4
  import { BaseService } from "../base/base.service";
6
5
  import type { WorkflowRepository } from "./workflow.repository";
7
6
  export declare class WorkflowService extends BaseService<{
8
7
  workflow: WorkflowRepository;
9
8
  }, never> {
10
- read(input: WorkflowReadInputSchema, { user }: {
11
- user: User;
12
- }): ServerResultAsync<WorkflowReadOutputSchema>;
13
- list(input: WorkflowListInputSchema, { user }: {
14
- user: User;
15
- }): ServerResultAsync<WorkflowListOutputSchema>;
9
+ readonly read: import("../base/base.procedure").ServiceProcedure<{
10
+ jobId: string;
11
+ }, {
12
+ actor?: import("../base/base.actor").AuthenticatedActor | null;
13
+ } & Record<string, unknown> & {
14
+ actor: import("../base/base.actor").UserActor;
15
+ }, {
16
+ id: string;
17
+ userId: string | null;
18
+ jobId: string;
19
+ jobName: string;
20
+ queueName: string;
21
+ tags: string[] | null;
22
+ input: unknown;
23
+ output: unknown;
24
+ status: "queued" | "running" | "completed" | "failed";
25
+ error: string | null;
26
+ retries: number;
27
+ finishedAt: Date | null;
28
+ processedAt: Date | null;
29
+ createdAt: Date;
30
+ updatedAt: Date;
31
+ }>;
32
+ readonly list: import("../base/base.procedure").ServiceProcedure<{
33
+ status?: ("queued" | "running" | "completed" | "failed")[] | undefined;
34
+ jobName?: string | undefined;
35
+ }, {
36
+ actor?: import("../base/base.actor").AuthenticatedActor | null;
37
+ } & Record<string, unknown> & {
38
+ actor: import("../base/base.actor").UserActor;
39
+ }, {
40
+ id: string;
41
+ userId: string | null;
42
+ jobId: string;
43
+ jobName: string;
44
+ queueName: string;
45
+ tags: string[] | null;
46
+ input: unknown;
47
+ output: unknown;
48
+ status: "queued" | "running" | "completed" | "failed";
49
+ error: string | null;
50
+ retries: number;
51
+ finishedAt: Date | null;
52
+ processedAt: Date | null;
53
+ createdAt: Date;
54
+ updatedAt: Date;
55
+ }[]>;
16
56
  added(params: Parameters<WorkflowRepository["added"]>[0]): ServerResultAsync<WorkflowReadOutputSchema>;
17
57
  addedMany(params: Parameters<WorkflowRepository["addedMany"]>[0]): ServerResultAsync<WorkflowReadOutputSchema[]>;
18
58
  started(job: Job): ServerResultAsync<WorkflowReadOutputSchema>;
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WorkflowService = void 0;
4
4
  const base_service_1 = require("../base/base.service");
5
5
  class WorkflowService extends base_service_1.BaseService {
6
- async read(input, { user }) {
7
- return await this.repository.workflow.read({ ...input, userId: user.id });
8
- }
9
- async list(input, { user }) {
10
- return await this.repository.workflow.list({ ...input, userId: user.id });
11
- }
6
+ read = this.procedure("workflowRead")
7
+ .requireAuth()
8
+ .handle(({ input, ctx }) => this.repository.workflow.read({ ...input, userId: ctx.actor.userId }));
9
+ list = this.procedure("workflowList")
10
+ .requireAuth()
11
+ .handle(({ input, ctx }) => this.repository.workflow.list({ ...input, userId: ctx.actor.userId }));
12
12
  async added(params) {
13
13
  return this.repository.workflow.added(params);
14
14
  }
@@ -1,7 +1,7 @@
1
- import type { WorkflowService } from "./workflow.service";
2
1
  import { type TRPCMethods } from "../../utils/trpc";
2
+ import type { WorkflowService } from "./workflow.service";
3
3
  export declare function createWorkflowTRPC({ router, privateProcedure: procedure }: TRPCMethods, workflowService: WorkflowService): import("@trpc/server").TRPCBuiltRouter<{
4
- ctx: import("../auth/auth.lib").Context;
4
+ ctx: import("../../utils/trpc").Context;
5
5
  meta: any;
6
6
  errorShape: import("@trpc/server").TRPCDefaultErrorShape;
7
7
  transformer: true;