@rpcbase/api 0.71.0 → 0.72.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/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './types';
2
2
  export * from './initApi';
3
+ export * from './pagination';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA"}
package/dist/index.js CHANGED
@@ -21174,6 +21174,17 @@ const initApi = async ({
21174
21174
  app.use("/api", (req, res) => {
21175
21175
  res.status(404).json({ error: `Not Found: ${req.method}:${req.originalUrl}` });
21176
21176
  });
21177
+ app.use("/api", (err, _req, res, next) => {
21178
+ if (res.headersSent) return next(err);
21179
+ const anyErr = err;
21180
+ const code = typeof anyErr?.code === "string" ? anyErr.code : null;
21181
+ const statusCode = typeof anyErr?.statusCode === "number" ? anyErr.statusCode : typeof anyErr?.status === "number" ? anyErr.status : null;
21182
+ if (code === "invalid_pagination") {
21183
+ res.status(statusCode ?? 400).json({ error: code });
21184
+ return;
21185
+ }
21186
+ next(err);
21187
+ });
21177
21188
  };
21178
21189
  export {
21179
21190
  MOCK_TYPE,
@@ -1 +1 @@
1
- {"version":3,"file":"initApi.d.ts","sourceRoot":"","sources":["../src/initApi.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAS,MAAM,SAAS,CAAA;AAiB5C,eAAO,MAAM,OAAO,GAAU,kBAG3B;IACD,GAAG,EAAE,WAAW,CAAA;IAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,CAAA;CAC3C,kBAgFA,CAAA"}
1
+ {"version":3,"file":"initApi.d.ts","sourceRoot":"","sources":["../src/initApi.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAyC,MAAM,SAAS,CAAA;AAiB5E,eAAO,MAAM,OAAO,GAAU,kBAG3B;IACD,GAAG,EAAE,WAAW,CAAA;IAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,CAAA;CAC3C,kBAmGA,CAAA"}
@@ -0,0 +1,24 @@
1
+ export type PaginationDirection = "next" | "prev";
2
+ export type PaginationOrder = "asc" | "desc";
3
+ export type PaginationSort = Array<{
4
+ field: string;
5
+ order: PaginationOrder;
6
+ }>;
7
+ export type PaginationSpec = {
8
+ limit: number;
9
+ cursor?: string;
10
+ direction?: PaginationDirection;
11
+ sort: PaginationSort;
12
+ };
13
+ export type PaginationPageInfo = {
14
+ nextCursor?: string;
15
+ prevCursor?: string;
16
+ hasNextPage: boolean;
17
+ hasPrevPage: boolean;
18
+ };
19
+ export type PaginationResponse<TNode> = {
20
+ nodes: TNode[];
21
+ pageInfo: PaginationPageInfo;
22
+ totalCount?: number;
23
+ };
24
+ //# sourceMappingURL=pagination.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../src/pagination.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,MAAM,CAAA;AAEjD,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,MAAM,CAAA;AAE5C,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,eAAe,CAAC;CACxB,CAAC,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,mBAAmB,CAAC;IAChC,IAAI,EAAE,cAAc,CAAC;CACtB,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,EAAE,OAAO,CAAC;CACtB,CAAA;AAED,MAAM,MAAM,kBAAkB,CAAC,KAAK,IAAI;IACtC,KAAK,EAAE,KAAK,EAAE,CAAC;IACf,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/api",
3
- "version": "0.71.0",
3
+ "version": "0.72.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"