@shakerquiz/guards 0.0.2 → 0.0.4
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.
- package/.github/workflows/publish.yml +0 -3
- package/package.json +1 -1
- package/source/guards/QUERY/channels.js +11 -5
- package/source/guards/QUERY/participants.js +14 -8
- package/source/guards/channel-mailing-message.js +11 -4
- package/source/guards/channel.js +8 -2
- package/source/guards/mailing.js +11 -4
- package/source/guards/message.js +12 -5
- package/source/guards/participant.js +20 -10
|
@@ -18,15 +18,12 @@ jobs:
|
|
|
18
18
|
steps:
|
|
19
19
|
- uses: actions/checkout@v7
|
|
20
20
|
with:
|
|
21
|
-
fetch-depth: 0
|
|
22
21
|
ref: main
|
|
23
22
|
- uses: actions/setup-node@v7
|
|
24
23
|
with:
|
|
25
24
|
node-version: lts/*
|
|
26
|
-
- uses: oven-sh/setup-bun@v2
|
|
27
25
|
- run: git config user.name "github-actions[bot]"
|
|
28
26
|
- run: git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
29
27
|
- run: npm version patch
|
|
30
|
-
- run: bun install --frozen-lockfile
|
|
31
28
|
- run: npm publish --tag latest --access public
|
|
32
29
|
- run: git push --follow-tags
|
package/package.json
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import { Channel, Channels } from '@shakerquiz/utilities'
|
|
2
2
|
import { guardBody } from '../../utilities/guard-body.js'
|
|
3
3
|
|
|
4
|
-
export const
|
|
5
|
-
channel:
|
|
4
|
+
export const ChannelsQueryProp = Object.freeze({
|
|
5
|
+
channel: 'channel',
|
|
6
|
+
id: 'id',
|
|
7
|
+
})
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
export const ChannelsQueryProps = Object.freeze(Object.values(ChannelsQueryProp))
|
|
10
|
+
|
|
11
|
+
export const ChannelsQueryPropValidation = Object.freeze({
|
|
12
|
+
[ChannelsQueryProp.channel]: value => Object.hasOwn(Channel, value),
|
|
13
|
+
[ChannelsQueryProp.id]: value =>
|
|
8
14
|
Array.isArray(value)
|
|
9
15
|
? value.every(item => typeof item === 'string')
|
|
10
16
|
: value === 'Any',
|
|
11
17
|
})
|
|
12
18
|
|
|
13
19
|
export const ChannelsQueryPropException = Object.freeze({
|
|
14
|
-
channel: `Body.channel must be one of ${Channels.join(', ')}.`,
|
|
15
|
-
id: `Body.id must be 'Any' or an array of strings.`,
|
|
20
|
+
[ChannelsQueryProp.channel]: `Body.channel must be one of ${Channels.join(', ')}.`,
|
|
21
|
+
[ChannelsQueryProp.id]: `Body.id must be 'Any' or an array of strings.`,
|
|
16
22
|
})
|
|
17
23
|
|
|
18
24
|
export const guardChannelsQueryBody = guardBody('Object', ChannelsQueryPropValidation, ChannelsQueryPropException)
|
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
import { Pattern } from '@shakerquiz/utilities'
|
|
2
2
|
import { guardBody } from '../../utilities/guard-body.js'
|
|
3
3
|
|
|
4
|
+
export const ParticipantsQueryProp = Object.freeze({
|
|
5
|
+
id: 'id',
|
|
6
|
+
mongo_id: 'mongo_id',
|
|
7
|
+
username: 'username',
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
export const ParticipantsQueryProps = Object.freeze(Object.values(ParticipantsQueryProp))
|
|
11
|
+
|
|
4
12
|
export const ParticipantsQueryPropValidation = Object.freeze({
|
|
5
|
-
id: value =>
|
|
13
|
+
[ParticipantsQueryProp.id]: value =>
|
|
6
14
|
Array.isArray(value)
|
|
7
15
|
? value.every(item => typeof item === 'string' && Pattern.UUID.test(item))
|
|
8
16
|
: value === 'Any',
|
|
9
|
-
|
|
10
|
-
mongo_id: value =>
|
|
17
|
+
[ParticipantsQueryProp.mongo_id]: value =>
|
|
11
18
|
Array.isArray(value)
|
|
12
19
|
? value.every(item => typeof item === 'string')
|
|
13
20
|
: value === 'Any',
|
|
14
|
-
|
|
15
|
-
username: value =>
|
|
21
|
+
[ParticipantsQueryProp.username]: value =>
|
|
16
22
|
Array.isArray(value)
|
|
17
23
|
? value.every(item => typeof item === 'string')
|
|
18
24
|
: value === 'Any',
|
|
19
25
|
})
|
|
20
26
|
|
|
21
27
|
export const ParticipantsQueryPropException = Object.freeze({
|
|
22
|
-
id: `Body.id must be 'Any' or an array of uuid.`,
|
|
23
|
-
mongo_id: `Body.mongo_id must be 'Any' or an array of strings.`,
|
|
24
|
-
username: `Body.username must be 'Any' or an array of strings.`,
|
|
28
|
+
[ParticipantsQueryProp.id]: `Body.id must be 'Any' or an array of uuid.`,
|
|
29
|
+
[ParticipantsQueryProp.mongo_id]: `Body.mongo_id must be 'Any' or an array of strings.`,
|
|
30
|
+
[ParticipantsQueryProp.username]: `Body.username must be 'Any' or an array of strings.`,
|
|
25
31
|
})
|
|
26
32
|
|
|
27
33
|
export const guardParticipantsQueryBody = guardBody(
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { guardBody } from '../utilities/guard-body.js'
|
|
2
2
|
|
|
3
|
+
export const ChannelMailingMessageProp = Object.freeze({
|
|
4
|
+
recipient: 'recipient',
|
|
5
|
+
sender: 'sender',
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
export const ChannelMailingMessageProps = Object.freeze(Object.values(ChannelMailingMessageProp))
|
|
9
|
+
|
|
3
10
|
export const ChannelMailingMessagePropValidation = Object.freeze({
|
|
4
|
-
|
|
5
|
-
|
|
11
|
+
[ChannelMailingMessageProp.recipient]: value => typeof value === 'string' && value !== '',
|
|
12
|
+
[ChannelMailingMessageProp.sender]: value => typeof value === 'string' && value !== '',
|
|
6
13
|
})
|
|
7
14
|
|
|
8
15
|
export const ChannelMailingMessagePropException = Object.freeze({
|
|
9
|
-
|
|
10
|
-
|
|
16
|
+
[ChannelMailingMessageProp.recipient]: `Body.recipient must be a non-empty string.`,
|
|
17
|
+
[ChannelMailingMessageProp.sender]: `Body.sender must be a non-empty string.`,
|
|
11
18
|
})
|
|
12
19
|
|
|
13
20
|
export const guardChannelMailingMessageBody = guardBody(
|
package/source/guards/channel.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { guardBody } from '../utilities/guard-body.js'
|
|
2
2
|
|
|
3
|
+
export const ChannelProp = Object.freeze({
|
|
4
|
+
id: 'id',
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
export const ChannelProps = Object.freeze(Object.values(ChannelProp))
|
|
8
|
+
|
|
3
9
|
export const ChannelPropValidation = Object.freeze({
|
|
4
|
-
id: value => typeof value === 'string' && value !== '',
|
|
10
|
+
[ChannelProp.id]: value => typeof value === 'string' && value !== '',
|
|
5
11
|
})
|
|
6
12
|
|
|
7
13
|
export const ChannelPropException = Object.freeze({
|
|
8
|
-
id: `Body.id must be a non-empty string.`,
|
|
14
|
+
[ChannelProp.id]: `Body.id must be a non-empty string.`,
|
|
9
15
|
})
|
|
10
16
|
|
|
11
17
|
export const guardChannelBody = guardBody('Object', ChannelPropValidation, ChannelPropException)
|
package/source/guards/mailing.js
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import { Phase } from '@shakerquiz/utilities'
|
|
2
2
|
import { guardBody } from '../utilities/guard-body.js'
|
|
3
3
|
|
|
4
|
+
export const MailingProp = Object.freeze({
|
|
5
|
+
phase: 'phase',
|
|
6
|
+
reason: 'reason',
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
export const MailingProps = Object.freeze(Object.values(MailingProp))
|
|
10
|
+
|
|
4
11
|
export const MailingPropValidation = Object.freeze({
|
|
5
|
-
phase: value => Object.hasOwn(Phase, value),
|
|
6
|
-
reason: value => typeof value === 'string',
|
|
12
|
+
[MailingProp.phase]: value => Object.hasOwn(Phase, value),
|
|
13
|
+
[MailingProp.reason]: value => typeof value === 'string',
|
|
7
14
|
})
|
|
8
15
|
|
|
9
16
|
export const MailingPropException = Object.freeze({
|
|
10
|
-
phase: `Body.phase must be a Phase.`,
|
|
11
|
-
reason: `Body.reason must be a string.`,
|
|
17
|
+
[MailingProp.phase]: `Body.phase must be a Phase.`,
|
|
18
|
+
[MailingProp.reason]: `Body.reason must be a string.`,
|
|
12
19
|
})
|
|
13
20
|
|
|
14
21
|
export const guardMailingBody = guardBody('Object', MailingPropValidation, MailingPropException)
|
package/source/guards/message.js
CHANGED
|
@@ -2,15 +2,22 @@ import { MessageKind } from '@shakerquiz/utilities'
|
|
|
2
2
|
import { isStringTag } from '@yurkimus/string-tag'
|
|
3
3
|
import { guardBody } from '../utilities/guard-body.js'
|
|
4
4
|
|
|
5
|
+
export const MessageProp = Object.freeze({
|
|
6
|
+
content: 'content',
|
|
7
|
+
kind: 'kind',
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
export const MessageProps = Object.freeze(Object.values(MessageProp))
|
|
11
|
+
|
|
5
12
|
export const MessagePropValidation = Object.freeze({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
[MessageProp.content]: value =>
|
|
14
|
+
(isStringTag('Object', value) || isStringTag('Array', value)) && Object.keys(value).length > 0,
|
|
15
|
+
[MessageProp.kind]: value => value === MessageKind.Inline,
|
|
9
16
|
})
|
|
10
17
|
|
|
11
18
|
export const MessagePropException = Object.freeze({
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
[MessageProp.content]: `Body.content must be a non-empty object or array.`,
|
|
20
|
+
[MessageProp.kind]: `Body.kind must be '${MessageKind.Inline}'.`,
|
|
14
21
|
})
|
|
15
22
|
|
|
16
23
|
export const guardMessageBody = guardBody('Object', MessagePropValidation, MessagePropException)
|
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
import { ParticipantChoice } from '@shakerquiz/utilities'
|
|
2
2
|
import { guardBody } from '../utilities/guard-body.js'
|
|
3
3
|
|
|
4
|
+
export const ParticipantProp = Object.freeze({
|
|
5
|
+
choice: 'choice',
|
|
6
|
+
first_name: 'first_name',
|
|
7
|
+
last_name: 'last_name',
|
|
8
|
+
mongo_id: 'mongo_id',
|
|
9
|
+
username: 'username',
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
export const ParticipantProps = Object.freeze(Object.values(ParticipantProp))
|
|
13
|
+
|
|
4
14
|
export const ParticipantPropValidation = Object.freeze({
|
|
5
|
-
|
|
6
|
-
first_name: value => typeof value === 'string',
|
|
7
|
-
last_name: value => typeof value === 'string',
|
|
8
|
-
|
|
9
|
-
|
|
15
|
+
[ParticipantProp.choice]: value => Object.hasOwn(ParticipantChoice, value),
|
|
16
|
+
[ParticipantProp.first_name]: value => typeof value === 'string',
|
|
17
|
+
[ParticipantProp.last_name]: value => typeof value === 'string',
|
|
18
|
+
[ParticipantProp.mongo_id]: value => typeof value === 'string' && value !== '',
|
|
19
|
+
[ParticipantProp.username]: value => typeof value === 'string',
|
|
10
20
|
})
|
|
11
21
|
|
|
12
22
|
export const ParticipantPropException = Object.freeze({
|
|
13
|
-
|
|
14
|
-
first_name: `Body.first_name must be a string.`,
|
|
15
|
-
last_name: `Body.last_name must be a string.`,
|
|
16
|
-
|
|
17
|
-
|
|
23
|
+
[ParticipantProp.choice]: `Body.choice must be a ParticipantChoice.`,
|
|
24
|
+
[ParticipantProp.first_name]: `Body.first_name must be a string.`,
|
|
25
|
+
[ParticipantProp.last_name]: `Body.last_name must be a string.`,
|
|
26
|
+
[ParticipantProp.mongo_id]: `Body.mongo_id must be a non-empty string.`,
|
|
27
|
+
[ParticipantProp.username]: `Body.username must be a string.`,
|
|
18
28
|
})
|
|
19
29
|
|
|
20
30
|
export const guardParticipantBody = guardBody('Object', ParticipantPropValidation, ParticipantPropException)
|