@conduit-client/utils 2.0.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/README.md +12 -0
- package/dist/index.js +649 -0
- package/dist/index.js.map +1 -0
- package/dist/types/__tests__/bfs.spec.d.ts +1 -0
- package/dist/types/__tests__/command-decorators.spec.d.ts +1 -0
- package/dist/types/__tests__/deep-freeze.spec.d.ts +1 -0
- package/dist/types/__tests__/error-handling.spec.d.ts +1 -0
- package/dist/types/__tests__/file-parser-logger.spec.d.ts +1 -0
- package/dist/types/__tests__/include-exclude.spec.d.ts +1 -0
- package/dist/types/__tests__/logger.spec.d.ts +1 -0
- package/dist/types/__tests__/promises.spec.d.ts +1 -0
- package/dist/types/__tests__/query-params.spec.d.ts +1 -0
- package/dist/types/__tests__/result.spec.d.ts +1 -0
- package/dist/types/__tests__/set.spec.d.ts +1 -0
- package/dist/types/__tests__/string.spec.d.ts +1 -0
- package/dist/types/__tests__/subscribable.spec.d.ts +1 -0
- package/dist/types/__tests__/utils.spec.d.ts +1 -0
- package/dist/types/__tests__/version.spec.d.ts +1 -0
- package/dist/types/bfs.d.ts +1 -0
- package/dist/types/command-decorators.d.ts +34 -0
- package/dist/types/deep-freeze.d.ts +1 -0
- package/dist/types/error-handling.d.ts +35 -0
- package/dist/types/errors.d.ts +20 -0
- package/dist/types/file-parser-logger.d.ts +26 -0
- package/dist/types/include-exclude.d.ts +13 -0
- package/dist/types/index.d.ts +19 -0
- package/dist/types/language.d.ts +27 -0
- package/dist/types/logger.d.ts +46 -0
- package/dist/types/promises.d.ts +39 -0
- package/dist/types/query-params.d.ts +1 -0
- package/dist/types/result.d.ts +64 -0
- package/dist/types/service.d.ts +22 -0
- package/dist/types/set.d.ts +3 -0
- package/dist/types/string.d.ts +16 -0
- package/dist/types/subscribable.d.ts +30 -0
- package/dist/types/utility-types.d.ts +71 -0
- package/dist/types/utils.d.ts +42 -0
- package/dist/types/version.d.ts +17 -0
- package/package.json +34 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the concrete constructor type for an abstract constructor. The
|
|
3
|
+
* concrete constructor is assumed to have the same constructor parameters
|
|
4
|
+
* as the abstract constructor.
|
|
5
|
+
*/
|
|
6
|
+
export type ConcreteConstructor<AbstractConstructor extends abstract new (...params: Array<any>) => unknown> = new (...params: ConstructorParameters<AbstractConstructor>) => InstanceType<AbstractConstructor>;
|
|
7
|
+
/**
|
|
8
|
+
* As TypeScript's Partial<T> utility type, but recursive to also allow subsets of
|
|
9
|
+
* nested types.
|
|
10
|
+
*/
|
|
11
|
+
export type DeepPartial<T> = (T extends object ? {
|
|
12
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
13
|
+
} : T extends Array<infer U> ? Array<DeepPartial<U>> : T) | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* As TypeScript's Readonly<T> utility type, but recursive to also allow subsets of
|
|
16
|
+
* nested types.
|
|
17
|
+
*/
|
|
18
|
+
export type DeepReadonly<T> = T extends object ? {
|
|
19
|
+
readonly [P in keyof T]: DeepReadonly<T[P]>;
|
|
20
|
+
} : T extends Array<infer U> ? ReadonlyArray<DeepReadonly<U>> : T extends string | number | boolean | null | undefined ? T : never;
|
|
21
|
+
/**
|
|
22
|
+
* Returns just the public properties of a class.
|
|
23
|
+
*/
|
|
24
|
+
export type PublicInterface<Class> = {
|
|
25
|
+
[K in keyof Class]: Class[K];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Type used to express the intention that something can complete either
|
|
29
|
+
* synchronously or asynchronously.
|
|
30
|
+
*/
|
|
31
|
+
export type SyncOrAsync<D> = PromiseLike<D>;
|
|
32
|
+
/**
|
|
33
|
+
* A utility type for inferring the first part of a period delimited string
|
|
34
|
+
*/
|
|
35
|
+
type CurrentPath<T extends string> = T extends `${infer K}.${string}` ? K : T;
|
|
36
|
+
/**
|
|
37
|
+
* A utility type for inferring the part of a period delimited string after the first period
|
|
38
|
+
*/
|
|
39
|
+
type RestOfPath<T extends string> = T extends `${string}.${infer Rest}` ? Rest : never;
|
|
40
|
+
/**
|
|
41
|
+
* A utility type for extracting the values of a map type
|
|
42
|
+
*/
|
|
43
|
+
export type ValueOf<T> = T[keyof T];
|
|
44
|
+
/**
|
|
45
|
+
* A utility type for replacing a union of paths on a given JSON-like object
|
|
46
|
+
* with a new type
|
|
47
|
+
*/
|
|
48
|
+
type UpdatePath<T, Paths extends string, R> = T extends Array<any> ? T extends Array<infer Items> ? CurrentPath<Paths> extends '*' ? Array<R> : Array<UpdatePath<Items, Paths, R>> : never : T extends Record<string, any> ? {
|
|
49
|
+
[P in keyof T]: P extends CurrentPath<Paths> ? ValueOf<{
|
|
50
|
+
[Path in Paths as P extends CurrentPath<Path> ? Path : never]: RestOfPath<Path> extends never ? R : UpdatePath<T[P], RestOfPath<Path>, R>;
|
|
51
|
+
}> : T[P];
|
|
52
|
+
} : T;
|
|
53
|
+
/**
|
|
54
|
+
* A utility type for defining a path replacement, including what paths to replace,
|
|
55
|
+
* and what type to replace them with. Used with the `ApplyPathUpdates` type.
|
|
56
|
+
*/
|
|
57
|
+
type PathUpdateRule<Replacement, Paths extends string> = {
|
|
58
|
+
replacement: Replacement;
|
|
59
|
+
paths: Paths;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* A utility type that takes a tuple of `PathReplacement` types, and iteratively
|
|
63
|
+
* applies those replacements to an input type. Allows for updating many paths within a given object
|
|
64
|
+
* with new types.
|
|
65
|
+
*/
|
|
66
|
+
export type ApplyPathUpdates<T, PathUpdateRules extends PathUpdateRule<any, string>[]> = PathUpdateRules extends [infer First, ...infer Rest] ? First extends PathUpdateRule<any, string> ? Rest extends PathUpdateRule<any, string>[] ? ApplyPathUpdates<UpdatePath<T, First['paths'], First['replacement']>, Rest> : never : never : T;
|
|
67
|
+
export type InvalidateConfig = {
|
|
68
|
+
key: Record<string, string>;
|
|
69
|
+
ref: string;
|
|
70
|
+
};
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Result } from './result';
|
|
2
|
+
/**
|
|
3
|
+
* Recursively compares two values and indicates if they are equal.
|
|
4
|
+
*
|
|
5
|
+
* @param x first value
|
|
6
|
+
* @param y second value
|
|
7
|
+
* @returns true if x and y are recursively equal to each other; false if not
|
|
8
|
+
*/
|
|
9
|
+
export declare function deepEquals<T>(x: T, y: T): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* A deterministic JSON stringify implementation. Heavily adapted from https://github.com/epoberezkin/fast-json-stable-stringify.
|
|
12
|
+
* This is needed because insertion order for JSON.stringify(object) affects output:
|
|
13
|
+
* JSON.stringify({a: 1, b: 2})
|
|
14
|
+
* "{"a":1,"b":2}"
|
|
15
|
+
* JSON.stringify({b: 2, a: 1})
|
|
16
|
+
* "{"b":2,"a":1}"
|
|
17
|
+
* @param data Data to be JSON-stringified.
|
|
18
|
+
* @returns JSON.stringified value with consistent ordering of keys.
|
|
19
|
+
*/
|
|
20
|
+
export declare function stableJSONStringify(node: any): string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Converts an arbitrary value to an Error.
|
|
23
|
+
*
|
|
24
|
+
* @param x anything
|
|
25
|
+
* @returns Error corresponding to x
|
|
26
|
+
*/
|
|
27
|
+
export declare function toError(x: any): Error;
|
|
28
|
+
/**
|
|
29
|
+
* Deep copies a JSON object. Only works for non-complex values.
|
|
30
|
+
* No Date or Functions etc.
|
|
31
|
+
*/
|
|
32
|
+
export declare function deepCopy<T>(x: T): T | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Transforms a ReadableStream in to an AsyncIterable
|
|
35
|
+
*
|
|
36
|
+
* Allows consumption of a ReadableStream using for-await-of syntax.
|
|
37
|
+
* Ensures proper cleanup and error handling for all stream control paths.
|
|
38
|
+
*
|
|
39
|
+
* @param stream the ReadableStream to be transformed
|
|
40
|
+
* @returns Result<AsyncIterable<T>, Error> built from the provided ReadableStream
|
|
41
|
+
*/
|
|
42
|
+
export declare function readableStreamToAsyncIterable<T>(stream: ReadableStream<T>): Result<AsyncIterable<T>, Error>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type Version = `${number}.${number}` | `${number}.${number}.${number}`;
|
|
2
|
+
/**
|
|
3
|
+
* Indicates if a given instance of a service satisfies a request. Note that this function
|
|
4
|
+
* assumes the version numbers are valid strings.
|
|
5
|
+
*
|
|
6
|
+
* @param provided ServiceVersion of the service instance to be provided
|
|
7
|
+
* @param requested ServiceVersion requested
|
|
8
|
+
* @returns true if the service instance to be provided satisfies the request
|
|
9
|
+
*/
|
|
10
|
+
export declare function satisfies(provided: Version, requested: Version): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Indicates if a string is valid as a version.
|
|
13
|
+
*
|
|
14
|
+
* @param s arbitrary string
|
|
15
|
+
* @returns true if s is a valid version string
|
|
16
|
+
*/
|
|
17
|
+
export declare function stringIsVersion(s: string): s is Version;
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@conduit-client/utils",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Luvio utils",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/salesforce-experience-platform-emu/luvio-next.git",
|
|
8
|
+
"directory": "packages/@conduit-client/utils"
|
|
9
|
+
},
|
|
10
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "dist/index.js",
|
|
13
|
+
"module": "dist/index.js",
|
|
14
|
+
"types": "dist/types/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist/"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "vite build && tsc --build --emitDeclarationOnly",
|
|
20
|
+
"clean": "rm -rf dist",
|
|
21
|
+
"test": "vitest run",
|
|
22
|
+
"test:size": "size-limit",
|
|
23
|
+
"watch": "npm run build --watch"
|
|
24
|
+
},
|
|
25
|
+
"volta": {
|
|
26
|
+
"extends": "../../../package.json"
|
|
27
|
+
},
|
|
28
|
+
"size-limit": [
|
|
29
|
+
{
|
|
30
|
+
"path": "./dist/index.js",
|
|
31
|
+
"limit": "5.2 kB"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|