https://github.com/ehmpathy/as-procedure
easily create procedures within a pit-of-success
https://github.com/ehmpathy/as-procedure
Last synced: 4 months ago
JSON representation
easily create procedures within a pit-of-success
- Host: GitHub
- URL: https://github.com/ehmpathy/as-procedure
- Owner: ehmpathy
- License: mit
- Created: 2024-07-28T03:53:50.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-07-08T18:32:26.000Z (6 months ago)
- Last Synced: 2025-09-06T02:56:15.530Z (4 months ago)
- Language: TypeScript
- Size: 198 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
# as-procedure


easily create procedures within a pit-of-success
# install
```sh
npm install as-procedure
```
# use
### `asProcedure`
- detects name based on declarer file name
- with-log-trail for observability
```ts
const getJokes = asProcedure((input: { by: { ref: Ref }}, context) => {
// ...
})
```
### `withExpectOutput`
Wraps an async function that returns a `Record | null`, and adds an `.expect('isPresent')` method to assert that the output is not null.
#### usage
```ts
import { withExpectOutput } from './withExpectOutput';
const findUser = withExpectOutput(async (input: { id: string }) => {
if (input.id === 'missing') return null;
return { id: input.id, name: 'Alice' };
});
// with .expect('isPresent')
const userA = await findUser({ id: 'abc123' }).expect('isPresent');
console.log(user.name); // 'Alice'
// without .expect('isPresent')
const userB = await findUser({ id: 'abc123' })
console.log(user.name); // 🛑 @ts-expect-error: "name" is not a property of null, user may be null
```
behavior
- .expect('isPresent') throws a HelpfulError if the result is null
- attaches the original call stack as the .cause for better traceability
> tip: use .expect('isPresent') in tests or control flow where null is unexpected
### `withExpectOutkey`
```ts
const getFlagByExid = (input: { exid: string }, context: ContextLogTrail): { flag: Flag } | null => {...}
export const sdk = {
getFlagByExid: withExpectOutkey(getFlagByExid)
}
const { flag } = await sdk.getFlagByExid({ exid: 'usa' }, context).expect('flag', 'isPresent');
```