@tolki/ts 1.0.2 → 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/README.md +4990 -1924
- 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/package.json +7 -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tolki/ts",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
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,8 +39,9 @@
|
|
|
39
39
|
"tolki"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@tolki/
|
|
43
|
-
"@tolki/
|
|
42
|
+
"@tolki/enum": "^1.1.3",
|
|
43
|
+
"@tolki/types": "^1.9.0",
|
|
44
|
+
"@tolki/utils": "^1.6.0"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
47
|
"vite": "^7.0.0||^8.0.0"
|
|
@@ -74,8 +75,10 @@
|
|
|
74
75
|
"tolki": {
|
|
75
76
|
"docs": [
|
|
76
77
|
"ts/index.md",
|
|
78
|
+
"ts/publishing.md",
|
|
77
79
|
"ts/enums.md",
|
|
78
80
|
"ts/models.md",
|
|
81
|
+
"ts/model-metadata.md",
|
|
79
82
|
"ts/api-resources.md",
|
|
80
83
|
"ts/broadcast-channels.md",
|
|
81
84
|
"ts/broadcast-events.md",
|
|
@@ -92,6 +95,7 @@
|
|
|
92
95
|
"ts/vite-env.md",
|
|
93
96
|
"ts/vite-plugin.md",
|
|
94
97
|
"ts/customizing-the-pipeline.md",
|
|
98
|
+
"ts/analyzer-api.md",
|
|
95
99
|
"ts/configuration-reference.md"
|
|
96
100
|
]
|
|
97
101
|
},
|