@bothrs/util
Advanced tools
Comparing version 2.0.1 to 2.0.2-1
@@ -9,5 +9,7 @@ import { | ||
remove as removePure, | ||
Environment, | ||
FieldSet, | ||
Environment, | ||
Packed, | ||
SelectOptions, | ||
Unpacked, | ||
} from './airtable' | ||
@@ -22,40 +24,43 @@ export { byIds, pack, serialize, unpack, where } from './airtable' | ||
export async function create( | ||
export async function create<T extends FieldSet>( | ||
tableName: string, | ||
fields: FieldSet | ||
): Promise<FieldSet> { | ||
fields: T | ||
): Promise<Unpacked<T>> { | ||
return createPure(env, tableName, fields) | ||
} | ||
export async function find(tableName: string, id: string): Promise<FieldSet> { | ||
export async function find<T extends FieldSet>( | ||
tableName: string, | ||
id: string | ||
): Promise<Unpacked<T>> { | ||
return findPure(env, tableName, id) | ||
} | ||
export async function first( | ||
export async function first<T extends FieldSet>( | ||
tableName: string, | ||
filter: SelectOptions = {} | ||
): Promise<FieldSet | null> { | ||
): Promise<T | null> { | ||
return firstPure(env, tableName, filter) | ||
} | ||
export async function select( | ||
export async function select<T extends FieldSet>( | ||
tableName: string, | ||
filter: SelectOptions = {} | ||
): Promise<FieldSet[]> { | ||
): Promise<T[]> { | ||
return selectPure(env, tableName, filter) | ||
} | ||
export async function selectAll( | ||
export async function selectAll<T extends FieldSet>( | ||
tableName: string, | ||
filter: SelectOptions = {}, | ||
prepend: FieldSet[] = [] | ||
): Promise<FieldSet[]> { | ||
prepend: Packed<T>[] = [] | ||
): Promise<T[]> { | ||
return selectAllPure(env, tableName, filter, prepend) | ||
} | ||
export async function update( | ||
export async function update<T extends FieldSet>( | ||
tableName: string, | ||
id: string, | ||
fields: FieldSet | ||
): Promise<FieldSet> { | ||
fields: T | ||
): Promise<Unpacked<T>> { | ||
return updatePure(env, tableName, id, fields) | ||
@@ -62,0 +67,0 @@ } |
@@ -21,7 +21,7 @@ import { serialize } from './url' | ||
export async function create( | ||
export async function create<T extends FieldSet>( | ||
env: Environment, | ||
tableName: string, | ||
fields: FieldSet | ||
): Promise<FieldSet> { | ||
fields: T | ||
): Promise<Unpacked<T>> { | ||
env.log && env.log('create', tableName, fields) | ||
@@ -39,7 +39,7 @@ const body = await fetch(app(env.app) + tableName, { | ||
export async function find( | ||
export async function find<T extends FieldSet>( | ||
env: Environment, | ||
tableName: string, | ||
id: string | ||
): Promise<FieldSet> { | ||
): Promise<Unpacked<T>> { | ||
env.log && env.log('find', tableName, id) | ||
@@ -55,17 +55,17 @@ const body = await fetch(app(env.app) + tableName + '/' + id, { | ||
export async function first( | ||
export async function first<T extends FieldSet>( | ||
env: Environment, | ||
tableName: string, | ||
filter: SelectOptions = {} | ||
): Promise<FieldSet | null> { | ||
): Promise<Unpacked<T> | null> { | ||
env.log && env.log('first', tableName, filter) | ||
const items = await select(env, tableName, filter) | ||
const items = await select<T>(env, tableName, filter) | ||
return items.length ? items[0] : null | ||
} | ||
export async function select( | ||
export async function select<T extends FieldSet>( | ||
env: Environment, | ||
tableName: string, | ||
filter: SelectOptions = {} | ||
): Promise<FieldSet[]> { | ||
): Promise<Unpacked<T>[]> { | ||
env.log && env.log('select', tableName, filter) | ||
@@ -86,8 +86,8 @@ const body = await fetch(app(env.app) + tableName + '?' + serialize(filter), { | ||
export async function selectAll( | ||
export async function selectAll<T extends FieldSet>( | ||
env: Environment, | ||
tableName: string, | ||
filter: SelectOptions = {}, | ||
prepend: FieldSet[] = [] | ||
): Promise<FieldSet[]> { | ||
prepend: Packed<T>[] = [] | ||
): Promise<Unpacked<T>[]> { | ||
env.log && env.log('selectAll', tableName, filter, prepend.length) | ||
@@ -102,3 +102,3 @@ const body = await fetch(app(env.app) + tableName + '?' + serialize(filter), { | ||
if (offset) { | ||
return selectAll( | ||
return selectAll<T>( | ||
env, | ||
@@ -117,8 +117,8 @@ tableName, | ||
export async function update( | ||
export async function update<T extends FieldSet>( | ||
env: Environment, | ||
tableName: string, | ||
id: string, | ||
fields: FieldSet | ||
): Promise<FieldSet> { | ||
fields: T | ||
): Promise<Unpacked<T>> { | ||
env.log && env.log('update', tableName, fields) | ||
@@ -136,7 +136,7 @@ const body = await fetch(app(env.app) + tableName + '/' + id, { | ||
export async function remove( | ||
export async function remove<T extends FieldSet>( | ||
env: Environment, | ||
tableName: string, | ||
id: string | ||
): Promise<FieldSet> { | ||
): Promise<Unpacked<T>> { | ||
env.log && env.log('remove', tableName, id) | ||
@@ -155,3 +155,5 @@ const body = await fetch(app(env.app) + tableName + '/' + id, { | ||
export function pack(fields: FieldSet) { | ||
export function pack<T extends FieldSet & { _id: string }>( | ||
fields: Unpacked<T> | ||
): Packed<FieldSet> { | ||
return { | ||
@@ -164,3 +166,7 @@ id: fields._id, | ||
export function unpack({ id: _id, fields, createdTime }: FieldSet) { | ||
export function unpack<T extends FieldSet>({ | ||
id: _id, | ||
fields, | ||
createdTime, | ||
}: Packed<T>): Unpacked<T> { | ||
return { | ||
@@ -204,5 +210,14 @@ _id, | ||
export interface Packed<T extends FieldSet> { | ||
id: string | ||
fields: T | ||
createdTime: string | ||
} | ||
export type Unpacked<T extends FieldSet> = T & { | ||
_id: string | ||
} | ||
export interface FieldSet { | ||
_id?: string | ||
[key: string]: any | ||
} |
{ | ||
"name": "@bothrs/util", | ||
"version": "2.0.1", | ||
"version": "2.0.2-1", | ||
"description": "Common helper functions", | ||
@@ -13,3 +13,5 @@ "license": "MIT", | ||
"prepare": "yarn fix", | ||
"prepublishOnly": "npm run build" | ||
"prepublishOnly": "npm run build", | ||
"preversion": "yarn fix", | ||
"postversion": "echo $npm_package_version && sleep 3 && git push --tags && yarn publish . --tag $npm_package_version && git push && echo \"Successfully released version $npm_package_version!\"" | ||
}, | ||
@@ -16,0 +18,0 @@ "dependencies": {}, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
309749
129
5516
3
31
28