Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix arethetypesworking errors in all packages #1004

Merged
merged 21 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f40cc38
did-mailto tsconfig.json uses moduleResolution and module NodeNext to…
gobengo Oct 24, 2023
f7acf63
capabilities package builds with module/moduleResolution NodeNext to …
gobengo Oct 24, 2023
7a95162
packages/access-client uses tsconfig module/moduleResolution of NodeN…
gobengo Oct 24, 2023
7d44289
upload-api package is tsc with module/moduleResolution of NodeNext to…
gobengo Oct 24, 2023
baca19f
wip fix upload-client
gobengo Oct 24, 2023
e4e431d
w3up-client package uses module/moduleResolution NodeNext and now pas…
gobengo Oct 24, 2023
51fac46
filecoin-client fix attw
gobengo Oct 24, 2023
52724b2
fix attw in filecoin-api
gobengo Oct 24, 2023
7b6139a
root tsconfig.json (that others inherit from) use module=NodeNext and…
gobengo Oct 24, 2023
8980d10
Merge branch 'main' into fix-attw-1698165616
gobengo Oct 24, 2023
89f5c5e
all packages have an attw script
gobengo Oct 24, 2023
41ab164
github workflows for access-client and w3up-client run attw
gobengo Oct 24, 2023
5f1920d
prettier .attw.json
gobengo Oct 24, 2023
f8652a5
prettier
gobengo Oct 24, 2023
3b4156c
add atty as monorepo devDep
gobengo Oct 24, 2023
433ab1d
module=Node16 not NodeNext
gobengo Oct 24, 2023
cdf8b53
rm this file now that I merged in another commits that moves it to a …
gobengo Oct 24, 2023
7382e3d
rm unused var
gobengo Oct 24, 2023
1b5a476
remove child tsconfig.json explicitly using module=NodeNext and inste…
gobengo Oct 24, 2023
df5995b
add rationale for ts-expect-error in unixfs.test.js import of blockst…
gobengo Oct 24, 2023
e9882a4
rm unused ts-ignore
gobengo Oct 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .attw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignoreRules": ["cjs-resolves-to-esm"]
}
1 change: 1 addition & 0 deletions .github/workflows/access-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ jobs:
- run: pnpm -r --filter @web3-storage/access run lint
- run: pnpm -r --filter @web3-storage/access run test
- run: pnpm -r --filter @web3-storage/access exec depcheck
- run: pnpm --filter '@web3-storage/access' attw
1 change: 1 addition & 0 deletions .github/workflows/w3up-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
registry-url: https://registry.npmjs.org/
cache: 'pnpm'
- run: pnpm --filter '@web3-storage/w3up-client...' install
- run: pnpm --filter '@web3-storage/w3up-client' attw
- uses: ./packages/w3up-client/.github/actions/test
with:
w3up-client-dir: ./packages/w3up-client/
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"docs:markdown": "pnpm run build && docusaurus generate-typedoc"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.12.2",
"@docusaurus/core": "^2.3.1",
"docusaurus-plugin-typedoc": "^0.18.0",
"lint-staged": "^13.2.0",
Expand Down
1 change: 1 addition & 0 deletions packages/access-client/.attw.json
17 changes: 9 additions & 8 deletions packages/access-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"types": "dist/src/index.d.ts",
"main": "src/index.js",
"scripts": {
"attw": "attw --pack .",
"lint": "tsc --build && eslint '**/*.{js,ts}' && prettier --check '**/*.{js,ts,yml,json}' --ignore-path ../../.gitignore",
"build": "tsc --build",
"check": "tsc --build",
Expand All @@ -24,12 +25,12 @@
"rc": "npm version prerelease --preid rc"
},
"exports": {
".": "./src/index.js",
"./agent": "./src/agent.js",
"./drivers/*": "./src/drivers/*.js",
"./stores/*": "./src/stores/*.js",
"./types": "./src/types.js",
"./encoding": "./src/encoding.js"
".": "./dist/src/index.js",
Copy link
Contributor Author

@gobengo gobengo Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing where this points to resolved some atty errors. When we do it this way and let typescript also write the type declaration files with all its defaults next to the source files, then when another tsc in a depending lib finds all this config, it'll be able to find the src,types,etc again.

There are some tricky bits here that I learned from https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseESM.md#common-causes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the npm published files so we don't include src in the root?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"./agent": "./dist/src/agent.js",
"./drivers/*": "./dist/src/drivers/*.js",
"./stores/*": "./dist/src/stores/*.js",
"./types": "./dist/src/types.js",
"./encoding": "./dist/src/encoding.js"
},
"typesVersions": {
"*": {
Expand Down Expand Up @@ -67,9 +68,9 @@
"@web3-storage/capabilities": "workspace:^",
"@web3-storage/did-mailto": "workspace:^",
"bigint-mod-arith": "^3.1.2",
"conf": "10.2.0",
"conf": "11.0.2",
"multiformats": "^12.1.2",
"one-webcrypto": "^1.0.3",
"one-webcrypto": "git://github.com/web3-storage/one-webcrypto",
"p-defer": "^4.0.0",
"type-fest": "^3.3.0",
"uint8arrays": "^4.0.6"
Expand Down
26 changes: 13 additions & 13 deletions packages/access-client/src/agent-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import { CID } from 'multiformats'
import { Access } from '@web3-storage/capabilities'
import { isExpired } from './delegations.js'

/** @typedef {import('./types').AgentDataModel} AgentDataModel */
/** @typedef {import('./types.js').AgentDataModel} AgentDataModel */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of many small changes to ensure all imported module identifiers (e.g. type imports in comments like this) have a file suffix, which is required by tsc now that this PR enables moduleResolution=NodeNext for all tsc packages.


/** @implements {AgentDataModel} */
export class AgentData {
/** @type {(data: import('./types').AgentDataExport) => Promise<void> | void} */
/** @type {(data: import('./types.js').AgentDataExport) => Promise<void> | void} */
#save

/**
* @param {import('./types').AgentDataModel} data
* @param {import('./types').AgentDataOptions} [options]
* @param {import('./types.js').AgentDataModel} data
* @param {import('./types.js').AgentDataOptions} [options]
*/
constructor(data, options = {}) {
this.meta = data.meta
Expand All @@ -30,8 +30,8 @@ export class AgentData {
/**
* Create a new AgentData instance from the passed initialization data.
*
* @param {Partial<import('./types').AgentDataModel>} [init]
* @param {import('./types').AgentDataOptions} [options]
* @param {Partial<import('./types.js').AgentDataModel>} [init]
* @param {import('./types.js').AgentDataOptions} [options]
*/
static async create(init = {}, options = {}) {
const agentData = new AgentData(
Expand All @@ -53,11 +53,11 @@ export class AgentData {
/**
* Instantiate AgentData from previously exported data.
*
* @param {import('./types').AgentDataExport} raw
* @param {import('./types').AgentDataOptions} [options]
* @param {import('./types.js').AgentDataExport} raw
* @param {import('./types.js').AgentDataOptions} [options]
*/
static fromExport(raw, options) {
/** @type {import('./types').AgentDataModel['delegations']} */
/** @type {import('./types.js').AgentDataModel['delegations']} */
const dels = new Map()

for (const [key, value] of raw.delegations) {
Expand Down Expand Up @@ -89,7 +89,7 @@ export class AgentData {
* Export data in a format safe to pass to `structuredClone()`.
*/
export() {
/** @type {import('./types').AgentDataExport} */
/** @type {import('./types.js').AgentDataExport} */
const raw = {
meta: this.meta,
principal: this.principal.toArchive(),
Expand All @@ -112,7 +112,7 @@ export class AgentData {
/**
* @deprecated
* @param {import('@ucanto/interface').DID} did
* @param {import('./types').SpaceMeta} meta
* @param {import('./types.js').SpaceMeta} meta
* @param {import('@ucanto/interface').Delegation} [proof]
*/
async addSpace(did, meta, proof) {
Expand All @@ -131,7 +131,7 @@ export class AgentData {

/**
* @param {import('@ucanto/interface').Delegation} delegation
* @param {import('./types').DelegationMeta} [meta]
* @param {import('./types.js').DelegationMeta} [meta]
*/
async addDelegation(delegation, meta) {
this.delegations.set(delegation.cid.toString(), {
Expand Down Expand Up @@ -162,7 +162,7 @@ const isSessionCapability = (cap) => cap.can === Access.session.can
* Is the given delegation a session proof?
*
* @param {Ucanto.Delegation} delegation
* @returns {delegation is Ucanto.Delegation<[import('./types').AccessSession]>}
* @returns {delegation is Ucanto.Delegation<[import('./types.js').AccessSession]>}
*/
export const isSessionProof = (delegation) =>
delegation.capabilities.some((cap) => isSessionCapability(cap))
Expand Down
30 changes: 15 additions & 15 deletions packages/access-client/src/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const PRINCIPAL = DID.parse('did:web:web3.storage')
const agentToData = new WeakMap()

/**
* @typedef {import('./types').Service} Service
* @typedef {import('./types.js').Service} Service
* @typedef {import('@ucanto/interface').Receipt<any, any>} Receipt
*/

Expand Down Expand Up @@ -87,12 +87,12 @@ export function connection(options = {}) {
* @template {Record<string, any>} [S=Service]
*/
export class Agent {
/** @type {import('./agent-data').AgentData} */
/** @type {import('./agent-data.js').AgentData} */
#data

/**
* @param {import('./agent-data').AgentData} data - Agent data
* @param {import('./types').AgentOptions<S>} [options]
* @param {import('./agent-data.js').AgentData} data - Agent data
* @param {import('./types.js').AgentOptions<S>} [options]
*/
constructor(data, options = {}) {
/** @type { Client.Channel<S> & { url?: URL } | undefined } */
Expand All @@ -112,8 +112,8 @@ export class Agent {
* Create a new Agent instance, optionally with the passed initialization data.
*
* @template {Record<string, any>} [R=Service]
* @param {Partial<import('./types').AgentDataModel>} [init]
* @param {import('./types').AgentOptions<R> & import('./types').AgentDataOptions} [options]
* @param {Partial<import('./types.js').AgentDataModel>} [init]
* @param {import('./types.js').AgentOptions<R> & import('./types.js').AgentDataOptions} [options]
*/
static async create(init, options = {}) {
const data = await AgentData.create(init, options)
Expand All @@ -124,8 +124,8 @@ export class Agent {
* Instantiate an Agent from pre-exported agent data.
*
* @template {Record<string, any>} [R=Service]
* @param {import('./types').AgentDataExport} raw
* @param {import('./types').AgentOptions<R> & import('./types').AgentDataOptions} [options]
* @param {import('./types.js').AgentDataExport} raw
* @param {import('./types.js').AgentOptions<R> & import('./types.js').AgentDataOptions} [options]
*/
static from(raw, options = {}) {
const data = AgentData.fromExport(raw, options)
Expand Down Expand Up @@ -171,7 +171,7 @@ export class Agent {
*/
#delegations(caps) {
const _caps = new Set(caps)
/** @type {Array<{ delegation: Ucanto.Delegation, meta: import('./types').DelegationMeta }>} */
/** @type {Array<{ delegation: Ucanto.Delegation, meta: import('./types.js').DelegationMeta }>} */
const values = []
for (const [, value] of this.#data.delegations) {
// check expiration
Expand Down Expand Up @@ -320,7 +320,7 @@ export class Agent {
expiration: Infinity,
})

/** @type {import('./types').SpaceMeta} */
/** @type {import('./types.js').SpaceMeta} */
const meta = { isRegistered: false }
// eslint-disable-next-line eqeqeq
if (name != undefined) {
Expand All @@ -345,7 +345,7 @@ export class Agent {
* @param {Ucanto.Delegation} delegation
*/
async importSpaceFromDelegation(delegation) {
const meta = /** @type {import('./types').SpaceMeta} */ (
const meta = /** @type {import('./types.js').SpaceMeta} */ (
delegation.facts[0]?.space ?? { isRegistered: false }
)
// @ts-ignore
Expand Down Expand Up @@ -434,7 +434,7 @@ export class Agent {

/**
*
* @param {import('./types').DelegationOptions} options
* @param {import('./types.js').DelegationOptions} options
*/
async delegate(options) {
const space = this.currentSpaceWithMeta()
Expand Down Expand Up @@ -501,7 +501,7 @@ export class Agent {
* @template {Ucanto.URI} R
* @template {Ucanto.Caveats} C
* @param {Ucanto.TheCapabilityParser<Ucanto.CapabilityMatch<A, R, C>>} cap
* @param {import('./types').InvokeOptions<A, R, Ucanto.TheCapabilityParser<Ucanto.CapabilityMatch<A, R, C>>>} options
* @param {import('./types.js').InvokeOptions<A, R, Ucanto.TheCapabilityParser<Ucanto.CapabilityMatch<A, R, C>>>} options
* @returns {Promise<Ucanto.InferReceipt<Ucanto.Capability<A, R, C>, S>>}
*/
async invokeAndExecute(cap, options) {
Expand Down Expand Up @@ -554,7 +554,7 @@ export class Agent {
* @template {Ucanto.TheCapabilityParser<Ucanto.CapabilityMatch<A, R, C>>} CAP
* @template {Ucanto.Caveats} [C={}]
* @param {CAP} cap
* @param {import('./types').InvokeOptions<A, R, CAP>} options
* @param {import('./types.js').InvokeOptions<A, R, CAP>} options
*/
async invoke(cap, options) {
const space = options.with || this.currentSpace()
Expand Down Expand Up @@ -614,7 +614,7 @@ export class Agent {
throw inv.out.error
}

return /** @type {import('./types').SpaceInfoResult} */ (inv.out.ok)
return /** @type {import('./types.js').SpaceInfoResult} */ (inv.out.ok)
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/access-client/src/crypto/aes-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as uint8arrays from 'uint8arrays'
import { randomIV } from './encoding.js'

/**
* @typedef {import('./types').EncryptionKeypair} EncryptionKeypair
* @typedef {import('./types.js').EncryptionKeypair} EncryptionKeypair
* @implements {EncryptionKeypair}
*/
export class AesKey {
Expand Down
2 changes: 1 addition & 1 deletion packages/access-client/src/crypto/p256-ecdh.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function pubkeyBytesFromDID(did) {
}

/**
* @typedef {import('./types').KeyExchangeKeypair} SharedKey
* @typedef {import('./types.js').KeyExchangeKeypair} SharedKey
* @implements {SharedKey}
*/
export class EcdhKeypair {
Expand Down
2 changes: 1 addition & 1 deletion packages/access-client/src/drivers/conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as JSON from '../utils/json.js'

/**
* @template T
* @typedef {import('./types').Driver<T>} Driver
* @typedef {import('./types.js').Driver<T>} Driver
*/

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/access-client/src/drivers/indexeddb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import defer from 'p-defer'

/**
* @template T
* @typedef {import('./types').Driver<T>} Driver
* @typedef {import('./types.js').Driver<T>} Driver
*/

const STORE_NAME = 'AccessStore'
Expand Down
2 changes: 1 addition & 1 deletion packages/access-client/src/drivers/memory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @template T
* @typedef {import('./types').Driver<T>} Driver
* @typedef {import('./types.js').Driver<T>} Driver
*/

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/access-client/src/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function delegationsToBytes(delegations) {
* Decode bytes into Delegations
*
* @template {Types.Capabilities} [T=Types.Capabilities]
* @param {import('./types').BytesDelegation<T>} bytes
* @param {import('./types.js').BytesDelegation<T>} bytes
*/
export function bytesToDelegations(bytes) {
if (!(bytes instanceof Uint8Array) || bytes.length === 0) {
Expand Down Expand Up @@ -122,7 +122,7 @@ export function delegationToString(delegation, encoding) {
* Decode string into {@link Types.Delegation Delegation}
*
* @template {Types.Capabilities} [T=Types.Capabilities]
* @param {import('./types').EncodedDelegation<T>} raw
* @param {import('./types.js').EncodedDelegation<T>} raw
* @param {import('uint8arrays/to-string').SupportedEncodings} [encoding]
*/
export function stringToDelegations(raw, encoding = 'base64url') {
Expand All @@ -135,7 +135,7 @@ export function stringToDelegations(raw, encoding = 'base64url') {
* Decode string into a {@link Types.Delegation Delegation}
*
* @template {Types.Capabilities} [T=Types.Capabilities]
* @param {import('./types').EncodedDelegation<T>} raw
* @param {import('./types.js').EncodedDelegation<T>} raw
* @param {import('uint8arrays/to-string').SupportedEncodings} [encoding]
*/
export function stringToDelegation(raw, encoding) {
Expand Down
2 changes: 1 addition & 1 deletion packages/access-client/src/stores/store-conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import { ConfDriver } from '../drivers/conf.js'
* import { StoreConf } from '@web3-storage/access/stores/store-conf'
* ```
*
* @extends {ConfDriver<import('../types').AgentDataExport>}
* @extends {ConfDriver<import('../types.js').AgentDataExport>}
*/
export class StoreConf extends ConfDriver {}
2 changes: 1 addition & 1 deletion packages/access-client/src/stores/store-indexeddb.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import { IndexedDBDriver } from '../drivers/indexeddb.js'
* import { StoreIndexedDB } from '@web3-storage/access/stores/store-indexeddb'
* ```
*
* @extends {IndexedDBDriver<import('../types').AgentDataExport>}
* @extends {IndexedDBDriver<import('../types.js').AgentDataExport>}
*/
export class StoreIndexedDB extends IndexedDBDriver {}
2 changes: 1 addition & 1 deletion packages/access-client/src/stores/store-memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import { MemoryDriver } from '../drivers/memory.js'
* import { StoreMemory } from '@web3-storage/access/stores/store-memory'
* ```
*
* @extends {MemoryDriver<import('../types').AgentDataExport>}
* @extends {MemoryDriver<import('../types.js').AgentDataExport>}
*/
export class StoreMemory extends MemoryDriver {}
3 changes: 1 addition & 2 deletions packages/access-client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"lib": ["ESNext", "DOM"],
"emitDeclarationOnly": true
"lib": ["ESNext", "DOM"]
},
"include": ["src", "scripts", "test", "package.json"],
"exclude": ["**/node_modules/**"],
Expand Down
1 change: 1 addition & 0 deletions packages/capabilities/.attw.json
1 change: 1 addition & 0 deletions packages/capabilities/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"types": "dist/src/index.d.ts",
"main": "src/index.js",
"scripts": {
"attw": "attw --pack .",
"lint": "tsc && eslint '**/*.{js,ts}' && prettier --check '**/*.{js,ts,yml,json}' --ignore-path ../../.gitignore",
"build": "tsc --build",
"check": "tsc --build",
Expand Down
2 changes: 1 addition & 1 deletion packages/capabilities/src/filecoin/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const FR32_SHA2_256_TRUNC254_PADDED_BINARY_TREE = /** @type {const} */ (0x1011)
*/
const RAW_CODE = /** @type {const} */ (0x55)

export const PieceLink = /** @type {import('../types').PieceLinkSchema} */ (
export const PieceLink = /** @type {import('../types.js').PieceLinkSchema} */ (
Schema.link({
code: RAW_CODE,
version: 1,
Expand Down
1 change: 1 addition & 0 deletions packages/did-mailto/.attw.json
Loading
Loading