@polygonlabs/example-schemas 0.0.0 → 1.2.4
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 +248 -0
- package/LICENSE +201 -0
- package/MIGRATION.md +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/registry.d.ts +903 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +40 -0
- package/dist/registry.js.map +1 -0
- package/dist/routes/blocks.d.ts +76 -0
- package/dist/routes/blocks.d.ts.map +1 -0
- package/dist/routes/blocks.js +67 -0
- package/dist/routes/blocks.js.map +1 -0
- package/dist/routes/core.d.ts +52 -0
- package/dist/routes/core.d.ts.map +1 -0
- package/dist/routes/core.js +38 -0
- package/dist/routes/core.js.map +1 -0
- package/dist/routes/events.d.ts +64 -0
- package/dist/routes/events.d.ts.map +1 -0
- package/dist/routes/events.js +36 -0
- package/dist/routes/events.js.map +1 -0
- package/dist/routes/messages.d.ts +109 -0
- package/dist/routes/messages.d.ts.map +1 -0
- package/dist/routes/messages.js +75 -0
- package/dist/routes/messages.js.map +1 -0
- package/dist/routes/widgets.d.ts +56 -0
- package/dist/routes/widgets.d.ts.map +1 -0
- package/dist/routes/widgets.js +39 -0
- package/dist/routes/widgets.js.map +1 -0
- package/dist/schemas.d.ts +78 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +187 -0
- package/dist/schemas.js.map +1 -0
- package/openapi.json +807 -0
- package/package.json +46 -3
- package/README.md +0 -3
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widget route — the read side of the cache-aside example. `GET
|
|
3
|
+
* /api/widgets/{id}` reads a widget that lives in Firestore (the source of
|
|
4
|
+
* truth) through a Redis cache in front of it. The route itself is an
|
|
5
|
+
* ordinary registry GET; what makes it the canonical "managed local
|
|
6
|
+
* resource" example is the service package's integration suite, which stands
|
|
7
|
+
* up a Firestore emulator AND Redis from one `vitest.globalSetup` and proves
|
|
8
|
+
* the cache-aside behaviour end-to-end. See
|
|
9
|
+
* `packages/example-rest-api/tests/integration/`.
|
|
10
|
+
*
|
|
11
|
+
* 400 (path UUID validation failure) is auto-injected from `request.params`.
|
|
12
|
+
* 404 is handler-emitted, so it's declared explicitly with the canonical
|
|
13
|
+
* `ErrorResponse` shape — same pattern as `getMessage`.
|
|
14
|
+
*/
|
|
15
|
+
import { z } from 'zod';
|
|
16
|
+
import type { RouteWithOpId, TypedRegistry } from '@polygonlabs/openapi-registry';
|
|
17
|
+
export declare const addWidgetRoutes: <Ops extends Record<string, RouteWithOpId>, Schemes extends Record<string, true>>(r: TypedRegistry<Ops, Schemes>) => TypedRegistry<Ops & {
|
|
18
|
+
getWidget: import("@polygonlabs/openapi-registry").MergedRoute<{
|
|
19
|
+
readonly operationId: "getWidget";
|
|
20
|
+
readonly method: "get";
|
|
21
|
+
readonly path: "/api/widgets/{id}";
|
|
22
|
+
readonly summary: "Get a widget by id";
|
|
23
|
+
readonly description: string;
|
|
24
|
+
readonly request: {
|
|
25
|
+
readonly params: z.ZodObject<{
|
|
26
|
+
id: z.ZodUUID;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
};
|
|
29
|
+
readonly responses: {
|
|
30
|
+
readonly 200: {
|
|
31
|
+
readonly description: "Widget";
|
|
32
|
+
readonly content: {
|
|
33
|
+
readonly 'application/json': {
|
|
34
|
+
readonly schema: z.ZodObject<{
|
|
35
|
+
id: z.ZodUUID;
|
|
36
|
+
name: z.ZodString;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
readonly 404: {
|
|
42
|
+
readonly description: "Not found";
|
|
43
|
+
readonly content: {
|
|
44
|
+
readonly 'application/json': {
|
|
45
|
+
readonly schema: z.ZodObject<{
|
|
46
|
+
error: z.ZodLiteral<true>;
|
|
47
|
+
message: z.ZodString;
|
|
48
|
+
info: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
}, import("@polygonlabs/openapi-registry").DefaultErrors>;
|
|
55
|
+
}, Schemes, import("@polygonlabs/openapi-registry").DefaultErrors>;
|
|
56
|
+
//# sourceMappingURL=widgets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widgets.d.ts","sourceRoot":"","sources":["../../src/routes/widgets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAMlF,eAAO,MAAM,eAAe,GAC1B,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EACzC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EAEpC,GAAG,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kEAuB5B,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widget route — the read side of the cache-aside example. `GET
|
|
3
|
+
* /api/widgets/{id}` reads a widget that lives in Firestore (the source of
|
|
4
|
+
* truth) through a Redis cache in front of it. The route itself is an
|
|
5
|
+
* ordinary registry GET; what makes it the canonical "managed local
|
|
6
|
+
* resource" example is the service package's integration suite, which stands
|
|
7
|
+
* up a Firestore emulator AND Redis from one `vitest.globalSetup` and proves
|
|
8
|
+
* the cache-aside behaviour end-to-end. See
|
|
9
|
+
* `packages/example-rest-api/tests/integration/`.
|
|
10
|
+
*
|
|
11
|
+
* 400 (path UUID validation failure) is auto-injected from `request.params`.
|
|
12
|
+
* 404 is handler-emitted, so it's declared explicitly with the canonical
|
|
13
|
+
* `ErrorResponse` shape — same pattern as `getMessage`.
|
|
14
|
+
*/
|
|
15
|
+
import { z } from 'zod';
|
|
16
|
+
import { ErrorResponseSchema as ErrorResponse } from '@polygonlabs/openapi-registry/error-schemas';
|
|
17
|
+
import { Widget } from "../schemas.js";
|
|
18
|
+
export const addWidgetRoutes = (r) => r.registerPath({
|
|
19
|
+
operationId: 'getWidget',
|
|
20
|
+
method: 'get',
|
|
21
|
+
path: '/api/widgets/{id}',
|
|
22
|
+
summary: 'Get a widget by id',
|
|
23
|
+
description: 'Reads a widget from Firestore through a Redis cache (cache-aside). ' +
|
|
24
|
+
'First read populates the cache; subsequent reads are served from it.',
|
|
25
|
+
request: {
|
|
26
|
+
params: z.object({ id: z.uuid() })
|
|
27
|
+
},
|
|
28
|
+
responses: {
|
|
29
|
+
200: {
|
|
30
|
+
description: 'Widget',
|
|
31
|
+
content: { 'application/json': { schema: Widget } }
|
|
32
|
+
},
|
|
33
|
+
404: {
|
|
34
|
+
description: 'Not found',
|
|
35
|
+
content: { 'application/json': { schema: ErrorResponse } }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=widgets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widgets.js","sourceRoot":"","sources":["../../src/routes/widgets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,mBAAmB,IAAI,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAEnG,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,MAAM,CAAC,MAAM,eAAe,GAAG,CAI7B,CAA8B,EAC9B,EAAE,CACF,CAAC,CAAC,YAAY,CAAC;IACb,WAAW,EAAE,WAAW;IACxB,MAAM,EAAE,KAAK;IACb,IAAI,EAAE,mBAAmB;IACzB,OAAO,EAAE,oBAAoB;IAC7B,WAAW,EACT,qEAAqE;QACrE,sEAAsE;IACxE,OAAO,EAAE;QACP,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;KACnC;IACD,SAAS,EAAE;QACT,GAAG,EAAE;YACH,WAAW,EAAE,QAAQ;YACrB,OAAO,EAAE,EAAE,kBAAkB,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;SACpD;QACD,GAAG,EAAE;YACH,WAAW,EAAE,WAAW;YACxB,OAAO,EAAE,EAAE,kBAAkB,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,EAAE;SAC3D;KACF;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const HealthCheckResponse: z.ZodObject<{
|
|
3
|
+
success: z.ZodBoolean;
|
|
4
|
+
}, z.core.$strip>;
|
|
5
|
+
export declare const HelloResponse: z.ZodObject<{
|
|
6
|
+
message: z.ZodString;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
export declare const BlockNumberResponse: z.ZodObject<{
|
|
9
|
+
blockNumber: z.ZodCodec<z.ZodString, z.ZodBigIntFormat>;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
export declare const BlockMetadata: z.ZodObject<{
|
|
12
|
+
number: z.ZodCodec<z.ZodString, z.ZodBigIntFormat>;
|
|
13
|
+
hash: z.ZodString;
|
|
14
|
+
parentHash: z.ZodString;
|
|
15
|
+
timestamp: z.ZodCodec<z.ZodString, z.ZodBigIntFormat>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
export declare const Message: z.ZodObject<{
|
|
18
|
+
id: z.ZodUUID;
|
|
19
|
+
text: z.ZodString;
|
|
20
|
+
createdAt: z.ZodCodec<z.ZodISODateTime, z.ZodDate>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
export declare const MessageList: z.ZodObject<{
|
|
23
|
+
items: z.ZodArray<z.ZodObject<{
|
|
24
|
+
id: z.ZodUUID;
|
|
25
|
+
text: z.ZodString;
|
|
26
|
+
createdAt: z.ZodCodec<z.ZodISODateTime, z.ZodDate>;
|
|
27
|
+
}, z.core.$strip>>;
|
|
28
|
+
nextCursor: z.ZodNullable<z.ZodString>;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
export declare const CreateMessageRequest: z.ZodObject<{
|
|
31
|
+
text: z.ZodString;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
export declare const Widget: z.ZodObject<{
|
|
34
|
+
id: z.ZodUUID;
|
|
35
|
+
name: z.ZodString;
|
|
36
|
+
}, z.core.$strip>;
|
|
37
|
+
export declare const IndexedEvent: z.ZodObject<{
|
|
38
|
+
id: z.ZodString;
|
|
39
|
+
chain: z.ZodNumber;
|
|
40
|
+
contractAddress: z.ZodString;
|
|
41
|
+
eventName: z.ZodString;
|
|
42
|
+
blockNumber: z.ZodNumber;
|
|
43
|
+
transactionIndex: z.ZodOptional<z.ZodNumber>;
|
|
44
|
+
txHash: z.ZodString;
|
|
45
|
+
logIndex: z.ZodNumber;
|
|
46
|
+
args: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
47
|
+
indexedAt: z.ZodNumber;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
export declare const EventList: z.ZodObject<{
|
|
50
|
+
items: z.ZodArray<z.ZodObject<{
|
|
51
|
+
id: z.ZodString;
|
|
52
|
+
chain: z.ZodNumber;
|
|
53
|
+
contractAddress: z.ZodString;
|
|
54
|
+
eventName: z.ZodString;
|
|
55
|
+
blockNumber: z.ZodNumber;
|
|
56
|
+
transactionIndex: z.ZodOptional<z.ZodNumber>;
|
|
57
|
+
txHash: z.ZodString;
|
|
58
|
+
logIndex: z.ZodNumber;
|
|
59
|
+
args: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
60
|
+
indexedAt: z.ZodNumber;
|
|
61
|
+
}, z.core.$strip>>;
|
|
62
|
+
nextCursor: z.ZodNullable<z.ZodString>;
|
|
63
|
+
}, z.core.$strip>;
|
|
64
|
+
export declare const ListEventsQuery: z.ZodObject<{
|
|
65
|
+
chain: z.ZodOptional<z.ZodCodec<z.ZodString, z.ZodInt>>;
|
|
66
|
+
contractAddress: z.ZodOptional<z.ZodString>;
|
|
67
|
+
eventName: z.ZodOptional<z.ZodString>;
|
|
68
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
69
|
+
limit: z.ZodOptional<z.ZodCodec<z.ZodString, z.ZodNumber>>;
|
|
70
|
+
}, z.core.$strip>;
|
|
71
|
+
export declare const BlockNumberPathParams: z.ZodObject<{
|
|
72
|
+
blockNumber: z.ZodCodec<z.ZodString, z.ZodBigIntFormat>;
|
|
73
|
+
}, z.core.$strip>;
|
|
74
|
+
export declare const RecentMessagesQuery: z.ZodObject<{
|
|
75
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
76
|
+
since: z.ZodOptional<z.ZodCodec<z.ZodISODateTime, z.ZodDate>>;
|
|
77
|
+
}, z.core.$strip>;
|
|
78
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAkBxB,eAAO,MAAM,mBAAmB;;iBAIC,CAAC;AAElC,eAAO,MAAM,aAAa;;iBAIC,CAAC;AAU5B,eAAO,MAAM,mBAAmB;;iBAM5B,CAAC;AAUL,eAAO,MAAM,aAAa;;;;;iBAStB,CAAC;AAQL,eAAO,MAAM,OAAO;;;;iBAMC,CAAC;AAEtB,eAAO,MAAM,WAAW;;;;;;;iBAKC,CAAC;AAE1B,eAAO,MAAM,oBAAoB;;iBAIC,CAAC;AASnC,eAAO,MAAM,MAAM;;;iBAKC,CAAC;AAQrB,eAAO,MAAM,YAAY;;;;;;;;;;;iBAaC,CAAC;AAE3B,eAAO,MAAM,SAAS;;;;;;;;;;;;;;iBAMC,CAAC;AAqBxB,eAAO,MAAM,eAAe;;;;;;iBAQC,CAAC;AA4B9B,eAAO,MAAM,qBAAqB;;iBAIC,CAAC;AAMpC,eAAO,MAAM,mBAAmB;;;iBAKC,CAAC"}
|
package/dist/schemas.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Int64Codec, IsoDateCodec, SafeIntegerCodec } from '@polygonlabs/zod-codecs';
|
|
3
|
+
import { extendZodAndCodecsWithOpenApi } from '@polygonlabs/zod-codecs/openapi';
|
|
4
|
+
// Called here so this file is self-contained — any direct import triggers
|
|
5
|
+
// the extension before schemas are accessed. Drop-in for `extendZodWithOpenApi`
|
|
6
|
+
// from `@asteasolutions/zod-to-openapi` that also patches `ZodCodec.prototype`,
|
|
7
|
+
// so `.openapi(...)` works on codecs the same way it works on regular schemas
|
|
8
|
+
// (in zod v4, `ZodCodec` is a sibling of `ZodType`, not a subclass — the
|
|
9
|
+
// upstream patch never reaches codecs).
|
|
10
|
+
extendZodAndCodecsWithOpenApi(z);
|
|
11
|
+
// Export name === registry name. The @polygonlabs/zod-to-openapi-heyapi
|
|
12
|
+
// plugin emits `import { <registeredName> } from '<schemasFrom>'` and audits
|
|
13
|
+
// at codegen time that each registered name resolves to a Zod schema export
|
|
14
|
+
// of the same name; renaming the export breaks the generated client.
|
|
15
|
+
export const HealthCheckResponse = z
|
|
16
|
+
.object({
|
|
17
|
+
success: z.boolean()
|
|
18
|
+
})
|
|
19
|
+
.openapi('HealthCheckResponse');
|
|
20
|
+
export const HelloResponse = z
|
|
21
|
+
.object({
|
|
22
|
+
message: z.string()
|
|
23
|
+
})
|
|
24
|
+
.openapi('HelloResponse');
|
|
25
|
+
// `blockNumber` uses Int64Codec to demonstrate the codec pattern: wire format
|
|
26
|
+
// is a string (JSON has no native int64), runtime is `bigint`. The generated
|
|
27
|
+
// client's response transformer decodes the string into a bigint before it
|
|
28
|
+
// reaches the caller, so consumers see the type the codec promises.
|
|
29
|
+
//
|
|
30
|
+
// `.openapi(...)` chains directly onto codecs (via `extendZodAndCodecsWithOpenApi`
|
|
31
|
+
// — see top of file) just like any other Zod schema, so per-field description
|
|
32
|
+
// metadata can live where you'd naturally write it.
|
|
33
|
+
export const BlockNumberResponse = z
|
|
34
|
+
.object({
|
|
35
|
+
blockNumber: Int64Codec.openapi({ description: 'Block height — fits in int64.' })
|
|
36
|
+
})
|
|
37
|
+
.openapi('BlockNumberResponse', {
|
|
38
|
+
description: 'Latest block number from the configured RPC endpoint'
|
|
39
|
+
});
|
|
40
|
+
// Block metadata — the codec-on-path-param stress test. The path parameter
|
|
41
|
+
// `:blockNumber` uses Int64Codec (see operations.ts), and the response carries
|
|
42
|
+
// multiple Int64Codec fields. End-to-end this proves: the typed client accepts
|
|
43
|
+
// `bigint` for the path arg, default URL serialisation matches the codec's
|
|
44
|
+
// encode (digit-string), the server validates `req.params.blockNumber` against
|
|
45
|
+
// Int64Codec to produce a real `bigint` for the handler, and the response
|
|
46
|
+
// codecs round-trip back to `bigint` on the client. See INVESTIGATION-codecs.md
|
|
47
|
+
// for why this works without plugin extension for number-flavoured codecs.
|
|
48
|
+
export const BlockMetadata = z
|
|
49
|
+
.object({
|
|
50
|
+
number: Int64Codec,
|
|
51
|
+
hash: z.string(),
|
|
52
|
+
parentHash: z.string(),
|
|
53
|
+
timestamp: Int64Codec
|
|
54
|
+
})
|
|
55
|
+
.openapi('BlockMetadata', {
|
|
56
|
+
description: 'Block header metadata for a specific height'
|
|
57
|
+
});
|
|
58
|
+
// Messages — minimal CRUD surface to exercise body, query, and UUID path
|
|
59
|
+
// inputs. UUIDs keep path-param typing trivially symmetric on both sides
|
|
60
|
+
// (string in, string out, no codec). Codec coverage on this surface is the
|
|
61
|
+
// response-side `createdAt: IsoDateCodec` only — the client receives a real
|
|
62
|
+
// `Date` instance via the existing response-transformer pipeline.
|
|
63
|
+
export const Message = z
|
|
64
|
+
.object({
|
|
65
|
+
id: z.uuid(),
|
|
66
|
+
text: z.string().min(1),
|
|
67
|
+
createdAt: IsoDateCodec
|
|
68
|
+
})
|
|
69
|
+
.openapi('Message');
|
|
70
|
+
export const MessageList = z
|
|
71
|
+
.object({
|
|
72
|
+
items: z.array(Message),
|
|
73
|
+
nextCursor: z.string().nullable()
|
|
74
|
+
})
|
|
75
|
+
.openapi('MessageList');
|
|
76
|
+
export const CreateMessageRequest = z
|
|
77
|
+
.object({
|
|
78
|
+
text: z.string().min(1).max(280)
|
|
79
|
+
})
|
|
80
|
+
.openapi('CreateMessageRequest');
|
|
81
|
+
// Widget — the cache-aside example's domain entity. Deliberately a plain
|
|
82
|
+
// `{ id, name }` with no codec: the managed-local-resource example
|
|
83
|
+
// (Firestore source-of-truth + Redis cache, see the service package's
|
|
84
|
+
// tests/integration suite) teaches resource lifecycle and test isolation,
|
|
85
|
+
// not codec round-tripping — that lesson already lives on Message/Block.
|
|
86
|
+
// Keeping the shape trivial keeps the cache-aside read path the only thing
|
|
87
|
+
// under test.
|
|
88
|
+
export const Widget = z
|
|
89
|
+
.object({
|
|
90
|
+
id: z.uuid(),
|
|
91
|
+
name: z.string().min(1).max(120)
|
|
92
|
+
})
|
|
93
|
+
.openapi('Widget');
|
|
94
|
+
// Indexed event — the read side of the indexer→db→REST showcase. This is the
|
|
95
|
+
// API projection (camelCase) of the storage-facing `IndexedEvent` that
|
|
96
|
+
// `example-indexer` writes to `example-db` (snake_case); the rest-api's
|
|
97
|
+
// EventQueryService maps between the two at the boundary. Deliberately
|
|
98
|
+
// codec-free: the lesson here is the cross-service data flow, not codec
|
|
99
|
+
// round-tripping (that already lives on Message/Block).
|
|
100
|
+
export const IndexedEvent = z
|
|
101
|
+
.object({
|
|
102
|
+
id: z.string(),
|
|
103
|
+
chain: z.number().int(),
|
|
104
|
+
contractAddress: z.string(),
|
|
105
|
+
eventName: z.string(),
|
|
106
|
+
blockNumber: z.number().int(),
|
|
107
|
+
transactionIndex: z.number().int().optional(),
|
|
108
|
+
txHash: z.string(),
|
|
109
|
+
logIndex: z.number().int(),
|
|
110
|
+
args: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])),
|
|
111
|
+
indexedAt: z.number().int()
|
|
112
|
+
})
|
|
113
|
+
.openapi('IndexedEvent');
|
|
114
|
+
export const EventList = z
|
|
115
|
+
.object({
|
|
116
|
+
items: z.array(IndexedEvent),
|
|
117
|
+
// Opaque pagination token; pass back as `cursor` for the next page.
|
|
118
|
+
nextCursor: z.string().nullable()
|
|
119
|
+
})
|
|
120
|
+
.openapi('EventList');
|
|
121
|
+
// Query for GET /events. All filters optional. `chain` and `limit` arrive as
|
|
122
|
+
// URL strings, so they use codecs (wire string ↔ runtime number); the
|
|
123
|
+
// registry-driven validator runs this schema against `req.query` before the
|
|
124
|
+
// handler sees it, replacing the strings with the decoded numbers.
|
|
125
|
+
//
|
|
126
|
+
// NOT `z.coerce.number()`: in zod v4 a coercing schema's input type is
|
|
127
|
+
// `unknown`, so the generated OpenAPI documents the parameter as optional
|
|
128
|
+
// and nullable regardless of intent — `@polygonlabs/openapi-registry` v3
|
|
129
|
+
// rejects coercing schemas in parameter positions at generate time for
|
|
130
|
+
// exactly this reason. Codecs declare both sides honestly.
|
|
131
|
+
//
|
|
132
|
+
// `limit` is a locally-rolled codec because it carries range constraints:
|
|
133
|
+
// the constraint lives on the OUTPUT schema, so it applies to the decoded
|
|
134
|
+
// number (and to `z.encode` round-trips), not the wire string.
|
|
135
|
+
const LimitCodec = z.codec(z.string().regex(/^\d+$/), z.number().int().min(1).max(100), {
|
|
136
|
+
decode: (s) => Number(s),
|
|
137
|
+
encode: (n) => n.toString()
|
|
138
|
+
});
|
|
139
|
+
export const ListEventsQuery = z
|
|
140
|
+
.object({
|
|
141
|
+
chain: SafeIntegerCodec.optional(),
|
|
142
|
+
contractAddress: z.string().optional(),
|
|
143
|
+
eventName: z.string().optional(),
|
|
144
|
+
cursor: z.string().optional(),
|
|
145
|
+
limit: LimitCodec.optional()
|
|
146
|
+
})
|
|
147
|
+
.openapi('ListEventsQuery');
|
|
148
|
+
// Error response shapes are not hand-rolled here. The registry-driven
|
|
149
|
+
// router in `@polygonlabs/express` auto-injects the canonical
|
|
150
|
+
// `ErrorResponse` (for 401/5xx) and `ValidationErrorResponse` (for 400)
|
|
151
|
+
// shapes into every route's `responses` based on what the route
|
|
152
|
+
// declares — so the served spec, the runtime body, and the generated
|
|
153
|
+
// client agree without per-route boilerplate. See
|
|
154
|
+
// `@polygonlabs/openapi-registry`'s `inferStandardErrorResponses`.
|
|
155
|
+
// Handler-emitted statuses (404 from `NotFound` throws, 403 from
|
|
156
|
+
// authz checks, etc.) declare `ErrorResponse` explicitly at the route.
|
|
157
|
+
// ── Input schemas (request side) ──────────────────────────────────────────────
|
|
158
|
+
//
|
|
159
|
+
// Codec-bearing input schemas must be registered with `.openapi('Name')`
|
|
160
|
+
// and exported under that exact name. Since 2.0.0 the
|
|
161
|
+
// @polygonlabs/zod-to-openapi-heyapi plugin resolves input slot names
|
|
162
|
+
// from this registration metadata (never by module-instance identity,
|
|
163
|
+
// which broke under split module evaluation) and fails codegen loudly
|
|
164
|
+
// for a codec-bearing slot that isn't registered. Codec-free inline
|
|
165
|
+
// request schemas may stay anonymous.
|
|
166
|
+
// Codec-on-path stress test: `:blockNumber` is `Int64Codec`. The wire
|
|
167
|
+
// shape is a digit string; the runtime shape is `bigint`. With the
|
|
168
|
+
// plugin's input transformer in play, callers pass a `bigint` and the
|
|
169
|
+
// URL gets the digit string. Number-flavoured codecs round-trip even
|
|
170
|
+
// without the transformer (see INVESTIGATION-codecs.md), so this route
|
|
171
|
+
// is the ergonomic-typing test case rather than the runtime-fix case.
|
|
172
|
+
export const BlockNumberPathParams = z
|
|
173
|
+
.object({
|
|
174
|
+
blockNumber: Int64Codec
|
|
175
|
+
})
|
|
176
|
+
.openapi('BlockNumberPathParams');
|
|
177
|
+
// Codec on a query parameter — the case the input transformer is built for.
|
|
178
|
+
// `IsoDateCodec.encode = (d) => d.toISOString()` does not equal `String(d)`,
|
|
179
|
+
// so without the transformer a Date in `since` would land in the URL as the
|
|
180
|
+
// locale string and the server's parser would reject it.
|
|
181
|
+
export const RecentMessagesQuery = z
|
|
182
|
+
.object({
|
|
183
|
+
cursor: z.string().optional(),
|
|
184
|
+
since: IsoDateCodec.optional()
|
|
185
|
+
})
|
|
186
|
+
.openapi('RecentMessagesQuery');
|
|
187
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACrF,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAEhF,0EAA0E;AAC1E,gFAAgF;AAChF,gFAAgF;AAChF,8EAA8E;AAC9E,yEAAyE;AACzE,wCAAwC;AACxC,6BAA6B,CAAC,CAAC,CAAC,CAAC;AAEjC,wEAAwE;AACxE,6EAA6E;AAC7E,4EAA4E;AAC5E,qEAAqE;AAErE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC;KACjC,MAAM,CAAC;IACN,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE;CACrB,CAAC;KACD,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAElC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC;KAC3B,MAAM,CAAC;IACN,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;CACpB,CAAC;KACD,OAAO,CAAC,eAAe,CAAC,CAAC;AAE5B,8EAA8E;AAC9E,6EAA6E;AAC7E,2EAA2E;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