@tolki/ts 1.0.2 → 1.0.4
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/README.md +5842 -2089
- package/dist/enums.d.ts +2 -58
- package/dist/enums.d.ts.map +1 -1
- package/dist/enums.js +5 -58
- package/dist/index.js +1 -1
- package/dist/vite-plugin.d.ts +2 -10
- package/dist/vite-plugin.d.ts.map +1 -1
- package/dist/vite-plugin.js +64 -58
- package/package.json +12 -3
package/dist/enums.d.ts
CHANGED
|
@@ -1,59 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
/**
|
|
4
|
-
* Creates an enum instance from a case value similar to PHP's `BackedEnum::from()`
|
|
5
|
-
*
|
|
6
|
-
* It will remove all the cases and make the matching case's value available as `value`
|
|
7
|
-
*
|
|
8
|
-
* All instance methods will be flattened from an object of case keys & values to a key/value pair for the matched case.
|
|
9
|
-
*
|
|
10
|
-
* The enumObj is the published enum from the Laravel TypeScript Publish package.
|
|
11
|
-
*
|
|
12
|
-
* @see https://github.com/abetwothree/laravel-ts-publish#enum-metadata--tolki-enum-package
|
|
13
|
-
* @see https://tolki.abe.dev/enums/enum-utilities-list.html#from
|
|
14
|
-
*
|
|
15
|
-
* @param enumObj - The enum const object to resolve from.
|
|
16
|
-
* @param value - The case value to resolve. Must be one of the values defined in the enum const's cases.
|
|
17
|
-
* @returns The resolved enum case with its associated methods and properties for the value provided.
|
|
18
|
-
* @throws If the value does not match any case in the enum, an error is thrown.
|
|
19
|
-
*/
|
|
20
|
-
export declare function from<TEnum extends EnumConst, const TValue extends CaseValue<TEnum>>(enumObj: TEnum, value: TValue): FromResult<TEnum, TValue>;
|
|
21
|
-
/**
|
|
22
|
-
* Similar to the {@linkcode from | from} function but returns null instead of throwing an error for invalid values.
|
|
23
|
-
*
|
|
24
|
-
* Mirrors PHP's `BackedEnum::tryFrom()`.
|
|
25
|
-
*
|
|
26
|
-
* @see https://tolki.abe.dev/enums/enum-utilities-list.html#tryfrom
|
|
27
|
-
*
|
|
28
|
-
* @param enumObj - The enum const object to resolve from.
|
|
29
|
-
* @param value - The case value to resolve.
|
|
30
|
-
* @returns The resolved enum case, or null if the value does not match any case.
|
|
31
|
-
*/
|
|
32
|
-
export declare function tryFrom<TEnum extends EnumConst, const TValue extends CaseValue<TEnum>>(enumObj: TEnum, value: TValue): FromResult<TEnum, TValue> | null;
|
|
33
|
-
/**
|
|
34
|
-
* Returns all enum cases as resolved instances by running each case value through the {@linkcode from | from} function.
|
|
35
|
-
*
|
|
36
|
-
* Mirrors PHP's `BackedEnum::cases()`, returning one resolved instance per case defined in the enum const.
|
|
37
|
-
*
|
|
38
|
-
* @see https://tolki.abe.dev/enums/enum-utilities-list.html#cases
|
|
39
|
-
*
|
|
40
|
-
* @param enumObj - The enum const object to resolve all cases from.
|
|
41
|
-
* @returns An array of resolved enum instances, one for each case.
|
|
42
|
-
*/
|
|
43
|
-
export declare function cases<TEnum extends EnumConst>(enumObj: TEnum): Array<FromResult<TEnum, CaseValue<TEnum>>>;
|
|
44
|
-
/**
|
|
45
|
-
* Factory function that creates an enriched enum object
|
|
46
|
-
*
|
|
47
|
-
* It automatically binds Tolki helper methods {@linkcode from | from}, {@linkcode tryFrom | tryFrom}, and {@linkcode cases | cases}.
|
|
48
|
-
*
|
|
49
|
-
* This allows your published enum to have PHP-like enum behavior with type safety and autocompletion in TypeScript.
|
|
50
|
-
*
|
|
51
|
-
* The original enum data is preserved and the PHP like enum methods are attached directly to the returned object.
|
|
52
|
-
*
|
|
53
|
-
* @see https://tolki.abe.dev/enums/enum-utilities-list.html#defineenum
|
|
54
|
-
*
|
|
55
|
-
* @param enumObj - The raw enum const object to enrich.
|
|
56
|
-
* @returns The enum object with `from`, `tryFrom`, and `cases` methods bound to it.
|
|
57
|
-
*/
|
|
58
|
-
export declare function defineEnum<const TEnum extends EnumConst>(enumObj: TEnum): DefineEnumResult<TEnum>;
|
|
1
|
+
export type { AsEnum, CaseValue, DefineEnumResult, EnumConst, FromResult, } from '@tolki/enum';
|
|
2
|
+
export { cases, defineEnum, from, tryFrom } from '@tolki/enum';
|
|
59
3
|
//# sourceMappingURL=enums.d.ts.map
|
package/dist/enums.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":"AACA,YAAY,EACR,MAAM,EACN,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,UAAU,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/enums.js
CHANGED
|
@@ -1,60 +1,7 @@
|
|
|
1
|
-
import {
|
|
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;
|
|
27
|
-
}
|
|
28
|
-
function p(e, s) {
|
|
29
|
-
try {
|
|
30
|
-
return a(e, s);
|
|
31
|
-
} catch {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function u(e) {
|
|
36
|
-
return (e._cases ?? []).map(
|
|
37
|
-
(s) => a(e, e[s])
|
|
38
|
-
);
|
|
39
|
-
}
|
|
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
|
-
);
|
|
54
|
-
}
|
|
1
|
+
import { cases as m, defineEnum as o, from as f, tryFrom as n } from "@tolki/enum";
|
|
55
2
|
export {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
3
|
+
m as cases,
|
|
4
|
+
o as defineEnum,
|
|
5
|
+
f as from,
|
|
6
|
+
n as tryFrom
|
|
60
7
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cases as o, defineEnum as a, from as f, tryFrom as u } from "
|
|
1
|
+
import { cases as o, defineEnum as a, from as f, tryFrom as u } from "@tolki/enum";
|
|
2
2
|
import { addRouteDefault as s, annotatePageProps as n, annotateRequestPayload as m, defineRoute as R, formSafeOptions as d, getRouteDefaults as l, resetRouteDefaults as p, setRouteDefaults as D } from "./routes.js";
|
|
3
3
|
export {
|
|
4
4
|
s as addRouteDefault,
|
package/dist/vite-plugin.d.ts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
|
+
import { escapeShellArg } from '@tolki/utils';
|
|
1
2
|
import { Plugin } from 'vite';
|
|
2
|
-
|
|
3
|
-
* Escape a value for safe interpolation into a shell command string.
|
|
4
|
-
*
|
|
5
|
-
* Uses POSIX single-quote wrapping: the only character that requires
|
|
6
|
-
* escaping inside single quotes is the single quote itself.
|
|
7
|
-
*
|
|
8
|
-
* @param value - The raw string to escape.
|
|
9
|
-
* @returns A shell-safe string.
|
|
10
|
-
*/
|
|
11
|
-
export declare function escapeShellArg(value: string): string;
|
|
3
|
+
export { escapeShellArg };
|
|
12
4
|
export interface LaravelTsPublishOptions {
|
|
13
5
|
/**
|
|
14
6
|
* The command to run when a watched PHP file changes.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAKA,OAAO,EAEH,KAAK,MAAM,EAGd,MAAM,MAAM,CAAC;AAId
|
|
1
|
+
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAyB,MAAM,cAAc,CAAC;AACrE,OAAO,EAEH,KAAK,MAAM,EAGd,MAAM,MAAM,CAAC;AAId,OAAO,EAAE,cAAc,EAAE,CAAC;AAE1B,MAAM,WAAW,uBAAuB;IACpC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;;;;;;;;;;OAeG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC/B;;;;;;;;;;OAUG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;;;;;;;;OAUG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAcD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,wBAAgB,gBAAgB,CAC5B,OAAO,GAAE,uBAA4B,GACtC,MAAM,CA4PR"}
|
package/dist/vite-plugin.js
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
import { exec as R } from "node:child_process";
|
|
2
|
-
import { readFile as
|
|
2
|
+
import { readFile as k } from "node:fs/promises";
|
|
3
3
|
import q from "node:path";
|
|
4
|
-
import { promisify as
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
import { promisify as B } from "node:util";
|
|
5
|
+
import { escapeWindowsShellArg as H, escapeShellArg as D } from "@tolki/utils";
|
|
6
|
+
import { escapeShellArg as _ } from "@tolki/utils";
|
|
7
|
+
import { normalizePath as w } from "vite";
|
|
8
|
+
const J = B(R);
|
|
9
|
+
function L(c) {
|
|
10
|
+
return process.platform === "win32" ? H(c) : D(c);
|
|
9
11
|
}
|
|
10
|
-
function
|
|
12
|
+
function X(c = {}) {
|
|
11
13
|
const {
|
|
12
|
-
command:
|
|
13
|
-
filename:
|
|
14
|
-
directory:
|
|
14
|
+
command: a = "php artisan ts:publish",
|
|
15
|
+
filename: x = "laravel-ts-collected-files.json",
|
|
16
|
+
directory: z = "resources/js/types/data/",
|
|
15
17
|
runOnDevStart: P = !1,
|
|
16
18
|
runOnBuildStart: T = !0,
|
|
17
|
-
reload:
|
|
18
|
-
failOnError:
|
|
19
|
-
sourceCommand:
|
|
19
|
+
reload: F = !0,
|
|
20
|
+
failOnError: y,
|
|
21
|
+
sourceCommand: $,
|
|
20
22
|
onBuildOnlyFunctional: M = !0,
|
|
21
|
-
quiet:
|
|
22
|
-
} =
|
|
23
|
-
let t,
|
|
23
|
+
quiet: v = !0
|
|
24
|
+
} = c, f = $ === !1 ? !1 : $ ?? `${a} --source={file}`;
|
|
25
|
+
let t, l;
|
|
24
26
|
const r = /* @__PURE__ */ new Map();
|
|
25
|
-
let u = "",
|
|
27
|
+
let u = "", p = !1;
|
|
26
28
|
const d = [], n = "[laravel-ts-publish]", b = async () => {
|
|
27
29
|
r.clear();
|
|
28
30
|
try {
|
|
29
|
-
const e = await
|
|
30
|
-
for (const
|
|
31
|
-
const
|
|
32
|
-
r.set(
|
|
31
|
+
const e = await k(u, "utf-8"), o = JSON.parse(e);
|
|
32
|
+
for (const i of o) {
|
|
33
|
+
const g = w(q.resolve(t.root, i));
|
|
34
|
+
r.set(g, i);
|
|
33
35
|
}
|
|
34
36
|
} catch (e) {
|
|
35
37
|
if (e instanceof Error && e.code === "ENOENT") {
|
|
@@ -42,40 +44,44 @@ function G(a = {}) {
|
|
|
42
44
|
`${n} Failed to read manifest: ${e instanceof Error ? e.message : String(e)}`
|
|
43
45
|
);
|
|
44
46
|
}
|
|
45
|
-
},
|
|
46
|
-
if (
|
|
47
|
+
}, S = () => {
|
|
48
|
+
if (l)
|
|
47
49
|
for (const e of r.keys())
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
if (
|
|
50
|
+
l.watcher.add(e);
|
|
51
|
+
}, W = () => y !== void 0 ? y : t.command === "build", m = async (e = null, o) => {
|
|
52
|
+
if (p) {
|
|
51
53
|
d.includes(e) || d.push(e);
|
|
52
54
|
return;
|
|
53
55
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
p = !0;
|
|
57
|
+
const i = o ?? a, g = e && f ? f : i;
|
|
58
|
+
let h = e && f ? (
|
|
59
|
+
// A function replacer keeps `$&` and friends in the path literal.
|
|
60
|
+
f.replaceAll(
|
|
61
|
+
"{file}",
|
|
62
|
+
() => L(e)
|
|
63
|
+
)
|
|
64
|
+
) : i;
|
|
65
|
+
v && !g.includes("--quiet") && (h += " --quiet");
|
|
60
66
|
try {
|
|
61
|
-
t.logger.info(`${n} Running: ${
|
|
67
|
+
t.logger.info(`${n} Running: ${h}`, {
|
|
62
68
|
timestamp: !0
|
|
63
|
-
}), await
|
|
69
|
+
}), await J(h, { cwd: t.root }), t.logger.info(`${n} Types published successfully`, {
|
|
64
70
|
timestamp: !0
|
|
65
|
-
}),
|
|
66
|
-
} catch (
|
|
67
|
-
const
|
|
68
|
-
(
|
|
71
|
+
}), F && l && l.ws.send({ type: "full-reload" });
|
|
72
|
+
} catch (s) {
|
|
73
|
+
const O = s instanceof Error ? s.message : String(s), { stdout: j, stderr: N } = s, C = [N?.trim(), j?.trim()].filter(
|
|
74
|
+
(A) => !!A && !O.includes(A)
|
|
69
75
|
).join(`
|
|
70
|
-
`),
|
|
71
|
-
${
|
|
72
|
-
if (
|
|
73
|
-
throw new Error(
|
|
74
|
-
t.logger.error(
|
|
76
|
+
`), E = `${n} Command failed: ${O}${C ? `
|
|
77
|
+
${C}` : ""}`;
|
|
78
|
+
if (W())
|
|
79
|
+
throw new Error(E, { cause: s });
|
|
80
|
+
t.logger.error(E);
|
|
75
81
|
} finally {
|
|
76
|
-
if (
|
|
77
|
-
const
|
|
78
|
-
await m(
|
|
82
|
+
if (p = !1, d.length > 0) {
|
|
83
|
+
const s = d.shift();
|
|
84
|
+
await m(s);
|
|
79
85
|
}
|
|
80
86
|
}
|
|
81
87
|
};
|
|
@@ -83,41 +89,41 @@ ${O}` : ""}`;
|
|
|
83
89
|
name: "@tolki/vite-plugin-laravel-ts-publish",
|
|
84
90
|
enforce: "pre",
|
|
85
91
|
configResolved(e) {
|
|
86
|
-
t = e, u =
|
|
87
|
-
q.resolve(t.root,
|
|
92
|
+
t = e, u = w(
|
|
93
|
+
q.resolve(t.root, z, x)
|
|
88
94
|
);
|
|
89
95
|
},
|
|
90
96
|
configureServer(e) {
|
|
91
|
-
|
|
97
|
+
l = e;
|
|
92
98
|
},
|
|
93
99
|
async buildStart() {
|
|
94
100
|
if (t.command === "build") {
|
|
95
101
|
if (T) {
|
|
96
|
-
let e = M && !
|
|
97
|
-
|
|
102
|
+
let e = M && !a.includes("--only-functional") ? `${a} --only-functional` : a;
|
|
103
|
+
v && !e.includes("--quiet") && (e += " --quiet"), await m(null, e);
|
|
98
104
|
}
|
|
99
105
|
return;
|
|
100
106
|
}
|
|
101
|
-
await b(),
|
|
107
|
+
await b(), S(), r.size > 0 && t.logger.info(
|
|
102
108
|
`${n} Watching ${r.size} PHP file${r.size === 1 ? "" : "s"} for changes`,
|
|
103
109
|
{ timestamp: !0 }
|
|
104
110
|
), P && await m();
|
|
105
111
|
},
|
|
106
112
|
async handleHotUpdate({ file: e }) {
|
|
107
|
-
const o =
|
|
113
|
+
const o = w(e);
|
|
108
114
|
if (o === u)
|
|
109
115
|
return t.logger.info(
|
|
110
116
|
`${n} Manifest changed, reloading watched files`,
|
|
111
117
|
{ timestamp: !0 }
|
|
112
|
-
), await b(),
|
|
118
|
+
), await b(), S(), [];
|
|
113
119
|
if (r.has(o)) {
|
|
114
|
-
const
|
|
115
|
-
return await m(
|
|
120
|
+
const i = r.get(o) ?? null;
|
|
121
|
+
return await m(i), [];
|
|
116
122
|
}
|
|
117
123
|
}
|
|
118
124
|
};
|
|
119
125
|
}
|
|
120
126
|
export {
|
|
121
|
-
|
|
122
|
-
|
|
127
|
+
_ as escapeShellArg,
|
|
128
|
+
X as laravelTsPublish
|
|
123
129
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tolki/ts",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "A set of TypeScript utilities for the Laravel TypeScript Publish PHP package.",
|
|
5
5
|
"author": "Abraham Arango <https://github.com/abetwothree>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,12 +39,18 @@
|
|
|
39
39
|
"tolki"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@tolki/
|
|
43
|
-
"@tolki/
|
|
42
|
+
"@tolki/enum": "^1.1.4",
|
|
43
|
+
"@tolki/types": "^1.11.0",
|
|
44
|
+
"@tolki/utils": "^1.6.2"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
47
|
"vite": "^7.0.0||^8.0.0"
|
|
47
48
|
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"vite": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
53
|
+
},
|
|
48
54
|
"sideEffects": false,
|
|
49
55
|
"files": [
|
|
50
56
|
"dist"
|
|
@@ -74,8 +80,10 @@
|
|
|
74
80
|
"tolki": {
|
|
75
81
|
"docs": [
|
|
76
82
|
"ts/index.md",
|
|
83
|
+
"ts/publishing.md",
|
|
77
84
|
"ts/enums.md",
|
|
78
85
|
"ts/models.md",
|
|
86
|
+
"ts/model-metadata.md",
|
|
79
87
|
"ts/api-resources.md",
|
|
80
88
|
"ts/broadcast-channels.md",
|
|
81
89
|
"ts/broadcast-events.md",
|
|
@@ -92,6 +100,7 @@
|
|
|
92
100
|
"ts/vite-env.md",
|
|
93
101
|
"ts/vite-plugin.md",
|
|
94
102
|
"ts/customizing-the-pipeline.md",
|
|
103
|
+
"ts/analyzer-api.md",
|
|
95
104
|
"ts/configuration-reference.md"
|
|
96
105
|
]
|
|
97
106
|
},
|