@shakerquiz/utilities 0.1.37

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Шейкер Квиз
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dprint.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "typescript": {
3
+ "quoteStyle": "preferSingle",
4
+ "semiColons": "asi",
5
+ "indentWidth": 2,
6
+ "useTabs": false,
7
+ "useBraces": "maintain",
8
+ "arrowFunction.useParentheses": "preferNone",
9
+ "lineWidth": 80
10
+ },
11
+
12
+ "json": {},
13
+
14
+ "markdown": {},
15
+
16
+ "dockerfile": {},
17
+
18
+ "yaml": {},
19
+
20
+ "excludes": [
21
+ "**/node_modules",
22
+ "**/*-lock.json"
23
+ ],
24
+
25
+ "plugins": [
26
+ "https://plugins.dprint.dev/typescript-0.93.0.wasm",
27
+ "https://plugins.dprint.dev/json-0.19.3.wasm",
28
+ "https://plugins.dprint.dev/markdown-0.17.8.wasm",
29
+ "https://plugins.dprint.dev/dockerfile-0.3.2.wasm",
30
+ "https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.0.wasm"
31
+ ]
32
+ }
package/jsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+
5
+ "module": "NodeNext",
6
+ "moduleResolution": "nodenext",
7
+
8
+ "strictBindCallApply": true,
9
+ "allowArbitraryExtensions": true
10
+ }
11
+ }
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@shakerquiz/utilities",
3
+ "version": "0.1.37",
4
+ "author": "yurkimus <yurkimus@gmail.com>",
5
+ "license": "ISC",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./source/index.d.ts",
9
+ "import": "./source/index.js",
10
+ "edge-light": "./source/index.js"
11
+ }
12
+ },
13
+ "dependencies": {
14
+ "@yurkimus/cookies": "0.0.7",
15
+ "@yurkimus/errors": "0.1.3",
16
+ "@yurkimus/message": "0.0.13",
17
+ "@yurkimus/response-status": "0.1.0",
18
+ "@yurkimus/url": "0.2.7"
19
+ }
20
+ }
@@ -0,0 +1,3 @@
1
+ export let Constants: {
2
+ NilUuid: '00000000-0000-0000-0000-000000000000'
3
+ }
@@ -0,0 +1,6 @@
1
+ export let Constants = {
2
+ /**
3
+ * @see https://www.rfc-editor.org/rfc/rfc9562.html#name-nil-uuid
4
+ */
5
+ NilUuid: '00000000-0000-0000-0000-000000000000',
6
+ }
@@ -0,0 +1,5 @@
1
+ export let Cookies: {
2
+ Token: 'shaker-quiz-token',
3
+ Refresh: 'shaker-quiz-refresh-token',
4
+ Role: 'shaker-quiz-user-role',
5
+ }
@@ -0,0 +1,5 @@
1
+ export let Cookies = {
2
+ Token: 'shaker-quiz-token',
3
+ Refresh: 'shaker-quiz-refresh-token',
4
+ Role: 'shaker-quiz-user-role',
5
+ }
@@ -0,0 +1,58 @@
1
+ import { URLOptions } from '@yurkimus/url'
2
+
3
+ import { Kinds } from './kinds'
4
+ import { Networks } from './networks'
5
+
6
+ export let Features: {
7
+ Checkin: 'Checkin'
8
+
9
+ City: 'City'
10
+ Cities: 'Cities'
11
+
12
+ CityPublic: 'CityPublic'
13
+ CitiesPublic: 'CitiesPublic'
14
+
15
+ Game: 'Game'
16
+ Games: 'Games'
17
+
18
+ GamePublic: 'GamePublic'
19
+ GamesPublic: 'GamesPublic'
20
+
21
+ Theme: 'Theme'
22
+ Themes: 'Themes'
23
+
24
+ User: 'User'
25
+ Users: 'Users'
26
+ }
27
+
28
+ export let FeatureKinds: {
29
+ [Features.Checkin]: Kinds.Item
30
+
31
+ [Features.City]: Kinds.Item
32
+ [Features.Cities]: Kinds.List
33
+
34
+ [Features.CityPublic]: Kinds.Item
35
+ [Features.CitiesPublic]: Kinds.List
36
+
37
+ [Features.Game]: Kinds.Item
38
+ [Features.Games]: Kinds.List
39
+
40
+ [Features.GamePublic]: Kinds.Item
41
+ [Features.GamesPublic]: Kinds.List
42
+
43
+ [Features.Theme]: Kinds.Item
44
+ [Features.Themes]: Kinds.List
45
+
46
+ [Features.User]: Kinds.Item
47
+ [Features.Users]: Kinds.List
48
+ }
49
+
50
+ export let FeatureRequests: Map<
51
+ keyof typeof Features,
52
+ Set<'DELETE' | 'GET' | 'OPTIONS' | 'POST' | 'PATCH'>
53
+ >
54
+
55
+ export let FeatureUrls: Map<
56
+ keyof typeof Features,
57
+ Map<keyof typeof Networks, (options: URLOptions) => URL>
58
+ >
@@ -0,0 +1,49 @@
1
+ import { Kinds } from './kinds.js'
2
+
3
+ export let Features = {
4
+ Checkin: 'Checkin',
5
+
6
+ City: 'City',
7
+ Cities: 'Cities',
8
+
9
+ CityPublic: 'CityPublic',
10
+ CitiesPublic: 'CitiesPublic',
11
+
12
+ Game: 'Game',
13
+ Games: 'Games',
14
+
15
+ GamePublic: 'GamePublic',
16
+ GamesPublic: 'GamesPublic',
17
+
18
+ Theme: 'Theme',
19
+ Themes: 'Themes',
20
+
21
+ User: 'User',
22
+ Users: 'Users',
23
+ }
24
+
25
+ export let FeatureKinds = {
26
+ [Features.Checkin]: Kinds.Item,
27
+
28
+ [Features.City]: Kinds.Item,
29
+ [Features.Cities]: Kinds.List,
30
+
31
+ [Features.CityPublic]: Kinds.Item,
32
+ [Features.CitiesPublic]: Kinds.List,
33
+
34
+ [Features.Game]: Kinds.Item,
35
+ [Features.Games]: Kinds.List,
36
+
37
+ [Features.GamePublic]: Kinds.Item,
38
+ [Features.GamesPublic]: Kinds.List,
39
+
40
+ [Features.Theme]: Kinds.Item,
41
+ [Features.Themes]: Kinds.List,
42
+
43
+ [Features.User]: Kinds.Item,
44
+ [Features.Users]: Kinds.List,
45
+ }
46
+
47
+ export let FeatureRequests = new Map()
48
+
49
+ export let FeatureUrls = new Map()
@@ -0,0 +1,39 @@
1
+ import { Roles } from './roles.js'
2
+
3
+ export let GameStatuses: {
4
+ Approved: 'APPROVED'
5
+ Archive: 'ARCHIVE'
6
+ Closed: 'CLOSED'
7
+ Finished: 'FINISHED'
8
+ Invitation: 'FORINVITES'
9
+ Moderation: 'MODERATION'
10
+ Published: 'PUBLISHED'
11
+ Rejected: 'REJECTED'
12
+ Reserved: 'IS_RESERVE'
13
+ }
14
+
15
+ export let RoleGameStatuses: {
16
+ [Roles.Admin]: [
17
+ typeof GameStatuses.Approved,
18
+ typeof GameStatuses.Moderation,
19
+ typeof GameStatuses.Published,
20
+ typeof GameStatuses.Rejected,
21
+ typeof GameStatuses.Finished,
22
+ typeof GameStatuses.Archive,
23
+ typeof GameStatuses.Invitation,
24
+ typeof GameStatuses.Reserved,
25
+ typeof GameStatuses.Closed,
26
+ ]
27
+
28
+ [Roles.Organizer]: [
29
+ typeof GameStatuses.Approved,
30
+ typeof GameStatuses.Published,
31
+ typeof GameStatuses.Finished,
32
+ typeof GameStatuses.Archive,
33
+ typeof GameStatuses.Invitation,
34
+ typeof GameStatuses.Reserved,
35
+ typeof GameStatuses.Closed,
36
+ ]
37
+
38
+ [Roles.Default]: []
39
+ }
@@ -0,0 +1,39 @@
1
+ import { Roles } from './roles.js'
2
+
3
+ export let GameStatuses = {
4
+ Approved: 'APPROVED',
5
+ Archive: 'ARCHIVE',
6
+ Closed: 'CLOSED',
7
+ Finished: 'FINISHED',
8
+ Invitation: 'FORINVITES',
9
+ Moderation: 'MODERATION',
10
+ Published: 'PUBLISHED',
11
+ Rejected: 'REJECTED',
12
+ Reserved: 'IS_RESERVE',
13
+ }
14
+
15
+ export let RoleGameStatuses = {
16
+ [Roles.Admin]: [
17
+ GameStatuses.Approved,
18
+ GameStatuses.Moderation,
19
+ GameStatuses.Published,
20
+ GameStatuses.Rejected,
21
+ GameStatuses.Finished,
22
+ GameStatuses.Archive,
23
+ GameStatuses.Invitation,
24
+ GameStatuses.Reserved,
25
+ GameStatuses.Closed,
26
+ ],
27
+
28
+ [Roles.Organizer]: [
29
+ GameStatuses.Approved,
30
+ GameStatuses.Published,
31
+ GameStatuses.Finished,
32
+ GameStatuses.Archive,
33
+ GameStatuses.Invitation,
34
+ GameStatuses.Reserved,
35
+ GameStatuses.Closed,
36
+ ],
37
+
38
+ [Roles.Default]: [],
39
+ }
@@ -0,0 +1,4 @@
1
+ export let Kinds: {
2
+ Item: 'Item'
3
+ List: 'List'
4
+ }
@@ -0,0 +1,4 @@
1
+ export let Kinds = {
2
+ Item: 'Item',
3
+ List: 'List',
4
+ }
@@ -0,0 +1,7 @@
1
+ export let Methods: {
2
+ DELETE: 'DELETE'
3
+ GET: 'GET'
4
+ OPTIONS: 'OPTIONS'
5
+ PATCH: 'PATCH'
6
+ POST: 'POST'
7
+ }
@@ -0,0 +1,7 @@
1
+ export let Methods = {
2
+ DELETE: 'DELETE',
3
+ GET: 'GET',
4
+ OPTIONS: 'OPTIONS',
5
+ PATCH: 'PATCH',
6
+ POST: 'POST',
7
+ }
@@ -0,0 +1,4 @@
1
+ export let Networks: {
2
+ Private: 'Private'
3
+ Public: 'Public'
4
+ }
@@ -0,0 +1,4 @@
1
+ export let Networks = {
2
+ Private: 'Private',
3
+ Public: 'Public',
4
+ }
@@ -0,0 +1,7 @@
1
+ export let Phases: {
2
+ Aborted: 'Aborted'
3
+ Failed: 'Failed'
4
+ Idle: 'Idle'
5
+ Loaded: 'Loaded'
6
+ Loading: 'Loading'
7
+ }
@@ -0,0 +1,7 @@
1
+ export let Phases = {
2
+ Aborted: 'Aborted',
3
+ Failed: 'Failed',
4
+ Idle: 'Idle',
5
+ Loaded: 'Loaded',
6
+ Loading: 'Loading',
7
+ }
@@ -0,0 +1,4 @@
1
+ export let RegExps: {
2
+ Uuid: RegExp
3
+ ElementId: RegExp
4
+ }
@@ -0,0 +1,6 @@
1
+ export let RegExps = {
2
+ Uuid: /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/,
3
+
4
+ ElementId:
5
+ /\d+:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}:\d+/,
6
+ }
@@ -0,0 +1,5 @@
1
+ export let Roles: {
2
+ Admin: 'admin'
3
+ Organizer: 'organizer'
4
+ Default: 'default'
5
+ }
@@ -0,0 +1,5 @@
1
+ export let Roles = {
2
+ Admin: 'admin',
3
+ Organizer: 'organizer',
4
+ Default: 'default',
5
+ }
@@ -0,0 +1,131 @@
1
+ import { URLOptions } from '@yurkimus/url'
2
+
3
+ import { Features } from '../enumerations/features'
4
+ import { Methods } from '../enumerations/methods'
5
+ import { Networks } from '../enumerations/networks'
6
+
7
+ export let Extensions: WeakMap<
8
+ Function,
9
+ Map<
10
+ | 'onbefore'
11
+ | 'onfulfilled'
12
+ | 'onrejected',
13
+ Set<Function>
14
+ >
15
+ >
16
+
17
+ export let useRequest: <
18
+ Feature extends keyof typeof Features,
19
+ Method extends keyof typeof Methods,
20
+ Network extends keyof typeof Networks,
21
+ >(
22
+ feature: Feature,
23
+ method: Method,
24
+ network: Network,
25
+ ) => (options: URLOptions, init: RequestInit) => Promise<
26
+ {
27
+ [Features.Checkin]: {
28
+ [Methods.DELETE]: unknown
29
+ [Methods.GET]: CheckinResult
30
+ [Methods.OPTIONS]: unknown
31
+ [Methods.PATCH]: unknown
32
+ [Methods.POST]: unknown
33
+ }
34
+
35
+ [Features.City]: {
36
+ [Methods.DELETE]: unknown
37
+ [Methods.GET]: CityResult
38
+ [Methods.OPTIONS]: unknown
39
+ [Methods.PATCH]: unknown
40
+ [Methods.POST]: unknown
41
+ }
42
+
43
+ [Features.Cities]: {
44
+ [Methods.DELETE]: unknown
45
+ [Methods.GET]: CityResult[]
46
+ [Methods.OPTIONS]: unknown
47
+ [Methods.PATCH]: unknown
48
+ [Methods.POST]: unknown
49
+ }
50
+
51
+ [Features.CityPublic]: {
52
+ [Methods.DELETE]: unknown
53
+ [Methods.GET]: CityPublicResult
54
+ [Methods.OPTIONS]: unknown
55
+ [Methods.PATCH]: unknown
56
+ [Methods.POST]: unknown
57
+ }
58
+
59
+ [Features.CitiesPublic]: {
60
+ [Methods.DELETE]: unknown
61
+ [Methods.GET]: CityPublicResult[]
62
+ [Methods.OPTIONS]: unknown
63
+ [Methods.PATCH]: unknown
64
+ [Methods.POST]: unknown
65
+ }
66
+
67
+ [Features.Theme]: {
68
+ [Methods.DELETE]: unknown
69
+ [Methods.GET]: ThemeResult
70
+ [Methods.OPTIONS]: unknown
71
+ [Methods.PATCH]: unknown
72
+ [Methods.POST]: unknown
73
+ }
74
+
75
+ [Features.Themes]: {
76
+ [Methods.DELETE]: unknown
77
+ [Methods.GET]: ThemeResult[]
78
+ [Methods.OPTIONS]: unknown
79
+ [Methods.PATCH]: unknown
80
+ [Methods.POST]: unknown
81
+ }
82
+
83
+ [Features.Game]: {
84
+ [Methods.DELETE]: unknown
85
+ [Methods.GET]: unknown
86
+ [Methods.OPTIONS]: GameResult
87
+ [Methods.PATCH]: unknown
88
+ [Methods.POST]: unknown
89
+ }
90
+
91
+ [Features.Games]: {
92
+ [Methods.DELETE]: unknown
93
+ [Methods.GET]: GameResult[]
94
+ [Methods.OPTIONS]: unknown
95
+ [Methods.PATCH]: unknown
96
+ [Methods.POST]: unknown
97
+ }
98
+
99
+ [Features.GamePublic]: {
100
+ [Methods.DELETE]: unknown
101
+ [Methods.GET]: GamePublicResult
102
+ [Methods.OPTIONS]: unknown
103
+ [Methods.PATCH]: unknown
104
+ [Methods.POST]: unknown
105
+ }
106
+
107
+ [Features.GamesPublic]: {
108
+ [Methods.DELETE]: unknown
109
+ [Methods.GET]: GamePublicResult[]
110
+ [Methods.OPTIONS]: unknown
111
+ [Methods.PATCH]: unknown
112
+ [Methods.POST]: unknown
113
+ }
114
+
115
+ [Features.User]: {
116
+ [Methods.DELETE]: unknown
117
+ [Methods.GET]: unknown
118
+ [Methods.OPTIONS]: unknown
119
+ [Methods.PATCH]: unknown
120
+ [Methods.POST]: unknown
121
+ }
122
+
123
+ [Features.Users]: {
124
+ [Methods.DELETE]: unknown
125
+ [Methods.GET]: unknown
126
+ [Methods.OPTIONS]: unknown
127
+ [Methods.PATCH]: unknown
128
+ [Methods.POST]: unknown
129
+ }
130
+ }[Feature][Method]
131
+ >