@igstack/app-catalog-shared-core 0.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Igor Golovin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,127 @@
1
+ /**
2
+ * App Catalog Types - Universal Software Access Request Catalog
3
+ *
4
+ * These types define a standardized catalog of software applications and their
5
+ * access/approval methods. The typing system is designed to be universal across companies.
6
+ */
7
+ /**
8
+ * Person who can approve access requests
9
+ */
10
+ export interface Person {
11
+ firstName: string;
12
+ lastName: string;
13
+ email: string;
14
+ slack?: string;
15
+ }
16
+ /**
17
+ * Approval type for UI selection
18
+ */
19
+ export type ApprovalType = 'none' | 'service' | 'person' | 'other' | 'unknown';
20
+ /**
21
+ * Approval type options for UI display
22
+ */
23
+ export declare const APPROVAL_TYPES: ReadonlyArray<{
24
+ value: ApprovalType;
25
+ label: string;
26
+ }>;
27
+ /**
28
+ * Common fields for all approval method types
29
+ */
30
+ export interface BaseApprovalMethod {
31
+ comment?: string;
32
+ roles?: Array<AppRole>;
33
+ approvalPolicy?: string;
34
+ postApprovalInstructions?: string;
35
+ seeMoreUrls?: Array<string>;
36
+ }
37
+ /**
38
+ * Service-based approval (bot or ticketing system)
39
+ */
40
+ export interface ServiceApprovalMethod extends BaseApprovalMethod {
41
+ type: 'service';
42
+ serviceId: string;
43
+ url?: string;
44
+ prompt?: string;
45
+ requestFormTemplate?: string;
46
+ }
47
+ /**
48
+ * Person-based approval
49
+ */
50
+ export interface PersonApprovalMethod extends BaseApprovalMethod {
51
+ type: 'person';
52
+ person: Person;
53
+ url?: string;
54
+ additionalInfo?: string;
55
+ }
56
+ /**
57
+ * Other/custom approval method (TBC)
58
+ */
59
+ export interface OtherApprovalMethod extends BaseApprovalMethod {
60
+ type: 'other';
61
+ description: string;
62
+ }
63
+ /**
64
+ * Unknown approval method
65
+ */
66
+ export interface UnknownApprovalMethod extends BaseApprovalMethod {
67
+ type: 'unknown';
68
+ }
69
+ /**
70
+ * No approval needed
71
+ */
72
+ export interface NoneApprovalMethod {
73
+ type: 'none';
74
+ }
75
+ /**
76
+ * Union of all approval method types
77
+ */
78
+ export type ApprovalMethod = NoneApprovalMethod | ServiceApprovalMethod | PersonApprovalMethod | OtherApprovalMethod | UnknownApprovalMethod;
79
+ /**
80
+ * Service approval configuration - unified bot and ticketing systems
81
+ */
82
+ export interface ServiceApproval {
83
+ id: string;
84
+ name: string;
85
+ serviceType: 'bot' | 'ticket';
86
+ platform?: 'slack' | 'teams' | 'web' | 'other';
87
+ system?: 'jira' | 'servicenow' | 'zendesk' | 'freshdesk' | 'other';
88
+ baseUrl?: string;
89
+ url?: string;
90
+ icon?: string;
91
+ instructions?: string;
92
+ }
93
+ /**
94
+ * Role that can be requested for an app
95
+ */
96
+ export interface AppRole {
97
+ name: string;
98
+ description?: string;
99
+ }
100
+ /**
101
+ * Application entry in the catalog
102
+ */
103
+ export interface AppForCatalog {
104
+ id: string;
105
+ slug: string;
106
+ displayName: string;
107
+ description?: string;
108
+ approvalMethod?: ApprovalMethod;
109
+ teams?: Array<string>;
110
+ notes?: string;
111
+ tags?: Array<string>;
112
+ appUrl?: string;
113
+ links?: Array<{
114
+ url: string;
115
+ title?: string;
116
+ }>;
117
+ iconName?: string;
118
+ screenshotIds?: Array<string>;
119
+ }
120
+ export interface AppCategory {
121
+ id: string;
122
+ name: string;
123
+ }
124
+ export interface AppCatalogData {
125
+ apps: Array<AppForCatalog>;
126
+ categories: Array<AppCategory>;
127
+ }
@@ -0,0 +1 @@
1
+ export * from './nullToUndefined.js';
@@ -0,0 +1,6 @@
1
+ import { nullToUndefined, undefinedToNull } from "./nullToUndefined.js";
2
+ export {
3
+ nullToUndefined,
4
+ undefinedToNull
5
+ };
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,21 @@
1
+ import { Primitive } from 'type-fest';
2
+ export type NullToUndefined<T> = T extends null ? undefined : T extends Primitive | Function | Date | RegExp ? T : T extends Array<infer U> ? Array<NullToUndefined<U>> : T extends Map<infer K, infer V> ? Map<K, NullToUndefined<V>> : T extends Set<infer U> ? Set<NullToUndefined<U>> : T extends object ? {
3
+ [K in keyof T]: NullToUndefined<T[K]>;
4
+ } : unknown;
5
+ export type UndefinedToNull<T> = T extends undefined ? null : T extends Primitive | Function | Date | RegExp ? T : T extends Array<infer U> ? Array<UndefinedToNull<U>> : T extends Map<infer K, infer V> ? Map<K, UndefinedToNull<V>> : T extends Set<infer U> ? Set<NullToUndefined<U>> : T extends object ? {
6
+ [K in keyof T]: UndefinedToNull<T[K]>;
7
+ } : unknown;
8
+ /**
9
+ * Recursively converts all null values to undefined.
10
+ *
11
+ * @param obj object to convert
12
+ * @returns a copy of the object with all its null values converted to undefined
13
+ */
14
+ export declare function nullToUndefined<T>(obj: T): NullToUndefined<T>;
15
+ /**
16
+ * Recursively converts all undefined values to null.
17
+ *
18
+ * @param obj object to convert
19
+ * @returns a copy of the object with all its undefined values converted to null
20
+ */
21
+ export declare function undefinedToNull<T>(obj: T): UndefinedToNull<T>;
@@ -0,0 +1,41 @@
1
+ function _nullToUndefined(obj) {
2
+ if (obj === null) {
3
+ return void 0;
4
+ }
5
+ if (typeof obj === "object") {
6
+ if (obj instanceof Map) {
7
+ obj.forEach((value, key) => obj.set(key, _nullToUndefined(value)));
8
+ } else {
9
+ for (const key in obj) {
10
+ obj[key] = _nullToUndefined(obj[key]);
11
+ }
12
+ }
13
+ }
14
+ return obj;
15
+ }
16
+ function nullToUndefined(obj) {
17
+ return _nullToUndefined(structuredClone(obj));
18
+ }
19
+ function _undefinedToNull(obj) {
20
+ if (obj === void 0) {
21
+ return null;
22
+ }
23
+ if (typeof obj === "object") {
24
+ if (obj instanceof Map) {
25
+ obj.forEach((value, key) => obj.set(key, _undefinedToNull(value)));
26
+ } else {
27
+ for (const key in obj) {
28
+ obj[key] = _undefinedToNull(obj[key]);
29
+ }
30
+ }
31
+ }
32
+ return obj;
33
+ }
34
+ function undefinedToNull(obj) {
35
+ return _undefinedToNull(structuredClone(obj));
36
+ }
37
+ export {
38
+ nullToUndefined,
39
+ undefinedToNull
40
+ };
41
+ //# sourceMappingURL=nullToUndefined.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nullToUndefined.js","sources":["../../src/nullToUndefined.ts"],"sourcesContent":["import type { Primitive } from 'type-fest'\n\n/*\n Taken from https://gist.github.com/tkrotoff/a6baf96eb6b61b445a9142e5555511a0\n * [Generic way to convert all instances of null to undefined in TypeScript](https://stackoverflow.com/q/50374869)\n *\n * This only works with JS objects hence the file name *Object*Values\n *\n * [\"I intend to stop using `null` in my JS code in favor of `undefined`\"](https://github.com/sindresorhus/meta/discussions/7)\n * [Proposal: NullToUndefined and UndefinedToNull](https://github.com/sindresorhus/type-fest/issues/603)\n *\n * Types implementation inspired by:\n * - https://github.com/sindresorhus/type-fest/blob/v2.12.2/source/delimiter-cased-properties-deep.d.ts\n * - https://github.com/sindresorhus/type-fest/blob/v2.12.2/source/readonly-deep.d.ts\n *\n * https://gist.github.com/tkrotoff/a6baf96eb6b61b445a9142e5555511a0\n */\nexport type NullToUndefined<T> = T extends null\n ? undefined\n : T extends Primitive | Function | Date | RegExp\n ? T\n : T extends Array<infer U>\n ? Array<NullToUndefined<U>>\n : T extends Map<infer K, infer V>\n ? Map<K, NullToUndefined<V>>\n : T extends Set<infer U>\n ? Set<NullToUndefined<U>>\n : T extends object\n ? { [K in keyof T]: NullToUndefined<T[K]> }\n : unknown\n\nexport type UndefinedToNull<T> = T extends undefined\n ? null\n : T extends Primitive | Function | Date | RegExp\n ? T\n : T extends Array<infer U>\n ? Array<UndefinedToNull<U>>\n : T extends Map<infer K, infer V>\n ? Map<K, UndefinedToNull<V>>\n : T extends Set<infer U>\n ? Set<NullToUndefined<U>>\n : T extends object\n ? { [K in keyof T]: UndefinedToNull<T[K]> }\n : unknown\n\nfunction _nullToUndefined<T>(obj: T): NullToUndefined<T> {\n if (obj === null) {\n return undefined as any\n }\n\n if (typeof obj === 'object') {\n if (obj instanceof Map) {\n obj.forEach((value, key) => obj.set(key, _nullToUndefined(value)))\n } else {\n for (const key in obj) {\n obj[key] = _nullToUndefined(obj[key]) as any\n }\n }\n }\n\n return obj as any\n}\n\n/**\n * Recursively converts all null values to undefined.\n *\n * @param obj object to convert\n * @returns a copy of the object with all its null values converted to undefined\n */\nexport function nullToUndefined<\n T,\n // Can cause: \"Type instantiation is excessively deep and possibly infinite.\"\n // extends Jsonifiable\n>(obj: T) {\n return _nullToUndefined(structuredClone(obj))\n}\n\nfunction _undefinedToNull<T>(obj: T): UndefinedToNull<T> {\n if (obj === undefined) {\n return null as any\n }\n\n if (typeof obj === 'object') {\n if (obj instanceof Map) {\n obj.forEach((value, key) => obj.set(key, _undefinedToNull(value)))\n } else {\n for (const key in obj) {\n obj[key] = _undefinedToNull(obj[key]) as any\n }\n }\n }\n\n return obj as any\n}\n\n/**\n * Recursively converts all undefined values to null.\n *\n * @param obj object to convert\n * @returns a copy of the object with all its undefined values converted to null\n */\nexport function undefinedToNull<\n T,\n // Can cause: \"Type instantiation is excessively deep and possibly infinite.\"\n // extends Jsonifiable\n>(obj: T) {\n return _undefinedToNull(structuredClone(obj))\n}\n"],"names":[],"mappings":"AA6CA,SAAS,iBAAoB,KAA4B;AACvD,MAAI,QAAQ,MAAM;AAChB,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,QAAQ,UAAU;AAC3B,QAAI,eAAe,KAAK;AACtB,UAAI,QAAQ,CAAC,OAAO,QAAQ,IAAI,IAAI,KAAK,iBAAiB,KAAK,CAAC,CAAC;AAAA,IACnE,OAAO;AACL,iBAAW,OAAO,KAAK;AACrB,YAAI,GAAG,IAAI,iBAAiB,IAAI,GAAG,CAAC;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAQO,SAAS,gBAId,KAAQ;AACR,SAAO,iBAAiB,gBAAgB,GAAG,CAAC;AAC9C;AAEA,SAAS,iBAAoB,KAA4B;AACvD,MAAI,QAAQ,QAAW;AACrB,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,QAAQ,UAAU;AAC3B,QAAI,eAAe,KAAK;AACtB,UAAI,QAAQ,CAAC,OAAO,QAAQ,IAAI,IAAI,KAAK,iBAAiB,KAAK,CAAC,CAAC;AAAA,IACnE,OAAO;AACL,iBAAW,OAAO,KAAK;AACrB,YAAI,GAAG,IAAI,iBAAiB,IAAI,GAAG,CAAC;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAQO,SAAS,gBAId,KAAQ;AACR,SAAO,iBAAiB,gBAAgB,GAAG,CAAC;AAC9C;"}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@igstack/app-catalog-shared-core",
3
+ "version": "0.0.1",
4
+ "description": "Shared core utilities for App Catalog",
5
+ "homepage": "https://github.com/lislon/app-catalog",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/lislon/app-catalog.git",
9
+ "directory": "packages/shared-core"
10
+ },
11
+ "license": "MIT",
12
+ "author": "Igor Golovin",
13
+ "sideEffects": false,
14
+ "type": "module",
15
+ "exports": {
16
+ ".": {
17
+ "my-custom-condition": "./src/index.ts",
18
+ "import": {
19
+ "types": "./dist/esm/index.d.ts",
20
+ "default": "./dist/esm/index.js"
21
+ }
22
+ },
23
+ "./package.json": "./package.json"
24
+ },
25
+ "module": "dist/esm/index.js",
26
+ "types": "dist/esm/index.d.ts",
27
+ "files": [
28
+ "dist",
29
+ "src"
30
+ ],
31
+ "dependencies": {
32
+ "eta": "^3.5.0",
33
+ "type-fest": "^5.4.4"
34
+ },
35
+ "devDependencies": {
36
+ "@tanstack/vite-config": "^0.4.3",
37
+ "@types/node": "^24.3.0",
38
+ "esbuild": "^0.25.5",
39
+ "tsx": "^4.19.4",
40
+ "typescript": "5.9.2"
41
+ },
42
+ "engines": {
43
+ "node": ">=16"
44
+ },
45
+ "scripts": {
46
+ "build": "vite build",
47
+ "clean": "premove ./dist ./coverage ./dist-ts",
48
+ "compile": "tsc --build",
49
+ "dev": "tsx watch src/index.ts",
50
+ "test:eslint": "eslint ./src",
51
+ "test:unit": "vitest",
52
+ "test:unit:dev": "pnpm run test:unit --watch"
53
+ }
54
+ }
@@ -0,0 +1,7 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ describe('dummy', () => {
4
+ it('always passes', () => {
5
+ expect(true).toBe(true)
6
+ })
7
+ })
@@ -0,0 +1,173 @@
1
+ /**
2
+ * App Catalog Types - Universal Software Access Request Catalog
3
+ *
4
+ * These types define a standardized catalog of software applications and their
5
+ * access/approval methods. The typing system is designed to be universal across companies.
6
+ */
7
+
8
+ // ============================================================================
9
+ // PERSON TYPE
10
+ // ============================================================================
11
+
12
+ /**
13
+ * Person who can approve access requests
14
+ */
15
+ export interface Person {
16
+ firstName: string
17
+ lastName: string
18
+ email: string
19
+ slack?: string
20
+ }
21
+
22
+ // ============================================================================
23
+ // APPROVAL METHOD TYPES
24
+ // ============================================================================
25
+
26
+ /**
27
+ * Approval type for UI selection
28
+ */
29
+ export type ApprovalType = 'none' | 'service' | 'person' | 'other' | 'unknown'
30
+
31
+ /**
32
+ * Approval type options for UI display
33
+ */
34
+ export const APPROVAL_TYPES: ReadonlyArray<{
35
+ value: ApprovalType
36
+ label: string
37
+ }> = [
38
+ { value: 'none', label: 'None' },
39
+ { value: 'service', label: 'Service' },
40
+ { value: 'person', label: 'Person' },
41
+ { value: 'other', label: 'Other' },
42
+ { value: 'unknown', label: 'Unknown' },
43
+ ]
44
+
45
+ /**
46
+ * Common fields for all approval method types
47
+ */
48
+ export interface BaseApprovalMethod {
49
+ comment?: string
50
+ roles?: Array<AppRole>
51
+ approvalPolicy?: string
52
+ postApprovalInstructions?: string
53
+ seeMoreUrls?: Array<string>
54
+ }
55
+
56
+ /**
57
+ * Service-based approval (bot or ticketing system)
58
+ */
59
+ export interface ServiceApprovalMethod extends BaseApprovalMethod {
60
+ type: 'service'
61
+ serviceId: string // References a specific service (bot or ticket system)
62
+ url?: string
63
+ prompt?: string // For bots
64
+ requestFormTemplate?: string // For ticket systems
65
+ }
66
+
67
+ /**
68
+ * Person-based approval
69
+ */
70
+ export interface PersonApprovalMethod extends BaseApprovalMethod {
71
+ type: 'person'
72
+ person: Person // Person details embedded directly
73
+ url?: string
74
+ additionalInfo?: string
75
+ }
76
+
77
+ /**
78
+ * Other/custom approval method (TBC)
79
+ */
80
+ export interface OtherApprovalMethod extends BaseApprovalMethod {
81
+ type: 'other'
82
+ description: string // Free-form text description
83
+ }
84
+
85
+ /**
86
+ * Unknown approval method
87
+ */
88
+ export interface UnknownApprovalMethod extends BaseApprovalMethod {
89
+ type: 'unknown'
90
+ }
91
+
92
+ /**
93
+ * No approval needed
94
+ */
95
+ export interface NoneApprovalMethod {
96
+ type: 'none'
97
+ }
98
+
99
+ /**
100
+ * Union of all approval method types
101
+ */
102
+ export type ApprovalMethod =
103
+ | NoneApprovalMethod
104
+ | ServiceApprovalMethod
105
+ | PersonApprovalMethod
106
+ | OtherApprovalMethod
107
+ | UnknownApprovalMethod
108
+
109
+ // ============================================================================
110
+ // SERVICE APPROVAL TYPES (BOT & TICKETING)
111
+ // ============================================================================
112
+
113
+ /**
114
+ * Service approval configuration - unified bot and ticketing systems
115
+ */
116
+ export interface ServiceApproval {
117
+ id: string
118
+ name: string
119
+ serviceType: 'bot' | 'ticket'
120
+ // Bot-specific fields
121
+ platform?: 'slack' | 'teams' | 'web' | 'other'
122
+ // Ticket-specific fields
123
+ system?: 'jira' | 'servicenow' | 'zendesk' | 'freshdesk' | 'other'
124
+ baseUrl?: string
125
+ url?: string
126
+ icon?: string
127
+ instructions?: string
128
+ }
129
+
130
+ // ============================================================================
131
+ // ROLE TYPE
132
+ // ============================================================================
133
+
134
+ /**
135
+ * Role that can be requested for an app
136
+ */
137
+ export interface AppRole {
138
+ name: string
139
+ description?: string
140
+ }
141
+
142
+ // ============================================================================
143
+ // APP CATALOG TYPES
144
+ // ============================================================================
145
+
146
+ /**
147
+ * Application entry in the catalog
148
+ */
149
+ export interface AppForCatalog {
150
+ id: string
151
+ slug: string
152
+ displayName: string
153
+ description?: string
154
+ approvalMethod?: ApprovalMethod
155
+ teams?: Array<string> // Teams that use this app
156
+ notes?: string
157
+ tags?: Array<string>
158
+ appUrl?: string
159
+ links?: Array<{ url: string; title?: string }>
160
+ iconName?: string
161
+ screenshotIds?: Array<string>
162
+ }
163
+
164
+ // Derived catalog data returned by backend
165
+ export interface AppCategory {
166
+ id: string
167
+ name: string
168
+ }
169
+
170
+ export interface AppCatalogData {
171
+ apps: Array<AppForCatalog>
172
+ categories: Array<AppCategory>
173
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './nullToUndefined'
@@ -0,0 +1,108 @@
1
+ import type { Primitive } from 'type-fest'
2
+
3
+ /*
4
+ Taken from https://gist.github.com/tkrotoff/a6baf96eb6b61b445a9142e5555511a0
5
+ * [Generic way to convert all instances of null to undefined in TypeScript](https://stackoverflow.com/q/50374869)
6
+ *
7
+ * This only works with JS objects hence the file name *Object*Values
8
+ *
9
+ * ["I intend to stop using `null` in my JS code in favor of `undefined`"](https://github.com/sindresorhus/meta/discussions/7)
10
+ * [Proposal: NullToUndefined and UndefinedToNull](https://github.com/sindresorhus/type-fest/issues/603)
11
+ *
12
+ * Types implementation inspired by:
13
+ * - https://github.com/sindresorhus/type-fest/blob/v2.12.2/source/delimiter-cased-properties-deep.d.ts
14
+ * - https://github.com/sindresorhus/type-fest/blob/v2.12.2/source/readonly-deep.d.ts
15
+ *
16
+ * https://gist.github.com/tkrotoff/a6baf96eb6b61b445a9142e5555511a0
17
+ */
18
+ export type NullToUndefined<T> = T extends null
19
+ ? undefined
20
+ : T extends Primitive | Function | Date | RegExp
21
+ ? T
22
+ : T extends Array<infer U>
23
+ ? Array<NullToUndefined<U>>
24
+ : T extends Map<infer K, infer V>
25
+ ? Map<K, NullToUndefined<V>>
26
+ : T extends Set<infer U>
27
+ ? Set<NullToUndefined<U>>
28
+ : T extends object
29
+ ? { [K in keyof T]: NullToUndefined<T[K]> }
30
+ : unknown
31
+
32
+ export type UndefinedToNull<T> = T extends undefined
33
+ ? null
34
+ : T extends Primitive | Function | Date | RegExp
35
+ ? T
36
+ : T extends Array<infer U>
37
+ ? Array<UndefinedToNull<U>>
38
+ : T extends Map<infer K, infer V>
39
+ ? Map<K, UndefinedToNull<V>>
40
+ : T extends Set<infer U>
41
+ ? Set<NullToUndefined<U>>
42
+ : T extends object
43
+ ? { [K in keyof T]: UndefinedToNull<T[K]> }
44
+ : unknown
45
+
46
+ function _nullToUndefined<T>(obj: T): NullToUndefined<T> {
47
+ if (obj === null) {
48
+ return undefined as any
49
+ }
50
+
51
+ if (typeof obj === 'object') {
52
+ if (obj instanceof Map) {
53
+ obj.forEach((value, key) => obj.set(key, _nullToUndefined(value)))
54
+ } else {
55
+ for (const key in obj) {
56
+ obj[key] = _nullToUndefined(obj[key]) as any
57
+ }
58
+ }
59
+ }
60
+
61
+ return obj as any
62
+ }
63
+
64
+ /**
65
+ * Recursively converts all null values to undefined.
66
+ *
67
+ * @param obj object to convert
68
+ * @returns a copy of the object with all its null values converted to undefined
69
+ */
70
+ export function nullToUndefined<
71
+ T,
72
+ // Can cause: "Type instantiation is excessively deep and possibly infinite."
73
+ // extends Jsonifiable
74
+ >(obj: T) {
75
+ return _nullToUndefined(structuredClone(obj))
76
+ }
77
+
78
+ function _undefinedToNull<T>(obj: T): UndefinedToNull<T> {
79
+ if (obj === undefined) {
80
+ return null as any
81
+ }
82
+
83
+ if (typeof obj === 'object') {
84
+ if (obj instanceof Map) {
85
+ obj.forEach((value, key) => obj.set(key, _undefinedToNull(value)))
86
+ } else {
87
+ for (const key in obj) {
88
+ obj[key] = _undefinedToNull(obj[key]) as any
89
+ }
90
+ }
91
+ }
92
+
93
+ return obj as any
94
+ }
95
+
96
+ /**
97
+ * Recursively converts all undefined values to null.
98
+ *
99
+ * @param obj object to convert
100
+ * @returns a copy of the object with all its undefined values converted to null
101
+ */
102
+ export function undefinedToNull<
103
+ T,
104
+ // Can cause: "Type instantiation is excessively deep and possibly infinite."
105
+ // extends Jsonifiable
106
+ >(obj: T) {
107
+ return _undefinedToNull(structuredClone(obj))
108
+ }