@zkp2p/indexer-schema 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/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # @zkp2p/indexer-schema
2
+
3
+ Exports the GraphQL schema used by the ZKP2P indexer.
4
+
5
+ Install
6
+ ```
7
+ pnpm add @zkp2p/indexer-schema
8
+ ```
9
+
10
+ Usage
11
+ ```
12
+ // Load the SDL string (GraphQL schema) in Node
13
+ import { schemaSDL } from '@zkp2p/indexer-schema';
14
+ // or CommonJS: const { schemaSDL } = require('@zkp2p/indexer-schema');
15
+
16
+ // Path reference for codegen configs
17
+ schema: node_modules/@zkp2p/indexer-schema/dist/schema.graphql
18
+ ```
19
+
20
+ Notes
21
+ - Includes: Deposit, Intent, DepositPaymentMethod, MethodCurrency.
22
+ - The file is generated at publish time from the indexer repo.
23
+
24
+
25
+ ## Backend Codegen Example (using domain.graphql)
26
+
27
+ This is a minimal example to generate TypeScript types from the exported domain schema.
28
+
29
+ ### 1) Install codegen tooling
30
+
31
+ ```
32
+ pnpm add -D @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-operations
33
+ ```
34
+
35
+ ### 2) Add a codegen config (codegen.yml)
36
+
37
+ ```
38
+ schema: node_modules/@zkp2p/indexer-schema/dist/schema.graphql
39
+ # Alternatively, if using a workspace dependency:
40
+ # schema: ../zkp2p-indexer/dist/schema.graphql
41
+
42
+ generates:
43
+ src/__generated__/types.ts:
44
+ plugins:
45
+ - typescript
46
+ - typescript-operations
47
+ config:
48
+ avoidOptionals: true
49
+ ```
50
+
51
+ ### 3) Add an npm script
52
+
53
+ ```
54
+ "scripts": {
55
+ "codegen": "graphql-codegen --config codegen.yml"
56
+ }
57
+ ```
58
+
59
+ ### 4) Use the generated types
60
+
61
+ - Import `Deposit`, `Intent`, etc. operation and type definitions from `src/__generated__/types.ts`.
62
+ - If you serve GraphQL in the backend, you can build an executable schema from `domain.graphql` and provide resolvers that read from the indexer’s DB.
63
+ - If you serve REST, use the generated types to type DTOs and service responses.
64
+
65
+ Notes
66
+ - We export the schema needed by backend consumers (no raw event entities). It matches the data model our handlers populate.
67
+ - When the schema changes in a breaking way (e.g., a field becomes non‑null), bump the schema package version and update your backend accordingly.
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const schemaSDL = fs.readFileSync(path.join(__dirname, 'schema.graphql'), 'utf8');
4
+ module.exports = { schemaSDL };
@@ -0,0 +1,73 @@
1
+ # Domain types
2
+
3
+ type Deposit {
4
+ id: ID! # escrowAddress_depositId
5
+ chainId: Int!
6
+ escrowAddress: String!
7
+ depositId: BigInt!
8
+ depositor: String!
9
+ token: String!
10
+ amount: BigInt!
11
+ remainingDeposits: BigInt!
12
+ intentAmountMin: BigInt!
13
+ intentAmountMax: BigInt!
14
+ acceptingIntents: Boolean!
15
+ status: String! # ACTIVE | CLOSED | WITHDRAWN
16
+
17
+ # Pre-calculated fields
18
+ outstandingIntentAmount: BigInt!
19
+ availableLiquidity: BigInt!
20
+
21
+ # Intent counters
22
+ totalIntents: Int!
23
+ signaledIntents: Int!
24
+ fulfilledIntents: Int!
25
+ prunedIntents: Int!
26
+
27
+ # Metadata
28
+ blockNumber: BigInt!
29
+ timestamp: BigInt!
30
+ txHash: String!
31
+ updatedAt: BigInt!
32
+ }
33
+
34
+ type DepositPaymentMethod {
35
+ id: ID!
36
+ chainId: Int!
37
+ depositIdOnContract: BigInt!
38
+ depositId: String!
39
+ paymentMethodHash: String!
40
+ verifierAddress: String!
41
+ intentGatingService: String!
42
+ payeeDetailsHash: String!
43
+ }
44
+
45
+ type MethodCurrency {
46
+ id: ID!
47
+ chainId: Int!
48
+ depositIdOnContract: BigInt!
49
+ depositId: String!
50
+ paymentMethodHash: String!
51
+ currencyCode: String!
52
+ minConversionRate: BigInt! # Currently contract emits this field as conversionRate; todo: update it on contract
53
+ }
54
+
55
+ type Intent {
56
+ id: ID! # chainId_intentHash
57
+ intentHash: String!
58
+ depositId: String!
59
+ verifier: String!
60
+ owner: String!
61
+ toAddress: String!
62
+ amount: BigInt!
63
+ fiatCurrency: String!
64
+ conversionRate: BigInt!
65
+ status: String! # SIGNALED | FULFILLED | PRUNED
66
+ signalTimestamp: BigInt!
67
+ signalTxHash: String!
68
+ fulfillTxHash: String
69
+ pruneTxHash: String
70
+
71
+ # Association to payment method
72
+ paymentMethodHash: String
73
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@zkp2p/indexer-schema",
3
+ "version": "0.1.0",
4
+ "description": "ZKP2P Indexer GraphQL schema",
5
+ "private": false,
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "license": "MIT",
10
+ "type": "commonjs",
11
+ "main": "dist/index.js",
12
+ "exports": {
13
+ ".": "./dist/index.js",
14
+ "./schema.graphql": "./dist/schema.graphql"
15
+ },
16
+ "files": [
17
+ "dist/schema.graphql",
18
+ "dist/index.js",
19
+ "README.md"
20
+ ],
21
+ "scripts": {
22
+ "prepack": "node scripts/copy-schema.js",
23
+ "pack:local": "npm pack"
24
+ },
25
+ "engines": {
26
+ "node": ">=16"
27
+ }
28
+ }