@open-pioneer/core 1.2.2 → 1.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/CHANGELOG.md +16 -0
- package/README.md +8 -6
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/resources.d.ts +9 -0
- package/resources.js +7 -1
- package/resources.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @open-pioneer/core
|
|
2
2
|
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 50550d3: Add `destroyResources(resources)` to destroy an array of resources.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 5c62522: Update wording and harmonize structure
|
|
12
|
+
|
|
13
|
+
## 1.2.3
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 5d3aafd: Harmonize references to Open Pioneer Trails in README.
|
|
18
|
+
|
|
3
19
|
## 1.2.2
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# @open-pioneer/core
|
|
2
2
|
|
|
3
|
-
This package contains basic utility functions and classes used
|
|
3
|
+
This package contains basic utility functions and classes used in Open Pioneer Trails applications.
|
|
4
4
|
|
|
5
5
|
## Events
|
|
6
6
|
|
|
7
7
|
The package exports the `EventEmitter` class that supports emitting and subscribing to user defined events.
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
### Errors
|
|
10
12
|
|
|
11
13
|
The `Error` class extends JavaScript's global error class with a user defined `id` value that
|
|
12
14
|
can be used to explicitly identify error conditions.
|
|
@@ -32,19 +34,19 @@ try {
|
|
|
32
34
|
const errors = getErrorChain(error);
|
|
33
35
|
```
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
### Resources
|
|
36
38
|
|
|
37
39
|
The `Resource` type exported from this package is used by objects with a destructor.
|
|
38
40
|
All object needing some cleanup action to be called should use the `destroy` method for consistency and easier handling.
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
### Logger
|
|
41
43
|
|
|
42
44
|
The 'Logger' class provides a logger for standardized application wide logging.
|
|
43
|
-
The log level is configured globally in the vite.config.js
|
|
45
|
+
The log level is configured globally in the file `vite.config.js`.
|
|
44
46
|
|
|
45
47
|
To create a logger instance, call the `createLogger` method.
|
|
46
48
|
It takes a prefix (string) to prepend to each message.
|
|
47
|
-
|
|
49
|
+
To encode hierarchical names, use `:` as a separator (for example `"some-package:SomeClass"`).
|
|
48
50
|
|
|
49
51
|
The logger provides log methods for the following log levels with the following order: DEBUG < INFO < WARN < ERROR.
|
|
50
52
|
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Error, getErrorChain, isAbortError, throwAbortError, createAbortError, rethrowAbortError } from "./error";
|
|
2
2
|
export { EventEmitter, type EventSource, type EventNames } from "./events";
|
|
3
|
-
export { destroyResource, type Resource } from "./resources";
|
|
3
|
+
export { destroyResource, destroyResources, type Resource } from "./resources";
|
|
4
4
|
export { createLogger, type Logger, type LogLevel, type LogMethod } from "./Logger";
|
|
5
5
|
export { createManualPromise, type ManualPromise } from "./utils";
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { Error, createAbortError, getErrorChain, isAbortError, rethrowAbortError, throwAbortError } from './error.js';
|
|
2
2
|
export { EventEmitter } from './events.js';
|
|
3
|
-
export { destroyResource } from './resources.js';
|
|
3
|
+
export { destroyResource, destroyResources } from './resources.js';
|
|
4
4
|
export { createLogger } from './Logger.js';
|
|
5
5
|
export { createManualPromise } from './utils.js';
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
package/resources.d.ts
CHANGED
|
@@ -21,3 +21,12 @@ export interface Resource {
|
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
23
|
export declare function destroyResource<R extends Resource>(resource: R | undefined): undefined;
|
|
24
|
+
/**
|
|
25
|
+
* A helper function that invokes `destroy()` on each resource in the given array.
|
|
26
|
+
*
|
|
27
|
+
* This function destroys the resources in reverse order (starting from the last element).
|
|
28
|
+
* This is done to reverse the order of construction.
|
|
29
|
+
*
|
|
30
|
+
* The array will be cleared by this function.
|
|
31
|
+
*/
|
|
32
|
+
export declare function destroyResources<R extends Resource>(resources: R[]): void;
|
package/resources.js
CHANGED
|
@@ -2,6 +2,12 @@ function destroyResource(resource) {
|
|
|
2
2
|
resource?.destroy();
|
|
3
3
|
return void 0;
|
|
4
4
|
}
|
|
5
|
+
function destroyResources(resources) {
|
|
6
|
+
let resource;
|
|
7
|
+
while (resource = resources.pop()) {
|
|
8
|
+
resource.destroy();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
5
11
|
|
|
6
|
-
export { destroyResource };
|
|
12
|
+
export { destroyResource, destroyResources };
|
|
7
13
|
//# sourceMappingURL=resources.js.map
|
package/resources.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.js","sources":["resources.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n/**\n * An object that has some cleanup code associated with it.\n */\nexport interface Resource {\n /** A function that releases any state held by the resource. */\n destroy(): void;\n}\n\n/**\n * A helper function that invokes `destroy()` on the given resource and returns undefined.\n *\n * Example:\n *\n * ```js\n * class Holder {\n * private myResource: Resource | undefined;\n *\n * destroy() {\n * this.myResource = destroyResource(this.myResource);\n * }\n * }\n * ```\n */\nexport function destroyResource<R extends Resource>(resource: R | undefined): undefined {\n resource?.destroy();\n return undefined;\n}\n"],"names":[],"mappings":"AAyBO,SAAS,gBAAoC,QAAoC,EAAA;AACpF,EAAA,QAAA,EAAU,OAAQ,EAAA,CAAA;AAClB,EAAO,OAAA,KAAA,CAAA,CAAA;AACX;;;;"}
|
|
1
|
+
{"version":3,"file":"resources.js","sources":["resources.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n/**\n * An object that has some cleanup code associated with it.\n */\nexport interface Resource {\n /** A function that releases any state held by the resource. */\n destroy(): void;\n}\n\n/**\n * A helper function that invokes `destroy()` on the given resource and returns undefined.\n *\n * Example:\n *\n * ```js\n * class Holder {\n * private myResource: Resource | undefined;\n *\n * destroy() {\n * this.myResource = destroyResource(this.myResource);\n * }\n * }\n * ```\n */\nexport function destroyResource<R extends Resource>(resource: R | undefined): undefined {\n resource?.destroy();\n return undefined;\n}\n\n/**\n * A helper function that invokes `destroy()` on each resource in the given array.\n *\n * This function destroys the resources in reverse order (starting from the last element).\n * This is done to reverse the order of construction.\n *\n * The array will be cleared by this function.\n */\nexport function destroyResources<R extends Resource>(resources: R[]): void {\n // `destroy()` might call us in a cycle, so we modify the array in place.\n let resource: Resource | undefined;\n while ((resource = resources.pop())) {\n resource.destroy();\n }\n}\n"],"names":[],"mappings":"AAyBO,SAAS,gBAAoC,QAAoC,EAAA;AACpF,EAAA,QAAA,EAAU,OAAQ,EAAA,CAAA;AAClB,EAAO,OAAA,KAAA,CAAA,CAAA;AACX,CAAA;AAUO,SAAS,iBAAqC,SAAsB,EAAA;AAEvE,EAAI,IAAA,QAAA,CAAA;AACJ,EAAQ,OAAA,QAAA,GAAW,SAAU,CAAA,GAAA,EAAQ,EAAA;AACjC,IAAA,QAAA,CAAS,OAAQ,EAAA,CAAA;AAAA,GACrB;AACJ;;;;"}
|