@logto/shared
Advanced tools
Comparing version 3.1.0 to 3.1.1
@@ -1,2 +0,1 @@ | ||
import type { IdentifierSqlToken } from 'slonik'; | ||
export type SchemaValuePrimitive = string | number | boolean | undefined; | ||
@@ -11,5 +10,2 @@ export type SchemaValue = SchemaValuePrimitive | Record<string, unknown> | unknown[] | null; | ||
}; | ||
export type FieldIdentifiers<Key extends string> = { | ||
[key in Key]: IdentifierSqlToken; | ||
}; | ||
export type OrderDirection = 'asc' | 'desc'; | ||
@@ -16,0 +12,0 @@ export type UpdateWhereData<SetKey extends string, WhereKey extends string> = { |
@@ -0,2 +1,5 @@ | ||
/** | ||
* @fileoverview This file is used for jest only. This package does not need jest for testing. | ||
*/ | ||
declare const proxy: ProxyConstructor; | ||
export default proxy; |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @fileoverview This file is used for jest only. This package does not need jest for testing. | ||
*/ | ||
const { jest } = import.meta; | ||
@@ -2,0 +5,0 @@ // For testing |
export * from './universal.js'; | ||
export * from './node/index.js'; | ||
export * from './database/sql.js'; |
export * from './universal.js'; | ||
export * from './node/index.js'; | ||
export * from './database/sql.js'; |
export default class ConsoleLog { | ||
/** A prefix to prepend to all log messages. */ | ||
readonly prefix?: string | undefined; | ||
/** | ||
* The number of spaces to pad the prefix. For example, if the prefix is `custom` and the | ||
* padding is 8, the output will be `custom `. | ||
* | ||
* @default 8 | ||
*/ | ||
readonly padding: number; | ||
static prefixes: Readonly<{ | ||
@@ -8,6 +17,13 @@ info: string; | ||
}>; | ||
plain: { | ||
(...data: any[]): void; | ||
(message?: any, ...optionalParams: any[]): void; | ||
}; | ||
constructor( | ||
/** A prefix to prepend to all log messages. */ | ||
prefix?: string | undefined, | ||
/** | ||
* The number of spaces to pad the prefix. For example, if the prefix is `custom` and the | ||
* padding is 8, the output will be `custom `. | ||
* | ||
* @default 8 | ||
*/ | ||
padding?: number); | ||
plain: typeof console.log; | ||
info: typeof console.log; | ||
@@ -18,2 +34,3 @@ succeed: typeof console.log; | ||
fatal: (...args: Parameters<typeof console.log>) => never; | ||
protected getArgs(args: Parameters<typeof console.log>): [message?: any, ...optionalParams: any[]]; | ||
} |
import chalk from 'chalk'; | ||
export default class ConsoleLog { | ||
constructor() { | ||
this.plain = console.log; | ||
static { this.prefixes = Object.freeze({ | ||
info: chalk.bold(chalk.blue('info')), | ||
warn: chalk.bold(chalk.yellow('warn')), | ||
error: chalk.bold(chalk.red('error')), | ||
fatal: chalk.bold(chalk.red('fatal')), | ||
}); } | ||
constructor( | ||
/** A prefix to prepend to all log messages. */ | ||
prefix, | ||
/** | ||
* The number of spaces to pad the prefix. For example, if the prefix is `custom` and the | ||
* padding is 8, the output will be `custom `. | ||
* | ||
* @default 8 | ||
*/ | ||
padding = 8) { | ||
this.prefix = prefix; | ||
this.padding = padding; | ||
this.plain = (...args) => { | ||
console.log(...this.getArgs(args)); | ||
}; | ||
this.info = (...args) => { | ||
console.log(ConsoleLog.prefixes.info, ...args); | ||
this.plain(ConsoleLog.prefixes.info, ...args); | ||
}; | ||
@@ -12,9 +31,9 @@ this.succeed = (...args) => { | ||
this.warn = (...args) => { | ||
console.warn(ConsoleLog.prefixes.warn, ...args); | ||
console.warn(...this.getArgs([ConsoleLog.prefixes.warn, ...args])); | ||
}; | ||
this.error = (...args) => { | ||
console.error(ConsoleLog.prefixes.error, ...args); | ||
console.error(...this.getArgs([ConsoleLog.prefixes.error, ...args])); | ||
}; | ||
this.fatal = (...args) => { | ||
console.error(ConsoleLog.prefixes.fatal, ...args); | ||
console.error(...this.getArgs([ConsoleLog.prefixes.fatal, ...args])); | ||
// eslint-disable-next-line unicorn/no-process-exit | ||
@@ -24,8 +43,9 @@ process.exit(1); | ||
} | ||
static { this.prefixes = Object.freeze({ | ||
info: chalk.bold(chalk.blue('info')), | ||
warn: chalk.bold(chalk.yellow('warn')), | ||
error: chalk.bold(chalk.red('error')), | ||
fatal: chalk.bold(chalk.red('fatal')), | ||
}); } | ||
getArgs(args) { | ||
if (this.prefix) { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
return [this.prefix.padEnd(this.padding), ...args]; | ||
} | ||
return args; | ||
} | ||
} |
@@ -0,1 +1,2 @@ | ||
import { afterEach, describe, expect, it } from 'vitest'; | ||
import UrlSet from './UrlSet.js'; | ||
@@ -2,0 +3,0 @@ describe('UrlSet', () => { |
@@ -0,1 +1,2 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { generateStandardId, generateStandardSecret, generateStandardShortId } from './id.js'; | ||
@@ -2,0 +3,0 @@ describe('standard id generator', () => { |
@@ -0,6 +1,8 @@ | ||
export * from './fetch.js'; | ||
export * from './id.js'; | ||
export * from './normalize-error.js'; | ||
export * from './object.js'; | ||
export * from './phone.js'; | ||
export * from './sub-domain.js'; | ||
export * from './ttl-cache.js'; | ||
export * from './id.js'; | ||
export * from './user-display-name.js'; | ||
export * from './phone.js'; | ||
export * from './sub-domain.js'; |
@@ -0,6 +1,8 @@ | ||
export * from './fetch.js'; | ||
export * from './id.js'; | ||
export * from './normalize-error.js'; | ||
export * from './object.js'; | ||
export * from './phone.js'; | ||
export * from './sub-domain.js'; | ||
export * from './ttl-cache.js'; | ||
export * from './id.js'; | ||
export * from './user-display-name.js'; | ||
export * from './phone.js'; | ||
export * from './sub-domain.js'; |
@@ -0,1 +1,2 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { isValidSubdomain } from './sub-domain.js'; | ||
@@ -2,0 +3,0 @@ describe('isValidSubdomain()', () => { |
@@ -0,16 +1,16 @@ | ||
import { afterEach, describe, expect, it, beforeEach, vi } from 'vitest'; | ||
import { TtlCache } from './ttl-cache.js'; | ||
const { jest } = import.meta; | ||
describe('TtlCache', () => { | ||
beforeEach(() => { | ||
jest.useFakeTimers(); | ||
vi.useFakeTimers(); | ||
}); | ||
afterEach(() => { | ||
jest.useRealTimers(); | ||
vi.useRealTimers(); | ||
}); | ||
it('should return cached value after a long time if ttl is not set', () => { | ||
jest.setSystemTime(0); | ||
vi.setSystemTime(0); | ||
const cache = new TtlCache(); | ||
const someObject = Object.freeze({ foo: 'bar', baz: 123 }); | ||
cache.set('foo', someObject); | ||
jest.setSystemTime(100_000_000); | ||
vi.setSystemTime(100_000_000); | ||
expect(cache.get('foo')).toBe(someObject); | ||
@@ -20,3 +20,3 @@ expect(cache.has('foo')).toBe(true); | ||
it('should return cached value and honor ttl', () => { | ||
jest.setSystemTime(0); | ||
vi.setSystemTime(0); | ||
const cache = new TtlCache(100); | ||
@@ -26,3 +26,3 @@ const someObject = Object.freeze({ foo: 'bar', baz: 123 }); | ||
cache.set('foo', someObject, 99); | ||
jest.setSystemTime(100); | ||
vi.setSystemTime(100); | ||
expect(cache.get(123)).toBe(someObject); | ||
@@ -34,3 +34,3 @@ expect(cache.has(123)).toBe(true); | ||
expect(cache.has('foo')).toBe(false); | ||
jest.setSystemTime(101); | ||
vi.setSystemTime(101); | ||
expect(cache.get(123)).toBe(undefined); | ||
@@ -37,0 +37,0 @@ expect(cache.has(123)).toBe(false); |
@@ -0,1 +1,2 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { getUserDisplayName } from './user-display-name.js'; | ||
@@ -2,0 +3,0 @@ describe('getUserDisplayName', () => { |
{ | ||
"name": "@logto/shared", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"main": "lib/index.js", | ||
@@ -29,12 +29,12 @@ "author": "Silverhand Inc. <contact@silverhand.io>", | ||
"devDependencies": { | ||
"@logto/connector-kit": "^2.1.0", | ||
"@silverhand/eslint-config": "5.0.0", | ||
"@silverhand/ts-config": "5.0.0", | ||
"@types/jest": "^29.4.0", | ||
"@jest/globals": "^29.7.0", | ||
"@silverhand/eslint-config": "6.0.1", | ||
"@silverhand/ts-config": "6.0.0", | ||
"@types/node": "^20.9.5", | ||
"eslint": "^8.44.0", | ||
"jest": "^29.7.0", | ||
"@vitest/coverage-v8": "^1.4.0", | ||
"eslint": "^8.56.0", | ||
"lint-staged": "^15.0.0", | ||
"prettier": "^3.0.0", | ||
"typescript": "^5.3.3" | ||
"typescript": "^5.3.3", | ||
"vitest": "^1.4.0" | ||
}, | ||
@@ -56,4 +56,3 @@ "engines": { | ||
"libphonenumber-js": "^1.9.49", | ||
"nanoid": "^5.0.1", | ||
"slonik": "^30.0.0" | ||
"nanoid": "^5.0.1" | ||
}, | ||
@@ -63,10 +62,9 @@ "scripts": { | ||
"build": "rm -rf lib/ && tsc -p tsconfig.build.json", | ||
"build:test": "rm -rf lib/ && tsc -p tsconfig.test.json --sourcemap", | ||
"build:test": "pnpm build", | ||
"dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput --incremental", | ||
"lint": "eslint --ext .ts src", | ||
"lint:report": "pnpm lint --format json --output-file report.json", | ||
"test:only": "NODE_OPTIONS=--experimental-vm-modules jest", | ||
"test": "pnpm build:test && pnpm test:only", | ||
"test:ci": "pnpm test:only" | ||
"test": "vitest src", | ||
"test:ci": "pnpm run test --silent --coverage" | ||
} | ||
} |
69169
5
60
1151
- Removedslonik@^30.0.0
- Removedbase64-js@1.5.1(transitive)
- Removedbl@4.1.0(transitive)
- Removedbluebird@3.7.2(transitive)
- Removedbuffer@5.7.1(transitive)
- Removedbuffer-from@1.1.2(transitive)
- Removedbufferput@0.1.3(transitive)
- Removedconcat-stream@2.0.0(transitive)
- Removedes6-error@4.1.1(transitive)
- Removedfast-printf@1.6.10(transitive)
- Removedfast-safe-stringify@2.1.1(transitive)
- Removedget-stack-trace@2.1.1(transitive)
- Removedhyperid@2.3.1(transitive)
- Removedieee754@1.2.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedint64-buffer@0.99.1007(transitive)
- Removedis-plain-object@5.0.0(transitive)
- Removediso8601-duration@1.3.0(transitive)
- Removedlodash.sortby@4.7.0(transitive)
- Removedmulti-fork@0.0.2(transitive)
- Removedobuf@1.1.2(transitive)
- Removedp-defer@3.0.0(transitive)
- Removedpg@8.13.3(transitive)
- Removedpg-cloudflare@1.1.1(transitive)
- Removedpg-connection-string@2.7.0(transitive)
- Removedpg-copy-streams@6.0.6(transitive)
- Removedpg-copy-streams-binary@2.2.0(transitive)
- Removedpg-cursor@2.12.3(transitive)
- Removedpg-int8@1.0.1(transitive)
- Removedpg-numeric@1.0.2(transitive)
- Removedpg-pool@3.7.1(transitive)
- Removedpg-protocol@1.7.1(transitive)
- Removedpg-types@2.2.04.0.2(transitive)
- Removedpgpass@1.0.5(transitive)
- Removedpostgres-array@2.0.03.0.2(transitive)
- Removedpostgres-bytea@1.0.03.0.0(transitive)
- Removedpostgres-date@1.0.72.1.0(transitive)
- Removedpostgres-interval@1.2.03.0.04.0.2(transitive)
- Removedpostgres-range@1.1.4(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedroarr@7.21.1(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafe-stable-stringify@2.5.0(transitive)
- Removedsemver-compare@1.0.0(transitive)
- Removedserialize-error@8.1.0(transitive)
- Removedslonik@30.4.4(transitive)
- Removedsource-map@0.8.0-beta.0(transitive)
- Removedsplit2@4.2.0(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedthrough2@3.0.24.0.2(transitive)
- Removedtr46@1.0.1(transitive)
- Removedtype-fest@0.20.2(transitive)
- Removedtypedarray@0.0.6(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removeduuid@8.3.2(transitive)
- Removeduuid-parse@1.1.0(transitive)
- Removedwebidl-conversions@4.0.2(transitive)
- Removedwhatwg-url@7.1.0(transitive)
- Removedxtend@4.0.2(transitive)
- Removedzod@3.24.2(transitive)