pipeway-steps 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/LICENSE +21 -0
- package/dist/index.cjs +26 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pierre-Philippe Prévost
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var pipeway = require('pipeway');
|
|
4
|
+
|
|
5
|
+
// src/index.ts
|
|
6
|
+
var json = (data, status) => new Response(JSON.stringify(data), { status, headers: { "content-type": "application/json" } });
|
|
7
|
+
var body = (schema) => async (ctx) => {
|
|
8
|
+
let raw;
|
|
9
|
+
try {
|
|
10
|
+
raw = await ctx.req.json();
|
|
11
|
+
} catch {
|
|
12
|
+
return pipeway.fail(json({ error: "InvalidJson" }, 400));
|
|
13
|
+
}
|
|
14
|
+
const parsed = schema.safeParse(raw);
|
|
15
|
+
return parsed.success ? pipeway.ok({ body: parsed.data }) : pipeway.fail(json({ error: "ValidationError", issues: parsed.error.issues }, 400));
|
|
16
|
+
};
|
|
17
|
+
var query = (schema) => (ctx) => {
|
|
18
|
+
const obj = Object.fromEntries(new URL(ctx.req.url).searchParams);
|
|
19
|
+
const parsed = schema.safeParse(obj);
|
|
20
|
+
return parsed.success ? pipeway.ok({ query: parsed.data }) : pipeway.fail(json({ error: "ValidationError", issues: parsed.error.issues }, 400));
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
exports.body = body;
|
|
24
|
+
exports.query = query;
|
|
25
|
+
//# sourceMappingURL=index.cjs.map
|
|
26
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["fail","ok"],"mappings":";;;;;AAMA,IAAM,OAAO,CAAC,IAAA,EAAe,MAAA,KAC3B,IAAI,SAAS,IAAA,CAAK,SAAA,CAAU,IAAI,CAAA,EAAG,EAAE,MAAA,EAAQ,OAAA,EAAS,EAAE,cAAA,EAAgB,kBAAA,IAAsB,CAAA;AAGzF,IAAM,IAAA,GAAO,CAAI,MAAA,KAA4D,OAAO,GAAA,KAAQ;AACjG,EAAA,IAAI,GAAA;AACJ,EAAA,IAAI;AACF,IAAA,GAAA,GAAM,MAAM,GAAA,CAAI,GAAA,CAAI,IAAA,EAAK;AAAA,EAC3B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAOA,aAAK,IAAA,CAAK,EAAE,OAAO,aAAA,EAAc,EAAG,GAAG,CAAC,CAAA;AAAA,EACjD;AACA,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,SAAA,CAAU,GAAG,CAAA;AACnC,EAAA,OAAO,MAAA,CAAO,UAAUC,UAAA,CAAG,EAAE,MAAM,MAAA,CAAO,IAAA,EAAM,CAAA,GAAID,YAAA,CAAK,KAAK,EAAE,KAAA,EAAO,mBAAmB,MAAA,EAAQ,MAAA,CAAO,MAAM,MAAA,EAAO,EAAG,GAAG,CAAC,CAAA;AAC/H;AAGO,IAAM,KAAA,GAAQ,CAAI,MAAA,KAA6D,CAAC,GAAA,KAAQ;AAC7F,EAAA,MAAM,GAAA,GAAM,OAAO,WAAA,CAAY,IAAI,IAAI,GAAA,CAAI,GAAA,CAAI,GAAG,CAAA,CAAE,YAAY,CAAA;AAChE,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,SAAA,CAAU,GAAG,CAAA;AACnC,EAAA,OAAO,MAAA,CAAO,UAAUC,UAAA,CAAG,EAAE,OAAO,MAAA,CAAO,IAAA,EAAM,CAAA,GAAID,YAAA,CAAK,KAAK,EAAE,KAAA,EAAO,mBAAmB,MAAA,EAAQ,MAAA,CAAO,MAAM,MAAA,EAAO,EAAG,GAAG,CAAC,CAAA;AAChI","file":"index.cjs","sourcesContent":["import { ok, fail, type Step } from 'pipeway'\nimport type { ZodType } from 'zod'\n\n// Generic, app-agnostic steps. Auth / rate-limit are deliberately NOT bundled:\n// they depend on your stack. Compose your own the same way these are written.\n\nconst json = (data: unknown, status: number): Response =>\n new Response(JSON.stringify(data), { status, headers: { 'content-type': 'application/json' } })\n\n// Validates the JSON body against a Zod schema, adding a typed `body` to ctx.\nexport const body = <T>(schema: ZodType<T>): Step<{ req: Request }, { body: T }> => async (ctx) => {\n let raw: unknown\n try {\n raw = await ctx.req.json()\n } catch {\n return fail(json({ error: 'InvalidJson' }, 400))\n }\n const parsed = schema.safeParse(raw)\n return parsed.success ? ok({ body: parsed.data }) : fail(json({ error: 'ValidationError', issues: parsed.error.issues }, 400))\n}\n\n// Validates the URL search params against a Zod schema, adding typed `query`.\nexport const query = <T>(schema: ZodType<T>): Step<{ req: Request }, { query: T }> => (ctx) => {\n const obj = Object.fromEntries(new URL(ctx.req.url).searchParams)\n const parsed = schema.safeParse(obj)\n return parsed.success ? ok({ query: parsed.data }) : fail(json({ error: 'ValidationError', issues: parsed.error.issues }, 400))\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Step } from 'pipeway';
|
|
2
|
+
import { ZodType } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const body: <T>(schema: ZodType<T>) => Step<{
|
|
5
|
+
req: Request;
|
|
6
|
+
}, {
|
|
7
|
+
body: T;
|
|
8
|
+
}>;
|
|
9
|
+
declare const query: <T>(schema: ZodType<T>) => Step<{
|
|
10
|
+
req: Request;
|
|
11
|
+
}, {
|
|
12
|
+
query: T;
|
|
13
|
+
}>;
|
|
14
|
+
|
|
15
|
+
export { body, query };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Step } from 'pipeway';
|
|
2
|
+
import { ZodType } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const body: <T>(schema: ZodType<T>) => Step<{
|
|
5
|
+
req: Request;
|
|
6
|
+
}, {
|
|
7
|
+
body: T;
|
|
8
|
+
}>;
|
|
9
|
+
declare const query: <T>(schema: ZodType<T>) => Step<{
|
|
10
|
+
req: Request;
|
|
11
|
+
}, {
|
|
12
|
+
query: T;
|
|
13
|
+
}>;
|
|
14
|
+
|
|
15
|
+
export { body, query };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { fail, ok } from 'pipeway';
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
var json = (data, status) => new Response(JSON.stringify(data), { status, headers: { "content-type": "application/json" } });
|
|
5
|
+
var body = (schema) => async (ctx) => {
|
|
6
|
+
let raw;
|
|
7
|
+
try {
|
|
8
|
+
raw = await ctx.req.json();
|
|
9
|
+
} catch {
|
|
10
|
+
return fail(json({ error: "InvalidJson" }, 400));
|
|
11
|
+
}
|
|
12
|
+
const parsed = schema.safeParse(raw);
|
|
13
|
+
return parsed.success ? ok({ body: parsed.data }) : fail(json({ error: "ValidationError", issues: parsed.error.issues }, 400));
|
|
14
|
+
};
|
|
15
|
+
var query = (schema) => (ctx) => {
|
|
16
|
+
const obj = Object.fromEntries(new URL(ctx.req.url).searchParams);
|
|
17
|
+
const parsed = schema.safeParse(obj);
|
|
18
|
+
return parsed.success ? ok({ query: parsed.data }) : fail(json({ error: "ValidationError", issues: parsed.error.issues }, 400));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { body, query };
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAMA,IAAM,OAAO,CAAC,IAAA,EAAe,MAAA,KAC3B,IAAI,SAAS,IAAA,CAAK,SAAA,CAAU,IAAI,CAAA,EAAG,EAAE,MAAA,EAAQ,OAAA,EAAS,EAAE,cAAA,EAAgB,kBAAA,IAAsB,CAAA;AAGzF,IAAM,IAAA,GAAO,CAAI,MAAA,KAA4D,OAAO,GAAA,KAAQ;AACjG,EAAA,IAAI,GAAA;AACJ,EAAA,IAAI;AACF,IAAA,GAAA,GAAM,MAAM,GAAA,CAAI,GAAA,CAAI,IAAA,EAAK;AAAA,EAC3B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,KAAK,IAAA,CAAK,EAAE,OAAO,aAAA,EAAc,EAAG,GAAG,CAAC,CAAA;AAAA,EACjD;AACA,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,SAAA,CAAU,GAAG,CAAA;AACnC,EAAA,OAAO,MAAA,CAAO,UAAU,EAAA,CAAG,EAAE,MAAM,MAAA,CAAO,IAAA,EAAM,CAAA,GAAI,IAAA,CAAK,KAAK,EAAE,KAAA,EAAO,mBAAmB,MAAA,EAAQ,MAAA,CAAO,MAAM,MAAA,EAAO,EAAG,GAAG,CAAC,CAAA;AAC/H;AAGO,IAAM,KAAA,GAAQ,CAAI,MAAA,KAA6D,CAAC,GAAA,KAAQ;AAC7F,EAAA,MAAM,GAAA,GAAM,OAAO,WAAA,CAAY,IAAI,IAAI,GAAA,CAAI,GAAA,CAAI,GAAG,CAAA,CAAE,YAAY,CAAA;AAChE,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,SAAA,CAAU,GAAG,CAAA;AACnC,EAAA,OAAO,MAAA,CAAO,UAAU,EAAA,CAAG,EAAE,OAAO,MAAA,CAAO,IAAA,EAAM,CAAA,GAAI,IAAA,CAAK,KAAK,EAAE,KAAA,EAAO,mBAAmB,MAAA,EAAQ,MAAA,CAAO,MAAM,MAAA,EAAO,EAAG,GAAG,CAAC,CAAA;AAChI","file":"index.js","sourcesContent":["import { ok, fail, type Step } from 'pipeway'\nimport type { ZodType } from 'zod'\n\n// Generic, app-agnostic steps. Auth / rate-limit are deliberately NOT bundled:\n// they depend on your stack. Compose your own the same way these are written.\n\nconst json = (data: unknown, status: number): Response =>\n new Response(JSON.stringify(data), { status, headers: { 'content-type': 'application/json' } })\n\n// Validates the JSON body against a Zod schema, adding a typed `body` to ctx.\nexport const body = <T>(schema: ZodType<T>): Step<{ req: Request }, { body: T }> => async (ctx) => {\n let raw: unknown\n try {\n raw = await ctx.req.json()\n } catch {\n return fail(json({ error: 'InvalidJson' }, 400))\n }\n const parsed = schema.safeParse(raw)\n return parsed.success ? ok({ body: parsed.data }) : fail(json({ error: 'ValidationError', issues: parsed.error.issues }, 400))\n}\n\n// Validates the URL search params against a Zod schema, adding typed `query`.\nexport const query = <T>(schema: ZodType<T>): Step<{ req: Request }, { query: T }> => (ctx) => {\n const obj = Object.fromEntries(new URL(ctx.req.url).searchParams)\n const parsed = schema.safeParse(obj)\n return parsed.success ? ok({ query: parsed.data }) : fail(json({ error: 'ValidationError', issues: parsed.error.issues }, 400))\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pipeway-steps",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Generic Zod validation steps for pipeway (body, query).",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pipeway",
|
|
7
|
+
"zod",
|
|
8
|
+
"validation",
|
|
9
|
+
"middleware"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "Pierre-Philippe Prévost",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/ppprevost/pipeway.git",
|
|
16
|
+
"directory": "packages/steps"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://ppprevost.github.io/pipeway",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"require": "./dist/index.cjs"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"main": "./dist/index.cjs",
|
|
29
|
+
"module": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"zod": "^3.23.0",
|
|
36
|
+
"pipeway": "0.1.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"tsup": "^8.3.0",
|
|
40
|
+
"typescript": "^5.6.0",
|
|
41
|
+
"zod": "^3.23.0",
|
|
42
|
+
"pipeway": "0.1.0"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsup",
|
|
49
|
+
"typecheck": "tsc --noEmit"
|
|
50
|
+
}
|
|
51
|
+
}
|