@orioro/util 0.13.0 → 0.14.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/index.js +6 -2
  3. package/dist/index.mjs +6 -2
  4. package/dist/strExpr/syntheticJson.d.ts +1 -1
  5. package/package.json +1 -1
  6. package/dist/array/join.d.ts +0 -9
  7. package/dist/debug/debugFn.d.ts +0 -15
  8. package/dist/normalizeString/index.d.ts +0 -1
  9. package/dist/pathResolve/index.d.ts +0 -7
  10. package/dist/resolvePaths/index.d.ts +0 -4
  11. package/dist/strAutoCast/index.d.ts +0 -1
  12. package/dist/strAutoCast/strAutoCast.d.ts +0 -1
  13. package/dist/validate/async/index.d.ts +0 -18
  14. package/dist/validate/async/validateAsyncFn.d.ts +0 -2
  15. package/dist/validate/async/validators/index.d.ts +0 -2
  16. package/dist/validate/async/validators/logical.d.ts +0 -4
  17. package/dist/validate/async/validators/shape.d.ts +0 -7
  18. package/dist/validate/async/validators/tmpand.d.ts +0 -2
  19. package/dist/validate/async/validators/tmpor.d.ts +0 -2
  20. package/dist/validate/common/ValidationError.d.ts +0 -11
  21. package/dist/validate/common/util/defaultErrorMessage.d.ts +0 -2
  22. package/dist/validate/common/util/index.d.ts +0 -3
  23. package/dist/validate/common/util/parseValidatorInput.d.ts +0 -5
  24. package/dist/validate/common/util/resolveValidationResult.d.ts +0 -6
  25. package/dist/validate/common/validators/index.d.ts +0 -1
  26. package/dist/validate/common/validators/type.d.ts +0 -9
  27. package/dist/validate/index.d.ts +0 -3
  28. package/dist/validate/sync/index.d.ts +0 -18
  29. package/dist/validate/sync/validateSyncFn.d.ts +0 -2
  30. package/dist/validate/sync/validators/index.d.ts +0 -2
  31. package/dist/validate/sync/validators/logical.d.ts +0 -4
  32. package/dist/validate/sync/validators/shape.d.ts +0 -7
  33. package/dist/validate/types/async.d.ts +0 -5
  34. package/dist/validate/types/common.d.ts +0 -27
  35. package/dist/validate/types/index.d.ts +0 -3
  36. package/dist/validate/types/sync.d.ts +0 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @orioro/util
2
2
 
3
+ ## 0.14.0
4
+
5
+ ### Minor Changes
6
+
7
+ - syntheticJson fallback to full json in case of error
8
+
9
+ ## 0.13.2
10
+
11
+ ### Patch Changes
12
+
13
+ - undo export update
14
+
15
+ ## 0.13.1
16
+
17
+ ### Patch Changes
18
+
19
+ - fix exports to support import (mjs) and require (js)
20
+
3
21
  ## 0.13.0
4
22
 
5
23
  ### Minor Changes
package/dist/index.js CHANGED
@@ -1491,8 +1491,12 @@ function syntheticJson(str) {
1491
1491
  // Step 3: Parse as JSON
1492
1492
  try {
1493
1493
  return JSON.parse(normalized);
1494
- } catch (error) {
1495
- throw new Error("Invalid synthetic JSON: ".concat(str));
1494
+ } catch (err1) {
1495
+ try {
1496
+ return JSON.parse(str);
1497
+ } catch (err2) {
1498
+ throw new Error("Invalid synthetic JSON: ".concat(str));
1499
+ }
1496
1500
  }
1497
1501
  }
1498
1502
 
package/dist/index.mjs CHANGED
@@ -1489,8 +1489,12 @@ function syntheticJson(str) {
1489
1489
  // Step 3: Parse as JSON
1490
1490
  try {
1491
1491
  return JSON.parse(normalized);
1492
- } catch (error) {
1493
- throw new Error("Invalid synthetic JSON: ".concat(str));
1492
+ } catch (err1) {
1493
+ try {
1494
+ return JSON.parse(str);
1495
+ } catch (err2) {
1496
+ throw new Error("Invalid synthetic JSON: ".concat(str));
1497
+ }
1494
1498
  }
1495
1499
  }
1496
1500
 
@@ -1 +1 @@
1
- export declare function syntheticJson(str: string, maxLength?: number): unknown;
1
+ export declare function syntheticJson<T = unknown>(str: string, maxLength?: number): T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orioro/util",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "packageManager": "yarn@4.0.2",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",
@@ -1,9 +0,0 @@
1
- type Entry = Record<string, any>;
2
- type Dataset = Entry[];
3
- type OnKey = string;
4
- type DatasetInput = Dataset | [OnKey, Dataset, string?];
5
- export declare function join(datasets: DatasetInput[], { key: defaultOnKey, mode, }?: {
6
- key?: string;
7
- mode?: 'left' | 'inner';
8
- }): Entry[];
9
- export {};
@@ -1,15 +0,0 @@
1
- import { Merge } from 'type-fest';
2
- type AnyFn = (...args: any[]) => any;
3
- export type FnCallLog<FnType extends AnyFn = AnyFn> = {
4
- type: 'call';
5
- callId: string;
6
- fnName: string;
7
- args: Parameters<FnType>;
8
- };
9
- export type FnResultLog<FnType extends AnyFn = AnyFn> = Merge<FnCallLog<FnType>, {
10
- type: 'result';
11
- result: ReturnType<FnType>;
12
- }>;
13
- export type FnDebugLog<FnType extends AnyFn = AnyFn> = FnCallLog<FnType> | FnResultLog<FnType>;
14
- export declare function debugFn<FnType extends AnyFn = AnyFn>(fnName: string, fn: FnType, logCall?: (log: FnCallLog<FnType>) => void, logResult?: (log: FnResultLog<FnType>) => void): (...args: Parameters<FnType>) => ReturnType<FnType>;
15
- export {};
@@ -1 +0,0 @@
1
- export declare function normalizeString(str: string): string;
@@ -1,7 +0,0 @@
1
- type PathSpec = {
2
- path: string;
3
- defaultValue?: any;
4
- };
5
- type PathSpecInput = PathSpec | PathSpec['path'];
6
- export declare function pathResolve(obj: any, pathSpecInput: PathSpecInput): any;
7
- export {};
@@ -1,4 +0,0 @@
1
- type Resolver = string | ((sourceObj: Record<string, any>) => any);
2
- type PathSpec = string | [string, Resolver];
3
- export declare function resolvePaths(sourceObj: Record<string, any>, paths: PathSpec[]): Record<string, any>;
4
- export {};
@@ -1 +0,0 @@
1
- export * from './strAutoCast';
@@ -1 +0,0 @@
1
- export declare function strAutoCast(str: string): string | boolean | number | JSON | null | undefined;
@@ -1,18 +0,0 @@
1
- import * as common from '../common/validators';
2
- import * as asyncValidators from './validators';
3
- import { DetailedInvalid, AsyncValidatorSystem, Valid } from '../types';
4
- declare function assertValidAsync<InputT = any>(validator: AsyncValidatorSystem['ValidatorInput'], input: InputT): Promise<InputT>;
5
- interface ValidateAsync {
6
- (validatorInput: AsyncValidatorSystem['ValidatorInput'], input: any): Promise<Valid | DetailedInvalid>;
7
- type: typeof common.typeValidator;
8
- obj: typeof asyncValidators.obj;
9
- objOf: typeof asyncValidators.objOf;
10
- tuple: typeof asyncValidators.tuple;
11
- arrayOf: typeof asyncValidators.arrayOf;
12
- and: typeof asyncValidators.and;
13
- or: typeof asyncValidators.or;
14
- not: typeof asyncValidators.not;
15
- assertValid: typeof assertValidAsync;
16
- }
17
- export declare const validateAsync: ValidateAsync;
18
- export {};
@@ -1,2 +0,0 @@
1
- import { DetailedInvalid, Valid, AsyncValidatorSystem } from '../types';
2
- export declare function validateAsyncFn(validatorInput: AsyncValidatorSystem['ValidatorInput'], input: any): Promise<Valid | DetailedInvalid>;
@@ -1,2 +0,0 @@
1
- export * from './shape';
2
- export * from './logical';
@@ -1,4 +0,0 @@
1
- import { AsyncValidatorSystem } from '../../types';
2
- export declare function and(validators: AsyncValidatorSystem['ValidatorInput'][]): AsyncValidatorSystem['ValidatorFn'];
3
- export declare function or(validators: AsyncValidatorSystem['ValidatorInput'][]): AsyncValidatorSystem['ValidatorFn'];
4
- export declare function not(validator: AsyncValidatorSystem['ValidatorInput']): AsyncValidatorSystem['ValidatorFn'];
@@ -1,7 +0,0 @@
1
- import { AsyncValidatorSystem } from '../../types';
2
- export declare function obj(objShape: {
3
- [key: string]: AsyncValidatorSystem['ValidatorInput'];
4
- }): AsyncValidatorSystem['ValidatorFn'];
5
- export declare function objOf(ofType: AsyncValidatorSystem['ValidatorInput']): AsyncValidatorSystem['ValidatorFn'];
6
- export declare function tuple(tupleShape: AsyncValidatorSystem['ValidatorInput'][]): AsyncValidatorSystem['ValidatorFn'];
7
- export declare function arrayOf(ofType: AsyncValidatorSystem['ValidatorInput']): AsyncValidatorSystem['ValidatorFn'];
@@ -1,2 +0,0 @@
1
- import { AsyncValidatorSystem } from '../../types';
2
- export declare function and(validators: AsyncValidatorSystem['ValidatorInput'][]): AsyncValidatorSystem['ValidatorFn'];
@@ -1,2 +0,0 @@
1
- import { AsyncValidatorSystem } from '../../types';
2
- export declare function or(validators: AsyncValidatorSystem['ValidatorInput'][]): AsyncValidatorSystem['ValidatorFn'];
@@ -1,11 +0,0 @@
1
- import { DetailedInvalid } from '../types';
2
- export declare class ValidationError extends Error {
3
- input: any;
4
- code?: string;
5
- error?: Error;
6
- path?: string;
7
- nestedErrors?: DetailedInvalid[];
8
- name: string;
9
- constructor({ message, ...details }: DetailedInvalid);
10
- toJSON(): DetailedInvalid;
11
- }
@@ -1,2 +0,0 @@
1
- import { DetailedInvalid } from '../../types';
2
- export declare function defaultErrorMessage({ input, message, nestedErrors, expectedTypes, }: DetailedInvalid): string;
@@ -1,3 +0,0 @@
1
- export * from './defaultErrorMessage';
2
- export * from './resolveValidationResult';
3
- export * from './parseValidatorInput';
@@ -1,5 +0,0 @@
1
- export declare function parseValidatorInput<ValidatorInputT, ValidatorFnT, ValidatorT>({ objValidator, }: {
2
- objValidator: (objShape: {
3
- [key: string]: ValidatorInputT;
4
- }) => ValidatorFnT;
5
- }, validatorInput: ValidatorInputT): ValidatorT;
@@ -1,6 +0,0 @@
1
- import { DetailedInvalid, Valid, ValidatorErrorMessageFn, ValidatorResult } from '../../types';
2
- export declare function resolveValidationResult({ input, result, errorMessage, }: {
3
- input: any;
4
- result: ValidatorResult;
5
- errorMessage: ValidatorErrorMessageFn;
6
- }): Valid | DetailedInvalid;
@@ -1 +0,0 @@
1
- export * from './type';
@@ -1,9 +0,0 @@
1
- import { TypeOfType } from '../../../typeOf';
2
- import { CommonValidatorFn } from '../../types';
3
- type ParsedExpectedType = {
4
- type: TypeOfType;
5
- required: boolean;
6
- };
7
- type ExpectedTypesInput = (string | ParsedExpectedType)[] | string | ParsedExpectedType;
8
- export declare function typeValidator(expectedTypesInput: ExpectedTypesInput): CommonValidatorFn;
9
- export {};
@@ -1,3 +0,0 @@
1
- export * from './sync';
2
- export * from './async';
3
- export * from './common/ValidationError';
@@ -1,18 +0,0 @@
1
- import * as common from '../common/validators';
2
- import * as sync from './validators';
3
- import { DetailedInvalid, SyncValidatorSystem, Valid } from '../types';
4
- declare function assertValidSync<InputT = any>(validator: SyncValidatorSystem['ValidatorInput'], input: InputT): InputT;
5
- interface Validate {
6
- (validatorInput: SyncValidatorSystem['ValidatorInput'], input: any): Valid | DetailedInvalid;
7
- type: typeof common.typeValidator;
8
- obj: typeof sync.obj;
9
- objOf: typeof sync.objOf;
10
- tuple: typeof sync.tuple;
11
- arrayOf: typeof sync.arrayOf;
12
- and: typeof sync.and;
13
- or: typeof sync.or;
14
- not: typeof sync.not;
15
- assertValid: typeof assertValidSync;
16
- }
17
- export declare const validate: Validate;
18
- export {};
@@ -1,2 +0,0 @@
1
- import { DetailedInvalid, Valid, SyncValidatorSystem } from '../types';
2
- export declare function validateSyncFn(validatorInput: SyncValidatorSystem['ValidatorInput'], input: any): Valid | DetailedInvalid;
@@ -1,2 +0,0 @@
1
- export * from './logical';
2
- export * from './shape';
@@ -1,4 +0,0 @@
1
- import { SyncValidatorSystem } from '../../types';
2
- export declare function and(validators: SyncValidatorSystem['ValidatorInput'][]): SyncValidatorSystem['ValidatorFn'];
3
- export declare function or(validators: SyncValidatorSystem['ValidatorInput'][]): SyncValidatorSystem['ValidatorFn'];
4
- export declare function not(validator: SyncValidatorSystem['ValidatorInput']): SyncValidatorSystem['ValidatorFn'];
@@ -1,7 +0,0 @@
1
- import { SyncValidatorSystem } from '../../types';
2
- export declare function obj(objShape: {
3
- [key: string]: SyncValidatorSystem['ValidatorInput'];
4
- }): SyncValidatorSystem['ValidatorFn'];
5
- export declare function objOf(ofType: SyncValidatorSystem['ValidatorInput']): SyncValidatorSystem['ValidatorFn'];
6
- export declare function tuple(tupleShape: SyncValidatorSystem['ValidatorInput'][]): SyncValidatorSystem['ValidatorFn'];
7
- export declare function arrayOf(ofType: SyncValidatorSystem['ValidatorInput']): SyncValidatorSystem['ValidatorFn'];
@@ -1,5 +0,0 @@
1
- import { DetailedInvalid, Valid, ValidatorResult, ValidatorSystem } from './common';
2
- export type AsyncValidatorSystem = ValidatorSystem<(input: any, context: {
3
- validateAsync: AsyncValidateFn;
4
- }) => ValidatorResult | Promise<ValidatorResult>>;
5
- export type AsyncValidateFn = (validatorInput: AsyncValidatorSystem['ValidatorInput'], input: any) => Promise<Valid | DetailedInvalid>;
@@ -1,27 +0,0 @@
1
- export type Valid = true;
2
- export type SimpleInvalid = false | undefined | null;
3
- export type ErrorMessageInvalid = string;
4
- export type ErrorInvalid = Error;
5
- export type DetailedInvalid = {
6
- input: any;
7
- message?: string;
8
- code?: string;
9
- error?: Error;
10
- path?: string;
11
- nestedErrors?: DetailedInvalid[];
12
- expectedTypes?: string;
13
- };
14
- export type ValidatorResult = Valid | SimpleInvalid | ErrorMessageInvalid | ErrorInvalid | DetailedInvalid;
15
- export type ValidatorErrorMessageFn = (props: DetailedInvalid) => string;
16
- export type ValidatorErrorMessageInput = string | ValidatorErrorMessageFn;
17
- export type CommonValidatorFn = (input: any) => ValidatorResult;
18
- type _ValidatorFnInput<ValidatorFn> = string | {
19
- [key: string]: _ValidatorFnInput<ValidatorFn> | [_ValidatorFnInput<ValidatorFn>, ValidatorErrorMessageInput];
20
- } | ValidatorFn;
21
- export type ValidatorSystem<ValidatorFn> = {
22
- ValidatorFn: ValidatorFn;
23
- ValidatorFnInput: _ValidatorFnInput<ValidatorFn>;
24
- Validator: [ValidatorFn, ValidatorErrorMessageFn];
25
- ValidatorInput: _ValidatorFnInput<ValidatorFn> | [_ValidatorFnInput<ValidatorFn>, ValidatorErrorMessageInput];
26
- };
27
- export {};
@@ -1,3 +0,0 @@
1
- export * from './common';
2
- export * from './sync';
3
- export * from './async';
@@ -1,5 +0,0 @@
1
- import { DetailedInvalid, Valid, ValidatorResult, ValidatorSystem } from './common';
2
- export type SyncValidatorSystem = ValidatorSystem<(input: any, context: {
3
- validateSync: SyncValidateFn;
4
- }) => ValidatorResult>;
5
- export type SyncValidateFn = (validatorInput: SyncValidatorSystem['ValidatorInput'], input: any) => Valid | DetailedInvalid;