@marcoappio/marco-config 2.0.494 → 2.0.495

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 (31) hide show
  1. package/dist/zero/index.d.ts +224 -0
  2. package/dist/zero/index.d.ts.map +1 -1
  3. package/dist/zero/index.js +2 -1
  4. package/dist/zero/mutators/accountMutators/accountMutators.d.ts +61 -0
  5. package/dist/zero/mutators/accountMutators/accountMutators.d.ts.map +1 -1
  6. package/dist/zero/mutators/accountMutators/accountMutators.js +78 -78
  7. package/dist/zero/mutators/accountMutators/index.d.ts +1 -1
  8. package/dist/zero/mutators/accountMutators/index.d.ts.map +1 -1
  9. package/dist/zero/mutators/accountMutators/index.js +1 -1
  10. package/dist/zero/mutators/draftMutators/draftMutators.d.ts +94 -0
  11. package/dist/zero/mutators/draftMutators/draftMutators.d.ts.map +1 -1
  12. package/dist/zero/mutators/draftMutators/draftMutators.js +75 -76
  13. package/dist/zero/mutators/draftMutators/index.d.ts +1 -1
  14. package/dist/zero/mutators/draftMutators/index.d.ts.map +1 -1
  15. package/dist/zero/mutators/draftMutators/index.js +1 -1
  16. package/dist/zero/mutators/index.d.ts +224 -0
  17. package/dist/zero/mutators/index.d.ts.map +1 -1
  18. package/dist/zero/mutators/index.js +10 -0
  19. package/dist/zero/mutators/threadMutators/index.d.ts +1 -1
  20. package/dist/zero/mutators/threadMutators/index.d.ts.map +1 -1
  21. package/dist/zero/mutators/threadMutators/index.js +1 -1
  22. package/dist/zero/mutators/threadMutators/threadMutators.d.ts +52 -0
  23. package/dist/zero/mutators/threadMutators/threadMutators.d.ts.map +1 -1
  24. package/dist/zero/mutators/threadMutators/threadMutators.js +41 -30
  25. package/dist/zero/mutators/userMutators/index.d.ts +1 -1
  26. package/dist/zero/mutators/userMutators/index.d.ts.map +1 -1
  27. package/dist/zero/mutators/userMutators/index.js +1 -1
  28. package/dist/zero/mutators/userMutators/userMutators.d.ts +19 -0
  29. package/dist/zero/mutators/userMutators/userMutators.d.ts.map +1 -1
  30. package/dist/zero/mutators/userMutators/userMutators.js +25 -26
  31. package/package.json +1 -1
@@ -2,65 +2,88 @@ import { defineMutator } from '@rocicorp/zero';
2
2
  import * as v from 'valibot';
3
3
  import { marcoSchemas } from '../../../schemas';
4
4
  import { zeroCRUD } from '../../../zero/crud';
5
- const accountAliasSchema = v.object({
6
- emailAddress: marcoSchemas.string.email(),
7
- id: marcoSchemas.string.required(),
8
- name: marcoSchemas.string.nullable(),
9
- });
10
- export const accountMutators = {
11
- createAccount: defineMutator(v.object({
5
+ export const accountMutatorSchemas = {
6
+ createAccount: v.object({
12
7
  aliasId: marcoSchemas.string.required(),
13
8
  color: marcoSchemas.string.required(),
14
9
  emailAddress: marcoSchemas.string.email(),
15
10
  id: marcoSchemas.string.required(),
16
- }), async ({ tx, ctx: { userId }, args }) => {
11
+ }),
12
+ createAlias: v.object({
13
+ accountId: marcoSchemas.string.required(),
14
+ alias: v.object({
15
+ emailAddress: marcoSchemas.string.email(),
16
+ id: marcoSchemas.string.required(),
17
+ name: marcoSchemas.string.nullable(),
18
+ }),
19
+ }),
20
+ deleteAccount: v.object({
21
+ id: marcoSchemas.string.required(),
22
+ }),
23
+ deleteAlias: v.object({
24
+ accountId: marcoSchemas.string.required(),
25
+ aliasId: marcoSchemas.string.required(),
26
+ }),
27
+ setAliasName: v.object({
28
+ accountId: marcoSchemas.string.required(),
29
+ aliasId: marcoSchemas.string.required(),
30
+ displayName: marcoSchemas.string.nullable(),
31
+ }),
32
+ setAliasPrimary: v.object({
33
+ accountId: marcoSchemas.string.required(),
34
+ aliasId: marcoSchemas.string.required(),
35
+ }),
36
+ setConnectionConfigImapRaw: v.object({
37
+ connectionConfig: marcoSchemas.emailAccount.connectionConfigImapRaw(),
38
+ id: marcoSchemas.string.required(),
39
+ }),
40
+ setConnectionConfigOauth: v.object({
41
+ connectionConfig: marcoSchemas.emailAccount.connectionConfigOauth(),
42
+ id: marcoSchemas.string.required(),
43
+ }),
44
+ setSettings: v.object({
45
+ color: v.optional(marcoSchemas.string.nullable()),
46
+ displayName: v.optional(marcoSchemas.string.nullable()),
47
+ id: marcoSchemas.string.required(),
48
+ }),
49
+ };
50
+ export const accountMutators = {
51
+ createAccount: defineMutator(accountMutatorSchemas.createAccount, async ({ tx, ctx: { userId }, args: { color, id, aliasId, emailAddress } }) => {
17
52
  await tx.mutate(zeroCRUD.account.insert({
18
- color: args.color,
53
+ color,
19
54
  displayName: null,
20
- id: args.id,
55
+ id,
21
56
  imapConnectionStatus: 'AWAITING_CONNECTION',
22
57
  mailProcessedCount: 0,
23
58
  mailTotalCount: 0,
24
- primaryAliasId: args.aliasId,
59
+ primaryAliasId: aliasId,
25
60
  userId,
26
61
  }));
27
62
  await tx.mutate(zeroCRUD.accountAlias.insert({
28
- accountId: args.id,
29
- emailAddress: args.emailAddress,
30
- id: args.aliasId,
63
+ accountId: id,
64
+ emailAddress,
65
+ id: aliasId,
31
66
  isPrimary: true,
32
67
  name: null,
33
68
  }));
34
69
  }),
35
- createAlias: defineMutator(v.object({
36
- accountId: marcoSchemas.string.required(),
37
- alias: accountAliasSchema,
38
- }), async ({ tx, args }) => {
70
+ createAlias: defineMutator(accountMutatorSchemas.createAlias, async ({ tx, args: { accountId, alias } }) => {
39
71
  await tx.mutate(zeroCRUD.accountAlias.insert({
40
- accountId: args.accountId,
41
- emailAddress: args.alias.emailAddress,
42
- id: args.alias.id,
72
+ accountId: accountId,
73
+ emailAddress: alias.emailAddress,
74
+ id: alias.id,
43
75
  isPrimary: false,
44
- name: args.alias.name ?? null,
76
+ name: alias.name ?? null,
45
77
  }));
46
78
  }),
47
- deleteAccount: defineMutator(v.object({
48
- id: marcoSchemas.string.required(),
49
- }), async ({ tx, args }) => {
50
- await tx.mutate(zeroCRUD.account.delete({
51
- id: args.id,
52
- }));
79
+ deleteAccount: defineMutator(accountMutatorSchemas.deleteAccount, async ({ tx, args: { id } }) => {
80
+ await tx.mutate(zeroCRUD.account.delete({ id }));
53
81
  }),
54
- deleteAlias: defineMutator(v.object({
55
- accountId: marcoSchemas.string.required(),
56
- aliasId: marcoSchemas.string.required(),
57
- }), async ({ tx, args }) => {
58
- const alias = await tx.query.accountAlias.where('id', args.aliasId).one().run();
59
- await tx.mutate(zeroCRUD.accountAlias.delete({
60
- id: args.aliasId,
61
- }));
82
+ deleteAlias: defineMutator(accountMutatorSchemas.deleteAlias, async ({ tx, args: { accountId, aliasId } }) => {
83
+ const alias = await tx.query.accountAlias.where('id', aliasId).one().run();
84
+ await tx.mutate(zeroCRUD.accountAlias.delete({ id: aliasId }));
62
85
  if (alias?.isPrimary) {
63
- const remainingAliases = await tx.query.accountAlias.where('accountId', args.accountId).run();
86
+ const remainingAliases = await tx.query.accountAlias.where('accountId', accountId).run();
64
87
  if (remainingAliases.length > 0) {
65
88
  const newPrimaryAlias = remainingAliases[0];
66
89
  await tx.mutate(zeroCRUD.accountAlias.update({
@@ -68,71 +91,48 @@ export const accountMutators = {
68
91
  isPrimary: true,
69
92
  }));
70
93
  await tx.mutate(zeroCRUD.account.update({
71
- id: args.accountId,
94
+ id: accountId,
72
95
  primaryAliasId: newPrimaryAlias.id,
73
96
  }));
74
97
  }
75
98
  else {
76
99
  await tx.mutate(zeroCRUD.account.update({
77
- id: args.accountId,
100
+ id: accountId,
78
101
  primaryAliasId: null,
79
102
  }));
80
103
  }
81
104
  }
82
105
  }),
83
- setAliasName: defineMutator(v.object({
84
- accountId: marcoSchemas.string.required(),
85
- aliasId: marcoSchemas.string.required(),
86
- displayName: marcoSchemas.string.nullable(),
87
- }), async ({ tx, args }) => {
106
+ setAliasName: defineMutator(accountMutatorSchemas.setAliasName, async ({ tx, args: { aliasId, displayName } }) => {
88
107
  await tx.mutate(zeroCRUD.accountAlias.update({
89
- id: args.aliasId,
90
- name: args.displayName,
108
+ id: aliasId,
109
+ name: displayName,
91
110
  }));
92
111
  }),
93
- setAliasPrimary: defineMutator(v.object({
94
- accountId: marcoSchemas.string.required(),
95
- aliasId: marcoSchemas.string.required(),
96
- }), async ({ tx, args }) => {
97
- const aliases = await tx.query.accountAlias.where('accountId', args.accountId).run();
112
+ setAliasPrimary: defineMutator(accountMutatorSchemas.setAliasPrimary, async ({ tx, args: { accountId, aliasId } }) => {
113
+ const aliases = await tx.query.accountAlias.where('accountId', accountId).run();
98
114
  for (const alias of aliases) {
99
115
  await tx.mutate(zeroCRUD.accountAlias.update({
100
116
  id: alias.id,
101
- isPrimary: alias.id === args.aliasId,
117
+ isPrimary: alias.id === aliasId,
102
118
  }));
103
119
  }
104
120
  await tx.mutate(zeroCRUD.account.update({
105
- id: args.accountId,
106
- primaryAliasId: args.aliasId,
121
+ id: accountId,
122
+ primaryAliasId: aliasId,
107
123
  }));
108
124
  }),
109
- setConnectionConfigImapRaw: defineMutator(v.object({
110
- connectionConfig: marcoSchemas.emailAccount.connectionConfigImapRaw(),
111
- id: marcoSchemas.string.required(),
112
- }), async ({ tx, args }) => {
113
- await tx.mutate(zeroCRUD.account.update({
114
- id: args.id,
115
- imapConnectionStatus: 'AWAITING_CONNECTION',
116
- }));
125
+ setConnectionConfigImapRaw: defineMutator(accountMutatorSchemas.setConnectionConfigImapRaw, async ({ tx, args: { id } }) => {
126
+ await tx.mutate(zeroCRUD.account.update({ id, imapConnectionStatus: 'AWAITING_CONNECTION' }));
117
127
  }),
118
- setConnectionConfigOauth: defineMutator(v.object({
119
- connectionConfig: marcoSchemas.emailAccount.connectionConfigOauth(),
120
- id: marcoSchemas.string.required(),
121
- }), async ({ tx, args }) => {
122
- await tx.mutate(zeroCRUD.account.update({
123
- id: args.id,
124
- imapConnectionStatus: 'AWAITING_CONNECTION',
125
- }));
128
+ setConnectionConfigOauth: defineMutator(accountMutatorSchemas.setConnectionConfigOauth, async ({ tx, args: { id } }) => {
129
+ await tx.mutate(zeroCRUD.account.update({ id, imapConnectionStatus: 'AWAITING_CONNECTION' }));
126
130
  }),
127
- setSettings: defineMutator(v.object({
128
- color: v.optional(marcoSchemas.string.nullable()),
129
- displayName: v.optional(marcoSchemas.string.nullable()),
130
- id: marcoSchemas.string.required(),
131
- }), async ({ tx, args }) => {
131
+ setSettings: defineMutator(accountMutatorSchemas.setSettings, async ({ tx, args: { id, color, displayName } }) => {
132
132
  await tx.mutate(zeroCRUD.account.update({
133
- color: args.color ? args.color : undefined,
134
- displayName: args.displayName ? args.displayName : undefined,
135
- id: args.id,
133
+ color: color ? color : undefined,
134
+ displayName: displayName ? displayName : undefined,
135
+ id,
136
136
  }));
137
137
  }),
138
138
  };
@@ -1,2 +1,2 @@
1
- export * from './accountMutators';
1
+ export { accountMutatorSchemas, accountMutators } from './accountMutators';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/accountMutators/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/accountMutators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA"}
@@ -1 +1 @@
1
- export * from './accountMutators';
1
+ export { accountMutatorSchemas, accountMutators } from './accountMutators';
@@ -1,3 +1,97 @@
1
+ import * as v from 'valibot';
2
+ export declare const draftMutatorSchemas: {
3
+ cancelSend: v.ObjectSchema<{
4
+ readonly id: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
5
+ readonly updatedAt: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
6
+ }, undefined>;
7
+ createAttachment: v.ObjectSchema<{
8
+ readonly attachment: v.ObjectSchema<{
9
+ readonly fileName: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
10
+ readonly id: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
11
+ readonly mimeType: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
12
+ readonly status: v.PicklistSchema<readonly ["PENDING", "COMPLETE", "FAILED"], undefined>;
13
+ readonly totalSize: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
14
+ }, undefined>;
15
+ readonly id: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
16
+ readonly updatedAt: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
17
+ }, undefined>;
18
+ deleteAttachment: v.ObjectSchema<{
19
+ readonly attachmentId: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
20
+ readonly id: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
21
+ readonly updatedAt: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
22
+ }, undefined>;
23
+ deleteDraft: v.ObjectSchema<{
24
+ readonly id: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
25
+ }, undefined>;
26
+ setContent: v.ObjectSchema<{
27
+ readonly id: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
28
+ readonly patch: v.ArraySchema<v.ObjectSchema<{
29
+ readonly index: v.NumberSchema<undefined>;
30
+ readonly type: v.UnionSchema<[v.LiteralSchema<"INSERTION", undefined>, v.LiteralSchema<"DELETION", undefined>], undefined>;
31
+ readonly value: v.StringSchema<undefined>;
32
+ }, undefined>, undefined>;
33
+ readonly updatedAt: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
34
+ }, undefined>;
35
+ setEnvelope: v.ObjectSchema<{
36
+ readonly envelope: Omit<v.ObjectSchema<{
37
+ readonly bcc: v.ArraySchema<v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.EmailAction<string, undefined>, v.MaxLengthAction<string, 255, undefined>]>, undefined>, undefined>;
38
+ readonly cc: v.ArraySchema<v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.EmailAction<string, undefined>, v.MaxLengthAction<string, 255, undefined>]>, undefined>, undefined>;
39
+ readonly content: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 384000, undefined>]>;
40
+ readonly subject: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
41
+ readonly to: v.ArraySchema<v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.EmailAction<string, undefined>, v.MaxLengthAction<string, 255, undefined>]>, undefined>, undefined>;
42
+ }, undefined>, "~standard" | "~run" | "~types" | "entries"> & {
43
+ readonly entries: Omit<{
44
+ readonly bcc: v.ArraySchema<v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.EmailAction<string, undefined>, v.MaxLengthAction<string, 255, undefined>]>, undefined>, undefined>;
45
+ readonly cc: v.ArraySchema<v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.EmailAction<string, undefined>, v.MaxLengthAction<string, 255, undefined>]>, undefined>, undefined>;
46
+ readonly content: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 384000, undefined>]>;
47
+ readonly subject: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
48
+ readonly to: v.ArraySchema<v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.EmailAction<string, undefined>, v.MaxLengthAction<string, 255, undefined>]>, undefined>, undefined>;
49
+ }, "content">;
50
+ readonly '~standard': v.StandardProps<{
51
+ bcc: string[];
52
+ cc: string[];
53
+ to: string[];
54
+ subject: string | null;
55
+ }, {
56
+ bcc: string[];
57
+ cc: string[];
58
+ to: string[];
59
+ subject: string | null;
60
+ }>;
61
+ readonly '~run': (dataset: v.UnknownDataset, config: v.Config<v.BaseIssue<unknown>>) => v.OutputDataset<{
62
+ bcc: string[];
63
+ cc: string[];
64
+ to: string[];
65
+ subject: string | null;
66
+ }, v.StringIssue | v.EmailIssue<string> | v.MaxLengthIssue<string, 255> | v.NonEmptyIssue<string> | v.MaxLengthIssue<string, number> | v.ObjectIssue | v.ArrayIssue | v.NonOptionalIssue>;
67
+ readonly '~types'?: {
68
+ readonly input: {
69
+ bcc: string[];
70
+ cc: string[];
71
+ to: string[];
72
+ subject: string | null;
73
+ };
74
+ readonly output: {
75
+ bcc: string[];
76
+ cc: string[];
77
+ to: string[];
78
+ subject: string | null;
79
+ };
80
+ readonly issue: v.StringIssue | v.EmailIssue<string> | v.MaxLengthIssue<string, 255> | v.NonEmptyIssue<string> | v.MaxLengthIssue<string, number> | v.ObjectIssue | v.ArrayIssue | v.NonOptionalIssue;
81
+ } | undefined;
82
+ };
83
+ readonly id: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
84
+ readonly updatedAt: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
85
+ }, undefined>;
86
+ setFrom: v.ObjectSchema<{
87
+ readonly accountId: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
88
+ readonly aliasId: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
89
+ readonly from: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.EmailAction<string, undefined>, v.MaxLengthAction<string, 255, undefined>]>, undefined>;
90
+ readonly fromName: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
91
+ readonly id: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
92
+ readonly updatedAt: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
93
+ }, undefined>;
94
+ };
1
95
  export declare const draftMutators: {
2
96
  cancelSend: import("@rocicorp/zero").MutatorDefinition<{
3
97
  id: string;
@@ -1 +1 @@
1
- {"version":3,"file":"draftMutators.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/draftMutators/draftMutators.ts"],"names":[],"mappings":"AAyDA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgOzB,CAAA"}
1
+ {"version":3,"file":"draftMutators.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/draftMutators/draftMutators.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAqD5B,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoC/B,CAAA;AAED,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyKzB,CAAA"}
@@ -4,8 +4,6 @@ import { marcoSchemas } from '../../../schemas';
4
4
  import { DRAFT_ATTACHMENT_UPLOAD_STATUSES, DRAFT_STATUSES, DRAFT_TYPES, MutationError } from '../../../types';
5
5
  import { stringPatch } from '../../../utils';
6
6
  import { zeroCRUD } from '../../../zero/crud';
7
- const draftStatusSchema = v.picklist(DRAFT_STATUSES);
8
- const draftTypeSchema = v.picklist(DRAFT_TYPES);
9
7
  const draftBodySchema = v.object({
10
8
  bcc: v.array(marcoSchemas.string.email()),
11
9
  cc: v.array(marcoSchemas.string.email()),
@@ -44,16 +42,50 @@ const draftModelSchema = v.object({
44
42
  id: marcoSchemas.string.required(),
45
43
  referencedMessageId: marcoSchemas.string.nullable(),
46
44
  scheduledFor: v.nullable(marcoSchemas.number.positiveInteger()),
47
- status: draftStatusSchema,
48
- type: draftTypeSchema,
45
+ status: v.picklist(DRAFT_STATUSES),
46
+ type: v.picklist(DRAFT_TYPES),
49
47
  updatedAt: marcoSchemas.number.positiveInteger(),
50
48
  });
51
- export const draftMutators = {
52
- cancelSend: defineMutator(v.object({
49
+ export const draftMutatorSchemas = {
50
+ cancelSend: v.object({
51
+ id: marcoSchemas.string.required(),
52
+ updatedAt: marcoSchemas.number.positiveInteger(),
53
+ }),
54
+ createAttachment: v.object({
55
+ attachment: draftAttachmentSchema,
56
+ id: marcoSchemas.string.required(),
57
+ updatedAt: marcoSchemas.number.positiveInteger(),
58
+ }),
59
+ deleteAttachment: v.object({
60
+ attachmentId: marcoSchemas.string.required(),
53
61
  id: marcoSchemas.string.required(),
54
62
  updatedAt: marcoSchemas.number.positiveInteger(),
55
- }), async ({ tx, args }) => {
56
- const draft = await tx.query.draft.where('id', args.id).one().run();
63
+ }),
64
+ deleteDraft: v.object({
65
+ id: marcoSchemas.string.required(),
66
+ }),
67
+ setContent: v.object({
68
+ id: marcoSchemas.string.required(),
69
+ patch: marcoSchemas.drafts.contentPatch.patch(),
70
+ updatedAt: marcoSchemas.number.positiveInteger(),
71
+ }),
72
+ setEnvelope: v.object({
73
+ envelope: v.omit(draftBodySchema, ['content']),
74
+ id: marcoSchemas.string.required(),
75
+ updatedAt: marcoSchemas.number.positiveInteger(),
76
+ }),
77
+ setFrom: v.object({
78
+ accountId: marcoSchemas.string.required(),
79
+ aliasId: marcoSchemas.string.required(),
80
+ from: marcoSchemas.string.email(),
81
+ fromName: marcoSchemas.string.nullable(),
82
+ id: marcoSchemas.string.required(),
83
+ updatedAt: marcoSchemas.number.positiveInteger(),
84
+ }),
85
+ };
86
+ export const draftMutators = {
87
+ cancelSend: defineMutator(draftMutatorSchemas.cancelSend, async ({ tx, args: { id, updatedAt } }) => {
88
+ const draft = await tx.query.draft.where('id', id).one().run();
57
89
  if (!draft) {
58
90
  throw new Error(MutationError.ENTITY_NOT_FOUND);
59
91
  }
@@ -61,29 +93,22 @@ export const draftMutators = {
61
93
  throw new Error(MutationError.ALREADY_APPLIED);
62
94
  }
63
95
  await tx.mutate(zeroCRUD.draft.update({
64
- id: args.id,
96
+ id,
65
97
  scheduledFor: null,
66
98
  status: 'DRAFT',
67
- updatedAt: args.updatedAt,
99
+ updatedAt,
68
100
  }));
69
101
  }),
70
- createAttachment: defineMutator(v.object({
71
- attachment: draftAttachmentSchema,
72
- id: marcoSchemas.string.required(),
73
- updatedAt: marcoSchemas.number.positiveInteger(),
74
- }), async ({ tx, args }) => {
102
+ createAttachment: defineMutator(draftMutatorSchemas.createAttachment, async ({ tx, args: { id, attachment, updatedAt } }) => {
75
103
  await tx.mutate(zeroCRUD.draftAttachment.insert({
76
- draftId: args.id,
77
- fileName: args.attachment.fileName,
78
- id: args.attachment.id,
79
- mimeType: args.attachment.mimeType,
80
- status: args.attachment.status,
81
- totalSize: args.attachment.totalSize,
82
- }));
83
- await tx.mutate(zeroCRUD.draft.update({
84
- id: args.id,
85
- updatedAt: args.updatedAt,
104
+ draftId: id,
105
+ fileName: attachment.fileName,
106
+ id: attachment.id,
107
+ mimeType: attachment.mimeType,
108
+ status: attachment.status,
109
+ totalSize: attachment.totalSize,
86
110
  }));
111
+ await tx.mutate(zeroCRUD.draft.update({ id, updatedAt }));
87
112
  }),
88
113
  createDraft: defineMutator(draftModelSchema, async ({ tx, ctx: { userId }, args }) => {
89
114
  await tx.mutate(zeroCRUD.draft.insert({
@@ -118,25 +143,14 @@ export const draftMutators = {
118
143
  }));
119
144
  }
120
145
  }),
121
- deleteAttachment: defineMutator(v.object({
122
- attachmentId: marcoSchemas.string.required(),
123
- id: marcoSchemas.string.required(),
124
- updatedAt: marcoSchemas.number.positiveInteger(),
125
- }), async ({ tx, args }) => {
146
+ deleteAttachment: defineMutator(draftMutatorSchemas.deleteAttachment, async ({ tx, args: { id, attachmentId, updatedAt } }) => {
126
147
  await tx.mutate(zeroCRUD.draftAttachment.delete({
127
- id: args.attachmentId,
128
- }));
129
- await tx.mutate(zeroCRUD.draft.update({
130
- id: args.id,
131
- updatedAt: args.updatedAt,
148
+ id: attachmentId,
132
149
  }));
150
+ await tx.mutate(zeroCRUD.draft.update({ id, updatedAt }));
133
151
  }),
134
- deleteDraft: defineMutator(v.object({
135
- id: marcoSchemas.string.required(),
136
- }), async ({ tx, args }) => {
137
- await tx.mutate(zeroCRUD.draft.delete({
138
- id: args.id,
139
- }));
152
+ deleteDraft: defineMutator(draftMutatorSchemas.deleteDraft, async ({ tx, args: { id } }) => {
153
+ await tx.mutate(zeroCRUD.draft.delete({ id }));
140
154
  }),
141
155
  scheduleSend: defineMutator(draftScheduleSchema, async ({ tx, args }) => {
142
156
  if (args.kind === 'IMMEDIATE') {
@@ -156,60 +170,45 @@ export const draftMutators = {
156
170
  }));
157
171
  }
158
172
  }),
159
- setContent: defineMutator(v.object({
160
- id: marcoSchemas.string.required(),
161
- patch: marcoSchemas.drafts.contentPatch.patch(),
162
- updatedAt: marcoSchemas.number.positiveInteger(),
163
- }), async ({ tx, args }) => {
164
- const draft = await tx.query.draft.where('id', args.id).one().run();
173
+ setContent: defineMutator(draftMutatorSchemas.setContent, async ({ tx, args: { id, patch, updatedAt } }) => {
174
+ const draft = await tx.query.draft.where('id', id).one().run();
165
175
  if (!draft) {
166
176
  throw new Error(MutationError.ENTITY_NOT_FOUND);
167
177
  }
168
178
  await tx.mutate(zeroCRUD.draft.update({
169
179
  body: {
170
180
  ...draft.body,
171
- content: stringPatch.apply(typeof draft.body?.content === 'string' ? draft.body.content : '', args.patch),
181
+ content: stringPatch.apply(typeof draft.body?.content === 'string' ? draft.body.content : '', patch),
172
182
  },
173
- id: args.id,
174
- updatedAt: args.updatedAt,
183
+ id,
184
+ updatedAt,
175
185
  }));
176
186
  }),
177
- setEnvelope: defineMutator(v.object({
178
- envelope: v.omit(draftBodySchema, ['content']),
179
- id: marcoSchemas.string.required(),
180
- updatedAt: marcoSchemas.number.positiveInteger(),
181
- }), async ({ tx, args }) => {
182
- const draft = await tx.query.draft.where('id', args.id).one().run();
187
+ setEnvelope: defineMutator(draftMutatorSchemas.setEnvelope, async ({ tx, args: { id, envelope, updatedAt } }) => {
188
+ const draft = await tx.query.draft.where('id', id).one().run();
183
189
  if (!draft) {
184
190
  throw new Error(MutationError.ENTITY_NOT_FOUND);
185
191
  }
186
192
  await tx.mutate(zeroCRUD.draft.update({
187
193
  body: {
188
- bcc: args.envelope.bcc,
189
- cc: args.envelope.cc,
194
+ bcc: envelope.bcc,
195
+ cc: envelope.cc,
190
196
  content: draft.body.content,
191
- to: args.envelope.to,
197
+ to: envelope.to,
192
198
  },
193
- id: args.id,
194
- subject: args.envelope.subject,
195
- updatedAt: args.updatedAt,
199
+ id,
200
+ subject: envelope.subject,
201
+ updatedAt,
196
202
  }));
197
203
  }),
198
- setFrom: defineMutator(v.object({
199
- accountId: marcoSchemas.string.required(),
200
- aliasId: marcoSchemas.string.required(),
201
- from: marcoSchemas.string.email(),
202
- fromName: marcoSchemas.string.nullable(),
203
- id: marcoSchemas.string.required(),
204
- updatedAt: marcoSchemas.number.positiveInteger(),
205
- }), async ({ tx, args }) => {
204
+ setFrom: defineMutator(draftMutatorSchemas.setFrom, async ({ tx, args: { id, accountId, aliasId, from, fromName, updatedAt } }) => {
206
205
  await tx.mutate(zeroCRUD.draft.update({
207
- accountId: args.accountId,
208
- fromAliasId: args.aliasId,
209
- fromEmail: args.from,
210
- fromName: args.fromName,
211
- id: args.id,
212
- updatedAt: args.updatedAt,
206
+ accountId,
207
+ fromAliasId: aliasId,
208
+ fromEmail: from,
209
+ fromName: fromName,
210
+ id,
211
+ updatedAt,
213
212
  }));
214
213
  }),
215
214
  };
@@ -1,2 +1,2 @@
1
- export * from './draftMutators';
1
+ export { draftMutatorSchemas, draftMutators } from './draftMutators';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/draftMutators/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/draftMutators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA"}
@@ -1 +1 @@
1
- export * from './draftMutators';
1
+ export { draftMutatorSchemas, draftMutators } from './draftMutators';