Skip to content

Commit

Permalink
feat(api): manual updates (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed May 22, 2024
1 parent d4a083a commit 7d8c569
Show file tree
Hide file tree
Showing 40 changed files with 104 additions and 168 deletions.
41 changes: 0 additions & 41 deletions .github/workflows/create-releases.yml

This file was deleted.

25 changes: 0 additions & 25 deletions .github/workflows/handle-release-pr-title-edit.yml

This file was deleted.

8 changes: 6 additions & 2 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# workflow for re-running publishing to NPM in case it fails for some reason
# you can run this workflow by navigating to https://www.github.com/meorphis/meorphis-test/actions/workflows/publish-npm.yml
# This workflow is triggered when a GitHub release is created.
# It can also be run manually to re-publish to NPM in case it failed for some reason.
# You can run this workflow by navigating to https://www.github.com/meorphis/test-repo-1/actions/workflows/publish-npm.yml
name: Publish NPM
on:
workflow_dispatch:

release:
types: [published]

jobs:
publish:
name: publish
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/release-doctor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: release doctor
runs-on: ubuntu-latest
environment: production-release
if: github.repository == 'meorphis/meorphis-test' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next')
if: github.repository == 'meorphis/test-repo-1' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next')

steps:
- uses: actions/checkout@v4
Expand All @@ -19,5 +19,4 @@ jobs:
run: |
bash ./bin/check-release-environment
env:
STAINLESS_API_KEY: ${{ secrets.STAINLESS_API_KEY }}
NPM_TOKEN: ${{ secrets.MEORPHIS_TEST_40_NPM_TOKEN || secrets.NPM_TOKEN }}
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,25 @@ If you’d like to use the repository from source, you can either install from g
To install via git:

```bash
npm install git+ssh://[email protected]:meorphis/meorphis-test.git
npm install git+ssh://[email protected]:meorphis/test-repo-1.git
```

Alternatively, to link a local copy of the repo:

```bash
# Clone
git clone https://www.github.com/meorphis/meorphis-test
cd meorphis-test
git clone https://www.github.com/meorphis/test-repo-1
cd test-repo-1

# With yarn
yarn link
cd ../my-package
yarn link test-repo-1
yarn link meorphis-test-40

# With pnpm
pnpm link --global
cd ../my-package
pnpm link -—global test-repo-1
pnpm link -—global meorphis-test-40
```

## Running tests
Expand Down Expand Up @@ -99,7 +99,7 @@ the changes aren't made through the automated pipeline, you may want to make rel

### Publish with a GitHub workflow

You can release to package managers by using [the `Publish NPM` GitHub action](https://www.github.com/meorphis/meorphis-test/actions/workflows/publish-npm.yml). This requires a setup organization or repository secret to be set up.
You can release to package managers by using [the `Publish NPM` GitHub action](https://www.github.com/meorphis/test-repo-1/actions/workflows/publish-npm.yml). This requires a setup organization or repository secret to be set up.

### Publish manually

Expand Down
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Meorphis Test 40 Node API Library

[![NPM version](https://img.shields.io/npm/v/test-repo-1.svg)](https://npmjs.org/package/test-repo-1)
[![NPM version](https://img.shields.io/npm/v/meorphis-test-40.svg)](https://npmjs.org/package/meorphis-test-40)

This library provides convenient access to the Meorphis Test 40 REST API from server-side TypeScript or JavaScript.

Expand All @@ -11,16 +11,19 @@ It is generated with [Stainless](https://www.stainlessapi.com/).
## Installation

```sh
npm install test-repo-1
npm install git+ssh://[email protected]:meorphis/test-repo-1.git
```

> [!NOTE]
> Once this package is [published to npm](https://app.stainlessapi.com/docs/guides/publish), this will become: `npm install meorphis-test-40`
## Usage

The full API of this library can be found in [api.md](api.md).

<!-- prettier-ignore -->
```js
import MeorphisTest40 from 'test-repo-1';
import MeorphisTest40 from 'meorphis-test-40';

const meorphisTest40 = new MeorphisTest40({
environment: 'environment_1', // defaults to 'production'
Expand All @@ -44,7 +47,7 @@ This library includes TypeScript definitions for all request params and response

<!-- prettier-ignore -->
```ts
import MeorphisTest40 from 'test-repo-1';
import MeorphisTest40 from 'meorphis-test-40';

const meorphisTest40 = new MeorphisTest40({
environment: 'environment_1', // defaults to 'production'
Expand Down Expand Up @@ -222,12 +225,12 @@ add the following import before your first import `from "MeorphisTest40"`:
```ts
// Tell TypeScript and the package to use the global web fetch instead of node-fetch.
// Note, despite the name, this does not add any polyfills, but expects them to be provided if needed.
import 'test-repo-1/shims/web';
import MeorphisTest40 from 'test-repo-1';
import 'meorphis-test-40/shims/web';
import MeorphisTest40 from 'meorphis-test-40';
```

To do the inverse, add `import "test-repo-1/shims/node"` (which does import polyfills).
This can also be useful if you are getting the wrong TypeScript types for `Response` ([more details](https://github.com/meorphis/meorphis-test/tree/main/src/_shims#readme)).
To do the inverse, add `import "meorphis-test-40/shims/node"` (which does import polyfills).
This can also be useful if you are getting the wrong TypeScript types for `Response` ([more details](https://github.com/meorphis/test-repo-1/tree/main/src/_shims#readme)).

### Logging and middleware

Expand All @@ -236,7 +239,7 @@ which can be used to inspect or alter the `Request` or `Response` before/after e

```ts
import { fetch } from 'undici'; // as one example
import MeorphisTest40 from 'test-repo-1';
import MeorphisTest40 from 'meorphis-test-40';

const client = new MeorphisTest40({
fetch: async (url: RequestInfo, init?: RequestInit): Promise<Response> => {
Expand Down Expand Up @@ -287,7 +290,7 @@ This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) con

We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.

We are keen for your feedback; please open an [issue](https://www.github.com/meorphis/meorphis-test/issues) with questions, bugs, or suggestions.
We are keen for your feedback; please open an [issue](https://www.github.com/meorphis/test-repo-1/issues) with questions, bugs, or suggestions.

## Requirements

Expand All @@ -296,7 +299,7 @@ TypeScript >= 4.5 is supported.
The following runtimes are supported:

- Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
- Deno v1.28.0 or higher, using `import MeorphisTest40 from "npm:test-repo-1"`.
- Deno v1.28.0 or higher, using `import MeorphisTest40 from "npm:meorphis-test-40"`.
- Bun 1.0 or later.
- Cloudflare Workers.
- Vercel Edge Runtime.
Expand Down
4 changes: 0 additions & 4 deletions bin/check-release-environment
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
warnings=()
errors=()

if [ -z "${STAINLESS_API_KEY}" ]; then
errors+=("The STAINLESS_API_KEY secret has not been set. Please contact Stainless for an API key & set it in your organization secrets on GitHub.")
fi

if [ -z "${NPM_TOKEN}" ]; then
warnings+=("The MEORPHIS_TEST_40_NPM_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets")
fi
Expand Down
6 changes: 3 additions & 3 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const config: JestConfigWithTsJest = {
'^.+\\.(t|j)sx?$': ['@swc/jest', { sourceMaps: 'inline' }],
},
moduleNameMapper: {
'^test-repo-1$': '<rootDir>/src/index.ts',
'^test-repo-1/_shims/auto/(.*)$': '<rootDir>/src/_shims/auto/$1-node',
'^test-repo-1/(.*)$': '<rootDir>/src/$1',
'^meorphis-test-40$': '<rootDir>/src/index.ts',
'^meorphis-test-40/_shims/auto/(.*)$': '<rootDir>/src/_shims/auto/$1-node',
'^meorphis-test-40/(.*)$': '<rootDir>/src/$1',
},
modulePathIgnorePatterns: [
'<rootDir>/ecosystem-tests/',
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "test-repo-1",
"name": "meorphis-test-40",
"version": "0.0.1-alpha.0",
"description": "The official TypeScript library for the Meorphis Test 40 API",
"author": "Meorphis Test 40 <[email protected]>",
"types": "dist/index.d.ts",
"main": "dist/index.js",
"type": "commonjs",
"repository": "github:meorphis/meorphis-test",
"repository": "github:meorphis/test-repo-1",
"license": "Apache-2.0",
"packageManager": "[email protected]",
"files": [
Expand Down Expand Up @@ -63,8 +63,8 @@
"./shims/web.mjs"
],
"imports": {
"test-repo-1": ".",
"test-repo-1/*": "./src/*"
"meorphis-test-40": ".",
"meorphis-test-40/*": "./src/*"
},
"exports": {
"./_shims/auto/*": {
Expand Down
6 changes: 3 additions & 3 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ node scripts/utils/check-version.cjs

# Build into dist and will publish the package from there,
# so that src/resources/foo.ts becomes <package root>/resources/foo.js
# This way importing from `"test-repo-1/resources/foo"` works
# This way importing from `"meorphis-test-40/resources/foo"` works
# even with `"moduleResolution": "node"`

rm -rf dist; mkdir dist
Expand Down Expand Up @@ -47,8 +47,8 @@ node scripts/utils/postprocess-files.cjs

# make sure that nothing crashes when we require the output CJS or
# import the output ESM
(cd dist && node -e 'require("test-repo-1")')
(cd dist && node -e 'import("test-repo-1")' --input-type=module)
(cd dist && node -e 'require("meorphis-test-40")')
(cd dist && node -e 'import("meorphis-test-40")' --input-type=module)

if command -v deno &> /dev/null && [ -e ./scripts/build-deno ]
then
Expand Down
4 changes: 2 additions & 2 deletions scripts/utils/postprocess-files.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const fs = require('fs');
const path = require('path');
const { parse } = require('@typescript-eslint/parser');

const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? 'test-repo-1/';
const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? 'meorphis-test-40/';

const distDir =
process.env['DIST_PATH'] ?
Expand Down Expand Up @@ -142,7 +142,7 @@ async function postprocess() {

if (file.endsWith('.d.ts')) {
// work around bad tsc behavior
// if we have `import { type Readable } from 'test-repo-1/_shims/index'`,
// if we have `import { type Readable } from 'meorphis-test-40/_shims/index'`,
// tsc sometimes replaces `Readable` with `import("stream").Readable` inline
// in the output .d.ts
transformed = transformed.replace(/import\("stream"\).Readable/g, 'Readable');
Expand Down
32 changes: 16 additions & 16 deletions src/_shims/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# 👋 Wondering what everything in here does?

`test-repo-1` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various
`meorphis-test-40` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various
edge runtimes, as well as both CommonJS (CJS) and EcmaScript Modules (ESM).

To do this, `test-repo-1` provides shims for either using `node-fetch` when in Node (because `fetch` is still experimental there) or the global `fetch` API built into the environment when not in Node.
To do this, `meorphis-test-40` provides shims for either using `node-fetch` when in Node (because `fetch` is still experimental there) or the global `fetch` API built into the environment when not in Node.

It uses [conditional exports](https://nodejs.org/api/packages.html#conditional-exports) to
automatically select the correct shims for each environment. However, conditional exports are a fairly new
Expand All @@ -15,32 +15,32 @@ getting the wrong raw `Response` type from `.asResponse()`, for example.

The user can work around these issues by manually importing one of:

- `import 'test-repo-1/shims/node'`
- `import 'test-repo-1/shims/web'`
- `import 'meorphis-test-40/shims/node'`
- `import 'meorphis-test-40/shims/web'`

All of the code here in `_shims` handles selecting the automatic default shims or manual overrides.

### How it works - Runtime

Runtime shims get installed by calling `setShims` exported by `test-repo-1/_shims/registry`.
Runtime shims get installed by calling `setShims` exported by `meorphis-test-40/_shims/registry`.

Manually importing `test-repo-1/shims/node` or `test-repo-1/shims/web`, calls `setShims` with the respective runtime shims.
Manually importing `meorphis-test-40/shims/node` or `meorphis-test-40/shims/web`, calls `setShims` with the respective runtime shims.

All client code imports shims from `test-repo-1/_shims/index`, which:
All client code imports shims from `meorphis-test-40/_shims/index`, which:

- checks if shims have been set manually
- if not, calls `setShims` with the shims from `test-repo-1/_shims/auto/runtime`
- re-exports the installed shims from `test-repo-1/_shims/registry`.
- if not, calls `setShims` with the shims from `meorphis-test-40/_shims/auto/runtime`
- re-exports the installed shims from `meorphis-test-40/_shims/registry`.

`test-repo-1/_shims/auto/runtime` exports web runtime shims.
If the `node` export condition is set, the export map replaces it with `test-repo-1/_shims/auto/runtime-node`.
`meorphis-test-40/_shims/auto/runtime` exports web runtime shims.
If the `node` export condition is set, the export map replaces it with `meorphis-test-40/_shims/auto/runtime-node`.

### How it works - Type time

All client code imports shim types from `test-repo-1/_shims/index`, which selects the manual types from `test-repo-1/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `test-repo-1/_shims/auto/types`.
All client code imports shim types from `meorphis-test-40/_shims/index`, which selects the manual types from `meorphis-test-40/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `meorphis-test-40/_shims/auto/types`.

`test-repo-1/_shims/manual-types` exports an empty namespace.
Manually importing `test-repo-1/shims/node` or `test-repo-1/shims/web` merges declarations into this empty namespace, so they get picked up by `test-repo-1/_shims/index`.
`meorphis-test-40/_shims/manual-types` exports an empty namespace.
Manually importing `meorphis-test-40/shims/node` or `meorphis-test-40/shims/web` merges declarations into this empty namespace, so they get picked up by `meorphis-test-40/_shims/index`.

`test-repo-1/_shims/auto/types` exports web type definitions.
If the `node` export condition is set, the export map replaces it with `test-repo-1/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`.
`meorphis-test-40/_shims/auto/types` exports web type definitions.
If the `node` export condition is set, the export map replaces it with `meorphis-test-40/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`.
2 changes: 1 addition & 1 deletion src/_shims/index-deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function getDefaultAgent(url: string) {
}
export function fileFromPath() {
throw new Error(
'The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/meorphis/meorphis-test#file-uploads',
'The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/meorphis/test-repo-1#file-uploads',
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/_shims/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
*/
import { manual } from './manual-types';
import * as auto from 'test-repo-1/_shims/auto/types';
import * as auto from 'meorphis-test-40/_shims/auto/types';
import { type RequestOptions } from '../core';

type SelectType<Manual, Auto> = unknown extends Manual ? Auto : Manual;
Expand Down
2 changes: 1 addition & 1 deletion src/_shims/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
*/
const shims = require('./registry');
const auto = require('test-repo-1/_shims/auto/runtime');
const auto = require('meorphis-test-40/_shims/auto/runtime');
if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
for (const property of Object.keys(shims)) {
Object.defineProperty(exports, property, {
Expand Down
Loading

0 comments on commit 7d8c569

Please sign in to comment.