@reharik/smart-enum 0.3.2 → 0.3.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 +1 -1
- package/dist/graphql.cjs +46 -0
- package/dist/graphql.cjs.map +1 -0
- package/dist/graphql.d.cts +5 -0
- package/dist/graphql.d.ts +5 -0
- package/dist/graphql.js +19 -0
- package/dist/graphql.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ The common workarounds each solve one piece:
|
|
|
11
11
|
- **Plain objects** (`{ ACTIVE: 'active' }`) — no iteration, no type narrowing, no metadata, annoying text duplication.
|
|
12
12
|
- **String unions** (`type Status = 'active' | 'inactive'`) — compile-time only. No runtime lookup, no `.display`, no `.items()`.
|
|
13
13
|
- **Arrays** (`['active', 'inactive'] as const`) — iterable, but no keyed access or metadata.
|
|
14
|
-
- **Constants** (
|
|
14
|
+
- **Constants** (const ME = "me") — scattered and hard to iterate
|
|
15
15
|
|
|
16
16
|
Smart Enums give you all of it in one construct:
|
|
17
17
|
|
package/dist/graphql.cjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/graphql.ts
|
|
21
|
+
var graphql_exports = {};
|
|
22
|
+
__export(graphql_exports, {
|
|
23
|
+
patchSchemaEnumSerializers: () => patchSchemaEnumSerializers
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(graphql_exports);
|
|
26
|
+
|
|
27
|
+
// src/utilities/patchSchemaEnumSerializers.ts
|
|
28
|
+
var import_graphql = require("graphql");
|
|
29
|
+
var patchSchemaEnumSerializers = (schema) => {
|
|
30
|
+
const typeMap = schema.getTypeMap();
|
|
31
|
+
for (const typeName in typeMap) {
|
|
32
|
+
if (typeName.startsWith("__")) continue;
|
|
33
|
+
const type = typeMap[typeName];
|
|
34
|
+
if (!(0, import_graphql.isEnumType)(type)) continue;
|
|
35
|
+
const originalSerialize = type.serialize.bind(type);
|
|
36
|
+
type.serialize = (value) => {
|
|
37
|
+
const raw = value?.value ?? value;
|
|
38
|
+
return originalSerialize(raw);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
patchSchemaEnumSerializers
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=graphql.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/graphql.ts","../src/utilities/patchSchemaEnumSerializers.ts"],"sourcesContent":["export { patchSchemaEnumSerializers } from './utilities/patchSchemaEnumSerializers.js';\n","import { isEnumType, type GraphQLSchema } from 'graphql';\n\nexport const patchSchemaEnumSerializers = (schema: GraphQLSchema): void => {\n const typeMap = schema.getTypeMap();\n\n for (const typeName in typeMap) {\n if (typeName.startsWith('__')) continue;\n\n const type = typeMap[typeName];\n if (!isEnumType(type)) continue;\n\n const originalSerialize = type.serialize.bind(type);\n\n type.serialize = (value: unknown): string | null | undefined => {\n const raw = (value as { value?: string })?.value ?? value;\n return originalSerialize(raw) as string | null | undefined;\n };\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAA+C;AAExC,IAAM,6BAA6B,CAAC,WAAgC;AACzE,QAAM,UAAU,OAAO,WAAW;AAElC,aAAW,YAAY,SAAS;AAC9B,QAAI,SAAS,WAAW,IAAI,EAAG;AAE/B,UAAM,OAAO,QAAQ,QAAQ;AAC7B,QAAI,KAAC,2BAAW,IAAI,EAAG;AAEvB,UAAM,oBAAoB,KAAK,UAAU,KAAK,IAAI;AAElD,SAAK,YAAY,CAAC,UAA8C;AAC9D,YAAM,MAAO,OAA8B,SAAS;AACpD,aAAO,kBAAkB,GAAG;AAAA,IAC9B;AAAA,EACF;AACF;","names":[]}
|
package/dist/graphql.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/utilities/patchSchemaEnumSerializers.ts
|
|
2
|
+
import { isEnumType } from "graphql";
|
|
3
|
+
var patchSchemaEnumSerializers = (schema) => {
|
|
4
|
+
const typeMap = schema.getTypeMap();
|
|
5
|
+
for (const typeName in typeMap) {
|
|
6
|
+
if (typeName.startsWith("__")) continue;
|
|
7
|
+
const type = typeMap[typeName];
|
|
8
|
+
if (!isEnumType(type)) continue;
|
|
9
|
+
const originalSerialize = type.serialize.bind(type);
|
|
10
|
+
type.serialize = (value) => {
|
|
11
|
+
const raw = value?.value ?? value;
|
|
12
|
+
return originalSerialize(raw);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
patchSchemaEnumSerializers
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=graphql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utilities/patchSchemaEnumSerializers.ts"],"sourcesContent":["import { isEnumType, type GraphQLSchema } from 'graphql';\n\nexport const patchSchemaEnumSerializers = (schema: GraphQLSchema): void => {\n const typeMap = schema.getTypeMap();\n\n for (const typeName in typeMap) {\n if (typeName.startsWith('__')) continue;\n\n const type = typeMap[typeName];\n if (!isEnumType(type)) continue;\n\n const originalSerialize = type.serialize.bind(type);\n\n type.serialize = (value: unknown): string | null | undefined => {\n const raw = (value as { value?: string })?.value ?? value;\n return originalSerialize(raw) as string | null | undefined;\n };\n }\n};\n"],"mappings":";AAAA,SAAS,kBAAsC;AAExC,IAAM,6BAA6B,CAAC,WAAgC;AACzE,QAAM,UAAU,OAAO,WAAW;AAElC,aAAW,YAAY,SAAS;AAC9B,QAAI,SAAS,WAAW,IAAI,EAAG;AAE/B,UAAM,OAAO,QAAQ,QAAQ;AAC7B,QAAI,CAAC,WAAW,IAAI,EAAG;AAEvB,UAAM,oBAAoB,KAAK,UAAU,KAAK,IAAI;AAElD,SAAK,YAAY,CAAC,UAA8C;AAC9D,YAAM,MAAO,OAA8B,SAAS;AACpD,aAAO,kBAAkB,GAAG;AAAA,IAC9B;AAAA,EACF;AACF;","names":[]}
|