@okam/core-lib 1.16.0 → 1.17.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 CHANGED
@@ -1,3 +1,20 @@
1
+ ## 1.17.0 (2025-07-24)
2
+
3
+ ### 🚀 Features
4
+
5
+ - **directus-next:** /api/redirect route handler to fetch + cache directus redirects ([c21b953](https://github.com/OKAMca/stack/commit/c21b953))
6
+
7
+ ### 🩹 Fixes
8
+
9
+ - update vite-plugin-dts to version 3 ([5d33c77](https://github.com/OKAMca/stack/commit/5d33c77))
10
+ - package deps error ([b665a45](https://github.com/OKAMca/stack/commit/b665a45))
11
+ - search field icon ([0850fde](https://github.com/OKAMca/stack/commit/0850fde))
12
+
13
+ ### ❤️ Thank You
14
+
15
+ - Marie-Maxime Tanguay
16
+ - Pierre-Olivier Clerson @poclerson
17
+
1
18
  ## 1.15.0 (2024-10-04)
2
19
 
3
20
 
@@ -0,0 +1,3 @@
1
+ export { JsonApiResponseFactory } from './json-api-response.factory';
2
+ export type { JsonApiResponse, JsonApiErrorResponse, JsonApiSuccessResponse, JsonApiResponseMeta, JsonApiError, } from './json-api-response.types';
3
+ export { isJsonApiErrorResponse, isJsonApiResponse, isJsonApiSuccessResponse } from './json-api.typeguard';
@@ -0,0 +1,6 @@
1
+ import type { Exception } from '@tsed/exceptions';
2
+ import type { JsonApiError } from './json-api-response.types';
3
+ export declare class JsonApiErrorFactory {
4
+ static fromCatchVariable: (error: unknown, defaultHttpStatus?: number) => JsonApiError;
5
+ static fromTsedException: (exception: Exception | Error | string, defaultHttpStatus?: number) => JsonApiError;
6
+ }
@@ -0,0 +1,5 @@
1
+ import type { JsonApiError, JsonApiErrorResponse, JsonApiSuccessResponse } from './json-api-response.types';
2
+ export declare class JsonApiResponseFactory {
3
+ static fromError: (errors: string | JsonApiError | JsonApiError[], httpStatus?: number) => JsonApiErrorResponse;
4
+ static fromSuccess: <T>(data: T, metadata?: JsonApiSuccessResponse<T>["meta"]) => JsonApiSuccessResponse<T>;
5
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @link https://jsonapi.org/format/#errors
3
+ */
4
+ export type JsonApiError = {
5
+ /** a short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization. */
6
+ title: string;
7
+ /** a unique identifier for this particular occurrence of the problem. */
8
+ id?: string | number;
9
+ /** the HTTP status code applicable to this problem, expressed as a string value. */
10
+ status?: number;
11
+ /** an application-specific error code, expressed as a string value. */
12
+ code?: string;
13
+ /** a human-readable explanation specific to this occurrence of the problem. Like title, this field’s value can be localized. */
14
+ detail?: string;
15
+ /** a string indicating which URI query parameter caused the error. */
16
+ parameter?: string;
17
+ /** a meta object containing non-standard meta-information about the error. */
18
+ meta?: Record<string, unknown>;
19
+ };
20
+ export type JsonApiErrorResponse = {
21
+ success: false;
22
+ errors: JsonApiError[];
23
+ };
24
+ export type JsonApiResponseMeta = {
25
+ meta?: {
26
+ cacheHit?: boolean;
27
+ } & Record<string, string | number | boolean | Record<string, unknown>>;
28
+ };
29
+ export type JsonApiSuccessResponse<T> = {
30
+ success: true;
31
+ data: T;
32
+ } & JsonApiResponseMeta;
33
+ export type JsonApiResponse<T> = JsonApiErrorResponse | JsonApiSuccessResponse<T>;
@@ -0,0 +1,4 @@
1
+ import type { JsonApiErrorResponse, JsonApiResponse, JsonApiSuccessResponse } from './json-api-response.types';
2
+ export declare const isJsonApiResponse: <T = unknown>(val: unknown) => val is JsonApiResponse<T>;
3
+ export declare const isJsonApiSuccessResponse: <T = unknown>(val: unknown) => val is JsonApiSuccessResponse<T>;
4
+ export declare const isJsonApiErrorResponse: (val: unknown) => val is JsonApiErrorResponse;
@@ -0,0 +1,2 @@
1
+ export { usePromise } from './use-promise';
2
+ export { useDeepCompareMemoize } from './use-deep-compare-memoize';
@@ -0,0 +1,3 @@
1
+ type SupportedValue = Record<string, unknown> | string | boolean | number | null;
2
+ export declare function useDeepCompareMemoize(value: SupportedValue): SupportedValue;
3
+ export {};
@@ -0,0 +1,13 @@
1
+ export type AsyncFnParams<TParams> = TParams;
2
+ export type AsyncFnWithParams<TResult, TParams extends Record<string, unknown>> = (variables: TParams) => Promise<TResult>;
3
+ export type AsyncFnWithoutParams<TResult> = () => Promise<TResult>;
4
+ export type AsyncFn<TResult, TParams extends Record<string, unknown> = Partial<Record<string, unknown>>> = AsyncFnWithParams<TResult, TParams> | AsyncFnWithoutParams<TResult>;
5
+ export interface UsePromiseOptions<TResult> {
6
+ initialData?: TResult;
7
+ }
8
+ export declare function usePromise<TResult, TVariables extends Record<string, unknown> = Partial<Record<string, unknown>>>(promise: AsyncFn<TResult, TVariables>, params: AsyncFnParams<TVariables>, options?: UsePromiseOptions<TResult>): {
9
+ error: Error | null;
10
+ isLoading: boolean;
11
+ data: TResult | null;
12
+ reload: () => void;
13
+ };
package/index.d.ts CHANGED
@@ -8,3 +8,4 @@ export { createCtxNullable } from './utils/createContext';
8
8
  export { default as getNestedObjectValueOfKey } from './utils/object-find-deep-nested';
9
9
  export { default as checkObjectProperty } from './utils/object-property';
10
10
  export { capitalizeFirstLetter } from './utils/string-transform';
11
+ export { normalizePath } from './utils/normalize-path';
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),p=e=>{if(typeof e!="string"||!/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(e))return!1;try{return new Date(e).toISOString()===e}catch{return!1}},c=(e,t=!0)=>typeof e=="string"&&(t?e.trim():e).length>0,b=e=>typeof e=="object"&&e!==null&&e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype,a=e=>typeof e=="number"&&Number.isSafeInteger(e),d=e=>typeof e=="number"&&!Number.isNaN(e)?!0:c(e)?!Number.isNaN(Number.parseInt(e,10)||Number.isNaN(Number.parseFloat(e))):!1,g=e=>{const t=typeof e=="string"&&/^-?\d+$/.test(e)?Number.parseInt(e,10):e;return a(t)},y=e=>a(e)&&e<600&&e>=100;class o{static isPresent(t,r){if(t==null)throw o.createException(r,"Value is null or undefined.")}static safeInteger(t,r){if(typeof t!="number"||!Number.isSafeInteger(t))throw o.createException(r,"Value is not a safe integer")}static nonEmptyString(t,r,n){if(!c(t,n??!0))throw o.createException(r)}static never(t,r){throw new Error(r??"Unexpected value")}static createException(t,r){throw typeof t=="string"||t===void 0?new Error(t??r??"Assertion did not pass."):t()}}function h(e,t){if([e,t].forEach((r,n)=>{if(!Number.isSafeInteger(r))throw new Error(`${n===0?"min":"max"} is not a valid integer`)}),t<e)throw new Error("Min cannot be greater than max");return e=Math.ceil(e),t=Math.floor(t),Math.floor(Math.random()*(t-e+1))+e}class N{static getRandom(t){return t[h(0,t.length-1)]}static removeItem(t,r){const n=t.indexOf(r);return n>-1&&t.splice(n,1),t}}function m(){const e=s.createContext(void 0);function t(){const r=s.useContext(e);if(r===void 0)throw new Error("useCtx must be inside a Provider");return r}return[t,e.Provider]}function x(){const e=s.createContext(void 0);function t(){const r=s.useContext(e);return r===void 0?{}:r}return[t,e.Provider]}function O(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function f(e,t,r){const n=Object.keys(e);let i;i||(i=r);for(const u of n){const l=e[u];if(O(l)&&(i||(i=f(l,t,i))),u===t)return e[t]}return i}const w=(e,t)=>{const r=e[t];return r!=null&&typeof r=="object"&&Object.prototype.hasOwnProperty.call(e,t)?r:null};function I(e){return e.charAt(0).toUpperCase()+e.slice(1)}const P=e=>`I'm the @okam/shared-ui component telling ${e} !`;exports.ArrayUtils=N;exports.Asserts=o;exports.capitalizeFirstLetter=I;exports.checkObjectProperty=w;exports.createCtx=m;exports.createCtxNullable=x;exports.getNestedObjectValueOfKey=f;exports.isHttpStatusCode=y;exports.isIsoDateString=p;exports.isNonEmptyString=c;exports.isParsableNumeric=d;exports.isParsableSafeInteger=g;exports.isPlainObject=b;exports.isSafeInteger=a;exports.sayHello=P;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),d=t=>{if(typeof t!="string"||!/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(t))return!1;try{return new Date(t).toISOString()===t}catch{return!1}},c=(t,e=!0)=>typeof t=="string"&&(e?t.trim():t).length>0,p=t=>typeof t=="object"&&t!==null&&t.constructor===Object&&Object.getPrototypeOf(t)===Object.prototype,a=t=>typeof t=="number"&&Number.isSafeInteger(t),b=t=>typeof t=="number"&&!Number.isNaN(t)?!0:c(t)?!Number.isNaN(Number.parseInt(t,10)||Number.isNaN(Number.parseFloat(t))):!1,g=t=>{const e=typeof t=="string"&&/^-?\d+$/.test(t)?Number.parseInt(t,10):t;return a(e)},h=t=>a(t)&&t<600&&t>=100;class i{static isPresent(e,r){if(e==null)throw i.createException(r,"Value is null or undefined.")}static safeInteger(e,r){if(typeof e!="number"||!Number.isSafeInteger(e))throw i.createException(r,"Value is not a safe integer")}static nonEmptyString(e,r,n){if(!c(e,n??!0))throw i.createException(r)}static never(e,r){throw new Error(r??"Unexpected value")}static createException(e,r){throw typeof e=="string"||e===void 0?new Error(e??r??"Assertion did not pass."):e()}}function y(t,e){if([t,e].forEach((r,n)=>{if(!Number.isSafeInteger(r))throw new Error(`${n===0?"min":"max"} is not a valid integer`)}),e<t)throw new Error("Min cannot be greater than max");return t=Math.ceil(t),e=Math.floor(e),Math.floor(Math.random()*(e-t+1))+t}class m{static getRandom(e){return e[y(0,e.length-1)]}static removeItem(e,r){const n=e.indexOf(r);return n>-1&&e.splice(n,1),e}}function N(){const t=s.createContext(void 0);function e(){const r=s.useContext(t);if(r===void 0)throw new Error("useCtx must be inside a Provider");return r}return[e,t.Provider]}function x(){const t=s.createContext(void 0);function e(){const r=s.useContext(t);return r===void 0?{}:r}return[e,t.Provider]}function P(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function f(t,e,r){const n=Object.keys(t);let o;o||(o=r);for(const u of n){const l=t[u];if(P(l)&&(o||(o=f(l,e,o))),u===e)return t[e]}return o}const O=(t,e)=>{const r=t[e];return r!=null&&typeof r=="object"&&Object.prototype.hasOwnProperty.call(t,e)?r:null};function w(t){return t.charAt(0).toUpperCase()+t.slice(1)}function I(t){return t.split("/").reduceRight((n,o)=>n.length===0&&o===""?n:[o,...n],[]).join("/")}const j=t=>`I'm the @okam/shared-ui component telling ${t} !`;exports.ArrayUtils=m;exports.Asserts=i;exports.capitalizeFirstLetter=w;exports.checkObjectProperty=O;exports.createCtx=N;exports.createCtxNullable=x;exports.getNestedObjectValueOfKey=f;exports.isHttpStatusCode=h;exports.isIsoDateString=d;exports.isNonEmptyString=c;exports.isParsableNumeric=b;exports.isParsableSafeInteger=g;exports.isPlainObject=p;exports.isSafeInteger=a;exports.normalizePath=I;exports.sayHello=j;
package/index.mjs CHANGED
@@ -7,10 +7,10 @@ const h = (t) => {
7
7
  } catch {
8
8
  return !1;
9
9
  }
10
- }, a = (t, e = !0) => typeof t == "string" && (e ? t.trim() : t).length > 0, g = (t) => typeof t == "object" && t !== null && t.constructor === Object && Object.getPrototypeOf(t) === Object.prototype, f = (t) => typeof t == "number" && Number.isSafeInteger(t), y = (t) => typeof t == "number" && !Number.isNaN(t) ? !0 : a(t) ? !Number.isNaN(Number.parseInt(t, 10) || Number.isNaN(Number.parseFloat(t))) : !1, N = (t) => {
10
+ }, a = (t, e = !0) => typeof t == "string" && (e ? t.trim() : t).length > 0, g = (t) => typeof t == "object" && t !== null && t.constructor === Object && Object.getPrototypeOf(t) === Object.prototype, f = (t) => typeof t == "number" && Number.isSafeInteger(t), m = (t) => typeof t == "number" && !Number.isNaN(t) ? !0 : a(t) ? !Number.isNaN(Number.parseInt(t, 10) || Number.isNaN(Number.parseFloat(t))) : !1, y = (t) => {
11
11
  const e = typeof t == "string" && /^-?\d+$/.test(t) ? Number.parseInt(t, 10) : t;
12
12
  return f(e);
13
- }, m = (t) => f(t) && t < 600 && t >= 100;
13
+ }, N = (t) => f(t) && t < 600 && t >= 100;
14
14
  class i {
15
15
  static isPresent(e, r) {
16
16
  if (e == null)
@@ -80,28 +80,32 @@ function d(t, e, r) {
80
80
  }
81
81
  return o;
82
82
  }
83
- const O = (t, e) => {
83
+ const P = (t, e) => {
84
84
  const r = t[e];
85
85
  return r != null && typeof r == "object" && Object.prototype.hasOwnProperty.call(t, e) ? r : null;
86
86
  };
87
- function C(t) {
87
+ function O(t) {
88
88
  return t.charAt(0).toUpperCase() + t.slice(1);
89
89
  }
90
- const j = (t) => `I'm the @okam/shared-ui component telling ${t} !`;
90
+ function j(t) {
91
+ return t.split("/").reduceRight((n, o) => n.length === 0 && o === "" ? n : [o, ...n], []).join("/");
92
+ }
93
+ const C = (t) => `I'm the @okam/shared-ui component telling ${t} !`;
91
94
  export {
92
95
  x as ArrayUtils,
93
96
  i as Asserts,
94
- C as capitalizeFirstLetter,
95
- O as checkObjectProperty,
97
+ O as capitalizeFirstLetter,
98
+ P as checkObjectProperty,
96
99
  w as createCtx,
97
100
  I as createCtxNullable,
98
101
  d as getNestedObjectValueOfKey,
99
- m as isHttpStatusCode,
102
+ N as isHttpStatusCode,
100
103
  h as isIsoDateString,
101
104
  a as isNonEmptyString,
102
- y as isParsableNumeric,
103
- N as isParsableSafeInteger,
105
+ m as isParsableNumeric,
106
+ y as isParsableSafeInteger,
104
107
  g as isPlainObject,
105
108
  f as isSafeInteger,
106
- j as sayHello
109
+ j as normalizePath,
110
+ C as sayHello
107
111
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@okam/core-lib",
3
- "version": "1.16.0",
3
+ "version": "1.17.0",
4
4
  "main": "./index.js",
5
5
  "types": "./index.d.ts",
6
6
  "license": "MIT",
@@ -0,0 +1 @@
1
+ export declare function normalizePath(path: string): string;
@@ -0,0 +1,4 @@
1
+ export declare class StringConvert {
2
+ static toSafeInteger: (value: string | unknown) => number | null;
3
+ static toFloat: (value: string | unknown) => number | null;
4
+ }
@@ -0,0 +1,4 @@
1
+ export type Maybe<T> = T | null;
2
+ export declare function isNonNullable<T>(x: T): x is NonNullable<T>;
3
+ export declare function maybeWithDefault<T>(x: Maybe<T>, defaultValue: NonNullable<T>): NonNullable<T>;
4
+ export declare function unknownToString(str: string | unknown): string;
@@ -1,8 +1,8 @@
1
1
  export type IsoDateString = string;
2
- export declare const isIsoDateString: (dateStr: unknown) => dateStr is string;
2
+ export declare const isIsoDateString: (dateStr: unknown) => dateStr is IsoDateString;
3
3
  export declare const isNonEmptyString: (v: unknown, trim?: boolean) => v is string;
4
4
  export declare const isPlainObject: <T = unknown, K extends string | number = string>(v: unknown) => v is Record<K, T>;
5
5
  export declare const isSafeInteger: (v: unknown) => v is number;
6
- export declare const isParsableNumeric: (v: unknown) => v is string | number;
7
- export declare const isParsableSafeInteger: (v: unknown) => v is string | number;
6
+ export declare const isParsableNumeric: (v: unknown) => v is number | string;
7
+ export declare const isParsableSafeInteger: (v: unknown) => v is number | string;
8
8
  export declare const isHttpStatusCode: (v: unknown) => v is number;