@xylabs/enum 4.12.44 → 4.13.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.
@@ -1,84 +1,87 @@
1
- /**
2
- * Transforms a given record object into a readonly "enum-like" structure while preserving
3
- * the literal types of its values. This allows you to use the returned object both at runtime
4
- * (for lookups) and at compile time (for strongly typed values).
5
- *
6
- * To maintain literal types (i.e., prevent them from being widened to `string`, `number`, etc.),
7
- * ensure you annotate your object with `as const` before passing it to `Enum`.
8
- *
9
- * @template T - A record type with string keys and any kind of values.
10
- * @param obj - A readonly record object annotated with `as const`.
11
- * @returns A readonly version of the provided record, preserving exact literal value types.
12
- *
13
- * @example
14
- * ```typescript
15
- * // Defining a record with literal types using as const:
16
- * const DnsRecordType = Enum({
17
- * A: 1,
18
- * AAAA: 28,
19
- * CAA: 257,
20
- * CNAME: 5,
21
- * DNAME: 39,
22
- * MX: 15,
23
- * NS: 2,
24
- * PTR: 12,
25
- * SOA: 6,
26
- * SPF: 99,
27
- * SRV: 33,
28
- * TXT: 16,
29
- * } as const);
30
- *
31
- * // DnsRecordType is now a readonly object:
32
- * // {
33
- * // readonly A: 1;
34
- * // readonly AAAA: 28;
35
- * // readonly CAA: 257;
36
- * // readonly CNAME: 5;
37
- * // readonly DNAME: 39;
38
- * // readonly MX: 15;
39
- * // readonly NS: 2;
40
- * // readonly PTR: 12;
41
- * // readonly SOA: 6;
42
- * // readonly SPF: 99;
43
- * // readonly SRV: 33;
44
- * // readonly TXT: 16;
45
- * // }
46
- * ```
47
- */
48
- export declare const Enum: <const T extends Record<string | number | symbol, unknown>>(obj: Readonly<T>) => Enum<T>;
49
- /**
50
- * A utility type that, given a `Record<string, unknown>`, returns a readonly version
51
- * of that record. This results in a type where all properties of `T` are readonly.
52
- *
53
- * @template T - The record type to make readonly.
54
- *
55
- * @example
56
- * ```typescript
57
- * // Given a record:
58
- * export const DnsRecordType = Enum({
59
- * A: 1,
60
- * AAAA: 28,
61
- * CAA: 257,
62
- * CNAME: 5,
63
- * DNAME: 39,
64
- * MX: 15,
65
- * NS: 2,
66
- * PTR: 12,
67
- * SOA: 6,
68
- * SPF: 99,
69
- * SRV: 33,
70
- * TXT: 16,
71
- * })
72
- *
73
- * // Now the type inference will preserve the literal types:
74
- * export type DnsRecordType = Enum<typeof DnsRecordType>
75
- * ```
76
- */
77
- export type Enum<T extends Readonly<Record<string | number | symbol, unknown>>> = {
78
- readonly [K in keyof T]: T[K];
79
- };
80
- /**
81
- * A utility type that, given an `Enum` object, returns the union of its values.
82
- */
83
- export type EnumValue<T extends Record<string | number | symbol, unknown>, K = Enum<T>> = K[keyof K];
84
- //# sourceMappingURL=Enum.d.ts.map
1
+ /**
2
+ * Transforms a given record object into a readonly "enum-like" structure while preserving
3
+ * the literal types of its values. This allows you to use the returned object both at runtime
4
+ * (for lookups) and at compile time (for strongly typed values).
5
+ *
6
+ * To maintain literal types (i.e., prevent them from being widened to `string`, `number`, etc.),
7
+ * ensure you annotate your object with `as const` before passing it to `Enum`.
8
+ *
9
+ * @template T - A record type with string keys and any kind of values.
10
+ * @param obj - A readonly record object annotated with `as const`.
11
+ * @returns A readonly version of the provided record, preserving exact literal value types.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // Defining a record with literal types using as const:
16
+ * const DnsRecordType = Enum({
17
+ * A: 1,
18
+ * AAAA: 28,
19
+ * CAA: 257,
20
+ * CNAME: 5,
21
+ * DNAME: 39,
22
+ * MX: 15,
23
+ * NS: 2,
24
+ * PTR: 12,
25
+ * SOA: 6,
26
+ * SPF: 99,
27
+ * SRV: 33,
28
+ * TXT: 16,
29
+ * } as const);
30
+ *
31
+ * // DnsRecordType is now a readonly object:
32
+ * // {
33
+ * // readonly A: 1;
34
+ * // readonly AAAA: 28;
35
+ * // readonly CAA: 257;
36
+ * // readonly CNAME: 5;
37
+ * // readonly DNAME: 39;
38
+ * // readonly MX: 15;
39
+ * // readonly NS: 2;
40
+ * // readonly PTR: 12;
41
+ * // readonly SOA: 6;
42
+ * // readonly SPF: 99;
43
+ * // readonly SRV: 33;
44
+ * // readonly TXT: 16;
45
+ * // }
46
+ * ```
47
+ */
48
+ export declare const Enum: <const T extends Record<string | number | symbol, unknown>>(obj: Readonly<T>) => Enum<T>;
49
+
50
+ /**
51
+ * A utility type that, given a `Record<string, unknown>`, returns a readonly version
52
+ * of that record. This results in a type where all properties of `T` are readonly.
53
+ *
54
+ * @template T - The record type to make readonly.
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * // Given a record:
59
+ * export const DnsRecordType = Enum({
60
+ * A: 1,
61
+ * AAAA: 28,
62
+ * CAA: 257,
63
+ * CNAME: 5,
64
+ * DNAME: 39,
65
+ * MX: 15,
66
+ * NS: 2,
67
+ * PTR: 12,
68
+ * SOA: 6,
69
+ * SPF: 99,
70
+ * SRV: 33,
71
+ * TXT: 16,
72
+ * })
73
+ *
74
+ * // Now the type inference will preserve the literal types:
75
+ * export type DnsRecordType = Enum<typeof DnsRecordType>
76
+ * ```
77
+ */
78
+ export declare type Enum<T extends Readonly<Record<string | number | symbol, unknown>>> = {
79
+ readonly [K in keyof T]: T[K];
80
+ };
81
+
82
+ /**
83
+ * A utility type that, given an `Enum` object, returns the union of its values.
84
+ */
85
+ export declare type EnumValue<T extends Record<string | number | symbol, unknown>, K = Enum<T>> = K[keyof K];
86
+
87
+ export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/enum",
3
- "version": "4.12.44",
3
+ "version": "4.13.1",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -21,16 +21,16 @@
21
21
  "type": "module",
22
22
  "exports": {
23
23
  ".": {
24
- "types": "./dist/types/index.d.ts",
24
+ "types": "./dist/neutral/index.d.ts",
25
25
  "default": "./dist/neutral/index.mjs"
26
26
  },
27
27
  "./package.json": "./package.json"
28
28
  },
29
29
  "module": "dist/neutral/index.mjs",
30
- "types": "dist/types/index.d.ts",
30
+ "types": "dist/neutral/index.d.ts",
31
31
  "devDependencies": {
32
- "@xylabs/ts-scripts-yarn3": "^6.5.12",
33
- "@xylabs/tsconfig": "^6.5.12",
32
+ "@xylabs/ts-scripts-yarn3": "^7.0.0-rc.7",
33
+ "@xylabs/tsconfig": "^7.0.0-rc.7",
34
34
  "typescript": "^5.8.3"
35
35
  },
36
36
  "publishConfig": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"Enum.d.ts","sourceRoot":"","sources":["../../src/Enum.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,IAAI,GAAI,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAG,IAAI,CAAC,CAAC,CAExG,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI;IAChF,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAC9B,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './Enum.ts';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}