@forklaunch/common 0.2.10 → 0.3.0

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/lib/index.d.mts CHANGED
@@ -13,6 +13,8 @@ declare function extractArgumentNames(func: {
13
13
  toString(): string;
14
14
  }): string[];
15
15
 
16
+ declare function isAsyncGenerator<T>(value: unknown): value is AsyncGenerator<T>;
17
+
16
18
  /**
17
19
  * Type guard that checks if a value is of type never
18
20
  * @param value - The value to check
@@ -20,6 +22,8 @@ declare function extractArgumentNames(func: {
20
22
  */
21
23
  declare function isNever(value: never): value is never;
22
24
 
25
+ declare function isNodeJsWriteableStream(value: unknown): value is NodeJS.WritableStream;
26
+
23
27
  /**
24
28
  * Check if the given object is a record.
25
29
  *
@@ -42,6 +46,15 @@ declare function isRecord(obj: unknown): obj is Record<string, unknown>;
42
46
  */
43
47
  declare function isTrue(value: true): true;
44
48
 
49
+ declare class InMemoryFile extends File {
50
+ content: string;
51
+ constructor(content: string, name: string, { type, endings, lastModified }: {
52
+ type?: string;
53
+ endings?: 'transparent' | 'native';
54
+ lastModified?: number;
55
+ });
56
+ }
57
+
45
58
  /**
46
59
  * A no-operation function that does nothing when called.
47
60
  * This is commonly used as a default or placeholder function
@@ -55,11 +68,14 @@ declare function isTrue(value: true): true;
55
68
  * }
56
69
  * ```
57
70
  */
58
- declare function noop(): void;
71
+ declare function noop(..._args: unknown[]): void;
72
+
73
+ declare function readableStreamToAsyncIterable<T>(stream: ReadableStream<T>): AsyncIterable<T>;
74
+
75
+ declare function safeParse<T>(input: unknown): T;
59
76
 
60
77
  /**
61
78
  * Safely stringifies any JavaScript value, handling special cases like:
62
- * - Circular references
63
79
  * - Error objects
64
80
  * - BigInt
65
81
  * - Functions
@@ -74,11 +90,6 @@ declare function noop(): void;
74
90
  *
75
91
  * @example
76
92
  * ```typescript
77
- * // Handle circular references
78
- * const circular = { a: 1 };
79
- * circular.self = circular;
80
- * safeStringify(circular); // '{"a":1,"self":"[Circular Reference]"}'
81
- *
82
93
  * // Handle Error objects
83
94
  * safeStringify(new Error("test")); // '{"name":"Error","message":"test","stack":"..."}'
84
95
  *
@@ -160,6 +171,8 @@ type InstanceTypeRecord<T extends Record<string, new (...args: never[]) => unkno
160
171
  [K in keyof T]: InstanceType<T[K]>;
161
172
  };
162
173
 
174
+ type ExclusiveRecord<T, U> = T extends object ? U extends object ? T & Record<Exclude<keyof T, keyof U>, never> : T : T;
175
+
163
176
  /**
164
177
  * A type that represents the values of an object type `T`.
165
178
  *
@@ -215,6 +228,8 @@ type MakePropertyOptionalIfChildrenOptional<T> = {
215
228
  [K in keyof T as AllPropertiesOptional<T[K]> extends true ? never : K]: T[K];
216
229
  };
217
230
 
231
+ type MimeType = 'application/json' | 'application/xml' | 'application/x-www-form-urlencoded' | 'multipart/form-data' | 'text/html' | 'text/plain' | 'image/jpeg' | 'image/png' | 'video/mp4' | 'audio/mpeg' | 'application/pdf' | 'application/zip' | 'application/octet-stream' | string;
232
+
218
233
  /**
219
234
  * A type that "prettifies" the structure of an object type `T`.
220
235
  *
@@ -238,4 +253,8 @@ type Prettify<T> = {
238
253
  */
239
254
  type RemoveTrailingSlash<T extends string> = T extends `${infer Route}/` ? Route : T;
240
255
 
241
- export { type Flatten, type FlattenKeys, type FlattenValues, type IdDto, type IdsDto, type InstanceTypeRecord, type MakePropertyOptionalIfChildrenOptional, type Prettify, type RecordTimingDto, type RemoveTrailingSlash, type ReturnTypeRecord, extractArgumentNames, isNever, isRecord, isTrue, noop, safeStringify, sortObjectKeys, stripUndefinedProperties };
256
+ type TypeSafeFunction = (...args: never[]) => unknown;
257
+
258
+ type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
259
+
260
+ export { type ExclusiveRecord, type Flatten, type FlattenKeys, type FlattenValues, type IdDto, type IdsDto, InMemoryFile, type InstanceTypeRecord, type MakePropertyOptionalIfChildrenOptional, type MimeType, type Prettify, type RecordTimingDto, type RemoveTrailingSlash, type ReturnTypeRecord, type TypeSafeFunction, type UnionToIntersection, extractArgumentNames, isAsyncGenerator, isNever, isNodeJsWriteableStream, isRecord, isTrue, noop, readableStreamToAsyncIterable, safeParse, safeStringify, sortObjectKeys, stripUndefinedProperties };
package/lib/index.d.ts CHANGED
@@ -13,6 +13,8 @@ declare function extractArgumentNames(func: {
13
13
  toString(): string;
14
14
  }): string[];
15
15
 
16
+ declare function isAsyncGenerator<T>(value: unknown): value is AsyncGenerator<T>;
17
+
16
18
  /**
17
19
  * Type guard that checks if a value is of type never
18
20
  * @param value - The value to check
@@ -20,6 +22,8 @@ declare function extractArgumentNames(func: {
20
22
  */
21
23
  declare function isNever(value: never): value is never;
22
24
 
25
+ declare function isNodeJsWriteableStream(value: unknown): value is NodeJS.WritableStream;
26
+
23
27
  /**
24
28
  * Check if the given object is a record.
25
29
  *
@@ -42,6 +46,15 @@ declare function isRecord(obj: unknown): obj is Record<string, unknown>;
42
46
  */
43
47
  declare function isTrue(value: true): true;
44
48
 
49
+ declare class InMemoryFile extends File {
50
+ content: string;
51
+ constructor(content: string, name: string, { type, endings, lastModified }: {
52
+ type?: string;
53
+ endings?: 'transparent' | 'native';
54
+ lastModified?: number;
55
+ });
56
+ }
57
+
45
58
  /**
46
59
  * A no-operation function that does nothing when called.
47
60
  * This is commonly used as a default or placeholder function
@@ -55,11 +68,14 @@ declare function isTrue(value: true): true;
55
68
  * }
56
69
  * ```
57
70
  */
58
- declare function noop(): void;
71
+ declare function noop(..._args: unknown[]): void;
72
+
73
+ declare function readableStreamToAsyncIterable<T>(stream: ReadableStream<T>): AsyncIterable<T>;
74
+
75
+ declare function safeParse<T>(input: unknown): T;
59
76
 
60
77
  /**
61
78
  * Safely stringifies any JavaScript value, handling special cases like:
62
- * - Circular references
63
79
  * - Error objects
64
80
  * - BigInt
65
81
  * - Functions
@@ -74,11 +90,6 @@ declare function noop(): void;
74
90
  *
75
91
  * @example
76
92
  * ```typescript
77
- * // Handle circular references
78
- * const circular = { a: 1 };
79
- * circular.self = circular;
80
- * safeStringify(circular); // '{"a":1,"self":"[Circular Reference]"}'
81
- *
82
93
  * // Handle Error objects
83
94
  * safeStringify(new Error("test")); // '{"name":"Error","message":"test","stack":"..."}'
84
95
  *
@@ -160,6 +171,8 @@ type InstanceTypeRecord<T extends Record<string, new (...args: never[]) => unkno
160
171
  [K in keyof T]: InstanceType<T[K]>;
161
172
  };
162
173
 
174
+ type ExclusiveRecord<T, U> = T extends object ? U extends object ? T & Record<Exclude<keyof T, keyof U>, never> : T : T;
175
+
163
176
  /**
164
177
  * A type that represents the values of an object type `T`.
165
178
  *
@@ -215,6 +228,8 @@ type MakePropertyOptionalIfChildrenOptional<T> = {
215
228
  [K in keyof T as AllPropertiesOptional<T[K]> extends true ? never : K]: T[K];
216
229
  };
217
230
 
231
+ type MimeType = 'application/json' | 'application/xml' | 'application/x-www-form-urlencoded' | 'multipart/form-data' | 'text/html' | 'text/plain' | 'image/jpeg' | 'image/png' | 'video/mp4' | 'audio/mpeg' | 'application/pdf' | 'application/zip' | 'application/octet-stream' | string;
232
+
218
233
  /**
219
234
  * A type that "prettifies" the structure of an object type `T`.
220
235
  *
@@ -238,4 +253,8 @@ type Prettify<T> = {
238
253
  */
239
254
  type RemoveTrailingSlash<T extends string> = T extends `${infer Route}/` ? Route : T;
240
255
 
241
- export { type Flatten, type FlattenKeys, type FlattenValues, type IdDto, type IdsDto, type InstanceTypeRecord, type MakePropertyOptionalIfChildrenOptional, type Prettify, type RecordTimingDto, type RemoveTrailingSlash, type ReturnTypeRecord, extractArgumentNames, isNever, isRecord, isTrue, noop, safeStringify, sortObjectKeys, stripUndefinedProperties };
256
+ type TypeSafeFunction = (...args: never[]) => unknown;
257
+
258
+ type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
259
+
260
+ export { type ExclusiveRecord, type Flatten, type FlattenKeys, type FlattenValues, type IdDto, type IdsDto, InMemoryFile, type InstanceTypeRecord, type MakePropertyOptionalIfChildrenOptional, type MimeType, type Prettify, type RecordTimingDto, type RemoveTrailingSlash, type ReturnTypeRecord, type TypeSafeFunction, type UnionToIntersection, extractArgumentNames, isAsyncGenerator, isNever, isNodeJsWriteableStream, isRecord, isTrue, noop, readableStreamToAsyncIterable, safeParse, safeStringify, sortObjectKeys, stripUndefinedProperties };
package/lib/index.js CHANGED
@@ -20,11 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ InMemoryFile: () => InMemoryFile,
23
24
  extractArgumentNames: () => extractArgumentNames,
25
+ isAsyncGenerator: () => isAsyncGenerator,
24
26
  isNever: () => isNever,
27
+ isNodeJsWriteableStream: () => isNodeJsWriteableStream,
25
28
  isRecord: () => isRecord,
26
29
  isTrue: () => isTrue,
27
30
  noop: () => noop,
31
+ readableStreamToAsyncIterable: () => readableStreamToAsyncIterable,
32
+ safeParse: () => safeParse,
28
33
  safeStringify: () => safeStringify,
29
34
  sortObjectKeys: () => sortObjectKeys,
30
35
  stripUndefinedProperties: () => stripUndefinedProperties
@@ -59,11 +64,21 @@ function extractArgumentNames(func) {
59
64
  return result;
60
65
  }
61
66
 
67
+ // src/guards/isAsyncGenerator.ts
68
+ function isAsyncGenerator(value) {
69
+ return value != null && typeof value === "object" && "next" in value && typeof value.next === "function" && "return" in value && typeof value.return === "function" && "throw" in value && typeof value.throw === "function";
70
+ }
71
+
62
72
  // src/guards/isNever.ts
63
73
  function isNever(value) {
64
74
  return true;
65
75
  }
66
76
 
77
+ // src/guards/isNodeJsWriteableStream.ts
78
+ function isNodeJsWriteableStream(value) {
79
+ return value != null && typeof value === "object" && "write" in value && typeof value.write === "function" && "end" in value && typeof value.end === "function";
80
+ }
81
+
67
82
  // src/guards/isRecord.ts
68
83
  function isRecord(obj) {
69
84
  return obj !== null && typeof obj === "object" && !Array.isArray(obj);
@@ -74,8 +89,47 @@ function isTrue(value) {
74
89
  return value;
75
90
  }
76
91
 
92
+ // src/InMemoryFile.ts
93
+ var InMemoryFile = class extends File {
94
+ constructor(content, name, {
95
+ type,
96
+ endings,
97
+ lastModified
98
+ }) {
99
+ super([Buffer.from(content)], name, {
100
+ type,
101
+ endings,
102
+ lastModified
103
+ });
104
+ this.content = content;
105
+ }
106
+ };
107
+
77
108
  // src/noop.ts
78
- function noop() {
109
+ function noop(..._args) {
110
+ }
111
+
112
+ // src/readableStreamToAsyncIterable.ts
113
+ async function* readableStreamToAsyncIterable(stream) {
114
+ const reader = stream.getReader();
115
+ try {
116
+ while (true) {
117
+ const { value, done } = await reader.read();
118
+ if (done) break;
119
+ yield value;
120
+ }
121
+ } finally {
122
+ reader.releaseLock();
123
+ }
124
+ }
125
+
126
+ // src/safeParse.ts
127
+ function safeParse(input) {
128
+ try {
129
+ return JSON.parse(input);
130
+ } catch {
131
+ return input;
132
+ }
79
133
  }
80
134
 
81
135
  // src/safeStringify.ts
@@ -86,14 +140,7 @@ function safeStringify(arg) {
86
140
  if (arg == null) {
87
141
  return String(arg);
88
142
  }
89
- const seen = /* @__PURE__ */ new WeakSet();
90
143
  const replacer = (key, value) => {
91
- if (value && typeof value === "object") {
92
- if (seen.has(value)) {
93
- return "[Circular Reference]";
94
- }
95
- seen.add(value);
96
- }
97
144
  if (value instanceof Error) {
98
145
  return {
99
146
  name: value.name,
@@ -181,11 +228,16 @@ function stripUndefinedProperties(obj) {
181
228
  }
182
229
  // Annotate the CommonJS export names for ESM import in node:
183
230
  0 && (module.exports = {
231
+ InMemoryFile,
184
232
  extractArgumentNames,
233
+ isAsyncGenerator,
185
234
  isNever,
235
+ isNodeJsWriteableStream,
186
236
  isRecord,
187
237
  isTrue,
188
238
  noop,
239
+ readableStreamToAsyncIterable,
240
+ safeParse,
189
241
  safeStringify,
190
242
  sortObjectKeys,
191
243
  stripUndefinedProperties
package/lib/index.mjs CHANGED
@@ -26,11 +26,21 @@ function extractArgumentNames(func) {
26
26
  return result;
27
27
  }
28
28
 
29
+ // src/guards/isAsyncGenerator.ts
30
+ function isAsyncGenerator(value) {
31
+ return value != null && typeof value === "object" && "next" in value && typeof value.next === "function" && "return" in value && typeof value.return === "function" && "throw" in value && typeof value.throw === "function";
32
+ }
33
+
29
34
  // src/guards/isNever.ts
30
35
  function isNever(value) {
31
36
  return true;
32
37
  }
33
38
 
39
+ // src/guards/isNodeJsWriteableStream.ts
40
+ function isNodeJsWriteableStream(value) {
41
+ return value != null && typeof value === "object" && "write" in value && typeof value.write === "function" && "end" in value && typeof value.end === "function";
42
+ }
43
+
34
44
  // src/guards/isRecord.ts
35
45
  function isRecord(obj) {
36
46
  return obj !== null && typeof obj === "object" && !Array.isArray(obj);
@@ -41,8 +51,47 @@ function isTrue(value) {
41
51
  return value;
42
52
  }
43
53
 
54
+ // src/InMemoryFile.ts
55
+ var InMemoryFile = class extends File {
56
+ constructor(content, name, {
57
+ type,
58
+ endings,
59
+ lastModified
60
+ }) {
61
+ super([Buffer.from(content)], name, {
62
+ type,
63
+ endings,
64
+ lastModified
65
+ });
66
+ this.content = content;
67
+ }
68
+ };
69
+
44
70
  // src/noop.ts
45
- function noop() {
71
+ function noop(..._args) {
72
+ }
73
+
74
+ // src/readableStreamToAsyncIterable.ts
75
+ async function* readableStreamToAsyncIterable(stream) {
76
+ const reader = stream.getReader();
77
+ try {
78
+ while (true) {
79
+ const { value, done } = await reader.read();
80
+ if (done) break;
81
+ yield value;
82
+ }
83
+ } finally {
84
+ reader.releaseLock();
85
+ }
86
+ }
87
+
88
+ // src/safeParse.ts
89
+ function safeParse(input) {
90
+ try {
91
+ return JSON.parse(input);
92
+ } catch {
93
+ return input;
94
+ }
46
95
  }
47
96
 
48
97
  // src/safeStringify.ts
@@ -53,14 +102,7 @@ function safeStringify(arg) {
53
102
  if (arg == null) {
54
103
  return String(arg);
55
104
  }
56
- const seen = /* @__PURE__ */ new WeakSet();
57
105
  const replacer = (key, value) => {
58
- if (value && typeof value === "object") {
59
- if (seen.has(value)) {
60
- return "[Circular Reference]";
61
- }
62
- seen.add(value);
63
- }
64
106
  if (value instanceof Error) {
65
107
  return {
66
108
  name: value.name,
@@ -147,11 +189,16 @@ function stripUndefinedProperties(obj) {
147
189
  );
148
190
  }
149
191
  export {
192
+ InMemoryFile,
150
193
  extractArgumentNames,
194
+ isAsyncGenerator,
151
195
  isNever,
196
+ isNodeJsWriteableStream,
152
197
  isRecord,
153
198
  isTrue,
154
199
  noop,
200
+ readableStreamToAsyncIterable,
201
+ safeParse,
155
202
  safeStringify,
156
203
  sortObjectKeys,
157
204
  stripUndefinedProperties
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/common",
3
- "version": "0.2.10",
3
+ "version": "0.3.0",
4
4
  "description": "Common package for base types, interfaces, implementations.",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {
@@ -28,15 +28,16 @@
28
28
  "lib/**"
29
29
  ],
30
30
  "devDependencies": {
31
- "@eslint/js": "^9.24.0",
31
+ "@eslint/js": "^9.27.0",
32
+ "@types/node": "^22.15.21",
32
33
  "depcheck": "^1.4.7",
33
- "eslint": "^9.24.0",
34
- "globals": "^16.0.0",
35
- "tsup": "^8.4.0",
36
- "typedoc": "^0.28.2",
34
+ "eslint": "^9.27.0",
35
+ "globals": "^16.1.0",
36
+ "tsup": "^8.5.0",
37
+ "typedoc": "^0.28.4",
37
38
  "typescript": "^5.8.3",
38
- "typescript-eslint": "^8.30.1",
39
- "vitest": "^3.1.1"
39
+ "typescript-eslint": "^8.32.1",
40
+ "vitest": "^3.1.4"
40
41
  },
41
42
  "scripts": {
42
43
  "build": "tsc --noEmit && tsup index.ts --format cjs,esm --no-splitting --tsconfig tsconfig.json --outDir lib --dts --clean",