klaim 1.0.1 → 1.0.3
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/release.yml +35 -0
- package/.release-it.json +5 -2
- package/Makefile +5 -5
- package/bun.lockb +0 -0
- package/eslint.config.mjs +210 -210
- package/index.ts +5 -5
- package/package.json +5 -3
- package/src/core/Api.ts +63 -63
- package/src/index.ts +4 -4
- package/src/tools/cleanUrl.ts +12 -12
- package/src/tools/slugify.ts +17 -17
- package/src/tools/toCamelCase.ts +11 -11
- package/src/tools/token.ts +14 -14
- package/tests/arguments.test.ts +89 -89
- package/vite.config.ts +26 -26
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: Release & Publish to NPM
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches:
|
|
5
|
+
- main
|
|
6
|
+
jobs:
|
|
7
|
+
release:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
steps:
|
|
10
|
+
- name: Checkout
|
|
11
|
+
uses: actions/checkout@v2
|
|
12
|
+
- name: Setup Bun
|
|
13
|
+
uses: oven-sh/setup-bun@v1
|
|
14
|
+
with:
|
|
15
|
+
bun-version: "latest"
|
|
16
|
+
- name: Install Dependencies
|
|
17
|
+
run: bun install
|
|
18
|
+
- name: Lint & Check
|
|
19
|
+
run: bun run lint
|
|
20
|
+
- name: Build
|
|
21
|
+
run: bun run build
|
|
22
|
+
- name: Initialize Git
|
|
23
|
+
run: |
|
|
24
|
+
git config --global user.email "antho.eclips@gmail.com"
|
|
25
|
+
git config --global user.name "Anthony Bellancourt"
|
|
26
|
+
- name: Configure NPM
|
|
27
|
+
run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
|
|
28
|
+
env:
|
|
29
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
30
|
+
- name: Release
|
|
31
|
+
run: bun run release --ci
|
|
32
|
+
env:
|
|
33
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
34
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
35
|
+
|
package/.release-it.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://unpkg.com/release-it/schema/release-it.json",
|
|
3
3
|
"github": {
|
|
4
|
-
"release": true
|
|
4
|
+
"release": true,
|
|
5
|
+
"tokenRef": "GITHUB_TOKEN"
|
|
5
6
|
},
|
|
6
7
|
"npm": {
|
|
7
|
-
"publish": true
|
|
8
|
+
"publish": true,
|
|
9
|
+
"tokenRef": "NPM_TOKEN"
|
|
8
10
|
},
|
|
9
11
|
"git": {
|
|
10
12
|
"requiredBranch": "main",
|
|
13
|
+
"requireCleanWorkingDir": false,
|
|
11
14
|
"commitMessage": "chore: release v%s"
|
|
12
15
|
},
|
|
13
16
|
"hooks": {
|
package/Makefile
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
dev:
|
|
2
|
-
nr dev
|
|
3
|
-
|
|
4
|
-
dev-test:
|
|
5
|
-
cd ../klaim-test && nr dev
|
|
1
|
+
dev:
|
|
2
|
+
nr dev
|
|
3
|
+
|
|
4
|
+
dev-test:
|
|
5
|
+
cd ../klaim-test && nr dev
|
package/bun.lockb
CHANGED
|
Binary file
|
package/eslint.config.mjs
CHANGED
|
@@ -1,210 +1,210 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import stylistic from "@stylistic/eslint-plugin";
|
|
3
|
-
import simpleImportSort from "eslint-plugin-simple-import-sort";
|
|
4
|
-
import JSdoc from "eslint-plugin-jsdoc";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import eslint from '@eslint/js';
|
|
8
|
-
import tseslint from 'typescript-eslint';
|
|
9
|
-
|
|
10
|
-
export default tseslint.config(
|
|
11
|
-
eslint.configs.recommended,
|
|
12
|
-
...tseslint.configs.recommended,
|
|
13
|
-
{
|
|
14
|
-
plugins: {
|
|
15
|
-
"@stylistic": stylistic,
|
|
16
|
-
"simple-import-sort": simpleImportSort,
|
|
17
|
-
"jsdoc": JSdoc
|
|
18
|
-
},
|
|
19
|
-
files: ["src/**/*.ts"],
|
|
20
|
-
rules: {
|
|
21
|
-
// ----------------------------------------
|
|
22
|
-
// ---------------------- Simple Import Sort
|
|
23
|
-
// ----------------------------------------
|
|
24
|
-
"simple-import-sort/exports": "error",
|
|
25
|
-
"simple-import-sort/imports": [
|
|
26
|
-
"error",
|
|
27
|
-
{
|
|
28
|
-
"groups": [
|
|
29
|
-
["^\u0000"],
|
|
30
|
-
["^@?\\w"],
|
|
31
|
-
["^/"],
|
|
32
|
-
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
|
|
33
|
-
[
|
|
34
|
-
"^\\./(?=.*/)(?!/?$)",
|
|
35
|
-
"^\\.(?!/?$)",
|
|
36
|
-
"^\\./?$"
|
|
37
|
-
],
|
|
38
|
-
["^.+\\.s?css$"]
|
|
39
|
-
]
|
|
40
|
-
}
|
|
41
|
-
],
|
|
42
|
-
// ----------------------------------------
|
|
43
|
-
// ---------------------- TypeScript
|
|
44
|
-
// ----------------------------------------
|
|
45
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
46
|
-
"@typescript-eslint/ban-ts-comment": "off",
|
|
47
|
-
"@typescript-eslint/no-dynamic-delete": "off",
|
|
48
|
-
"@typescript-eslint/no-namespace": "off",
|
|
49
|
-
"@typescript-eslint/ban-types": "error",
|
|
50
|
-
"@typescript-eslint/explicit-function-return-type": "error",
|
|
51
|
-
"@typescript-eslint/consistent-indexed-object-style": "error",
|
|
52
|
-
|
|
53
|
-
// ----------------------------------------
|
|
54
|
-
// ---------------------- Stylistic
|
|
55
|
-
// ----------------------------------------
|
|
56
|
-
"@stylistic/array-bracket-spacing": ["error", "always"],
|
|
57
|
-
"@stylistic/function-paren-newline": ["error", "multiline"],
|
|
58
|
-
"@stylistic/multiline-ternary": ["error", "always-multiline"],
|
|
59
|
-
"@stylistic/quotes": [
|
|
60
|
-
"error",
|
|
61
|
-
"double",
|
|
62
|
-
{
|
|
63
|
-
"avoidEscape": true, "allowTemplateLiterals": true
|
|
64
|
-
}
|
|
65
|
-
],
|
|
66
|
-
"@stylistic/semi": [
|
|
67
|
-
"error",
|
|
68
|
-
"always",
|
|
69
|
-
{
|
|
70
|
-
"omitLastInOneLineBlock": true, "omitLastInOneLineClassBody": true
|
|
71
|
-
}
|
|
72
|
-
],
|
|
73
|
-
"@stylistic/space-before-function-paren": ["error", "always"],
|
|
74
|
-
"@stylistic/space-in-parens": ["error", "never"],
|
|
75
|
-
"@stylistic/space-infix-ops": ["error", {"int32Hint": false}],
|
|
76
|
-
"@stylistic/space-before-blocks": ["error", "always"],
|
|
77
|
-
"@stylistic/space-unary-ops": ["error", {"words": true, "nonwords": false}],
|
|
78
|
-
"@stylistic/keyword-spacing": ["error", {"before": true, "after": true}],
|
|
79
|
-
"@stylistic/block-spacing": ["error", "always"],
|
|
80
|
-
"@stylistic/comma-dangle": ["error", "never"],
|
|
81
|
-
"@stylistic/array-bracket-newline": ["error", {"multiline": true}],
|
|
82
|
-
"@stylistic/array-element-newline": ["error", {"multiline": true, "minItems": 3}],
|
|
83
|
-
"@stylistic/object-curly-newline": ["error", {"multiline": true, "consistent": true}],
|
|
84
|
-
"@stylistic/max-len": [
|
|
85
|
-
"error",
|
|
86
|
-
{
|
|
87
|
-
"code": 120,
|
|
88
|
-
"tabWidth": 4,
|
|
89
|
-
"ignoreComments": true,
|
|
90
|
-
"ignoreUrls": true,
|
|
91
|
-
"ignoreStrings": true,
|
|
92
|
-
"ignoreTemplateLiterals": true,
|
|
93
|
-
"ignoreRegExpLiterals": true,
|
|
94
|
-
"ignorePattern": "d=.*"
|
|
95
|
-
}
|
|
96
|
-
],
|
|
97
|
-
"@stylistic/padded-blocks": ["error", "never"],
|
|
98
|
-
"@stylistic/no-multiple-empty-lines": ["error", {"max": 1, "maxEOF": 0}],
|
|
99
|
-
"@stylistic/eol-last": ["error", "always"],
|
|
100
|
-
"@stylistic/lines-between-class-members": ["error", "always"],
|
|
101
|
-
"@stylistic/brace-style": [
|
|
102
|
-
"error",
|
|
103
|
-
"1tbs",
|
|
104
|
-
{"allowSingleLine": true}
|
|
105
|
-
],
|
|
106
|
-
"@stylistic/object-curly-spacing": ["error", "always"],
|
|
107
|
-
"@stylistic/arrow-spacing": ["error", {"before": true, "after": true}],
|
|
108
|
-
"@stylistic/implicit-arrow-linebreak": ["error", "beside"],
|
|
109
|
-
"@stylistic/arrow-parens": ["error", "as-needed"],
|
|
110
|
-
"@stylistic/no-trailing-spaces": ["error"],
|
|
111
|
-
"@stylistic/no-tabs": ["error"],
|
|
112
|
-
"@stylistic/no-whitespace-before-property": ["error"],
|
|
113
|
-
"@stylistic/template-curly-spacing": ["error", "never"],
|
|
114
|
-
"@stylistic/rest-spread-spacing": ["error", "never"],
|
|
115
|
-
"@stylistic/operator-linebreak": ["error", "before"],
|
|
116
|
-
"@stylistic/type-annotation-spacing": [
|
|
117
|
-
"error",
|
|
118
|
-
{
|
|
119
|
-
"before": false, "after": true, "overrides": {
|
|
120
|
-
"arrow": {
|
|
121
|
-
"before": true, "after": true
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
],
|
|
126
|
-
"@stylistic/type-generic-spacing": ["error"],
|
|
127
|
-
"@stylistic/type-named-tuple-spacing": ["error"],
|
|
128
|
-
|
|
129
|
-
// ----------------------------------------
|
|
130
|
-
// ---------------------- JSdoc
|
|
131
|
-
// ----------------------------------------
|
|
132
|
-
"jsdoc/check-access": "error",
|
|
133
|
-
"jsdoc/check-alignment": "error",
|
|
134
|
-
"jsdoc/check-param-names": "error",
|
|
135
|
-
"jsdoc/check-property-names": "error",
|
|
136
|
-
"jsdoc/check-tag-names": "error",
|
|
137
|
-
"jsdoc/check-types": "error",
|
|
138
|
-
"jsdoc/check-values": "error",
|
|
139
|
-
"jsdoc/empty-tags": "error",
|
|
140
|
-
"jsdoc/implements-on-classes": "error",
|
|
141
|
-
"jsdoc/multiline-blocks": "error",
|
|
142
|
-
"jsdoc/no-defaults": "error",
|
|
143
|
-
"jsdoc/no-multi-asterisks": "error",
|
|
144
|
-
"jsdoc/require-jsdoc": [
|
|
145
|
-
"error",
|
|
146
|
-
{
|
|
147
|
-
"require": {
|
|
148
|
-
"FunctionDeclaration": true,
|
|
149
|
-
"MethodDefinition": true,
|
|
150
|
-
"ClassDeclaration": true,
|
|
151
|
-
"ArrowFunctionExpression": true,
|
|
152
|
-
"FunctionExpression": true
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
],
|
|
156
|
-
"jsdoc/require-param": "error",
|
|
157
|
-
"jsdoc/require-param-description": "error",
|
|
158
|
-
"jsdoc/require-param-name": "error",
|
|
159
|
-
"jsdoc/require-property": "error",
|
|
160
|
-
"jsdoc/require-property-description": "error",
|
|
161
|
-
"jsdoc/require-property-name": "error",
|
|
162
|
-
"jsdoc/require-returns": "error",
|
|
163
|
-
"jsdoc/require-returns-check": "error",
|
|
164
|
-
"jsdoc/require-returns-description": "error",
|
|
165
|
-
"jsdoc/require-yields": "error",
|
|
166
|
-
"jsdoc/require-yields-check": "error",
|
|
167
|
-
"jsdoc/tag-lines": [
|
|
168
|
-
"error",
|
|
169
|
-
"never",
|
|
170
|
-
{
|
|
171
|
-
"applyToEndTag": false,
|
|
172
|
-
"count": 1,
|
|
173
|
-
"startLines": 1,
|
|
174
|
-
"endLines": 0
|
|
175
|
-
}
|
|
176
|
-
],
|
|
177
|
-
"jsdoc/valid-types": "error",
|
|
178
|
-
|
|
179
|
-
// ----------------------------------------
|
|
180
|
-
// ---------------------- General
|
|
181
|
-
// ----------------------------------------
|
|
182
|
-
|
|
183
|
-
"no-void": "off",
|
|
184
|
-
"no-undef": "off",
|
|
185
|
-
"indent": ["error", 4],
|
|
186
|
-
"no-console": [
|
|
187
|
-
"error",
|
|
188
|
-
{
|
|
189
|
-
allow: [
|
|
190
|
-
"warn",
|
|
191
|
-
"error",
|
|
192
|
-
"info",
|
|
193
|
-
"table"
|
|
194
|
-
]
|
|
195
|
-
}
|
|
196
|
-
],
|
|
197
|
-
"camelcase": [
|
|
198
|
-
"error",
|
|
199
|
-
{
|
|
200
|
-
"properties": "never", "ignoreDestructuring": true, "allow": ["^_[a-z]+_[a-z]+$"]
|
|
201
|
-
}
|
|
202
|
-
],
|
|
203
|
-
"dot-notation": "off",
|
|
204
|
-
"no-underscore-dangle": "off",
|
|
205
|
-
"func-style": ["error", "declaration"]
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
);
|
|
210
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
import stylistic from "@stylistic/eslint-plugin";
|
|
3
|
+
import simpleImportSort from "eslint-plugin-simple-import-sort";
|
|
4
|
+
import JSdoc from "eslint-plugin-jsdoc";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
import eslint from '@eslint/js';
|
|
8
|
+
import tseslint from 'typescript-eslint';
|
|
9
|
+
|
|
10
|
+
export default tseslint.config(
|
|
11
|
+
eslint.configs.recommended,
|
|
12
|
+
...tseslint.configs.recommended,
|
|
13
|
+
{
|
|
14
|
+
plugins: {
|
|
15
|
+
"@stylistic": stylistic,
|
|
16
|
+
"simple-import-sort": simpleImportSort,
|
|
17
|
+
"jsdoc": JSdoc
|
|
18
|
+
},
|
|
19
|
+
files: ["src/**/*.ts"],
|
|
20
|
+
rules: {
|
|
21
|
+
// ----------------------------------------
|
|
22
|
+
// ---------------------- Simple Import Sort
|
|
23
|
+
// ----------------------------------------
|
|
24
|
+
"simple-import-sort/exports": "error",
|
|
25
|
+
"simple-import-sort/imports": [
|
|
26
|
+
"error",
|
|
27
|
+
{
|
|
28
|
+
"groups": [
|
|
29
|
+
["^\u0000"],
|
|
30
|
+
["^@?\\w"],
|
|
31
|
+
["^/"],
|
|
32
|
+
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
|
|
33
|
+
[
|
|
34
|
+
"^\\./(?=.*/)(?!/?$)",
|
|
35
|
+
"^\\.(?!/?$)",
|
|
36
|
+
"^\\./?$"
|
|
37
|
+
],
|
|
38
|
+
["^.+\\.s?css$"]
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
// ----------------------------------------
|
|
43
|
+
// ---------------------- TypeScript
|
|
44
|
+
// ----------------------------------------
|
|
45
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
46
|
+
"@typescript-eslint/ban-ts-comment": "off",
|
|
47
|
+
"@typescript-eslint/no-dynamic-delete": "off",
|
|
48
|
+
"@typescript-eslint/no-namespace": "off",
|
|
49
|
+
"@typescript-eslint/ban-types": "error",
|
|
50
|
+
"@typescript-eslint/explicit-function-return-type": "error",
|
|
51
|
+
"@typescript-eslint/consistent-indexed-object-style": "error",
|
|
52
|
+
|
|
53
|
+
// ----------------------------------------
|
|
54
|
+
// ---------------------- Stylistic
|
|
55
|
+
// ----------------------------------------
|
|
56
|
+
"@stylistic/array-bracket-spacing": ["error", "always"],
|
|
57
|
+
"@stylistic/function-paren-newline": ["error", "multiline"],
|
|
58
|
+
"@stylistic/multiline-ternary": ["error", "always-multiline"],
|
|
59
|
+
"@stylistic/quotes": [
|
|
60
|
+
"error",
|
|
61
|
+
"double",
|
|
62
|
+
{
|
|
63
|
+
"avoidEscape": true, "allowTemplateLiterals": true
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
"@stylistic/semi": [
|
|
67
|
+
"error",
|
|
68
|
+
"always",
|
|
69
|
+
{
|
|
70
|
+
"omitLastInOneLineBlock": true, "omitLastInOneLineClassBody": true
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
"@stylistic/space-before-function-paren": ["error", "always"],
|
|
74
|
+
"@stylistic/space-in-parens": ["error", "never"],
|
|
75
|
+
"@stylistic/space-infix-ops": ["error", {"int32Hint": false}],
|
|
76
|
+
"@stylistic/space-before-blocks": ["error", "always"],
|
|
77
|
+
"@stylistic/space-unary-ops": ["error", {"words": true, "nonwords": false}],
|
|
78
|
+
"@stylistic/keyword-spacing": ["error", {"before": true, "after": true}],
|
|
79
|
+
"@stylistic/block-spacing": ["error", "always"],
|
|
80
|
+
"@stylistic/comma-dangle": ["error", "never"],
|
|
81
|
+
"@stylistic/array-bracket-newline": ["error", {"multiline": true}],
|
|
82
|
+
"@stylistic/array-element-newline": ["error", {"multiline": true, "minItems": 3}],
|
|
83
|
+
"@stylistic/object-curly-newline": ["error", {"multiline": true, "consistent": true}],
|
|
84
|
+
"@stylistic/max-len": [
|
|
85
|
+
"error",
|
|
86
|
+
{
|
|
87
|
+
"code": 120,
|
|
88
|
+
"tabWidth": 4,
|
|
89
|
+
"ignoreComments": true,
|
|
90
|
+
"ignoreUrls": true,
|
|
91
|
+
"ignoreStrings": true,
|
|
92
|
+
"ignoreTemplateLiterals": true,
|
|
93
|
+
"ignoreRegExpLiterals": true,
|
|
94
|
+
"ignorePattern": "d=.*"
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
"@stylistic/padded-blocks": ["error", "never"],
|
|
98
|
+
"@stylistic/no-multiple-empty-lines": ["error", {"max": 1, "maxEOF": 0}],
|
|
99
|
+
"@stylistic/eol-last": ["error", "always"],
|
|
100
|
+
"@stylistic/lines-between-class-members": ["error", "always"],
|
|
101
|
+
"@stylistic/brace-style": [
|
|
102
|
+
"error",
|
|
103
|
+
"1tbs",
|
|
104
|
+
{"allowSingleLine": true}
|
|
105
|
+
],
|
|
106
|
+
"@stylistic/object-curly-spacing": ["error", "always"],
|
|
107
|
+
"@stylistic/arrow-spacing": ["error", {"before": true, "after": true}],
|
|
108
|
+
"@stylistic/implicit-arrow-linebreak": ["error", "beside"],
|
|
109
|
+
"@stylistic/arrow-parens": ["error", "as-needed"],
|
|
110
|
+
"@stylistic/no-trailing-spaces": ["error"],
|
|
111
|
+
"@stylistic/no-tabs": ["error"],
|
|
112
|
+
"@stylistic/no-whitespace-before-property": ["error"],
|
|
113
|
+
"@stylistic/template-curly-spacing": ["error", "never"],
|
|
114
|
+
"@stylistic/rest-spread-spacing": ["error", "never"],
|
|
115
|
+
"@stylistic/operator-linebreak": ["error", "before"],
|
|
116
|
+
"@stylistic/type-annotation-spacing": [
|
|
117
|
+
"error",
|
|
118
|
+
{
|
|
119
|
+
"before": false, "after": true, "overrides": {
|
|
120
|
+
"arrow": {
|
|
121
|
+
"before": true, "after": true
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
"@stylistic/type-generic-spacing": ["error"],
|
|
127
|
+
"@stylistic/type-named-tuple-spacing": ["error"],
|
|
128
|
+
|
|
129
|
+
// ----------------------------------------
|
|
130
|
+
// ---------------------- JSdoc
|
|
131
|
+
// ----------------------------------------
|
|
132
|
+
"jsdoc/check-access": "error",
|
|
133
|
+
"jsdoc/check-alignment": "error",
|
|
134
|
+
"jsdoc/check-param-names": "error",
|
|
135
|
+
"jsdoc/check-property-names": "error",
|
|
136
|
+
"jsdoc/check-tag-names": "error",
|
|
137
|
+
"jsdoc/check-types": "error",
|
|
138
|
+
"jsdoc/check-values": "error",
|
|
139
|
+
"jsdoc/empty-tags": "error",
|
|
140
|
+
"jsdoc/implements-on-classes": "error",
|
|
141
|
+
"jsdoc/multiline-blocks": "error",
|
|
142
|
+
"jsdoc/no-defaults": "error",
|
|
143
|
+
"jsdoc/no-multi-asterisks": "error",
|
|
144
|
+
"jsdoc/require-jsdoc": [
|
|
145
|
+
"error",
|
|
146
|
+
{
|
|
147
|
+
"require": {
|
|
148
|
+
"FunctionDeclaration": true,
|
|
149
|
+
"MethodDefinition": true,
|
|
150
|
+
"ClassDeclaration": true,
|
|
151
|
+
"ArrowFunctionExpression": true,
|
|
152
|
+
"FunctionExpression": true
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
],
|
|
156
|
+
"jsdoc/require-param": "error",
|
|
157
|
+
"jsdoc/require-param-description": "error",
|
|
158
|
+
"jsdoc/require-param-name": "error",
|
|
159
|
+
"jsdoc/require-property": "error",
|
|
160
|
+
"jsdoc/require-property-description": "error",
|
|
161
|
+
"jsdoc/require-property-name": "error",
|
|
162
|
+
"jsdoc/require-returns": "error",
|
|
163
|
+
"jsdoc/require-returns-check": "error",
|
|
164
|
+
"jsdoc/require-returns-description": "error",
|
|
165
|
+
"jsdoc/require-yields": "error",
|
|
166
|
+
"jsdoc/require-yields-check": "error",
|
|
167
|
+
"jsdoc/tag-lines": [
|
|
168
|
+
"error",
|
|
169
|
+
"never",
|
|
170
|
+
{
|
|
171
|
+
"applyToEndTag": false,
|
|
172
|
+
"count": 1,
|
|
173
|
+
"startLines": 1,
|
|
174
|
+
"endLines": 0
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
"jsdoc/valid-types": "error",
|
|
178
|
+
|
|
179
|
+
// ----------------------------------------
|
|
180
|
+
// ---------------------- General
|
|
181
|
+
// ----------------------------------------
|
|
182
|
+
|
|
183
|
+
"no-void": "off",
|
|
184
|
+
"no-undef": "off",
|
|
185
|
+
"indent": ["error", 4],
|
|
186
|
+
"no-console": [
|
|
187
|
+
"error",
|
|
188
|
+
{
|
|
189
|
+
allow: [
|
|
190
|
+
"warn",
|
|
191
|
+
"error",
|
|
192
|
+
"info",
|
|
193
|
+
"table"
|
|
194
|
+
]
|
|
195
|
+
}
|
|
196
|
+
],
|
|
197
|
+
"camelcase": [
|
|
198
|
+
"error",
|
|
199
|
+
{
|
|
200
|
+
"properties": "never", "ignoreDestructuring": true, "allow": ["^_[a-z]+_[a-z]+$"]
|
|
201
|
+
}
|
|
202
|
+
],
|
|
203
|
+
"dot-notation": "off",
|
|
204
|
+
"no-underscore-dangle": "off",
|
|
205
|
+
"func-style": ["error", "declaration"]
|
|
206
|
+
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
);
|
|
210
|
+
|
package/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
|
|
3
|
-
export function getHello (): string {
|
|
4
|
-
return 'Hello, world! ???';
|
|
5
|
-
}
|
|
1
|
+
// src/index.ts
|
|
2
|
+
|
|
3
|
+
export function getHello (): string {
|
|
4
|
+
return 'Hello, world! ???';
|
|
5
|
+
}
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"homepage": "https://github.com/antharuu/klaim#readme",
|
|
22
22
|
"type": "module",
|
|
23
|
-
"version": "1.0.
|
|
23
|
+
"version": "1.0.3",
|
|
24
24
|
"main": "dist/klaim.cjs.js",
|
|
25
25
|
"module": "dist/klaim.es.js",
|
|
26
26
|
"types": "dist/index.d.ts",
|
|
@@ -28,8 +28,9 @@
|
|
|
28
28
|
"build": "vite build",
|
|
29
29
|
"dev": "vite build --watch",
|
|
30
30
|
"test": "vitest",
|
|
31
|
-
"lint": "eslint src
|
|
32
|
-
"
|
|
31
|
+
"lint": "eslint src",
|
|
32
|
+
"lint:fix": "eslint src --fix",
|
|
33
|
+
"release": "dotenv release-it --"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@eslint/js": "^9.6.0",
|
|
@@ -38,6 +39,7 @@
|
|
|
38
39
|
"@types/eslint__js": "^8.42.3",
|
|
39
40
|
"@types/node": "^20.14.9",
|
|
40
41
|
"@vitest/coverage-v8": "^1.6.0",
|
|
42
|
+
"dotenv-cli": "^7.4.2",
|
|
41
43
|
"eslint": "^9.6.0",
|
|
42
44
|
"eslint-plugin-jsdoc": "^48.5.0",
|
|
43
45
|
"eslint-plugin-simple-import-sort": "^12.1.0",
|
package/src/core/Api.ts
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import cleanUrl from "../tools/cleanUrl";
|
|
2
|
-
import toCamelCase from "../tools/toCamelCase";
|
|
3
|
-
|
|
4
|
-
import { Registry } from "./Registry";
|
|
5
|
-
import { Route } from "./Route";
|
|
6
|
-
|
|
7
|
-
interface IApi {
|
|
8
|
-
name: string;
|
|
9
|
-
url: string;
|
|
10
|
-
headers: IHeaders;
|
|
11
|
-
routes: Map<string, Route>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type IApiCallback = () => void;
|
|
15
|
-
export type IHeaders = Record<string, string>;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Represents an API
|
|
19
|
-
*/
|
|
20
|
-
export class Api implements IApi {
|
|
21
|
-
public name: string;
|
|
22
|
-
|
|
23
|
-
public url: string;
|
|
24
|
-
|
|
25
|
-
public headers: IHeaders;
|
|
26
|
-
|
|
27
|
-
public routes: Map<string, Route> = new Map<string, Route>();
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Constructor
|
|
31
|
-
*
|
|
32
|
-
* @param name - The name of the API
|
|
33
|
-
* @param url - The base URL of the API
|
|
34
|
-
* @param headers - The headers to be sent with each request
|
|
35
|
-
*/
|
|
36
|
-
private constructor (name: string, url: string, headers: IHeaders) {
|
|
37
|
-
this.name = name;
|
|
38
|
-
this.url = cleanUrl(url);
|
|
39
|
-
this.headers = headers || {};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Creates a new API
|
|
44
|
-
*
|
|
45
|
-
* @param name - The name of the API
|
|
46
|
-
* @param url - The base URL of the API
|
|
47
|
-
* @param callback - The callback to define the routes
|
|
48
|
-
* @param headers - The headers to be sent with each request
|
|
49
|
-
* @returns The new API
|
|
50
|
-
*/
|
|
51
|
-
public static create (name: string, url: string, callback: IApiCallback, headers: IHeaders = {}): Api {
|
|
52
|
-
const newName = toCamelCase(name);
|
|
53
|
-
if (newName !== name) {
|
|
54
|
-
console.warn(`API name "${name}" has been camelCased to "${newName}"`);
|
|
55
|
-
}
|
|
56
|
-
const api = new Api(newName, url, headers);
|
|
57
|
-
Registry.i.registerApi(api);
|
|
58
|
-
Registry.i.setCurrent(newName);
|
|
59
|
-
callback();
|
|
60
|
-
Registry.i.clearCurrent();
|
|
61
|
-
return api;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
1
|
+
import cleanUrl from "../tools/cleanUrl";
|
|
2
|
+
import toCamelCase from "../tools/toCamelCase";
|
|
3
|
+
|
|
4
|
+
import { Registry } from "./Registry";
|
|
5
|
+
import { Route } from "./Route";
|
|
6
|
+
|
|
7
|
+
interface IApi {
|
|
8
|
+
name: string;
|
|
9
|
+
url: string;
|
|
10
|
+
headers: IHeaders;
|
|
11
|
+
routes: Map<string, Route>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type IApiCallback = () => void;
|
|
15
|
+
export type IHeaders = Record<string, string>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Represents an API
|
|
19
|
+
*/
|
|
20
|
+
export class Api implements IApi {
|
|
21
|
+
public name: string;
|
|
22
|
+
|
|
23
|
+
public url: string;
|
|
24
|
+
|
|
25
|
+
public headers: IHeaders;
|
|
26
|
+
|
|
27
|
+
public routes: Map<string, Route> = new Map<string, Route>();
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Constructor
|
|
31
|
+
*
|
|
32
|
+
* @param name - The name of the API
|
|
33
|
+
* @param url - The base URL of the API
|
|
34
|
+
* @param headers - The headers to be sent with each request
|
|
35
|
+
*/
|
|
36
|
+
private constructor (name: string, url: string, headers: IHeaders) {
|
|
37
|
+
this.name = name;
|
|
38
|
+
this.url = cleanUrl(url);
|
|
39
|
+
this.headers = headers || {};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new API
|
|
44
|
+
*
|
|
45
|
+
* @param name - The name of the API
|
|
46
|
+
* @param url - The base URL of the API
|
|
47
|
+
* @param callback - The callback to define the routes
|
|
48
|
+
* @param headers - The headers to be sent with each request
|
|
49
|
+
* @returns The new API
|
|
50
|
+
*/
|
|
51
|
+
public static create (name: string, url: string, callback: IApiCallback, headers: IHeaders = {}): Api {
|
|
52
|
+
const newName = toCamelCase(name);
|
|
53
|
+
if (newName !== name) {
|
|
54
|
+
console.warn(`API name "${name}" has been camelCased to "${newName}"`);
|
|
55
|
+
}
|
|
56
|
+
const api = new Api(newName, url, headers);
|
|
57
|
+
Registry.i.registerApi(api);
|
|
58
|
+
Registry.i.setCurrent(newName);
|
|
59
|
+
callback();
|
|
60
|
+
Registry.i.clearCurrent();
|
|
61
|
+
return api;
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Api, type IApi } from "./core/Api";
|
|
2
|
-
export { Klaim } from "./core/Klaim";
|
|
3
|
-
export { Registry } from "./core/Registry";
|
|
4
|
-
export { type IRoute,Route } from "./core/Route";
|
|
1
|
+
export { Api, type IApi } from "./core/Api";
|
|
2
|
+
export { Klaim } from "./core/Klaim";
|
|
3
|
+
export { Registry } from "./core/Registry";
|
|
4
|
+
export { type IRoute,Route } from "./core/Route";
|
package/src/tools/cleanUrl.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Clean the URL by removing slashes at the beginning and end of the string.
|
|
3
|
-
*
|
|
4
|
-
* @param url - The URL to clean
|
|
5
|
-
* @returns The cleaned URL
|
|
6
|
-
*/
|
|
7
|
-
export default function (url: string): string {
|
|
8
|
-
return url
|
|
9
|
-
.trim()
|
|
10
|
-
// remove slashes at the beginning and end of the string
|
|
11
|
-
.replace(/^\/|\/$/g, "");
|
|
12
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Clean the URL by removing slashes at the beginning and end of the string.
|
|
3
|
+
*
|
|
4
|
+
* @param url - The URL to clean
|
|
5
|
+
* @returns The cleaned URL
|
|
6
|
+
*/
|
|
7
|
+
export default function (url: string): string {
|
|
8
|
+
return url
|
|
9
|
+
.trim()
|
|
10
|
+
// remove slashes at the beginning and end of the string
|
|
11
|
+
.replace(/^\/|\/$/g, "");
|
|
12
|
+
}
|
package/src/tools/slugify.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Slugify a text
|
|
3
|
-
*
|
|
4
|
-
* @param text - The text to slugify
|
|
5
|
-
* @param splitCharacter - The character to use to split the text
|
|
6
|
-
* @returns The slugified text
|
|
7
|
-
*/
|
|
8
|
-
export default function (text: string, splitCharacter: string = "_"): string {
|
|
9
|
-
return text
|
|
10
|
-
.toString()
|
|
11
|
-
.normalize("NFD") // split an accented letter in the base letter and the acent
|
|
12
|
-
.replace(/[\u0300-\u036f]/g, "") // remove all previously split accents
|
|
13
|
-
.toLowerCase()
|
|
14
|
-
.trim()
|
|
15
|
-
.replace(/[^a-z0-9 ]/g, "") // remove all chars not letters, numbers and spaces (to be replaced)
|
|
16
|
-
.replace(/\s+/g, splitCharacter); // separator
|
|
17
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Slugify a text
|
|
3
|
+
*
|
|
4
|
+
* @param text - The text to slugify
|
|
5
|
+
* @param splitCharacter - The character to use to split the text
|
|
6
|
+
* @returns The slugified text
|
|
7
|
+
*/
|
|
8
|
+
export default function (text: string, splitCharacter: string = "_"): string {
|
|
9
|
+
return text
|
|
10
|
+
.toString()
|
|
11
|
+
.normalize("NFD") // split an accented letter in the base letter and the acent
|
|
12
|
+
.replace(/[\u0300-\u036f]/g, "") // remove all previously split accents
|
|
13
|
+
.toLowerCase()
|
|
14
|
+
.trim()
|
|
15
|
+
.replace(/[^a-z0-9 ]/g, "") // remove all chars not letters, numbers and spaces (to be replaced)
|
|
16
|
+
.replace(/\s+/g, splitCharacter); // separator
|
|
17
|
+
}
|
package/src/tools/toCamelCase.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convert a string to camel case
|
|
3
|
-
*
|
|
4
|
-
* @param text - The text to convert
|
|
5
|
-
* @returns The text in camel case
|
|
6
|
-
*/
|
|
7
|
-
export default function (text: string): string {
|
|
8
|
-
return text
|
|
9
|
-
.replace(/([-_][a-z])/gi, match => match.toUpperCase().replace("-", "").replace("_", ""))
|
|
10
|
-
.replace(/(^\w)/, match => match.toLowerCase());
|
|
11
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Convert a string to camel case
|
|
3
|
+
*
|
|
4
|
+
* @param text - The text to convert
|
|
5
|
+
* @returns The text in camel case
|
|
6
|
+
*/
|
|
7
|
+
export default function (text: string): string {
|
|
8
|
+
return text
|
|
9
|
+
.replace(/([-_][a-z])/gi, match => match.toUpperCase().replace("-", "").replace("_", ""))
|
|
10
|
+
.replace(/(^\w)/, match => match.toLowerCase());
|
|
11
|
+
}
|
package/src/tools/token.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate a new token
|
|
3
|
-
*
|
|
4
|
-
* @param {number} length The length of the token
|
|
5
|
-
* @returns {string} The generated token
|
|
6
|
-
*/
|
|
7
|
-
export default function (length?: number): string {
|
|
8
|
-
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
9
|
-
let token = "";
|
|
10
|
-
for (let i = 0; i < (length || 32); i++) {
|
|
11
|
-
token += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
12
|
-
}
|
|
13
|
-
return token;
|
|
14
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Generate a new token
|
|
3
|
+
*
|
|
4
|
+
* @param {number} length The length of the token
|
|
5
|
+
* @returns {string} The generated token
|
|
6
|
+
*/
|
|
7
|
+
export default function (length?: number): string {
|
|
8
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
9
|
+
let token = "";
|
|
10
|
+
for (let i = 0; i < (length || 32); i++) {
|
|
11
|
+
token += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
12
|
+
}
|
|
13
|
+
return token;
|
|
14
|
+
}
|
package/tests/arguments.test.ts
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
import {describe, expect, it, vi} from 'vitest';
|
|
2
|
-
import {Route, RouteArgumentType} from '../src/core/Route';
|
|
3
|
-
|
|
4
|
-
// Mocks
|
|
5
|
-
vi.mock('../tools/token', () => ({
|
|
6
|
-
default: vi.fn(() => 'mocked-token'),
|
|
7
|
-
}));
|
|
8
|
-
|
|
9
|
-
vi.mock('../tools/slugify', () => ({
|
|
10
|
-
default: vi.fn((str: string) => str.replace(/\s+/g, '-').toLowerCase()),
|
|
11
|
-
}));
|
|
12
|
-
|
|
13
|
-
describe('Route.detectArgumentsOfUrl', () => {
|
|
14
|
-
it('should detect arguments of type ANY', () => {
|
|
15
|
-
const route = new Route('/user/[id]');
|
|
16
|
-
const args = route._arguments;
|
|
17
|
-
|
|
18
|
-
expect(args.size).toBe(1);
|
|
19
|
-
expect(Array.from(args)).toEqual([
|
|
20
|
-
{name: 'id', type: RouteArgumentType.ANY, default: null, required: true},
|
|
21
|
-
]);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('should detect multiple arguments', () => {
|
|
25
|
-
const route = new Route('/posts/[post]/comments/[comment]');
|
|
26
|
-
const args = route._arguments;
|
|
27
|
-
|
|
28
|
-
expect(args.size).toBe(2);
|
|
29
|
-
expect(Array.from(args)).toEqual([
|
|
30
|
-
{name: 'post', type: RouteArgumentType.ANY, default: null, required: true},
|
|
31
|
-
{name: 'comment', type: RouteArgumentType.ANY, default: null, required: true},
|
|
32
|
-
]);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should detect arguments with specific types', () => {
|
|
36
|
-
const route = new Route('/user/[id:number]');
|
|
37
|
-
const args = route._arguments;
|
|
38
|
-
|
|
39
|
-
expect(args.size).toBe(1);
|
|
40
|
-
expect(Array.from(args)).toEqual([
|
|
41
|
-
{name: 'id', type: RouteArgumentType.NUMBER, default: null, required: true},
|
|
42
|
-
]);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should detect arguments with default values', () => {
|
|
46
|
-
const route = new Route('/user/[id:number=1]');
|
|
47
|
-
const args = route._arguments;
|
|
48
|
-
|
|
49
|
-
expect(args.size).toBe(1);
|
|
50
|
-
expect(Array.from(args)).toEqual([
|
|
51
|
-
{name: 'id', type: RouteArgumentType.NUMBER, default: 1, required: true},
|
|
52
|
-
]);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should detect optional arguments', () => {
|
|
56
|
-
const route = new Route('/user/[name?]');
|
|
57
|
-
const args = route._arguments;
|
|
58
|
-
|
|
59
|
-
expect(args.size).toBe(1);
|
|
60
|
-
expect(Array.from(args)).toEqual([
|
|
61
|
-
{name: 'name', type: RouteArgumentType.ANY, default: null, required: false},
|
|
62
|
-
]);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('should detect multiple arguments with different types', () => {
|
|
66
|
-
const route = new Route('/profile/[user:string]/settings/[setting:boolean]');
|
|
67
|
-
const args = route._arguments;
|
|
68
|
-
|
|
69
|
-
expect(args.size).toBe(2);
|
|
70
|
-
expect(Array.from(args)).toEqual([
|
|
71
|
-
{name: 'user', type: RouteArgumentType.STRING, default: null, required: true},
|
|
72
|
-
{name: 'setting', type: RouteArgumentType.BOOLEAN, default: null, required: true},
|
|
73
|
-
]);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should handle invalid JSON in default value gracefully', () => {
|
|
77
|
-
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {
|
|
78
|
-
});
|
|
79
|
-
const route = new Route('/user/[id:number=invalid]');
|
|
80
|
-
const args = route._arguments;
|
|
81
|
-
|
|
82
|
-
expect(args.size).toBe(1);
|
|
83
|
-
expect(Array.from(args)).toEqual([
|
|
84
|
-
{name: 'id', type: RouteArgumentType.NUMBER, default: 'invalid', required: true},
|
|
85
|
-
]);
|
|
86
|
-
expect(consoleSpy).toHaveBeenCalled();
|
|
87
|
-
consoleSpy.mockRestore();
|
|
88
|
-
});
|
|
89
|
-
});
|
|
1
|
+
import {describe, expect, it, vi} from 'vitest';
|
|
2
|
+
import {Route, RouteArgumentType} from '../src/core/Route';
|
|
3
|
+
|
|
4
|
+
// Mocks
|
|
5
|
+
vi.mock('../tools/token', () => ({
|
|
6
|
+
default: vi.fn(() => 'mocked-token'),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
vi.mock('../tools/slugify', () => ({
|
|
10
|
+
default: vi.fn((str: string) => str.replace(/\s+/g, '-').toLowerCase()),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
describe('Route.detectArgumentsOfUrl', () => {
|
|
14
|
+
it('should detect arguments of type ANY', () => {
|
|
15
|
+
const route = new Route('/user/[id]');
|
|
16
|
+
const args = route._arguments;
|
|
17
|
+
|
|
18
|
+
expect(args.size).toBe(1);
|
|
19
|
+
expect(Array.from(args)).toEqual([
|
|
20
|
+
{name: 'id', type: RouteArgumentType.ANY, default: null, required: true},
|
|
21
|
+
]);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should detect multiple arguments', () => {
|
|
25
|
+
const route = new Route('/posts/[post]/comments/[comment]');
|
|
26
|
+
const args = route._arguments;
|
|
27
|
+
|
|
28
|
+
expect(args.size).toBe(2);
|
|
29
|
+
expect(Array.from(args)).toEqual([
|
|
30
|
+
{name: 'post', type: RouteArgumentType.ANY, default: null, required: true},
|
|
31
|
+
{name: 'comment', type: RouteArgumentType.ANY, default: null, required: true},
|
|
32
|
+
]);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should detect arguments with specific types', () => {
|
|
36
|
+
const route = new Route('/user/[id:number]');
|
|
37
|
+
const args = route._arguments;
|
|
38
|
+
|
|
39
|
+
expect(args.size).toBe(1);
|
|
40
|
+
expect(Array.from(args)).toEqual([
|
|
41
|
+
{name: 'id', type: RouteArgumentType.NUMBER, default: null, required: true},
|
|
42
|
+
]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should detect arguments with default values', () => {
|
|
46
|
+
const route = new Route('/user/[id:number=1]');
|
|
47
|
+
const args = route._arguments;
|
|
48
|
+
|
|
49
|
+
expect(args.size).toBe(1);
|
|
50
|
+
expect(Array.from(args)).toEqual([
|
|
51
|
+
{name: 'id', type: RouteArgumentType.NUMBER, default: 1, required: true},
|
|
52
|
+
]);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should detect optional arguments', () => {
|
|
56
|
+
const route = new Route('/user/[name?]');
|
|
57
|
+
const args = route._arguments;
|
|
58
|
+
|
|
59
|
+
expect(args.size).toBe(1);
|
|
60
|
+
expect(Array.from(args)).toEqual([
|
|
61
|
+
{name: 'name', type: RouteArgumentType.ANY, default: null, required: false},
|
|
62
|
+
]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should detect multiple arguments with different types', () => {
|
|
66
|
+
const route = new Route('/profile/[user:string]/settings/[setting:boolean]');
|
|
67
|
+
const args = route._arguments;
|
|
68
|
+
|
|
69
|
+
expect(args.size).toBe(2);
|
|
70
|
+
expect(Array.from(args)).toEqual([
|
|
71
|
+
{name: 'user', type: RouteArgumentType.STRING, default: null, required: true},
|
|
72
|
+
{name: 'setting', type: RouteArgumentType.BOOLEAN, default: null, required: true},
|
|
73
|
+
]);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should handle invalid JSON in default value gracefully', () => {
|
|
77
|
+
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {
|
|
78
|
+
});
|
|
79
|
+
const route = new Route('/user/[id:number=invalid]');
|
|
80
|
+
const args = route._arguments;
|
|
81
|
+
|
|
82
|
+
expect(args.size).toBe(1);
|
|
83
|
+
expect(Array.from(args)).toEqual([
|
|
84
|
+
{name: 'id', type: RouteArgumentType.NUMBER, default: 'invalid', required: true},
|
|
85
|
+
]);
|
|
86
|
+
expect(consoleSpy).toHaveBeenCalled();
|
|
87
|
+
consoleSpy.mockRestore();
|
|
88
|
+
});
|
|
89
|
+
});
|
package/vite.config.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { defineConfig } from 'vite';
|
|
2
|
-
import { configDefaults } from 'vitest/config';
|
|
3
|
-
|
|
4
|
-
export default defineConfig({
|
|
5
|
-
build: {
|
|
6
|
-
lib: {
|
|
7
|
-
entry: 'src/index.ts',
|
|
8
|
-
name: 'klaim',
|
|
9
|
-
fileName: format => `klaim.${format}.js`
|
|
10
|
-
},
|
|
11
|
-
rollupOptions: {
|
|
12
|
-
external: [],
|
|
13
|
-
output: {
|
|
14
|
-
globals: {}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
test: {
|
|
19
|
-
globals: true,
|
|
20
|
-
environment: 'jsdom',
|
|
21
|
-
coverage: {
|
|
22
|
-
provider: 'v8'
|
|
23
|
-
},
|
|
24
|
-
exclude: [...configDefaults.exclude, 'tests/e2e/**'],
|
|
25
|
-
},
|
|
26
|
-
});
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import { configDefaults } from 'vitest/config';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
build: {
|
|
6
|
+
lib: {
|
|
7
|
+
entry: 'src/index.ts',
|
|
8
|
+
name: 'klaim',
|
|
9
|
+
fileName: format => `klaim.${format}.js`
|
|
10
|
+
},
|
|
11
|
+
rollupOptions: {
|
|
12
|
+
external: [],
|
|
13
|
+
output: {
|
|
14
|
+
globals: {}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
test: {
|
|
19
|
+
globals: true,
|
|
20
|
+
environment: 'jsdom',
|
|
21
|
+
coverage: {
|
|
22
|
+
provider: 'v8'
|
|
23
|
+
},
|
|
24
|
+
exclude: [...configDefaults.exclude, 'tests/e2e/**'],
|
|
25
|
+
},
|
|
26
|
+
});
|