@atproto-labs/pipe 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE.txt +7 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/pipe.d.ts +31 -0
- package/dist/pipe.d.ts.map +1 -0
- package/dist/pipe.js +12 -0
- package/dist/pipe.js.map +1 -0
- package/dist/transformer.d.ts +2 -0
- package/dist/transformer.d.ts.map +1 -0
- package/dist/transformer.js +3 -0
- package/dist/transformer.js.map +1 -0
- package/package.json +32 -0
- package/src/index.ts +2 -0
- package/src/pipe.ts +63 -0
- package/src/transformer.ts +1 -0
- package/tsconfig.build.json +8 -0
- package/tsconfig.json +4 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @atproto-labs/pipe
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#2482](https://github.com/bluesky-social/atproto/pull/2482) [`a8d6c1123`](https://github.com/bluesky-social/atproto/commit/a8d6c112359f5c4c0cfbe2df63443ed275f2a646) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add OAuth provider capability & support for DPoP signed tokens
|
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Dual MIT/Apache-2.0 License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022-2024 Bluesky PBC, and Contributors
|
|
4
|
+
|
|
5
|
+
Except as otherwise noted in individual files, this software is licensed under the MIT license (<http://opensource.org/licenses/MIT>), or the Apache License, Version 2.0 (<http://www.apache.org/licenses/LICENSE-2.0>).
|
|
6
|
+
|
|
7
|
+
Downstream projects and end users may chose either license individually, or both together, at their discretion. The motivation for this dual-licensing is the additional software patent assurance provided by Apache 2.0.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pipeTwo = exports.pipe = void 0;
|
|
4
|
+
var pipe_js_1 = require("./pipe.js");
|
|
5
|
+
Object.defineProperty(exports, "pipe", { enumerable: true, get: function () { return pipe_js_1.pipe; } });
|
|
6
|
+
Object.defineProperty(exports, "pipeTwo", { enumerable: true, get: function () { return pipe_js_1.pipeTwo; } });
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAAyC;AAAhC,+FAAA,IAAI,OAAA;AAAE,kGAAA,OAAO,OAAA"}
|
package/dist/pipe.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Transformer } from './transformer.js';
|
|
2
|
+
type PipelineInput<T extends readonly Transformer<any>[]> = T extends [
|
|
3
|
+
Transformer<infer I, any>,
|
|
4
|
+
...any[]
|
|
5
|
+
] ? I : T extends Transformer<infer I, any>[] ? I : never;
|
|
6
|
+
type PipelineOutput<T extends readonly Transformer<any>[]> = T extends [
|
|
7
|
+
...any[],
|
|
8
|
+
Transformer<any, infer O>
|
|
9
|
+
] ? O : T extends Transformer<any, infer O>[] ? O : never;
|
|
10
|
+
type Pipeline<F extends readonly Transformer<any>[], Acc extends readonly Transformer<any>[] = []> = F extends [Transformer<infer I, infer O>] ? [...Acc, Transformer<I, O>] : F extends [Transformer<infer A, any>, ...infer Tail] ? Tail extends [Transformer<infer B, any>, ...any[]] ? Pipeline<Tail, [...Acc, Transformer<A, B>]> : Acc : Acc;
|
|
11
|
+
/**
|
|
12
|
+
* This utility function allows to properly type a pipeline of transformers.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // Will be typed as "(input: string) => Promise<number>"
|
|
17
|
+
* const parse = pipe(
|
|
18
|
+
* async (input: string) => JSON.parse(input),
|
|
19
|
+
* async (input: unknown) => {
|
|
20
|
+
* if (typeof input === 'number') return input
|
|
21
|
+
* throw new TypeError('Invalid input')
|
|
22
|
+
* },
|
|
23
|
+
* (input: number) => input * 2,
|
|
24
|
+
* )
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function pipe(): never;
|
|
28
|
+
export declare function pipe<T extends readonly Transformer<any>[]>(...pipeline: Pipeline<T> extends T ? T : Pipeline<T>): (input: PipelineInput<T>) => Promise<PipelineOutput<T>>;
|
|
29
|
+
export declare function pipeTwo<I, O, X = unknown>(first: Transformer<I, X>, second: Transformer<X, O>): (input: I) => Promise<O>;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=pipe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipe.d.ts","sourceRoot":"","sources":["../src/pipe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE9C,KAAK,aAAa,CAAC,CAAC,SAAS,SAAS,WAAW,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,SAAS;IACpE,WAAW,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC;IACzB,GAAG,GAAG,EAAE;CACT,GACG,CAAC,GACD,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,EAAE,GACnC,CAAC,GACD,KAAK,CAAA;AAEX,KAAK,cAAc,CAAC,CAAC,SAAS,SAAS,WAAW,CAAC,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AAE,CAAC,GAAG,OAAO,EACvC,KAAK,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EACxB,MAAM,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,GACxB,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAE1B"}
|
package/dist/pipe.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pipeTwo = exports.pipe = void 0;
|
|
4
|
+
function pipe(...pipeline) {
|
|
5
|
+
return pipeline.reduce(pipeTwo);
|
|
6
|
+
}
|
|
7
|
+
exports.pipe = pipe;
|
|
8
|
+
function pipeTwo(first, second) {
|
|
9
|
+
return async (input) => second(await first(input));
|
|
10
|
+
}
|
|
11
|
+
exports.pipeTwo = pipeTwo;
|
|
12
|
+
//# sourceMappingURL=pipe.js.map
|
package/dist/pipe.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipe.js","sourceRoot":"","sources":["../src/pipe.ts"],"names":[],"mappings":";;;AAmDA,SAAgB,IAAI,CAClB,GAAG,QAAiD;IAEpD,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;AACjC,CAAC;AAJD,oBAIC;AAED,SAAgB,OAAO,CACrB,KAAwB,EACxB,MAAyB;IAEzB,OAAO,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;AACpD,CAAC;AALD,0BAKC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../src/transformer.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformer.js","sourceRoot":"","sources":["../src/transformer.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atproto-labs/pipe",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Library for combining multiple functions into a single function.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"atproto",
|
|
8
|
+
"transformer"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://atproto.com",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/bluesky-social/atproto",
|
|
14
|
+
"directory": "packages/internal/pipe"
|
|
15
|
+
},
|
|
16
|
+
"type": "commonjs",
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"typescript": "^5.3.3"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc --build tsconfig.json"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/index.ts
ADDED
package/src/pipe.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Transformer } from './transformer.js'
|
|
2
|
+
|
|
3
|
+
type PipelineInput<T extends readonly Transformer<any>[]> = T extends [
|
|
4
|
+
Transformer<infer I, any>,
|
|
5
|
+
...any[],
|
|
6
|
+
]
|
|
7
|
+
? I
|
|
8
|
+
: T extends Transformer<infer I, any>[]
|
|
9
|
+
? I
|
|
10
|
+
: never
|
|
11
|
+
|
|
12
|
+
type PipelineOutput<T extends readonly Transformer<any>[]> = T extends [
|
|
13
|
+
...any[],
|
|
14
|
+
Transformer<any, infer O>,
|
|
15
|
+
]
|
|
16
|
+
? O
|
|
17
|
+
: T extends Transformer<any, infer O>[]
|
|
18
|
+
? O
|
|
19
|
+
: never
|
|
20
|
+
|
|
21
|
+
type Pipeline<
|
|
22
|
+
F extends readonly Transformer<any>[],
|
|
23
|
+
Acc extends readonly Transformer<any>[] = [],
|
|
24
|
+
> = F extends [Transformer<infer I, infer O>]
|
|
25
|
+
? [...Acc, Transformer<I, O>]
|
|
26
|
+
: F extends [Transformer<infer A, any>, ...infer Tail]
|
|
27
|
+
? Tail extends [Transformer<infer B, any>, ...any[]]
|
|
28
|
+
? Pipeline<Tail, [...Acc, Transformer<A, B>]>
|
|
29
|
+
: Acc
|
|
30
|
+
: Acc
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* This utility function allows to properly type a pipeline of transformers.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* // Will be typed as "(input: string) => Promise<number>"
|
|
38
|
+
* const parse = pipe(
|
|
39
|
+
* async (input: string) => JSON.parse(input),
|
|
40
|
+
* async (input: unknown) => {
|
|
41
|
+
* if (typeof input === 'number') return input
|
|
42
|
+
* throw new TypeError('Invalid input')
|
|
43
|
+
* },
|
|
44
|
+
* (input: number) => input * 2,
|
|
45
|
+
* )
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export function pipe(): never
|
|
49
|
+
export function pipe<T extends readonly Transformer<any>[]>(
|
|
50
|
+
...pipeline: Pipeline<T> extends T ? T : Pipeline<T>
|
|
51
|
+
): (input: PipelineInput<T>) => Promise<PipelineOutput<T>>
|
|
52
|
+
export function pipe<T extends readonly Transformer<any>[]>(
|
|
53
|
+
...pipeline: Pipeline<T> extends T ? T : Pipeline<T>
|
|
54
|
+
): (input: PipelineInput<T>) => Promise<PipelineOutput<T>> {
|
|
55
|
+
return pipeline.reduce(pipeTwo)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function pipeTwo<I, O, X = unknown>(
|
|
59
|
+
first: Transformer<I, X>,
|
|
60
|
+
second: Transformer<X, O>,
|
|
61
|
+
): (input: I) => Promise<O> {
|
|
62
|
+
return async (input) => second(await first(input))
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Transformer<I, O = I> = (input: I) => O | PromiseLike<O>
|
package/tsconfig.json
ADDED