@ryupold/vode 0.9.3 → 0.9.5
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/npm-publish.yml +5 -5
- package/index.ts +1 -3
- package/package.json +6 -3
- package/tsconfig.json +3 -1
- package/index.js +0 -6
- package/src/api-call.ts +0 -116
- package/src/helpers.ts +0 -44
- package/src/style.ts +0 -17
|
@@ -13,12 +13,12 @@ jobs:
|
|
|
13
13
|
id-token: write
|
|
14
14
|
steps:
|
|
15
15
|
- uses: actions/checkout@v4
|
|
16
|
-
# Setup .npmrc file to publish to npm
|
|
17
16
|
- uses: actions/setup-node@v4
|
|
18
17
|
with:
|
|
19
|
-
node-version: '
|
|
18
|
+
node-version: '22.x'
|
|
20
19
|
registry-url: 'https://registry.npmjs.org'
|
|
21
|
-
-
|
|
22
|
-
- run:
|
|
20
|
+
- uses: oven-sh/setup-bun@v2
|
|
21
|
+
- run: bun run build
|
|
22
|
+
- run: bun publish --provenance --access public
|
|
23
23
|
env:
|
|
24
|
-
|
|
24
|
+
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ryupold/vode",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
4
4
|
"description": "Small web framework for minimal websites",
|
|
5
5
|
"author": "Michael Scherbakow (ryupold)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,13 +20,16 @@
|
|
|
20
20
|
"url": "https://github.com/ryupold/vode/issues"
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/ryupold/vode#readme",
|
|
23
|
-
"
|
|
23
|
+
"module": "index.ts",
|
|
24
24
|
"scripts": {
|
|
25
|
+
"build": "bun build index.ts --outfile index.js",
|
|
26
|
+
"pack": "rm *.tgz && bun run build && bun pm pack",
|
|
27
|
+
"publish": "bun publish --provenance --access public",
|
|
25
28
|
"clean": "tsc -b --clean",
|
|
26
|
-
"build": "tsc -b",
|
|
27
29
|
"watch": "tsc -b -w"
|
|
28
30
|
},
|
|
29
31
|
"devDependencies": {
|
|
32
|
+
"bun": "^1.2.18",
|
|
30
33
|
"typescript": "^5.8.3"
|
|
31
34
|
}
|
|
32
35
|
}
|
package/tsconfig.json
CHANGED
package/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export * from "./src/vode.js";
|
|
2
|
-
export * from "./src/vode-tags.js";
|
|
3
|
-
export * from "./src/api-call.js";
|
|
4
|
-
export * from "./src/html.js";
|
|
5
|
-
export * from "./src/helpers.js";
|
|
6
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLGVBQWUsQ0FBQztBQUM5QixjQUFjLG9CQUFvQixDQUFDO0FBQ25DLGNBQWMsbUJBQW1CLENBQUM7QUFDbEMsY0FBYyxlQUFlLENBQUM7QUFDOUIsY0FBYyxrQkFBa0IsQ0FBQyJ9
|
package/src/api-call.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { Dispatch, Effect } from "./vode.js";
|
|
2
|
-
|
|
3
|
-
export const aborted = new Error("aborted");
|
|
4
|
-
|
|
5
|
-
export const metricDefaults = () => ({
|
|
6
|
-
metrics: {
|
|
7
|
-
requestCount: 0,
|
|
8
|
-
download: 0,
|
|
9
|
-
upload: 0,
|
|
10
|
-
},
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Make HTTP Request
|
|
16
|
-
* @param {ApiCallOptions} options
|
|
17
|
-
* @param {Dispatch?} dispatch
|
|
18
|
-
* @returns {Promise<any>} promise wrapping the http request resolving in the response if status < 400, otherwise rejecting with the response
|
|
19
|
-
*/
|
|
20
|
-
export function httpRequest<S extends object | unknown>(options: {
|
|
21
|
-
url: string,
|
|
22
|
-
method: string,
|
|
23
|
-
headers?: Record<string, string>,
|
|
24
|
-
data?: any,
|
|
25
|
-
timeout?: number,
|
|
26
|
-
withCredentials?: boolean,
|
|
27
|
-
metrics?: {
|
|
28
|
-
requestCount: number,
|
|
29
|
-
download: number,
|
|
30
|
-
upload: number,
|
|
31
|
-
},
|
|
32
|
-
}, dispatch?: {
|
|
33
|
-
patch: Dispatch<S>,
|
|
34
|
-
action?: Effect<S>,
|
|
35
|
-
abortAction?: Effect<S>,
|
|
36
|
-
errAction?: Effect<S>,
|
|
37
|
-
progressAction?: Effect<S>,
|
|
38
|
-
uploadProgressAction?: Effect<S>
|
|
39
|
-
}): Promise<any> & { abort: () => void } {
|
|
40
|
-
const xhr = new XMLHttpRequest();
|
|
41
|
-
const promise = new Promise((resolve, reject) => {
|
|
42
|
-
if (!options.metrics) options.metrics = metricDefaults().metrics;
|
|
43
|
-
if (options.metrics) options.metrics.requestCount++;
|
|
44
|
-
|
|
45
|
-
xhr.withCredentials = options.withCredentials === undefined || options.withCredentials;
|
|
46
|
-
if (options.timeout) xhr.timeout = options.timeout;
|
|
47
|
-
|
|
48
|
-
xhr.addEventListener("timeout", (err) => {
|
|
49
|
-
reject(err || new Error("timeout"));
|
|
50
|
-
if (dispatch?.errAction) {
|
|
51
|
-
dispatch.patch([dispatch.errAction, err]);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
if (dispatch?.uploadProgressAction) {
|
|
56
|
-
xhr.upload.addEventListener("progress", (event) => {
|
|
57
|
-
if (event.lengthComputable) {
|
|
58
|
-
if (options.metrics && event.loaded) options.metrics.upload += event.loaded;
|
|
59
|
-
dispatch.patch([dispatch.uploadProgressAction,
|
|
60
|
-
{ loaded: event.loaded, total: event.total }]);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (dispatch?.progressAction) {
|
|
66
|
-
xhr.addEventListener("progress", (event) => {
|
|
67
|
-
console.log("progress", event);
|
|
68
|
-
if (event.lengthComputable) {
|
|
69
|
-
if (options.metrics && event.loaded) options.metrics.download += event.loaded;
|
|
70
|
-
dispatch.patch([dispatch.progressAction, event]);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
xhr.addEventListener("loadend", (e: ProgressEvent<XMLHttpRequestEventTarget>) => {
|
|
76
|
-
if (xhr.readyState === 4) {
|
|
77
|
-
if (options.metrics && (e.loaded)) {
|
|
78
|
-
options.metrics.download += e.loaded;
|
|
79
|
-
}
|
|
80
|
-
if (xhr.status < 400) {
|
|
81
|
-
resolve(xhr.response);
|
|
82
|
-
dispatch?.action && dispatch.patch(<Effect<S>>[dispatch.action, xhr.response]);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
reject({ status: xhr.status, statusText: xhr.statusText, response: xhr.response });
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
xhr.addEventListener("abort", () => {
|
|
93
|
-
reject(aborted);
|
|
94
|
-
if (dispatch?.abortAction) {
|
|
95
|
-
dispatch.patch([dispatch.abortAction, aborted]);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
xhr.addEventListener("error", (err) => {
|
|
100
|
-
reject(err);
|
|
101
|
-
if (dispatch?.errAction) {
|
|
102
|
-
dispatch.patch([dispatch.errAction, err]);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
xhr.open(options.method, options.url, true);
|
|
107
|
-
if (options.headers) {
|
|
108
|
-
for (const key in options.headers) {
|
|
109
|
-
xhr.setRequestHeader(key, options.headers[key]);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
xhr.send(options.data);
|
|
113
|
-
});
|
|
114
|
-
(<any>promise).abort = () => xhr.abort();
|
|
115
|
-
return <any>promise;
|
|
116
|
-
}
|
package/src/helpers.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { DeepPartial } from "./vode.js";
|
|
2
|
-
|
|
3
|
-
type KeyPath<ObjectType extends object> =
|
|
4
|
-
{ [Key in keyof ObjectType & (string | number)]: ObjectType[Key] extends object
|
|
5
|
-
? `${Key}` | `${Key}.${KeyPath<ObjectType[Key]>}`
|
|
6
|
-
: `${Key}`
|
|
7
|
-
}[keyof ObjectType & (string | number)];
|
|
8
|
-
|
|
9
|
-
/** put a value deep inside an object addressed by a key path (creating necessary structure on the way). if target is null, a new object is created */
|
|
10
|
-
export function put<O extends object | unknown>(keyPath: O extends object ? KeyPath<O> : string, value: any = undefined, target: DeepPartial<O> | null = null) {
|
|
11
|
-
if (!target) target = {} as O as any;
|
|
12
|
-
|
|
13
|
-
const keys = keyPath.split('.');
|
|
14
|
-
if (keys.length > 1) {
|
|
15
|
-
let i = 0;
|
|
16
|
-
let raw = (<any>target)[keys[i]];
|
|
17
|
-
if (raw === undefined) {
|
|
18
|
-
(<any>target)[keys[i]] = raw = {};
|
|
19
|
-
}
|
|
20
|
-
for (i = 1; i < keys.length - 1; i++) {
|
|
21
|
-
const p = raw;
|
|
22
|
-
raw = raw[keys[i]];
|
|
23
|
-
if (raw === undefined) {
|
|
24
|
-
raw = {};
|
|
25
|
-
p[keys[i]] = raw;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
if (keys[i] === undefined) console.log(keyPath);
|
|
29
|
-
raw[keys[i]] = value;
|
|
30
|
-
} else {
|
|
31
|
-
(<any>target)[keys[0]] = value;
|
|
32
|
-
}
|
|
33
|
-
return target
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** get a value deep inside an object by its key path */
|
|
37
|
-
export function get<O extends object | unknown>(keyPath: O extends object ? KeyPath<O> : string, source: DeepPartial<O>) {
|
|
38
|
-
const keys = keyPath.split('.');
|
|
39
|
-
let raw = source ? (<any>source)[keys[0]] : undefined;
|
|
40
|
-
for (let i = 1; i < keys.length && !!raw; i++) {
|
|
41
|
-
raw = raw[keys[i]];
|
|
42
|
-
}
|
|
43
|
-
return raw;
|
|
44
|
-
}
|
package/src/style.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { StyleProp } from "./vode.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function generateCSS(style: StyleProp) {
|
|
5
|
-
let css = '';
|
|
6
|
-
for (const key in style) {
|
|
7
|
-
const value = style[key];
|
|
8
|
-
//transform camelCase to kebab-case
|
|
9
|
-
const kebab = key.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
|
|
10
|
-
css += `${kebab}:${value};`;
|
|
11
|
-
}
|
|
12
|
-
return css;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function keyToKebab(key: string) : string {
|
|
16
|
-
return key.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
|
|
17
|
-
}
|