@digitaldefiance/branded-enum 0.0.1 → 0.0.2

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.
@@ -0,0 +1,21 @@
1
+ /**
2
+ * branded-enum - Runtime-identifiable enum-like types for TypeScript
3
+ *
4
+ * This library provides enum-like objects with embedded metadata for runtime
5
+ * identification, enabling you to determine which enum a string value belongs to.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ export type { BrandedEnumMetadata, BrandedEnum, BrandedEnumValue, RegistryEntry, BrandedEnumRegistry, EnumConsumerEntry, EnumConsumerRegistry, AnyBrandedEnum, EnumKeys, EnumValues, ValidEnumValue, StrictEnumParam, } from './lib/types.js';
10
+ export { createBrandedEnum } from './lib/factory.js';
11
+ export { getRegistry, getAllEnumIds, getEnumById, findEnumSources, } from './lib/registry.js';
12
+ export { isFromEnum, assertFromEnum, parseEnum, safeParseEnum } from './lib/guards.js';
13
+ export type { SafeParseSuccess, SafeParseFailure, SafeParseError, SafeParseErrorCode, SafeParseResult } from './lib/guards.js';
14
+ export { getEnumId, getEnumValues, enumSize } from './lib/accessors.js';
15
+ export { hasValue, getKeyForValue, isValidKey, enumEntries, } from './lib/utils.js';
16
+ export { mergeEnums } from './lib/merge.js';
17
+ export { enumSubset, enumExclude, enumMap, enumFromKeys, enumDiff, enumIntersect, enumToRecord, watchEnum, watchAllEnums, clearAllEnumWatchers, getEnumWatcherCount, getGlobalWatcherCount, exhaustive, exhaustiveGuard, toJsonSchema, toZodSchema, enumSerializer } from './lib/advanced.js';
18
+ export type { EnumDiffResult, EnumIntersectEntry, EnumAccessType, EnumAccessEvent, EnumWatchCallback, WatchEnumResult, ToJsonSchemaOptions, EnumJsonSchema, ToZodSchemaOptions, ZodEnumSchemaDefinition, EnumSerializerOptions, DeserializeSuccess, DeserializeFailure, DeserializeResult, EnumSerializer } from './lib/advanced.js';
19
+ export { EnumValue, EnumClass, getEnumConsumers, getConsumedEnums, getAllEnumConsumers, } from './lib/decorators.js';
20
+ export type { EnumValueOptions } from './lib/decorators.js';
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,YAAY,EACV,mBAAmB,EACnB,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,QAAQ,EACR,UAAU,EACV,cAAc,EACd,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAMxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAMrD,OAAO,EACL,WAAW,EACX,aAAa,EACb,WAAW,EACX,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACvF,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,cAAc,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAM/H,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAMxE,OAAO,EACL,QAAQ,EACR,cAAc,EACd,UAAU,EACV,WAAW,GACZ,MAAM,gBAAgB,CAAC;AAMxB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAM5C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,UAAU,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC9R,YAAY,EAAE,cAAc,EAAE,kBAAkB,EAAE,cAAc,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,mBAAmB,EAAE,cAAc,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAMrU,OAAO,EACL,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Metadata accessors for branded enums.
3
+ *
4
+ * Provides functions to retrieve metadata from branded enum objects,
5
+ * including enum ID, values array, and size.
6
+ */
7
+ import { AnyBrandedEnum, EnumValues } from './types.js';
8
+ /**
9
+ * Gets the enum ID from a branded enum.
10
+ *
11
+ * Retrieves the unique identifier that was assigned when the enum was created.
12
+ * Returns undefined for objects that are not branded enums.
13
+ *
14
+ * @param enumObj - The object to get the enum ID from. Can be any type.
15
+ * @returns The enum ID string if enumObj is a branded enum, `undefined` otherwise.
16
+ *
17
+ * @example
18
+ * // Get ID from branded enum
19
+ * const Status = createBrandedEnum('status', { Active: 'active' } as const);
20
+ * getEnumId(Status); // 'status'
21
+ *
22
+ * @example
23
+ * // Returns undefined for non-branded objects
24
+ * getEnumId({}); // undefined
25
+ * getEnumId({ Active: 'active' }); // undefined
26
+ * getEnumId(null); // undefined
27
+ */
28
+ export declare function getEnumId(enumObj: unknown): string | undefined;
29
+ /**
30
+ * Gets all values from a branded enum as an array.
31
+ *
32
+ * Returns an array containing all the string values in the enum.
33
+ * The order of values is not guaranteed.
34
+ *
35
+ * @template E - The branded enum type
36
+ * @param enumObj - The object to get values from. Can be any type.
37
+ * @returns Array of all enum values if enumObj is a branded enum,
38
+ * `undefined` otherwise.
39
+ *
40
+ * @example
41
+ * // Get values from branded enum
42
+ * const Status = createBrandedEnum('status', {
43
+ * Active: 'active',
44
+ * Inactive: 'inactive'
45
+ * } as const);
46
+ * getEnumValues(Status); // ['active', 'inactive']
47
+ *
48
+ * @example
49
+ * // Returns undefined for non-branded objects
50
+ * getEnumValues({}); // undefined
51
+ * getEnumValues({ Active: 'active' }); // undefined
52
+ */
53
+ export declare function getEnumValues<E extends AnyBrandedEnum>(enumObj: E): EnumValues<E>[] | undefined;
54
+ export declare function getEnumValues(enumObj: unknown): string[] | undefined;
55
+ /**
56
+ * Gets the number of values in a branded enum.
57
+ *
58
+ * Returns the count of unique values in the enum. This is equivalent to
59
+ * the number of key-value pairs defined when the enum was created.
60
+ *
61
+ * @param enumObj - The object to get the size of. Can be any type.
62
+ * @returns The number of values in the enum if enumObj is a branded enum,
63
+ * `undefined` otherwise.
64
+ *
65
+ * @example
66
+ * // Get size of branded enum
67
+ * const Status = createBrandedEnum('status', {
68
+ * Active: 'active',
69
+ * Inactive: 'inactive'
70
+ * } as const);
71
+ * enumSize(Status); // 2
72
+ *
73
+ * @example
74
+ * // Returns undefined for non-branded objects
75
+ * enumSize({}); // undefined
76
+ * enumSize({ Active: 'active' }); // undefined
77
+ */
78
+ export declare function enumSize(enumObj: unknown): number | undefined;
79
+ //# sourceMappingURL=accessors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accessors.d.ts","sourceRoot":"","sources":["../../src/lib/accessors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,cAAc,EAKd,UAAU,EACX,MAAM,YAAY,CAAC;AAmBpB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAK9D;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,cAAc,EACpD,OAAO,EAAE,CAAC,GACT,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC;AAC/B,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC;AAQtE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAK7D"}