@harborclient/sdk 0.6.17 → 0.7.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/dist/components/index.d.ts +0 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +0 -1
- package/dist/http/resolveRequest.test.js +1 -2
- package/dist/runtime/react.d.ts +0 -6
- package/dist/runtime/react.js +2 -70
- package/dist/runtime/reactHost.js +0 -52
- package/dist/runtime/store.d.ts +0 -101
- package/dist/runtime/store.d.ts.map +1 -1
- package/dist/runtime/store.js +0 -94
- package/dist/runtime/store.ts +0 -203
- package/dist/runtime/viewHost.js +1 -2
- package/dist/runtime-utils.d.ts +0 -59
- package/dist/runtime-utils.d.ts.map +1 -1
- package/dist/runtime-utils.js +0 -66
- package/dist/runtime-utils.test.js +1 -74
- package/dist/storage/index.d.ts +0 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +0 -1
- package/dist/types.d.ts +0 -14
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -35
- package/dist/build/index.d.ts +0 -59
- package/dist/build/index.d.ts.map +0 -1
- package/dist/build/index.js +0 -107
- package/dist/components/portalToBody.d.ts +0 -10
- package/dist/components/portalToBody.d.ts.map +0 -1
- package/dist/components/portalToBody.js +0 -14
- package/dist/eslint/index.d.ts +0 -9
- package/dist/eslint/index.d.ts.map +0 -1
- package/dist/eslint/index.js +0 -18
- package/dist/runtime/jsx-runtime-host.d.ts +0 -44
- package/dist/runtime/jsx-runtime-host.js +0 -42
- package/dist/runtime/react-dom.d.ts +0 -1
- package/dist/runtime/react-dom.js +0 -16
- package/dist/storage/validate.d.ts +0 -71
- package/dist/storage/validate.d.ts.map +0 -1
- package/dist/storage/validate.js +0 -111
- package/dist/storage/validate.test.d.ts +0 -2
- package/dist/storage/validate.test.d.ts.map +0 -1
- package/dist/storage/validate.test.js +0 -78
- package/dist/store.test.d.ts +0 -2
- package/dist/store.test.d.ts.map +0 -1
- package/dist/store.test.js +0 -248
- package/tsconfig.base.json +0 -15
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { createPortal } from '@harborclient/sdk/react-dom';
|
|
2
|
-
/**
|
|
3
|
-
* Portals modal content to document.body so fixed positioning is not clipped by
|
|
4
|
-
* the sidebar or other overflow-hidden plugin webview containers.
|
|
5
|
-
*
|
|
6
|
-
* @param node - Modal element to render.
|
|
7
|
-
* @returns Portal into document.body, or the node unchanged when document is unavailable.
|
|
8
|
-
*/
|
|
9
|
-
export function portalToBody(node) {
|
|
10
|
-
if (typeof document !== 'undefined') {
|
|
11
|
-
return createPortal(node, document.body);
|
|
12
|
-
}
|
|
13
|
-
return node;
|
|
14
|
-
}
|
package/dist/eslint/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared flat ESLint config for HarborClient plugins (ESLint 10 compatible).
|
|
3
|
-
*
|
|
4
|
-
* Plugins re-export this from `eslint.config.mjs`:
|
|
5
|
-
* `export { default } from '@harborclient/sdk/eslint';`
|
|
6
|
-
*/
|
|
7
|
-
declare const _default: import("typescript-eslint").FlatConfig.ConfigArray;
|
|
8
|
-
export default _default;
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/eslint/index.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;;AACH,wBAaE"}
|
package/dist/eslint/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import eslint from '@eslint/js';
|
|
2
|
-
import eslintConfigPrettier from 'eslint-config-prettier';
|
|
3
|
-
import globals from 'globals';
|
|
4
|
-
import tseslint from 'typescript-eslint';
|
|
5
|
-
/**
|
|
6
|
-
* Shared flat ESLint config for HarborClient plugins (ESLint 10 compatible).
|
|
7
|
-
*
|
|
8
|
-
* Plugins re-export this from `eslint.config.mjs`:
|
|
9
|
-
* `export { default } from '@harborclient/sdk/eslint';`
|
|
10
|
-
*/
|
|
11
|
-
export default tseslint.config({
|
|
12
|
-
ignores: ['**/node_modules', '**/dist', 'pnpm-lock.yaml']
|
|
13
|
-
}, eslint.configs.recommended, tseslint.configs.recommended, {
|
|
14
|
-
files: ['**/*.mjs'],
|
|
15
|
-
languageOptions: {
|
|
16
|
-
globals: globals.node
|
|
17
|
-
}
|
|
18
|
-
}, eslintConfigPrettier);
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type * as React from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Host React fragment, resolved from the externalized `react` module at runtime.
|
|
5
|
-
*/
|
|
6
|
-
export declare const Fragment: React.ExoticComponent<{ children?: React.ReactNode }>;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Automatic JSX runtime entry for third-party deps aliased to this module.
|
|
10
|
-
*/
|
|
11
|
-
export function jsx(
|
|
12
|
-
type: React.ElementType,
|
|
13
|
-
props: Record<string, unknown> | null | undefined,
|
|
14
|
-
key?: string | number
|
|
15
|
-
): React.ReactElement;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Automatic JSX runtime entry for elements with multiple children.
|
|
19
|
-
*/
|
|
20
|
-
export function jsxs(
|
|
21
|
-
type: React.ElementType,
|
|
22
|
-
props: Record<string, unknown> | null | undefined,
|
|
23
|
-
key?: string | number
|
|
24
|
-
): React.ReactElement;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Development JSX transform entry; delegates to {@link jsx}.
|
|
28
|
-
*/
|
|
29
|
-
export function jsxDEV(
|
|
30
|
-
type: React.ElementType,
|
|
31
|
-
props: Record<string, unknown> | null | undefined,
|
|
32
|
-
key?: string | number
|
|
33
|
-
): React.ReactElement;
|
|
34
|
-
|
|
35
|
-
export namespace JSX {
|
|
36
|
-
interface Element extends React.JSX.Element {}
|
|
37
|
-
interface ElementClass extends React.JSX.ElementClass {}
|
|
38
|
-
interface ElementAttributesProperty extends React.JSX.ElementAttributesProperty {}
|
|
39
|
-
interface ElementChildrenAttribute extends React.JSX.ElementChildrenAttribute {}
|
|
40
|
-
type LibraryManagedAttributes<C, P> = React.JSX.LibraryManagedAttributes<C, P>;
|
|
41
|
-
interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {}
|
|
42
|
-
interface IntrinsicClassAttributes<T> extends React.JSX.IntrinsicClassAttributes<T> {}
|
|
43
|
-
interface IntrinsicElements extends React.JSX.IntrinsicElements {}
|
|
44
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
export const Fragment = React.Fragment;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Builds a React element using the externalized host React directly.
|
|
7
|
-
*
|
|
8
|
-
* Used when bundling third-party deps (e.g. @uiw/react-codemirror,
|
|
9
|
-
* @fortawesome/react-fontawesome) that import `react/jsx-runtime`. Aliasing
|
|
10
|
-
* those imports to this module keeps them on the same host React instance as
|
|
11
|
-
* the plugin shell without requiring installReact() to have run first.
|
|
12
|
-
*
|
|
13
|
-
* @param {import('react').ElementType} type - Element type or Fragment.
|
|
14
|
-
* @param {Record<string, unknown> | null | undefined} props - Element props.
|
|
15
|
-
* @param {string | number | undefined} key - React key when provided by the compiler.
|
|
16
|
-
* @returns {import('react').ReactElement}
|
|
17
|
-
*/
|
|
18
|
-
function build(type, props, key) {
|
|
19
|
-
const { children, ...rest } = props ?? {};
|
|
20
|
-
if (key !== undefined) {
|
|
21
|
-
rest.key = key;
|
|
22
|
-
}
|
|
23
|
-
return React.createElement(type, props === null ? props : rest, children);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** @type {typeof import('react/jsx-runtime').jsx} */
|
|
27
|
-
export const jsx = build;
|
|
28
|
-
|
|
29
|
-
/** @type {typeof import('react/jsx-runtime').jsxs} */
|
|
30
|
-
export const jsxs = build;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Development JSX transform entry; delegates to the production jsx helper.
|
|
34
|
-
*
|
|
35
|
-
* @param {import('react').ElementType} type - Element type or Fragment.
|
|
36
|
-
* @param {Record<string, unknown> | null | undefined} props - Element props.
|
|
37
|
-
* @param {string | number | undefined} key - React key when provided by the compiler.
|
|
38
|
-
* @returns {import('react').ReactElement}
|
|
39
|
-
*/
|
|
40
|
-
export function jsxDEV(type, props, key) {
|
|
41
|
-
return build(type, props, key);
|
|
42
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { createPortal } from 'react-dom';
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { requireHostReactDom } from './reactHost.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Creates a React portal into the host DOM tree.
|
|
5
|
-
*
|
|
6
|
-
* Delegates to the installed host React DOM instance so portals reconcile with
|
|
7
|
-
* the same React copy as {@link @harborclient/sdk/react} hooks.
|
|
8
|
-
*
|
|
9
|
-
* @param {import('react').ReactNode} children - Portal content.
|
|
10
|
-
* @param {Element | DocumentFragment} container - DOM mount target.
|
|
11
|
-
* @param {string | null} [key] - Optional React key for the portal.
|
|
12
|
-
* @returns {import('react').ReactPortal} Portal element.
|
|
13
|
-
*/
|
|
14
|
-
export function createPortal(children, container, key) {
|
|
15
|
-
return requireHostReactDom().createPortal(children, container, key);
|
|
16
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns true when a value is a plain object record (not null, not an array).
|
|
3
|
-
*
|
|
4
|
-
* @param value - Candidate value from plugin storage.
|
|
5
|
-
*/
|
|
6
|
-
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
7
|
-
/**
|
|
8
|
-
* Narrows an unknown storage value to a string-keyed record, or null when invalid.
|
|
9
|
-
*
|
|
10
|
-
* @param value - Raw value from plugin storage.
|
|
11
|
-
*/
|
|
12
|
-
export declare function asRecord(value: unknown): Record<string, unknown> | null;
|
|
13
|
-
/**
|
|
14
|
-
* Returns a string when the value is a string; otherwise the fallback.
|
|
15
|
-
*
|
|
16
|
-
* @param value - Candidate field value.
|
|
17
|
-
* @param fallback - Value used when the candidate is not a string.
|
|
18
|
-
*/
|
|
19
|
-
export declare function str<F>(value: unknown, fallback: F): string | F;
|
|
20
|
-
/**
|
|
21
|
-
* Returns a finite number when the value is a number; otherwise the fallback.
|
|
22
|
-
*
|
|
23
|
-
* @param value - Candidate field value.
|
|
24
|
-
* @param fallback - Value used when the candidate is not a finite number.
|
|
25
|
-
*/
|
|
26
|
-
export declare function num<F>(value: unknown, fallback: F): number | F;
|
|
27
|
-
/**
|
|
28
|
-
* Returns a boolean when the value is a boolean; otherwise the fallback.
|
|
29
|
-
*
|
|
30
|
-
* @param value - Candidate field value.
|
|
31
|
-
* @param fallback - Value used when the candidate is not a boolean.
|
|
32
|
-
*/
|
|
33
|
-
export declare function bool<F>(value: unknown, fallback: F): boolean | F;
|
|
34
|
-
/**
|
|
35
|
-
* Returns the candidate when it is one of the allowed string literals; otherwise the fallback.
|
|
36
|
-
*
|
|
37
|
-
* @param value - Candidate field value.
|
|
38
|
-
* @param allowed - Permitted string literals.
|
|
39
|
-
* @param fallback - Value used when the candidate is not in {@link allowed}.
|
|
40
|
-
*/
|
|
41
|
-
export declare function oneOf<T extends string, F>(value: unknown, allowed: readonly T[], fallback: F): T | F;
|
|
42
|
-
/**
|
|
43
|
-
* Filters an array to finite numbers; returns an empty array when the input is not an array.
|
|
44
|
-
*
|
|
45
|
-
* @param value - Candidate array from plugin storage.
|
|
46
|
-
*/
|
|
47
|
-
export declare function numArray(value: unknown): number[];
|
|
48
|
-
/**
|
|
49
|
-
* Filters an array to non-empty strings; returns an empty array when the input is not an array.
|
|
50
|
-
*
|
|
51
|
-
* @param value - Candidate array from plugin storage.
|
|
52
|
-
*/
|
|
53
|
-
export declare function strArray(value: unknown): string[];
|
|
54
|
-
/**
|
|
55
|
-
* Filters an array through a type guard; returns an empty array when the input is not an array.
|
|
56
|
-
*
|
|
57
|
-
* @param value - Candidate array from plugin storage.
|
|
58
|
-
* @param guard - Predicate that narrows each element.
|
|
59
|
-
*/
|
|
60
|
-
export declare function arrayOf<T>(value: unknown, guard: (entry: unknown) => entry is T): T[];
|
|
61
|
-
/**
|
|
62
|
-
* Builds a string-keyed record from entries that pass a type guard.
|
|
63
|
-
*
|
|
64
|
-
* Non-record inputs (including arrays) return an empty object so callers can treat
|
|
65
|
-
* malformed storage as "no data" without throwing.
|
|
66
|
-
*
|
|
67
|
-
* @param value - Raw value from plugin storage.
|
|
68
|
-
* @param guard - Predicate that narrows each property value.
|
|
69
|
-
*/
|
|
70
|
-
export declare function recordOf<T>(value: unknown, guard: (entry: unknown) => entry is T): Record<string, T>;
|
|
71
|
-
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/storage/validate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAEvE;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,GAAG,MAAM,GAAG,CAAC,CAE9D;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,GAAG,MAAM,GAAG,CAAC,CAE9D;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,GAAG,OAAO,GAAG,CAAC,CAEhE;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EACvC,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,SAAS,CAAC,EAAE,EACrB,QAAQ,EAAE,CAAC,GACV,CAAC,GAAG,CAAC,CAIP;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,EAAE,CAOjD;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,EAAE,CAKjD;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAKrF;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,GACpC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAYnB"}
|
package/dist/storage/validate.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns true when a value is a plain object record (not null, not an array).
|
|
3
|
-
*
|
|
4
|
-
* @param value - Candidate value from plugin storage.
|
|
5
|
-
*/
|
|
6
|
-
export function isRecord(value) {
|
|
7
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Narrows an unknown storage value to a string-keyed record, or null when invalid.
|
|
11
|
-
*
|
|
12
|
-
* @param value - Raw value from plugin storage.
|
|
13
|
-
*/
|
|
14
|
-
export function asRecord(value) {
|
|
15
|
-
return isRecord(value) ? value : null;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Returns a string when the value is a string; otherwise the fallback.
|
|
19
|
-
*
|
|
20
|
-
* @param value - Candidate field value.
|
|
21
|
-
* @param fallback - Value used when the candidate is not a string.
|
|
22
|
-
*/
|
|
23
|
-
export function str(value, fallback) {
|
|
24
|
-
return typeof value === 'string' ? value : fallback;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Returns a finite number when the value is a number; otherwise the fallback.
|
|
28
|
-
*
|
|
29
|
-
* @param value - Candidate field value.
|
|
30
|
-
* @param fallback - Value used when the candidate is not a finite number.
|
|
31
|
-
*/
|
|
32
|
-
export function num(value, fallback) {
|
|
33
|
-
return typeof value === 'number' && Number.isFinite(value) ? value : fallback;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Returns a boolean when the value is a boolean; otherwise the fallback.
|
|
37
|
-
*
|
|
38
|
-
* @param value - Candidate field value.
|
|
39
|
-
* @param fallback - Value used when the candidate is not a boolean.
|
|
40
|
-
*/
|
|
41
|
-
export function bool(value, fallback) {
|
|
42
|
-
return typeof value === 'boolean' ? value : fallback;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Returns the candidate when it is one of the allowed string literals; otherwise the fallback.
|
|
46
|
-
*
|
|
47
|
-
* @param value - Candidate field value.
|
|
48
|
-
* @param allowed - Permitted string literals.
|
|
49
|
-
* @param fallback - Value used when the candidate is not in {@link allowed}.
|
|
50
|
-
*/
|
|
51
|
-
export function oneOf(value, allowed, fallback) {
|
|
52
|
-
return typeof value === 'string' && allowed.includes(value)
|
|
53
|
-
? value
|
|
54
|
-
: fallback;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Filters an array to finite numbers; returns an empty array when the input is not an array.
|
|
58
|
-
*
|
|
59
|
-
* @param value - Candidate array from plugin storage.
|
|
60
|
-
*/
|
|
61
|
-
export function numArray(value) {
|
|
62
|
-
if (!Array.isArray(value)) {
|
|
63
|
-
return [];
|
|
64
|
-
}
|
|
65
|
-
return value.filter((entry) => typeof entry === 'number' && Number.isFinite(entry));
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Filters an array to non-empty strings; returns an empty array when the input is not an array.
|
|
69
|
-
*
|
|
70
|
-
* @param value - Candidate array from plugin storage.
|
|
71
|
-
*/
|
|
72
|
-
export function strArray(value) {
|
|
73
|
-
if (!Array.isArray(value)) {
|
|
74
|
-
return [];
|
|
75
|
-
}
|
|
76
|
-
return value.filter((entry) => typeof entry === 'string');
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Filters an array through a type guard; returns an empty array when the input is not an array.
|
|
80
|
-
*
|
|
81
|
-
* @param value - Candidate array from plugin storage.
|
|
82
|
-
* @param guard - Predicate that narrows each element.
|
|
83
|
-
*/
|
|
84
|
-
export function arrayOf(value, guard) {
|
|
85
|
-
if (!Array.isArray(value)) {
|
|
86
|
-
return [];
|
|
87
|
-
}
|
|
88
|
-
return value.filter(guard);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Builds a string-keyed record from entries that pass a type guard.
|
|
92
|
-
*
|
|
93
|
-
* Non-record inputs (including arrays) return an empty object so callers can treat
|
|
94
|
-
* malformed storage as "no data" without throwing.
|
|
95
|
-
*
|
|
96
|
-
* @param value - Raw value from plugin storage.
|
|
97
|
-
* @param guard - Predicate that narrows each property value.
|
|
98
|
-
*/
|
|
99
|
-
export function recordOf(value, guard) {
|
|
100
|
-
const record = asRecord(value);
|
|
101
|
-
if (!record) {
|
|
102
|
-
return {};
|
|
103
|
-
}
|
|
104
|
-
const result = {};
|
|
105
|
-
for (const [key, entry] of Object.entries(record)) {
|
|
106
|
-
if (guard(entry)) {
|
|
107
|
-
result[key] = entry;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return result;
|
|
111
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate.test.d.ts","sourceRoot":"","sources":["../../src/storage/validate.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from '@jest/globals';
|
|
2
|
-
import { arrayOf, asRecord, bool, isRecord, num, numArray, oneOf, recordOf, str, strArray } from './validate.js';
|
|
3
|
-
describe('isRecord', () => {
|
|
4
|
-
it('accepts plain objects and rejects arrays and primitives', () => {
|
|
5
|
-
expect(isRecord({ a: 1 })).toBe(true);
|
|
6
|
-
expect(isRecord([])).toBe(false);
|
|
7
|
-
expect(isRecord(null)).toBe(false);
|
|
8
|
-
expect(isRecord('x')).toBe(false);
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
describe('asRecord', () => {
|
|
12
|
-
it('returns the record or null', () => {
|
|
13
|
-
const value = { key: 'v' };
|
|
14
|
-
expect(asRecord(value)).toBe(value);
|
|
15
|
-
expect(asRecord(null)).toBeNull();
|
|
16
|
-
expect(asRecord([1])).toBeNull();
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
describe('str', () => {
|
|
20
|
-
it('returns strings and falls back otherwise', () => {
|
|
21
|
-
expect(str('hello', '')).toBe('hello');
|
|
22
|
-
expect(str(42, 'fallback')).toBe('fallback');
|
|
23
|
-
expect(str(undefined, null)).toBeNull();
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
describe('num', () => {
|
|
27
|
-
it('returns finite numbers and falls back otherwise', () => {
|
|
28
|
-
expect(num(3, 0)).toBe(3);
|
|
29
|
-
expect(num(NaN, 0)).toBe(0);
|
|
30
|
-
expect(num(Infinity, 0)).toBe(0);
|
|
31
|
-
expect(num('3', null)).toBeNull();
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
describe('bool', () => {
|
|
35
|
-
it('returns booleans and falls back otherwise', () => {
|
|
36
|
-
expect(bool(true, false)).toBe(true);
|
|
37
|
-
expect(bool(false, true)).toBe(false);
|
|
38
|
-
expect(bool('true', true)).toBe(true);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
describe('oneOf', () => {
|
|
42
|
-
it('accepts allowed literals and falls back otherwise', () => {
|
|
43
|
-
expect(oneOf('delay', ['interval', 'delay'], 'interval')).toBe('delay');
|
|
44
|
-
expect(oneOf('other', ['interval', 'delay'], 'interval')).toBe('interval');
|
|
45
|
-
expect(oneOf(1, ['interval', 'delay'], 'interval')).toBe('interval');
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
describe('numArray', () => {
|
|
49
|
-
it('filters to finite numbers', () => {
|
|
50
|
-
expect(numArray([1, NaN, 2, 'x', Infinity])).toEqual([1, 2]);
|
|
51
|
-
expect(numArray(null)).toEqual([]);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
describe('strArray', () => {
|
|
55
|
-
it('filters to strings', () => {
|
|
56
|
-
expect(strArray(['a', 1, 'b'])).toEqual(['a', 'b']);
|
|
57
|
-
expect(strArray(undefined)).toEqual([]);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
describe('arrayOf', () => {
|
|
61
|
-
it('filters through a guard', () => {
|
|
62
|
-
const isNum = (entry) => typeof entry === 'number' && Number.isFinite(entry);
|
|
63
|
-
expect(arrayOf([1, 'x', 2], isNum)).toEqual([1, 2]);
|
|
64
|
-
expect(arrayOf('nope', isNum)).toEqual([]);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
describe('recordOf', () => {
|
|
68
|
-
it('keeps entries that pass the guard', () => {
|
|
69
|
-
const isNum = (entry) => typeof entry === 'number' && Number.isFinite(entry);
|
|
70
|
-
expect(recordOf({
|
|
71
|
-
a: 1,
|
|
72
|
-
b: 'x',
|
|
73
|
-
c: 2
|
|
74
|
-
}, isNum)).toEqual({ a: 1, c: 2 });
|
|
75
|
-
expect(recordOf([], isNum)).toEqual({});
|
|
76
|
-
expect(recordOf(null, isNum)).toEqual({});
|
|
77
|
-
});
|
|
78
|
-
});
|
package/dist/store.test.d.ts
DELETED
package/dist/store.test.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store.test.d.ts","sourceRoot":"","sources":["../src/store.test.ts"],"names":[],"mappings":""}
|