@atproto/common-web
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -1,2 +0,1 @@ | ||
const pkgJson = require('@npmcli/package-json') | ||
const { nodeExternalsPlugin } = require('esbuild-node-externals') | ||
@@ -7,9 +6,2 @@ | ||
if (process.argv.includes('--update-main-to-dist')) { | ||
return pkgJson | ||
.load(__dirname) | ||
.then((pkg) => pkg.update({ main: 'dist/index.js' })) | ||
.then((pkg) => pkg.save()) | ||
} | ||
require('esbuild').build({ | ||
@@ -16,0 +8,0 @@ logLevel: 'info', |
export * as check from './check'; | ||
export * as util from './util'; | ||
export * from './arrays'; | ||
export * from './async'; | ||
@@ -4,0 +5,0 @@ export * from './util'; |
export declare class TID { | ||
str: string; | ||
constructor(str: string); | ||
static next(): TID; | ||
static nextStr(): string; | ||
static next(prev?: TID): TID; | ||
static nextStr(prev?: string): string; | ||
static fromTime(timestamp: number, clockid: number): TID; | ||
@@ -7,0 +7,0 @@ static fromStr(str: string): TID; |
@@ -5,1 +5,2 @@ export declare const SECOND = 1000; | ||
export declare const DAY: number; | ||
export declare const lessThanAgoMs: (time: Date, range: number) => boolean; |
@@ -0,8 +1,10 @@ | ||
/// <reference types="node" /> | ||
export declare const noUndefinedVals: <T>(obj: Record<string, T>) => Record<string, T>; | ||
export declare const jitter: (maxMs: number) => number; | ||
export declare const wait: (ms: number) => Promise<unknown>; | ||
export declare const bailableWait: (ms: number) => { | ||
export declare type BailableWait = { | ||
bail: () => void; | ||
wait: () => Promise<void>; | ||
}; | ||
export declare const bailableWait: (ms: number) => BailableWait; | ||
export declare const flattenUint8Arrays: (arrs: Uint8Array[]) => Uint8Array; | ||
@@ -9,0 +11,0 @@ export declare const streamToBuffer: (stream: AsyncIterable<Uint8Array>) => Promise<Uint8Array>; |
{ | ||
"name": "@atproto/common-web", | ||
"version": "0.2.0", | ||
"main": "dist/index.js", | ||
"version": "0.2.1", | ||
"license": "MIT", | ||
"description": "Shared web-platform-friendly code for atproto libraries", | ||
"keywords": [ | ||
"atproto" | ||
], | ||
"homepage": "https://atproto.com", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/bluesky-social/atproto.git", | ||
"url": "https://github.com/bluesky-social/atproto", | ||
"directory": "packages/common-web" | ||
}, | ||
"main": "dist/index.js", | ||
"dependencies": { | ||
"graphemer": "^1.4.0", | ||
"multiformats": "^9.9.0", | ||
"uint8arrays": "3.0.0", | ||
"zod": "^3.21.4" | ||
}, | ||
"scripts": { | ||
"test": "jest", | ||
"prettier": "prettier --check src/ tests/", | ||
"prettier:fix": "prettier --write src/ tests/", | ||
"lint": "eslint . --ext .ts,.tsx", | ||
"lint:fix": "yarn lint --fix", | ||
"verify": "run-p prettier lint", | ||
"verify:fix": "yarn prettier:fix && yarn lint:fix", | ||
"build": "node ./build.js", | ||
"postbuild": "tsc --build tsconfig.build.json", | ||
"update-main-to-dist": "node ./update-pkg.js --update-main-to-dist", | ||
"update-main-to-src": "node ./update-pkg.js --update-main-to-src", | ||
"prepublish": "npm run update-main-to-dist", | ||
"postpublish": "npm run update-main-to-src" | ||
"update-main-to-dist": "node ../../update-main-to-dist.js packages/common-web" | ||
}, | ||
"dependencies": { | ||
"graphemer": "^1.4.0", | ||
"multiformats": "^9.6.4", | ||
"uint8arrays": "3.0.0", | ||
"zod": "^3.21.4" | ||
} | ||
} | ||
"types": "dist/index.d.ts" | ||
} |
@@ -1,3 +0,10 @@ | ||
# ATP Common Library for Web | ||
# @atproto/common-web | ||
A library containing code which is shared between web-friendly ATP packages. | ||
Shared TypeScript code for other `@atproto/*` packages, which is web-friendly (runs in-browser). | ||
[![NPM](https://img.shields.io/npm/v/@atproto/common)](https://www.npmjs.com/package/@atproto/common-web) | ||
[![Github CI Status](https://github.com/bluesky-social/atproto/actions/workflows/repo.yaml/badge.svg)](https://github.com/bluesky-social/atproto/actions/workflows/repo.yaml) | ||
## License | ||
MIT License |
export * as check from './check' | ||
export * as util from './util' | ||
export * from './arrays' | ||
export * from './async' | ||
@@ -5,0 +6,0 @@ export * from './util' |
@@ -24,3 +24,3 @@ import { s32encode, s32decode } from './util' | ||
static next(): TID { | ||
static next(prev?: TID): TID { | ||
// javascript does not have microsecond precision | ||
@@ -40,7 +40,11 @@ // instead, we append a counter to the timestamp to indicate if multiple timestamps were created within the same millisecond | ||
} | ||
return TID.fromTime(timestamp, clockid) | ||
const tid = TID.fromTime(timestamp, clockid) | ||
if (!prev || tid.newerThan(prev)) { | ||
return tid | ||
} | ||
return TID.fromTime(prev.timestamp() + 1, clockid) | ||
} | ||
static nextStr(): string { | ||
return TID.next().toString() | ||
static nextStr(prev?: string): string { | ||
return TID.next(prev ? new TID(prev) : undefined).toString() | ||
} | ||
@@ -47,0 +51,0 @@ |
@@ -5,1 +5,5 @@ export const SECOND = 1000 | ||
export const DAY = HOUR * 24 | ||
export const lessThanAgoMs = (time: Date, range: number) => { | ||
return Date.now() < time.getTime() + range | ||
} |
@@ -20,5 +20,8 @@ export const noUndefinedVals = <T>( | ||
export const bailableWait = ( | ||
ms: number, | ||
): { bail: () => void; wait: () => Promise<void> } => { | ||
export type BailableWait = { | ||
bail: () => void | ||
wait: () => Promise<void> | ||
} | ||
export const bailableWait = (ms: number): BailableWait => { | ||
let bail | ||
@@ -25,0 +28,0 @@ const waitPromise = new Promise<void>((res) => { |
@@ -29,2 +29,8 @@ import TID from '../src/tid' | ||
}) | ||
it('returns a next tid larger than a provided prev', () => { | ||
const prev = TID.fromTime((Date.now() + 5000) * 1000, 0).toString() | ||
const str = TID.nextStr(prev) | ||
expect(str > prev).toBe(true) | ||
}) | ||
}) | ||
@@ -31,0 +37,0 @@ |
{ | ||
"extends": "./tsconfig.json", | ||
"exclude": ["**/*.spec.ts", "**/*.test.ts"] | ||
} | ||
} |
@@ -8,3 +8,3 @@ { | ||
}, | ||
"include": ["./src","__tests__/**/**.ts"], | ||
} | ||
"include": ["./src", "__tests__/**/**.ts"] | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
35
15137
1
11
0
1864731
Updatedmultiformats@^9.9.0