New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@logto/shared

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@logto/shared - npm Package Compare versions

Comparing version 1.0.0-beta.18 to 1.0.0-rc.0

lib/utils/object.d.ts

3

lib/database/utils.d.ts

@@ -8,2 +8,5 @@ import type { SchemaValuePrimitive, SchemaValue } from '@logto/schemas';

}>;
export declare const conditionalArraySql: <T>(value: T[], buildSql: (value: T[]) => SqlSqlToken) => SqlSqlToken<{
[x: string]: any;
}>;
export declare const autoSetFields: readonly ["createdAt", "updatedAt"];

@@ -10,0 +13,0 @@ export type OmitAutoSetFields<T> = Omit<T, typeof autoSetFields[number]>;

import { notFalsy } from '@silverhand/essentials';
import { sql } from 'slonik';
export const conditionalSql = (value, buildSql) => notFalsy(value) ? buildSql(value) : sql ``;
export const conditionalArraySql = (value, buildSql) => (value.length > 0 ? buildSql(value) : sql ``);
export const autoSetFields = Object.freeze(['createdAt', 'updatedAt']);

@@ -5,0 +6,0 @@ export const excludeAutoSetFields = (fields) => Object.freeze(fields.filter((field) =>

8

lib/utils/function.d.ts

@@ -1,7 +0,11 @@

export declare const tryThat: <T, E extends Error>(exec: Promise<T> | (() => Promise<T>), onError: E | ((error: unknown) => never)) => Promise<T>;
export declare const isPromise: (value: unknown) => value is Promise<unknown>;
export type TryThat = {
<T>(exec: () => T, onError: Error | ((error: unknown) => never)): T;
<T>(exec: Promise<T> | (() => Promise<T>), onError: Error | ((error: unknown) => never)): Promise<T>;
};
export declare const tryThat: TryThat;
export type TrySafe = {
<T>(exec: () => T): T | undefined;
<T>(exec: Promise<T> | (() => Promise<T>)): Promise<T | undefined>;
<T>(exec: () => T): T | undefined;
};
export declare const trySafe: TrySafe;

@@ -1,18 +0,23 @@

export const tryThat = async (exec, onError) => {
try {
return await (typeof exec === 'function' ? exec() : exec);
}
catch (error) {
export const isPromise = (value) => value !== null &&
(typeof value === 'object' || typeof value === 'function') &&
'then' in value &&
typeof value.then === 'function';
export const tryThat = (exec, onError) => {
const handleError = (error) => {
if (onError instanceof Error) {
// https://github.com/typescript-eslint/typescript-eslint/issues/3814
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw onError;
}
return onError(error);
};
try {
const unwrapped = typeof exec === 'function' ? exec() : exec;
return isPromise(unwrapped)
? // eslint-disable-next-line promise/prefer-await-to-then
unwrapped.catch(handleError)
: unwrapped;
}
catch (error) {
return handleError(error);
}
};
export const isPromise = (value) => value !== null &&
(typeof value === 'object' || typeof value === 'function') &&
'then' in value &&
typeof value.then === 'function';
export const trySafe = (exec) => {

@@ -19,0 +24,0 @@ try {

@@ -1,6 +0,33 @@

import { trySafe } from './function.js';
import { trySafe, tryThat } from './function.js';
describe('tryThat()', () => {
it('should directly execute and return or throw if the function is not a Promise', () => {
expect(tryThat(() => 'foo', new Error('try'))).toStrictEqual('foo');
expect(() => tryThat(() => {
throw new Error('Test');
}, new Error('try'))).toThrowError(new Error('try'));
expect(() => tryThat(() => {
throw new Error('Test');
}, (error) => {
throw new Error(String(error instanceof Error && error.message) + ' try');
})).toThrowError(new Error('Test try'));
});
it('should execute or unwrap a Promise and throw the error', async () => {
expect(await tryThat(new Promise((resolve) => {
setTimeout(() => {
resolve('bar');
}, 0);
}), new Error('try'))).toStrictEqual('bar');
await expect(tryThat(async () => new Promise((resolve, reject) => {
reject();
}), () => {
throw new Error('try');
})).rejects.toStrictEqual(new Error('try'));
});
});
describe('trySafe()', () => {
it('should directly execute and return if the function is not a Promise', () => {
expect(trySafe(() => 'foo')).toStrictEqual('foo');
expect(trySafe(() => {
expect(
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
trySafe(() => {
throw new Error('Test');

@@ -7,0 +34,0 @@ })

export * from './function.js';
export * from './object.js';
export { default as findPackage } from './find-package.js';
export * from './function.js';
export * from './object.js';
export { default as findPackage } from './find-package.js';
{
"name": "@logto/shared",
"version": "1.0.0-beta.18",
"version": "1.0.0-rc.0",
"main": "lib/index.js",

@@ -26,3 +26,3 @@ "author": "Silverhand Inc. <contact@silverhand.io>",

"@types/jest": "^29.1.2",
"@types/node": "^16.0.0",
"@types/node": "^18.11.18",
"eslint": "^8.21.0",

@@ -35,3 +35,3 @@ "jest": "^29.1.2",

"engines": {
"node": "^16.13.0 || ^18.12.0"
"node": "^18.12.0"
},

@@ -50,3 +50,3 @@ "eslintConfig": {

"slonik": "^30.0.0",
"@logto/schemas": "1.0.0-beta.18"
"@logto/schemas": "1.0.0-rc.0"
},

@@ -53,0 +53,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc