saloe 0.0.1

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 (45) hide show
  1. package/README.md +19 -0
  2. package/demos/cloudflare-worker-actions/.wrangler/state/v3/cache/miniflare-CacheObject/9f458c07675338a7426a7b81ac4fb1baf92d034efbcaaf4336379640ed744ded.sqlite +0 -0
  3. package/demos/cloudflare-worker-actions/package.json +29 -0
  4. package/demos/cloudflare-worker-actions/public/input.js +5 -0
  5. package/demos/cloudflare-worker-actions/public/load.js +5 -0
  6. package/demos/cloudflare-worker-actions/public/submit.js +6 -0
  7. package/demos/cloudflare-worker-actions/server.js +93 -0
  8. package/demos/cloudflare-worker-actions/vite.config.js +25 -0
  9. package/demos/cloudflare-worker-actions/wrangler.toml +35 -0
  10. package/demos/cloudflare-worker-server/package.json +29 -0
  11. package/demos/cloudflare-worker-server/server.js +75 -0
  12. package/demos/cloudflare-worker-server/vite.config.js +25 -0
  13. package/demos/cloudflare-worker-server/wrangler.toml +32 -0
  14. package/dist/actions.cjs.js +280 -0
  15. package/dist/actions.es.js +280 -0
  16. package/dist/cloudflare-kv.cjs.js +29 -0
  17. package/dist/cloudflare-kv.es.js +29 -0
  18. package/dist/cloudflare-worker.cjs.js +19 -0
  19. package/dist/cloudflare-worker.es.js +19 -0
  20. package/dist/cookie.cjs.js +18 -0
  21. package/dist/cookie.es.js +18 -0
  22. package/dist/html.cjs.js +78 -0
  23. package/dist/html.es.js +78 -0
  24. package/dist/router.cjs.js +51 -0
  25. package/dist/router.es.js +51 -0
  26. package/dist/urlpattern.cjs.js +23 -0
  27. package/dist/urlpattern.es.js +6 -0
  28. package/dist/util.cjs.js +36 -0
  29. package/dist/util.es.js +36 -0
  30. package/dist/vite.cjs.js +102 -0
  31. package/dist/vite.es.js +101 -0
  32. package/dist/worker.cjs.js +43 -0
  33. package/dist/worker.es.js +43 -0
  34. package/package.json +63 -0
  35. package/src/actions.js +284 -0
  36. package/src/cloudflare-kv.js +36 -0
  37. package/src/cloudflare-worker.js +23 -0
  38. package/src/cookie.js +22 -0
  39. package/src/html.js +99 -0
  40. package/src/router.js +61 -0
  41. package/src/urlpattern.js +11 -0
  42. package/src/util.js +44 -0
  43. package/src/vite.js +127 -0
  44. package/src/worker.js +46 -0
  45. package/vite.config.js +36 -0
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const URLPatternPolyfill = require("urlpattern-polyfill");
4
+ function _interopNamespaceDefault(e) {
5
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
6
+ if (e) {
7
+ for (const k in e) {
8
+ if (k !== "default") {
9
+ const d = Object.getOwnPropertyDescriptor(e, k);
10
+ Object.defineProperty(n, k, d.get ? d : {
11
+ enumerable: true,
12
+ get: () => e[k]
13
+ });
14
+ }
15
+ }
16
+ }
17
+ n.default = e;
18
+ return Object.freeze(n);
19
+ }
20
+ const URLPatternPolyfill__namespace = /* @__PURE__ */ _interopNamespaceDefault(URLPatternPolyfill);
21
+ if (self == null ? void 0 : self.URLPattern) self.URLPattern = URLPatternPolyfill__namespace.URLPattern;
22
+ const getURLPatern = ({ pathname }) => new self.URLPattern({ pathname });
23
+ exports.getURLPatern = getURLPatern;
@@ -0,0 +1,6 @@
1
+ import * as URLPatternPolyfill from "urlpattern-polyfill";
2
+ if (self == null ? void 0 : self.URLPattern) self.URLPattern = URLPatternPolyfill.URLPattern;
3
+ const getURLPatern = ({ pathname }) => new self.URLPattern({ pathname });
4
+ export {
5
+ getURLPatern
6
+ };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const Scope = {
4
+ Cloudflare: "cloudflare-worker",
5
+ ServiceWorker: "service-worker",
6
+ Window: "window"
7
+ };
8
+ const Environment = {
9
+ Production: "prod",
10
+ Development: "dev",
11
+ Qa: "qa"
12
+ };
13
+ const isCloudflareWorker = ({ env }) => env == null ? void 0 : env.IS_CLOUDFLARE_WORKER;
14
+ const isServiceWorker = ({ env }) => env == null ? void 0 : env.IS_SERVICE_WORKER;
15
+ const isWindow = () => typeof window === "object";
16
+ const getScope = ({ env }) => {
17
+ if (isCloudflareWorker({ env })) return Scope.Cloudflare;
18
+ if (isServiceWorker({ env })) return Scope.ServiceWorker;
19
+ if (isWindow()) return Scope.Window;
20
+ };
21
+ const getEnv = ({ env } = {}) => {
22
+ var _a;
23
+ if (isCloudflareWorker({ env }) || isServiceWorker({ env })) return env.ENV;
24
+ if (isWindow()) return (_a = document == null ? void 0 : document.body) == null ? void 0 : _a.getAttribute("data-env");
25
+ };
26
+ const isProdEnv = ({ env }) => getEnv({ env }) === Environment.Production;
27
+ const isDevEnv = ({ env }) => getEnv({ env }) === Environment.Development;
28
+ const isQaEnv = ({ env }) => getEnv({ env }) === Environment.Qa;
29
+ exports.getEnv = getEnv;
30
+ exports.getScope = getScope;
31
+ exports.isCloudflareWorker = isCloudflareWorker;
32
+ exports.isDevEnv = isDevEnv;
33
+ exports.isProdEnv = isProdEnv;
34
+ exports.isQaEnv = isQaEnv;
35
+ exports.isServiceWorker = isServiceWorker;
36
+ exports.isWindow = isWindow;
@@ -0,0 +1,36 @@
1
+ const Scope = {
2
+ Cloudflare: "cloudflare-worker",
3
+ ServiceWorker: "service-worker",
4
+ Window: "window"
5
+ };
6
+ const Environment = {
7
+ Production: "prod",
8
+ Development: "dev",
9
+ Qa: "qa"
10
+ };
11
+ const isCloudflareWorker = ({ env }) => env == null ? void 0 : env.IS_CLOUDFLARE_WORKER;
12
+ const isServiceWorker = ({ env }) => env == null ? void 0 : env.IS_SERVICE_WORKER;
13
+ const isWindow = () => typeof window === "object";
14
+ const getScope = ({ env }) => {
15
+ if (isCloudflareWorker({ env })) return Scope.Cloudflare;
16
+ if (isServiceWorker({ env })) return Scope.ServiceWorker;
17
+ if (isWindow()) return Scope.Window;
18
+ };
19
+ const getEnv = ({ env } = {}) => {
20
+ var _a;
21
+ if (isCloudflareWorker({ env }) || isServiceWorker({ env })) return env.ENV;
22
+ if (isWindow()) return (_a = document == null ? void 0 : document.body) == null ? void 0 : _a.getAttribute("data-env");
23
+ };
24
+ const isProdEnv = ({ env }) => getEnv({ env }) === Environment.Production;
25
+ const isDevEnv = ({ env }) => getEnv({ env }) === Environment.Development;
26
+ const isQaEnv = ({ env }) => getEnv({ env }) === Environment.Qa;
27
+ export {
28
+ getEnv,
29
+ getScope,
30
+ isCloudflareWorker,
31
+ isDevEnv,
32
+ isProdEnv,
33
+ isQaEnv,
34
+ isServiceWorker,
35
+ isWindow
36
+ };
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
6
+ const listFiles = async ({ path: path$1 }) => {
7
+ let allFiles = [];
8
+ try {
9
+ const files = await fs.promises.readdir(path$1);
10
+ for (const file of files) {
11
+ const filePath = path.join(path$1, file);
12
+ const fileStats = await fs.promises.stat(filePath);
13
+ if (fileStats.isDirectory()) {
14
+ const subDirFiles = await listFiles({ path: filePath });
15
+ allFiles = allFiles.concat(subDirFiles);
16
+ } else {
17
+ allFiles.push(filePath);
18
+ }
19
+ }
20
+ } catch (err) {
21
+ console.error("Error reading directory:", err);
22
+ }
23
+ return allFiles;
24
+ };
25
+ const writeFile = async ({ code, filePath }) => {
26
+ try {
27
+ await fs.promises.writeFile(filePath, code);
28
+ console.info(`File '${filePath}' has been created`);
29
+ } catch (err) {
30
+ console.error("Error writing file:", err);
31
+ }
32
+ };
33
+ const getComponentFilePaths = ({ source }) => listFiles({ path: `src/${source}/` });
34
+ const getImportCode = async ({ sources }) => {
35
+ var _a;
36
+ let acumIndex = 0;
37
+ return Promise.all(
38
+ (_a = sources ?? []) == null ? void 0 : _a.map(async (source, sourceIndex) => {
39
+ var _a2;
40
+ const filePaths = await getComponentFilePaths({ source });
41
+ const code = (_a2 = filePaths == null ? void 0 : filePaths.map((path2, index) => {
42
+ var _a3;
43
+ if (!(path2 == null ? void 0 : path2.includes("/actions/"))) return "";
44
+ if (!(path2 == null ? void 0 : path2.endsWith(".js"))) return "";
45
+ acumIndex++;
46
+ const importPath = (_a3 = path2 == null ? void 0 : path2.replace(`src/${source}`, `@/${source}`)) == null ? void 0 : _a3.replace(".js", "");
47
+ return `import * as A${acumIndex} from '${importPath}'
48
+ console.log(A${acumIndex})
49
+ `;
50
+ })) == null ? void 0 : _a2.join("");
51
+ return { filePaths, code };
52
+ })
53
+ );
54
+ };
55
+ const getURLPath = ({ path: path2 }) => new URL(`${path2}`, typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.src || new URL("vite.cjs.js", document.baseURI).href).pathname;
56
+ const getInputPaths = async ({ sources }) => {
57
+ var _a;
58
+ try {
59
+ const componentsInfos = await getImportCode({ sources });
60
+ const actionImportCode = `${(_a = componentsInfos == null ? void 0 : componentsInfos.map((componentsInfo) => componentsInfo == null ? void 0 : componentsInfo.code)) == null ? void 0 : _a.join("\n")}`;
61
+ const actionsFilePath = "src/_actions_autogenerated.js";
62
+ await writeFile({ code: actionImportCode, filePath: actionsFilePath });
63
+ const paths = {
64
+ ...componentsInfos == null ? void 0 : componentsInfos.reduce((acc1, componentsInfo) => {
65
+ var _a2;
66
+ acc1 = {
67
+ ...acc1,
68
+ ...(_a2 = componentsInfo == null ? void 0 : componentsInfo.filePaths) == null ? void 0 : _a2.reduce((acc, componentFilePath) => {
69
+ var _a3;
70
+ if ((componentFilePath == null ? void 0 : componentFilePath.endsWith(".js")) && !(componentFilePath == null ? void 0 : componentFilePath.includes("/actions/"))) return acc;
71
+ const fileName = (_a3 = componentFilePath == null ? void 0 : componentFilePath.split("/")) == null ? void 0 : _a3.pop();
72
+ const componentName = fileName == null ? void 0 : fileName.replace(/\.[^.]+$/, "");
73
+ acc[componentName] = getURLPath({ path: componentFilePath });
74
+ return acc;
75
+ }, {})
76
+ };
77
+ return acc1;
78
+ }, {}),
79
+ actionsFilePath: getURLPath({ path: actionsFilePath })
80
+ // 'sw.worker': getURLPath({ path: '/src/sw.worker.js' }),
81
+ };
82
+ return paths;
83
+ } catch (err) {
84
+ console.error(err);
85
+ return {};
86
+ }
87
+ };
88
+ const closeBundle = async () => {
89
+ const distFilePaths = await listFiles({ path: "dist/" });
90
+ const cleanedDistFilePaths = distFilePaths == null ? void 0 : distFilePaths.filter((path2) => !(path2 == null ? void 0 : path2.endsWith(".DS_Store")));
91
+ await writeFile({ code: JSON.stringify(cleanedDistFilePaths), filePath: "dist/dist.json" });
92
+ };
93
+ const getPlugin = () => {
94
+ return [
95
+ {
96
+ name: "postbuild-command",
97
+ closeBundle
98
+ }
99
+ ];
100
+ };
101
+ exports.getInputPaths = getInputPaths;
102
+ exports.getPlugin = getPlugin;
@@ -0,0 +1,101 @@
1
+ import { promises } from "fs";
2
+ import { join } from "path";
3
+ const listFiles = async ({ path }) => {
4
+ let allFiles = [];
5
+ try {
6
+ const files = await promises.readdir(path);
7
+ for (const file of files) {
8
+ const filePath = join(path, file);
9
+ const fileStats = await promises.stat(filePath);
10
+ if (fileStats.isDirectory()) {
11
+ const subDirFiles = await listFiles({ path: filePath });
12
+ allFiles = allFiles.concat(subDirFiles);
13
+ } else {
14
+ allFiles.push(filePath);
15
+ }
16
+ }
17
+ } catch (err) {
18
+ console.error("Error reading directory:", err);
19
+ }
20
+ return allFiles;
21
+ };
22
+ const writeFile = async ({ code, filePath }) => {
23
+ try {
24
+ await promises.writeFile(filePath, code);
25
+ console.info(`File '${filePath}' has been created`);
26
+ } catch (err) {
27
+ console.error("Error writing file:", err);
28
+ }
29
+ };
30
+ const getComponentFilePaths = ({ source }) => listFiles({ path: `src/${source}/` });
31
+ const getImportCode = async ({ sources }) => {
32
+ var _a;
33
+ let acumIndex = 0;
34
+ return Promise.all(
35
+ (_a = sources ?? []) == null ? void 0 : _a.map(async (source, sourceIndex) => {
36
+ var _a2;
37
+ const filePaths = await getComponentFilePaths({ source });
38
+ const code = (_a2 = filePaths == null ? void 0 : filePaths.map((path, index) => {
39
+ var _a3;
40
+ if (!(path == null ? void 0 : path.includes("/actions/"))) return "";
41
+ if (!(path == null ? void 0 : path.endsWith(".js"))) return "";
42
+ acumIndex++;
43
+ const importPath = (_a3 = path == null ? void 0 : path.replace(`src/${source}`, `@/${source}`)) == null ? void 0 : _a3.replace(".js", "");
44
+ return `import * as A${acumIndex} from '${importPath}'
45
+ console.log(A${acumIndex})
46
+ `;
47
+ })) == null ? void 0 : _a2.join("");
48
+ return { filePaths, code };
49
+ })
50
+ );
51
+ };
52
+ const getURLPath = ({ path }) => new URL(`${path}`, import.meta.url).pathname;
53
+ const getInputPaths = async ({ sources }) => {
54
+ var _a;
55
+ try {
56
+ const componentsInfos = await getImportCode({ sources });
57
+ const actionImportCode = `${(_a = componentsInfos == null ? void 0 : componentsInfos.map((componentsInfo) => componentsInfo == null ? void 0 : componentsInfo.code)) == null ? void 0 : _a.join("\n")}`;
58
+ const actionsFilePath = "src/_actions_autogenerated.js";
59
+ await writeFile({ code: actionImportCode, filePath: actionsFilePath });
60
+ const paths = {
61
+ ...componentsInfos == null ? void 0 : componentsInfos.reduce((acc1, componentsInfo) => {
62
+ var _a2;
63
+ acc1 = {
64
+ ...acc1,
65
+ ...(_a2 = componentsInfo == null ? void 0 : componentsInfo.filePaths) == null ? void 0 : _a2.reduce((acc, componentFilePath) => {
66
+ var _a3;
67
+ if ((componentFilePath == null ? void 0 : componentFilePath.endsWith(".js")) && !(componentFilePath == null ? void 0 : componentFilePath.includes("/actions/"))) return acc;
68
+ const fileName = (_a3 = componentFilePath == null ? void 0 : componentFilePath.split("/")) == null ? void 0 : _a3.pop();
69
+ const componentName = fileName == null ? void 0 : fileName.replace(/\.[^.]+$/, "");
70
+ acc[componentName] = getURLPath({ path: componentFilePath });
71
+ return acc;
72
+ }, {})
73
+ };
74
+ return acc1;
75
+ }, {}),
76
+ actionsFilePath: getURLPath({ path: actionsFilePath })
77
+ // 'sw.worker': getURLPath({ path: '/src/sw.worker.js' }),
78
+ };
79
+ return paths;
80
+ } catch (err) {
81
+ console.error(err);
82
+ return {};
83
+ }
84
+ };
85
+ const closeBundle = async () => {
86
+ const distFilePaths = await listFiles({ path: "dist/" });
87
+ const cleanedDistFilePaths = distFilePaths == null ? void 0 : distFilePaths.filter((path) => !(path == null ? void 0 : path.endsWith(".DS_Store")));
88
+ await writeFile({ code: JSON.stringify(cleanedDistFilePaths), filePath: "dist/dist.json" });
89
+ };
90
+ const getPlugin = () => {
91
+ return [
92
+ {
93
+ name: "postbuild-command",
94
+ closeBundle
95
+ }
96
+ ];
97
+ };
98
+ export {
99
+ getInputPaths,
100
+ getPlugin
101
+ };
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const executeOnScheduler = async ({ callback, signal, priority }) => {
4
+ var _a;
5
+ try {
6
+ if (!((_a = self == null ? void 0 : self.scheduler) == null ? void 0 : _a.postTask)) return { data: await callback() };
7
+ const data = await scheduler.postTask(callback, { priority, signal });
8
+ return { data };
9
+ } catch (err) {
10
+ return { err };
11
+ }
12
+ };
13
+ const stream = ({ callbacks, headers, status }) => {
14
+ const { readable, writable } = new TransformStream();
15
+ const done = (async () => {
16
+ var _a;
17
+ for (const callback of callbacks) {
18
+ const abortController = new AbortController();
19
+ const executeOnSchedulerResult = await executeOnScheduler({ callback, signal: abortController.signal, priority: "background" });
20
+ const html = (executeOnSchedulerResult == null ? void 0 : executeOnSchedulerResult.err) ?? (executeOnSchedulerResult == null ? void 0 : executeOnSchedulerResult.data);
21
+ const response = new Response(html, { headers });
22
+ await ((_a = response.body) == null ? void 0 : _a.pipeTo(writable, { preventClose: true }));
23
+ abortController.abort();
24
+ }
25
+ writable.getWriter().close();
26
+ })();
27
+ return {
28
+ done,
29
+ response: new Response(readable, { headers, status: status ?? 200 })
30
+ };
31
+ };
32
+ const fetch = async ({ url, request, ...config }) => {
33
+ var _a;
34
+ try {
35
+ const response = await ((_a = self == null ? void 0 : self.fetch(url || request, config)) == null ? void 0 : _a.catch((err) => ({ err })));
36
+ if (response == null ? void 0 : response.err) return response;
37
+ return { response };
38
+ } catch (err) {
39
+ return { err };
40
+ }
41
+ };
42
+ exports.fetch = fetch;
43
+ exports.stream = stream;
@@ -0,0 +1,43 @@
1
+ const executeOnScheduler = async ({ callback, signal, priority }) => {
2
+ var _a;
3
+ try {
4
+ if (!((_a = self == null ? void 0 : self.scheduler) == null ? void 0 : _a.postTask)) return { data: await callback() };
5
+ const data = await scheduler.postTask(callback, { priority, signal });
6
+ return { data };
7
+ } catch (err) {
8
+ return { err };
9
+ }
10
+ };
11
+ const stream = ({ callbacks, headers, status }) => {
12
+ const { readable, writable } = new TransformStream();
13
+ const done = (async () => {
14
+ var _a;
15
+ for (const callback of callbacks) {
16
+ const abortController = new AbortController();
17
+ const executeOnSchedulerResult = await executeOnScheduler({ callback, signal: abortController.signal, priority: "background" });
18
+ const html = (executeOnSchedulerResult == null ? void 0 : executeOnSchedulerResult.err) ?? (executeOnSchedulerResult == null ? void 0 : executeOnSchedulerResult.data);
19
+ const response = new Response(html, { headers });
20
+ await ((_a = response.body) == null ? void 0 : _a.pipeTo(writable, { preventClose: true }));
21
+ abortController.abort();
22
+ }
23
+ writable.getWriter().close();
24
+ })();
25
+ return {
26
+ done,
27
+ response: new Response(readable, { headers, status: status ?? 200 })
28
+ };
29
+ };
30
+ const fetch = async ({ url, request, ...config }) => {
31
+ var _a;
32
+ try {
33
+ const response = await ((_a = self == null ? void 0 : self.fetch(url || request, config)) == null ? void 0 : _a.catch((err) => ({ err })));
34
+ if (response == null ? void 0 : response.err) return response;
35
+ return { response };
36
+ } catch (err) {
37
+ return { err };
38
+ }
39
+ };
40
+ export {
41
+ fetch,
42
+ stream
43
+ };
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "saloe",
3
+ "version": "0.0.1",
4
+ "description": "Tools for making web development easy and efficient",
5
+ "scripts": {
6
+ "build": "vite build",
7
+ "publish": "npm run build && npm publish --access public"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/jaimytacovega/salo.git"
12
+ },
13
+ "author": "Jaimy Taco",
14
+ "license": "ISC",
15
+ "exports": {
16
+ "./actions": {
17
+ "import": "./dist/actions.es.js",
18
+ "require": "./dist/actions.cjs.js"
19
+ },
20
+ "./cloudflare-kv": {
21
+ "import": "./dist/cloudflare-kv.es.js",
22
+ "require": "./dist/cloudflare-kv.cjs.js"
23
+ },
24
+ "./cloudflare-worker": {
25
+ "import": "./dist/cloudflare-worker.es.js",
26
+ "require": "./dist/cloudflare-worker.cjs.js"
27
+ },
28
+ "./cookie": {
29
+ "import": "./dist/cookie.es.js",
30
+ "require": "./dist/cookie.cjs.js"
31
+ },
32
+ "./html": {
33
+ "import": "./dist/html.es.js",
34
+ "require": "./dist/html.cjs.js"
35
+ },
36
+ "./router": {
37
+ "import": "./dist/router.es.js",
38
+ "require": "./dist/router.cjs.js"
39
+ },
40
+ "./urlpattern": {
41
+ "import": "./dist/urlpattern.es.js",
42
+ "require": "./dist/urlpattern.cjs.js"
43
+ },
44
+ "./util": {
45
+ "import": "./dist/util.es.js",
46
+ "require": "./dist/util.cjs.js"
47
+ },
48
+ "./vite": {
49
+ "import": "./dist/vite.es.js",
50
+ "require": "./dist/vite.cjs.js"
51
+ },
52
+ "./worker": {
53
+ "import": "./dist/worker.es.js",
54
+ "require": "./dist/worker.cjs.js"
55
+ }
56
+ },
57
+ "dependencies": {
58
+ "@cloudflare/kv-asset-handler": "^0.3.4",
59
+ "fs": "^0.0.1-security",
60
+ "urlpattern-polyfill": "^10.0.0",
61
+ "vite": "^5.4.2"
62
+ }
63
+ }