@standardserver/shared 0.0.12 → 0.0.16

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 ADDED
@@ -0,0 +1,25 @@
1
+ # @standardserver/shared
2
+
3
+ <div align="center">
4
+ <a href="https://codecov.io/gh/middleapi/standardserver">
5
+ <img alt="codecov" src="https://codecov.io/gh/middleapi/standardserver/branch/main/graph/badge.svg">
6
+ </a>
7
+ <a href="https://www.npmjs.com/package/@standardserver/shared">
8
+ <img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40standardserver%2Fshared?logo=npm" />
9
+ </a>
10
+ <a href="https://github.com/middleapi/standardserver/blob/main/LICENSE">
11
+ <img alt="MIT License" src="https://img.shields.io/github/license/middleapi/standardserver?logo=open-source-initiative" />
12
+ </a>
13
+ <a href="https://discord.gg/TXEbwRBvQn">
14
+ <img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
15
+ </a>
16
+ <a href="https://deepwiki.com/middleapi/standardserver">
17
+ <img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki">
18
+ </a>
19
+ </div>
20
+
21
+ This package contains shared types and utilities for the `@standardserver` ecosystem. It has no runtime dependencies and can be used in any JavaScript environment.
22
+
23
+ ## Learn more
24
+
25
+ For the higher-level project overview, see the root [Standard Server README](../../README.md).
package/dist/index.d.mts CHANGED
@@ -1,17 +1,5 @@
1
1
  declare function toArray<T>(value: T): T extends readonly any[] ? T : (T extends undefined | null ? never : T[]);
2
2
 
3
- declare const PACKAGE_NAME = "@standardserver/shared";
4
- declare const PACKAGE_VERSION = "0.0.12";
5
- /**
6
- * Generates a unique symbol for the specified name within the package scope.
7
- * The symbol is globally registered using `Symbol.for` to ensure consistency across modules.
8
- *
9
- * @remarks
10
- * - Ensure names are unique to avoid symbol collisions within the package.
11
- * - Ensure package versions are synchronized (e.g., when the core package is updated, this package should also be updated).
12
- */
13
- declare function getPackageSymbol(name: string): symbol;
14
-
15
3
  /**
16
4
  * Error thrown when an operation is aborted.
17
5
  * Uses the standardized 'AbortError' name for consistency with JavaScript APIs.
@@ -35,11 +23,18 @@ declare class SequentialIdGenerator {
35
23
  generate(): string;
36
24
  }
37
25
 
26
+ type AsyncCleanupFnState = {
27
+ kind: 'success';
28
+ error?: undefined;
29
+ } | {
30
+ kind: 'error';
31
+ error: unknown;
32
+ } | {
33
+ kind: 'cancelled';
34
+ error?: unknown;
35
+ };
38
36
  interface AsyncCleanupFn {
39
- (state: {
40
- isCancelled: boolean;
41
- error?: unknown;
42
- }): Promise<void>;
37
+ (state: AsyncCleanupFnState): Promise<void>;
43
38
  }
44
39
 
45
40
  declare function isAsyncIteratorObject(maybe: unknown): maybe is AsyncIteratorObject<any, any, any>;
@@ -126,5 +121,5 @@ declare function sleep(ms: number, { signal }?: SleepOptions): Promise<void>;
126
121
 
127
122
  declare function tryDecodeURIComponent(value: string): string;
128
123
 
129
- export { AbortError, AsyncIteratorClass, PACKAGE_NAME, PACKAGE_VERSION, Queue, SequentialIdGenerator, emitUnhandledRejection, getOrBind, getPackageSymbol, isAsyncIteratorObject, isTypescriptObject, omit, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray, tryDecodeURIComponent };
124
+ export { AbortError, AsyncIteratorClass, Queue, SequentialIdGenerator, emitUnhandledRejection, getOrBind, isAsyncIteratorObject, isTypescriptObject, omit, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray, tryDecodeURIComponent };
130
125
  export type { AsyncCleanupFn, AsyncIteratorClassNextFn, GetOrBindOptions, SleepOptions };
package/dist/index.d.ts CHANGED
@@ -1,17 +1,5 @@
1
1
  declare function toArray<T>(value: T): T extends readonly any[] ? T : (T extends undefined | null ? never : T[]);
2
2
 
3
- declare const PACKAGE_NAME = "@standardserver/shared";
4
- declare const PACKAGE_VERSION = "0.0.12";
5
- /**
6
- * Generates a unique symbol for the specified name within the package scope.
7
- * The symbol is globally registered using `Symbol.for` to ensure consistency across modules.
8
- *
9
- * @remarks
10
- * - Ensure names are unique to avoid symbol collisions within the package.
11
- * - Ensure package versions are synchronized (e.g., when the core package is updated, this package should also be updated).
12
- */
13
- declare function getPackageSymbol(name: string): symbol;
14
-
15
3
  /**
16
4
  * Error thrown when an operation is aborted.
17
5
  * Uses the standardized 'AbortError' name for consistency with JavaScript APIs.
@@ -35,11 +23,18 @@ declare class SequentialIdGenerator {
35
23
  generate(): string;
36
24
  }
37
25
 
26
+ type AsyncCleanupFnState = {
27
+ kind: 'success';
28
+ error?: undefined;
29
+ } | {
30
+ kind: 'error';
31
+ error: unknown;
32
+ } | {
33
+ kind: 'cancelled';
34
+ error?: unknown;
35
+ };
38
36
  interface AsyncCleanupFn {
39
- (state: {
40
- isCancelled: boolean;
41
- error?: unknown;
42
- }): Promise<void>;
37
+ (state: AsyncCleanupFnState): Promise<void>;
43
38
  }
44
39
 
45
40
  declare function isAsyncIteratorObject(maybe: unknown): maybe is AsyncIteratorObject<any, any, any>;
@@ -126,5 +121,5 @@ declare function sleep(ms: number, { signal }?: SleepOptions): Promise<void>;
126
121
 
127
122
  declare function tryDecodeURIComponent(value: string): string;
128
123
 
129
- export { AbortError, AsyncIteratorClass, PACKAGE_NAME, PACKAGE_VERSION, Queue, SequentialIdGenerator, emitUnhandledRejection, getOrBind, getPackageSymbol, isAsyncIteratorObject, isTypescriptObject, omit, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray, tryDecodeURIComponent };
124
+ export { AbortError, AsyncIteratorClass, Queue, SequentialIdGenerator, emitUnhandledRejection, getOrBind, isAsyncIteratorObject, isTypescriptObject, omit, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray, tryDecodeURIComponent };
130
125
  export type { AsyncCleanupFn, AsyncIteratorClassNextFn, GetOrBindOptions, SleepOptions };
package/dist/index.mjs CHANGED
@@ -2,12 +2,6 @@ function toArray(value) {
2
2
  return Array.isArray(value) ? value : value === void 0 || value === null ? [] : [value];
3
3
  }
4
4
 
5
- const PACKAGE_NAME = "@standardserver/shared";
6
- const PACKAGE_VERSION = "0.0.12";
7
- function getPackageSymbol(name) {
8
- return Symbol.for(`${PACKAGE_NAME}@${PACKAGE_VERSION}/${name}`);
9
- }
10
-
11
5
  class AbortError extends Error {
12
6
  constructor(...rest) {
13
7
  super(...rest);
@@ -72,7 +66,7 @@ class AsyncIteratorClass {
72
66
  } finally {
73
67
  if (this.isDone && !this.isExecuteComplete) {
74
68
  this.isExecuteComplete = true;
75
- await this.cleanup(errorRef ? { isCancelled: false, error: errorRef.value } : { isCancelled: false });
69
+ await this.cleanup(errorRef ? { kind: "error", error: errorRef.value } : { kind: "success" });
76
70
  }
77
71
  }
78
72
  });
@@ -81,7 +75,7 @@ class AsyncIteratorClass {
81
75
  this.isDone = true;
82
76
  if (!this.isExecuteComplete) {
83
77
  this.isExecuteComplete = true;
84
- await this.cleanup({ isCancelled: true });
78
+ await this.cleanup({ kind: "cancelled" });
85
79
  }
86
80
  return { done: true, value };
87
81
  }
@@ -89,7 +83,7 @@ class AsyncIteratorClass {
89
83
  this.isDone = true;
90
84
  if (!this.isExecuteComplete) {
91
85
  this.isExecuteComplete = true;
92
- await this.cleanup({ isCancelled: true, error });
86
+ await this.cleanup({ kind: "cancelled", error });
93
87
  }
94
88
  throw error;
95
89
  }
@@ -100,7 +94,7 @@ class AsyncIteratorClass {
100
94
  this.isDone = true;
101
95
  if (!this.isExecuteComplete) {
102
96
  this.isExecuteComplete = true;
103
- await this.cleanup({ isCancelled: true });
97
+ await this.cleanup({ kind: "cancelled" });
104
98
  }
105
99
  }
106
100
  [Symbol.asyncIterator]() {
@@ -240,4 +234,4 @@ function tryDecodeURIComponent(value) {
240
234
  }
241
235
  }
242
236
 
243
- export { AbortError, AsyncIteratorClass, PACKAGE_NAME, PACKAGE_VERSION, Queue, SequentialIdGenerator, emitUnhandledRejection, getOrBind, getPackageSymbol, isAsyncIteratorObject, isTypescriptObject, omit, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray, tryDecodeURIComponent };
237
+ export { AbortError, AsyncIteratorClass, Queue, SequentialIdGenerator, emitUnhandledRejection, getOrBind, isAsyncIteratorObject, isTypescriptObject, omit, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray, tryDecodeURIComponent };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@standardserver/shared",
3
3
  "type": "module",
4
- "version": "0.0.12",
4
+ "version": "0.0.16",
5
5
  "license": "MIT",
6
6
  "homepage": "https://standardserver.dev",
7
7
  "repository": {
@@ -11,6 +11,7 @@
11
11
  },
12
12
  "sideEffects": false,
13
13
  "exports": {
14
+ "./package.json": "./package.json",
14
15
  ".": {
15
16
  "types": "./dist/index.d.mts",
16
17
  "import": "./dist/index.mjs",