@candlerip/shared3 0.0.97 → 0.0.99

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@candlerip/shared3",
3
- "version": "0.0.97",
3
+ "version": "0.0.99",
4
4
  "type": "module",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -1,11 +1,13 @@
1
1
  import { Auth } from '../../auth/index.js';
2
2
  import { CookieConsent } from '../../cookie/index.js';
3
3
  import { Dictionary, Language } from '../../dictionary/index.js';
4
+ import { CandleFilterSort } from '../../filter-sort/index.js';
4
5
  import { CandlesPageData } from '../../page/index.js';
5
6
  export interface CandlesPageServerSideProps {
6
7
  auth: Auth;
7
8
  cookieConsent?: CookieConsent;
8
9
  dictionary: Dictionary;
10
+ filterSort: CandleFilterSort;
9
11
  language: Language;
10
12
  pageData: CandlesPageData;
11
13
  }
@@ -1 +1,2 @@
1
1
  export * from './type-guard.js';
2
+ export * from './validate.js';
@@ -1 +1,2 @@
1
1
  export * from './type-guard.js';
2
+ export * from './validate.js';
@@ -0,0 +1,6 @@
1
+ import { CustomError } from '../../error/index.js';
2
+ export declare const validateArray: <T>(data: unknown, name: string, valid: readonly T[]) => {
3
+ data: T[];
4
+ } | {
5
+ customError: CustomError;
6
+ };
@@ -0,0 +1,16 @@
1
+ import { customErrorWorker } from '../../error/index.js';
2
+ export const validateArray = (data, name, valid) => {
3
+ const { composeCustomError } = customErrorWorker({ data, name, valid });
4
+ if (!data) {
5
+ return composeCustomError(`Missing ${name}`);
6
+ }
7
+ if (!Array.isArray(data)) {
8
+ return composeCustomError(`Invalid ${name}`);
9
+ }
10
+ if (!data.every((it) => valid.includes(it))) {
11
+ return composeCustomError(`Invalid ${name}`);
12
+ }
13
+ return {
14
+ data,
15
+ };
16
+ };
@@ -1,2 +1,3 @@
1
1
  export * from './type-guard.js';
2
2
  export * from './validate.js';
3
+ export * from './validate-comma-separated-string/index.js';
@@ -1,2 +1,3 @@
1
1
  export * from './type-guard.js';
2
2
  export * from './validate.js';
3
+ export * from './validate-comma-separated-string/index.js';
@@ -0,0 +1,2 @@
1
+ import { ValidateCommaSeparatedString } from './types.js';
2
+ export declare const validateCommaSeparatedString: ValidateCommaSeparatedString;
@@ -0,0 +1,17 @@
1
+ import { customErrorWorker } from '../../../error/index.js';
2
+ import { validateArray } from '../../array/index.js';
3
+ import { isString } from '../type-guard.js';
4
+ export const validateCommaSeparatedString = (data, name, valid) => {
5
+ const { composeCustomError } = customErrorWorker({ data, name, valid });
6
+ if (!data) {
7
+ return composeCustomError(`Missing ${name}`);
8
+ }
9
+ if (!isString(data)) {
10
+ return composeCustomError(`${name} not string`);
11
+ }
12
+ const parsedArr = data.split(',');
13
+ if (parsedArr.length === 0) {
14
+ return composeCustomError(`Invalid ${name}`);
15
+ }
16
+ return validateArray(parsedArr, name, valid);
17
+ };
@@ -0,0 +1,6 @@
1
+ import { CustomError } from '../../../error/index.js';
2
+ export type ValidateCommaSeparatedString = <T>(data: unknown, name: string, valid: readonly T[]) => {
3
+ data: T[];
4
+ } | {
5
+ customError: CustomError;
6
+ };