@tolki/enum 1.1.4 → 1.1.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/dist/enums.js CHANGED
@@ -1,60 +1,40 @@
1
- import { isArray as y } from "@tolki/utils";
2
- function a(e, s) {
3
- const n = new Set(e._cases ?? []);
4
- let r;
5
- for (const t of n)
6
- if (e[t] === s) {
7
- r = t;
8
- break;
9
- }
10
- if (!r) {
11
- const t = Array.from(n).map((c) => e[c]);
12
- throw new Error(
13
- `Value "${String(s)}" does not match any case in the enum. Values: ${t.join(", ")}, Cases: ${[...n].join(", ")}`
14
- );
15
- }
16
- const o = { value: s }, f = new Set(e._methods ?? []), i = e._helpers, h = new Set(
17
- y(i) ? i : []
18
- ), l = /* @__PURE__ */ new Set([
19
- "_cases",
20
- "_methods",
21
- "_helpers",
22
- "_static"
23
- ]);
24
- for (const [t, c] of Object.entries(e))
25
- l.has(t) || n.has(t) || h.has(t) || (f.has(t) ? o[t] = c[r] : o[t] = c);
26
- return o.name = r, o;
1
+ import { isArray as e } from "@tolki/utils";
2
+ // src/enums.ts
3
+ function t(t, n) {
4
+ let r = new Set(t._cases ?? []), i;
5
+ for (let e of r) if (t[e] === n) {
6
+ i = e;
7
+ break;
8
+ }
9
+ if (!i) {
10
+ let e = Array.from(r).map((e) => t[e]);
11
+ throw Error(`Value "${String(n)}" does not match any case in the enum. Values: ${e.join(", ")}, Cases: ${[...r].join(", ")}`);
12
+ }
13
+ let a = { value: n }, o = new Set(t._methods ?? []), s = t._helpers, c = new Set(e(s) ? s : []), l = /* @__PURE__ */ new Set([
14
+ "_cases",
15
+ "_methods",
16
+ "_helpers",
17
+ "_static"
18
+ ]);
19
+ for (let [e, n] of Object.entries(t)) l.has(e) || r.has(e) || c.has(e) || (a[e] = o.has(e) ? n[i] : n);
20
+ return a.name = i, a;
27
21
  }
28
- function p(e, s) {
29
- try {
30
- return a(e, s);
31
- } catch {
32
- return null;
33
- }
22
+ function n(e, n) {
23
+ try {
24
+ return t(e, n);
25
+ } catch {
26
+ return null;
27
+ }
34
28
  }
35
- function u(e) {
36
- return (e._cases ?? []).map(
37
- (s) => a(e, e[s])
38
- );
29
+ function r(e) {
30
+ return (e._cases ?? []).map((n) => t(e, e[n]));
39
31
  }
40
- function m(e) {
41
- const s = {
42
- from: (r) => a(e, r),
43
- tryFrom: (r) => p(e, r),
44
- cases: () => u(e)
45
- }, n = Object.keys(s);
46
- return Object.assign(
47
- /* @__PURE__ */ Object.create(null),
48
- e,
49
- s,
50
- {
51
- _helpers: n
52
- }
53
- );
32
+ function i(e) {
33
+ let i = {
34
+ from: (n) => t(e, n),
35
+ tryFrom: (t) => n(e, t),
36
+ cases: () => r(e)
37
+ }, a = Object.keys(i);
38
+ return Object.assign(Object.create(null), e, i, { _helpers: a });
54
39
  }
55
- export {
56
- u as cases,
57
- m as defineEnum,
58
- a as from,
59
- p as tryFrom
60
- };
40
+ export { r as cases, i as defineEnum, t as from, n as tryFrom };
package/dist/index.js CHANGED
@@ -1,9 +1,3 @@
1
- import { cases as e, defineEnum as m, from as t, tryFrom as f } from "./enums.js";
2
- import { SortDirection as n } from "./php-enums.js";
3
- export {
4
- n as SortDirection,
5
- e as cases,
6
- m as defineEnum,
7
- t as from,
8
- f as tryFrom
9
- };
1
+ import { cases as e, defineEnum as t, from as n, tryFrom as r } from "./enums.js";
2
+ import { SortDirection as i } from "./php-enums.js";
3
+ export { i as SortDirection, e as cases, t as defineEnum, n as from, r as tryFrom };
@@ -1,4 +1,4 @@
1
- import { DefineEnumResult } from '@tolki/ts';
1
+ import { DefineEnumResult } from './enums';
2
2
  export declare const SortDirection: DefineEnumResult<{
3
3
  readonly Ascending: "Ascending";
4
4
  readonly Descending: "Descending";
package/dist/php-enums.js CHANGED
@@ -1,10 +1,9 @@
1
1
  import { defineEnum as e } from "./enums.js";
2
- const c = e({
3
- Ascending: "Ascending",
4
- Descending: "Descending",
5
- backed: !1,
6
- _cases: ["Ascending", "Descending"]
2
+ // src/php-enums.ts
3
+ var t = e({
4
+ Ascending: "Ascending",
5
+ Descending: "Descending",
6
+ backed: !1,
7
+ _cases: ["Ascending", "Descending"]
7
8
  });
8
- export {
9
- c as SortDirection
10
- };
9
+ export { t as SortDirection };
@@ -1,116 +1,74 @@
1
- import { exec as W } from "node:child_process";
2
- import { readFile as k } from "node:fs/promises";
3
- import S from "node:path";
4
- import { promisify as A } from "node:util";
5
- import { normalizePath as g } from "vite";
6
- const B = A(W);
7
- function U(q = {}) {
8
- const {
9
- command: a = "php artisan ts:publish",
10
- filename: z = "laravel-ts-collected-files.json",
11
- directory: P = "resources/js/types/data/",
12
- runOnDevStart: T = !1,
13
- runOnBuildStart: x = !0,
14
- reload: F = !0,
15
- failOnError: p,
16
- sourceCommand: h,
17
- onBuildOnlyEnums: M = !0,
18
- quiet: w = !0
19
- } = q, y = h === !1 ? !1 : h ?? `${a} --source="{file}"`;
20
- let t, l;
21
- const r = /* @__PURE__ */ new Map();
22
- let u = "", m = !1;
23
- const f = [], n = "[laravel-ts-publish]", $ = async () => {
24
- r.clear();
25
- try {
26
- const e = await k(u, "utf-8"), o = JSON.parse(e);
27
- for (const c of o) {
28
- const i = g(S.resolve(t.root, c));
29
- r.set(i, c);
30
- }
31
- } catch (e) {
32
- if (e instanceof Error && e.code === "ENOENT") {
33
- t.logger.warn(
34
- `${n} Manifest not found: ${u}`
35
- );
36
- return;
37
- }
38
- t.logger.error(
39
- `${n} Failed to read manifest: ${e instanceof Error ? e.message : String(e)}`
40
- );
41
- }
42
- }, v = () => {
43
- if (l)
44
- for (const e of r.keys())
45
- l.watcher.add(e);
46
- }, j = () => p !== void 0 ? p : t.command === "build", d = async (e = null, o) => {
47
- if (m) {
48
- f.includes(e) || f.push(e);
49
- return;
50
- }
51
- m = !0;
52
- let i = e && y ? y.replaceAll("{file}", e) : o ?? a;
53
- w && !i.includes("--quiet") && (i += " --quiet");
54
- try {
55
- t.logger.info(`${n} Running: ${i}`, {
56
- timestamp: !0
57
- }), await B(i, { cwd: t.root }), t.logger.info(`${n} Types published successfully`, {
58
- timestamp: !0
59
- }), F && l && l.ws.send({ type: "full-reload" });
60
- } catch (s) {
61
- const b = s instanceof Error ? s.message : String(s), { stdout: N, stderr: R } = s, C = [R?.trim(), N?.trim()].filter(
62
- (O) => !!O && !b.includes(O)
63
- ).join(`
64
- `), E = `${n} Command failed: ${b}${C ? `
65
- ${C}` : ""}`;
66
- if (j())
67
- throw new Error(E, { cause: s });
68
- t.logger.error(E);
69
- } finally {
70
- if (m = !1, f.length > 0) {
71
- const s = f.shift();
72
- await d(s);
73
- }
74
- }
75
- };
76
- return {
77
- name: "@tolki/vite-plugin-laravel-ts-publish",
78
- enforce: "pre",
79
- configResolved(e) {
80
- t = e, u = g(
81
- S.resolve(t.root, P, z)
82
- );
83
- },
84
- configureServer(e) {
85
- l = e;
86
- },
87
- async buildStart() {
88
- if (t.command === "build") {
89
- if (x) {
90
- let e = M && !a.includes("--only-enums") ? `${a} --only-enums` : a;
91
- w && !e.includes("--quiet") && (e += " --quiet"), await d(null, e);
92
- }
93
- return;
94
- }
95
- await $(), v(), r.size > 0 && t.logger.info(
96
- `${n} Watching ${r.size} PHP file${r.size === 1 ? "" : "s"} for changes`,
97
- { timestamp: !0 }
98
- ), T && await d();
99
- },
100
- async handleHotUpdate({ file: e }) {
101
- const o = g(e);
102
- if (o === u)
103
- return t.logger.info(
104
- `${n} Manifest changed, reloading watched files`,
105
- { timestamp: !0 }
106
- ), await $(), v(), [];
107
- if (r.has(o)) {
108
- const c = r.get(o) ?? null;
109
- return await d(c), [];
110
- }
111
- }
112
- };
1
+ import { exec as e } from "node:child_process";
2
+ import { readFile as t } from "node:fs/promises";
3
+ import n from "node:path";
4
+ import { promisify as r } from "node:util";
5
+ import { normalizePath as i } from "vite";
6
+ // src/vite-plugin.ts
7
+ var a = r(e);
8
+ function o(e = {}) {
9
+ let { command: r = "php artisan ts:publish", filename: o = "laravel-ts-collected-files.json", directory: s = "resources/js/types/data/", runOnDevStart: c = !1, runOnBuildStart: l = !0, reload: u = !0, failOnError: d, sourceCommand: f, onBuildOnlyEnums: p = !0, quiet: m = !0 } = e, h = f === !1 ? !1 : f ?? `${r} --source="{file}"`, g, _, v = /* @__PURE__ */ new Map(), y = "", b = !1, x = [], S = "[laravel-ts-publish]", C = async () => {
10
+ v.clear();
11
+ try {
12
+ let e = await t(y, "utf-8"), r = JSON.parse(e);
13
+ for (let e of r) {
14
+ let t = i(n.resolve(g.root, e));
15
+ v.set(t, e);
16
+ }
17
+ } catch (e) {
18
+ if (e instanceof Error && e.code === "ENOENT") {
19
+ g.logger.warn(`${S} Manifest not found: ${y}`);
20
+ return;
21
+ }
22
+ g.logger.error(`${S} Failed to read manifest: ${e instanceof Error ? e.message : String(e)}`);
23
+ }
24
+ }, w = () => {
25
+ if (_) for (let e of v.keys()) _.watcher.add(e);
26
+ }, T = () => d === void 0 ? g.command === "build" : d, E = async (e = null, t) => {
27
+ if (b) {
28
+ x.includes(e) || x.push(e);
29
+ return;
30
+ }
31
+ b = !0;
32
+ let n = e && h ? h.replaceAll("{file}", e) : t ?? r;
33
+ m && !n.includes("--quiet") && (n += " --quiet");
34
+ try {
35
+ g.logger.info(`${S} Running: ${n}`, { timestamp: !0 }), await a(n, { cwd: g.root }), g.logger.info(`${S} Types published successfully`, { timestamp: !0 }), u && _ && _.ws.send({ type: "full-reload" });
36
+ } catch (e) {
37
+ let t = e instanceof Error ? e.message : String(e), { stdout: n, stderr: r } = e, i = [r?.trim(), n?.trim()].filter((e) => !!e && !t.includes(e)).join("\n"), a = `${S} Command failed: ${t}${i ? `\n${i}` : ""}`;
38
+ if (T()) throw Error(a, { cause: e });
39
+ g.logger.error(a);
40
+ } finally {
41
+ if (b = !1, x.length > 0) {
42
+ let e = x.shift();
43
+ await E(e);
44
+ }
45
+ }
46
+ };
47
+ return {
48
+ name: "@tolki/vite-plugin-laravel-ts-publish",
49
+ enforce: "pre",
50
+ configResolved(e) {
51
+ g = e, y = i(n.resolve(g.root, s, o));
52
+ },
53
+ configureServer(e) {
54
+ _ = e;
55
+ },
56
+ async buildStart() {
57
+ if (g.command === "build") {
58
+ if (l) {
59
+ let e = p && !r.includes("--only-enums") ? `${r} --only-enums` : r;
60
+ m && !e.includes("--quiet") && (e += " --quiet"), await E(null, e);
61
+ }
62
+ } else await C(), w(), v.size > 0 && g.logger.info(`${S} Watching ${v.size} PHP file${v.size === 1 ? "" : "s"} for changes`, { timestamp: !0 }), c && await E();
63
+ },
64
+ async handleHotUpdate({ file: e }) {
65
+ let t = i(e);
66
+ if (t === y) return g.logger.info(`${S} Manifest changed, reloading watched files`, { timestamp: !0 }), await C(), w(), [];
67
+ if (v.has(t)) {
68
+ let e = v.get(t) ?? null;
69
+ return await E(e), [];
70
+ }
71
+ }
72
+ };
113
73
  }
114
- export {
115
- U as laravelTsPublish
116
- };
74
+ export { o as laravelTsPublish };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolki/enum",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "A set of enum utilities for the Laravel TypeScript Publish PHP package.",
5
5
  "author": "Abraham Arango <https://github.com/abetwothree>",
6
6
  "license": "MIT",
@@ -38,7 +38,10 @@
38
38
  ],
39
39
  "dependencies": {
40
40
  "@tolki/types": "^1.11.0",
41
- "@tolki/utils": "^1.6.2"
41
+ "@tolki/utils": "^1.6.3"
42
+ },
43
+ "devDependencies": {
44
+ "vite": "^8.3.5"
42
45
  },
43
46
  "peerDependencies": {
44
47
  "vite": "^8.0.0||^7.0.0"