Skip to content

Commit 2567ea9

Browse files
committed
feat: split up the types
1 parent 118832d commit 2567ea9

20 files changed

+285
-213
lines changed

packages/js/src/schemas/schemas.ts

Lines changed: 22 additions & 213 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
import { ZodError, type ZodSchema, z } from "zod";
1+
import { ZodError, type ZodSchema } from "zod";
2+
3+
// Import and re-export all schemas
4+
export * from "./schemas/access-token";
5+
export * from "./schemas/application";
6+
export * from "./schemas/base-platform";
7+
export * from "./schemas/blockchain-network";
8+
export * from "./schemas/blockchain-node";
9+
export * from "./schemas/custom-deployment";
10+
export * from "./schemas/ethereum";
11+
export * from "./schemas/insights";
12+
export * from "./schemas/integration-tool";
13+
export * from "./schemas/middleware";
14+
export * from "./schemas/private-key";
15+
export * from "./schemas/search-key";
16+
export * from "./schemas/service-type";
17+
export * from "./schemas/settlemint-client-env";
18+
export * from "./schemas/storage";
19+
export * from "./schemas/unique-name";
20+
export * from "./schemas/url";
21+
export * from "./schemas/workspace";
22+
export * from "./schemas/ws-appl-platform";
223

3-
/**
4-
* Validates the given value against the provided Zod schema.
5-
* @param schema The Zod schema to validate against.
6-
* @param value The value to validate.
7-
* @returns The validated and parsed data if successful.
8-
* @throws {Error} If validation fails, with a formatted error message.
9-
*/
1024
export function validate<T extends ZodSchema>(schema: T, value: unknown): T["_output"] {
1125
try {
1226
return schema.parse(value);
@@ -18,208 +32,3 @@ export function validate<T extends ZodSchema>(schema: T, value: unknown): T["_ou
1832
throw error; // Re-throw if it's not a ZodError
1933
}
2034
}
21-
22-
export const AccessTokenSchema = z.string().regex(/^btp_pat_.*|btp_aat_.*$/);
23-
24-
export const UniqueNameSchema = z.string().regex(/^[a-z-]+-[a-z0-9]{5}$/);
25-
export type UniqueName = z.infer<typeof UniqueNameSchema>;
26-
27-
export const SearchKeySchema = z.string().regex(/^[a-z0-9]{5}$/);
28-
29-
export const UrlSchema = z.string().url();
30-
31-
export const ServiceTypeSchema = z.enum([
32-
"workspace",
33-
"application",
34-
"blockchain-network",
35-
"blockchain-node",
36-
"smart-contract-set",
37-
"middleware",
38-
"integration-tool",
39-
"storage",
40-
"private-key",
41-
"insights",
42-
"custom-deployment",
43-
]);
44-
export type ServiceType = z.infer<typeof ServiceTypeSchema>;
45-
46-
export const EthereumAddressSchema = z.string().regex(/^0x[a-fA-F0-9]{40}$/);
47-
48-
export const EthereumPublicKeySchema = z.string().regex(/^0x[a-fA-F0-9]{64}$/);
49-
50-
export const SettleMintClientEnvSchema = z.object({
51-
SETTLEMINT_ACCESS_TOKEN: AccessTokenSchema,
52-
SETTLEMINT_INSTANCE: UrlSchema,
53-
SETTLEMINT_DEFAULT_BLOCKCHAIN_NETWORK: UniqueNameSchema.optional(),
54-
SETTLEMINT_DEFAULT_BLOCKCHAIN_NODE: UniqueNameSchema.optional(),
55-
SETTLEMINT_DEFAULT_STORAGE: UniqueNameSchema.optional(),
56-
SETTLEMINT_DEFAULT_PRIVATE_KEY: UniqueNameSchema.optional(),
57-
SETTLEMINT_DEFAULT_INTEGRATION_TOOL: UniqueNameSchema.optional(),
58-
SETTLEMINT_DEFAULT_MIDDLEWARE: UniqueNameSchema.optional(),
59-
SETTLEMINT_DEFAULT_CUSTOM_DEPLOYMENT: UniqueNameSchema.optional(),
60-
SETTLEMINT_DEFAULT_INSIGHTS: UniqueNameSchema.optional(),
61-
SETTLEMINT_DEFAULT_WORKSPACE: UniqueNameSchema.optional(),
62-
SETTLEMINT_DEFAULT_APPLICATION: UniqueNameSchema.optional(),
63-
});
64-
65-
const BasePlatformReturnValueSchema = z.object({
66-
uniqueName: UniqueNameSchema,
67-
displayName: z.string(),
68-
});
69-
70-
export const WorkspaceReturnValueSchema = BasePlatformReturnValueSchema.extend({});
71-
export type WorkspaceReturnValue = z.infer<typeof WorkspaceReturnValueSchema>;
72-
73-
export const ApplicationReturnValueSchema = BasePlatformReturnValueSchema.extend({
74-
workspace: UniqueNameSchema,
75-
});
76-
export type ApplicationReturnValue = z.infer<typeof ApplicationReturnValueSchema>;
77-
78-
const WsApplPlatformReturnValueSchema = BasePlatformReturnValueSchema.extend({
79-
workspace: UniqueNameSchema,
80-
application: UniqueNameSchema,
81-
});
82-
83-
export const BlockchainNetworkReturnValueSchema = WsApplPlatformReturnValueSchema.extend({
84-
serviceSubType: z.string(),
85-
chainId: z.string(),
86-
});
87-
export type BlockchainNetworkReturnValue = z.infer<typeof BlockchainNetworkReturnValueSchema>;
88-
89-
export const BlockchainNodeReturnValueSchema = WsApplPlatformReturnValueSchema.extend({
90-
serviceSubType: z.string(),
91-
network: UniqueNameSchema,
92-
endpoints: z.object({
93-
base: UrlSchema,
94-
jsonRpc: UrlSchema,
95-
jsonWs: UrlSchema,
96-
graphQl: UrlSchema,
97-
}),
98-
});
99-
export type BlockchainNodeReturnValue = z.infer<typeof BlockchainNodeReturnValueSchema>;
100-
101-
const BaseMiddlewareSchema = WsApplPlatformReturnValueSchema.extend({
102-
serviceSubType: z.string(),
103-
endpoints: z.object({
104-
base: UrlSchema,
105-
}),
106-
});
107-
108-
const PortalMiddlewareSchema = BaseMiddlewareSchema.extend({
109-
serviceSubType: z.literal("SMART_CONTRACT_PORTAL"),
110-
endpoints: z.object({
111-
base: UrlSchema,
112-
jsonRpc: UrlSchema,
113-
jsonWs: UrlSchema,
114-
graphQl: UrlSchema,
115-
}),
116-
});
117-
118-
const TheGraphMiddlewareSchema = BaseMiddlewareSchema.extend({
119-
serviceSubType: z.literal("HA_GRAPH"),
120-
endpoints: z.object({
121-
base: UrlSchema,
122-
subgraph: UrlSchema,
123-
defaultSubgraph: UrlSchema,
124-
}),
125-
});
126-
127-
export const MiddlewareReturnValueSchema = z.union([
128-
PortalMiddlewareSchema,
129-
TheGraphMiddlewareSchema,
130-
BaseMiddlewareSchema,
131-
]);
132-
133-
export type MiddlewareReturnValue = z.infer<typeof MiddlewareReturnValueSchema>;
134-
135-
const BaseIntegrationToolSchema = WsApplPlatformReturnValueSchema.extend({
136-
serviceSubType: z.string(),
137-
endpoints: z.object({
138-
base: UrlSchema,
139-
}),
140-
});
141-
142-
const HasuraIntegrationToolSchema = BaseIntegrationToolSchema.extend({
143-
serviceSubType: z.literal("HASURA"),
144-
endpoints: z.object({
145-
base: UrlSchema,
146-
graphQl: UrlSchema,
147-
}),
148-
secrets: z.object({
149-
adminSecret: z.string(),
150-
}),
151-
});
152-
153-
export const IntegrationToolReturnValueSchema = z.union([HasuraIntegrationToolSchema, BaseIntegrationToolSchema]);
154-
export type IntegrationToolReturnValue = z.infer<typeof IntegrationToolReturnValueSchema>;
155-
156-
const BaseStorageSchema = WsApplPlatformReturnValueSchema.extend({
157-
serviceSubType: z.string(),
158-
endpoints: z.object({
159-
base: UrlSchema,
160-
}),
161-
});
162-
163-
const IpfsStorageSchema = BaseStorageSchema.extend({
164-
serviceSubType: z.literal("IPFS"),
165-
endpoints: z.object({
166-
base: UrlSchema,
167-
api: UrlSchema,
168-
gateway: UrlSchema,
169-
clusterApi: UrlSchema,
170-
pinning: UrlSchema,
171-
}),
172-
secrets: z.object({
173-
password: z.string(),
174-
}),
175-
});
176-
177-
const MinioStorageSchema = BaseStorageSchema.extend({
178-
serviceSubType: z.literal("MINIO"),
179-
endpoints: z.object({
180-
base: UrlSchema,
181-
s3Api: UrlSchema,
182-
}),
183-
secrets: z.object({
184-
accessKey: z.string(),
185-
secretKey: z.string(),
186-
}),
187-
});
188-
189-
export const StorageReturnValueSchema = z.union([IpfsStorageSchema, MinioStorageSchema, BaseStorageSchema]);
190-
export type StorageReturnValue = z.infer<typeof StorageReturnValueSchema>;
191-
192-
const BasePrivateKeySchema = WsApplPlatformReturnValueSchema.extend({
193-
serviceSubType: z.string(),
194-
});
195-
196-
const HdPrivateKeySchema = BasePrivateKeySchema.extend({
197-
serviceSubType: z.literal("HD_ECDSA_P256"),
198-
});
199-
200-
const EcdsaPrivateKeySchema = BasePrivateKeySchema.extend({
201-
serviceSubType: z.literal("MINIO"),
202-
address: EthereumAddressSchema,
203-
publicKey: EthereumPublicKeySchema,
204-
});
205-
206-
export const PrivateKeyReturnValueSchema = z.union([HdPrivateKeySchema, EcdsaPrivateKeySchema, BasePrivateKeySchema]);
207-
export type PrivateKeyReturnValue = z.infer<typeof PrivateKeyReturnValueSchema>;
208-
209-
export const InsightsReturnValueSchema = WsApplPlatformReturnValueSchema.extend({
210-
serviceSubType: z.string(),
211-
protocol: z.string(),
212-
endpoints: z.object({
213-
base: UrlSchema,
214-
}),
215-
});
216-
export type InsightsReturnValue = z.infer<typeof InsightsReturnValueSchema>;
217-
218-
export const CustomDeploymentReturnValueSchema = WsApplPlatformReturnValueSchema.extend({
219-
serviceSubType: z.string(),
220-
protocol: z.string(),
221-
endpoints: z.object({
222-
base: UrlSchema,
223-
}),
224-
});
225-
export type CustomDeploymentReturnValue = z.infer<typeof CustomDeploymentReturnValueSchema>;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { z } from "zod";
2+
3+
export const AccessTokenSchema = z.string().regex(/^btp_pat_.*|btp_aat_.*$/);
4+
export type AccessToken = z.infer<typeof AccessTokenSchema>;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { z } from "zod";
2+
import { BasePlatformReturnValueSchema } from "./base-platform";
3+
import { UniqueNameSchema } from "./unique-name";
4+
5+
export const ApplicationReturnValueSchema = BasePlatformReturnValueSchema.extend({
6+
workspace: UniqueNameSchema,
7+
});
8+
export type ApplicationReturnValue = z.infer<typeof ApplicationReturnValueSchema>;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { z } from "zod";
2+
import { UniqueNameSchema } from "./unique-name";
3+
4+
export const BasePlatformReturnValueSchema = z.object({
5+
uniqueName: UniqueNameSchema,
6+
displayName: z.string(),
7+
});
8+
export type BasePlatformReturnValue = z.infer<typeof BasePlatformReturnValueSchema>;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { z } from "zod";
2+
import { WsApplPlatformReturnValueSchema } from "../ws-appl-platform";
3+
4+
export const BlockchainNetworkReturnValueSchema = WsApplPlatformReturnValueSchema.extend({
5+
serviceSubType: z.string(),
6+
chainId: z.string(),
7+
});
8+
export type BlockchainNetworkReturnValue = z.infer<typeof BlockchainNetworkReturnValueSchema>;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { z } from "zod";
2+
import { WsApplPlatformReturnValueSchema } from "../ws-appl-platform";
3+
import { UniqueNameSchema } from "./unique-name";
4+
import { UrlSchema } from "./url";
5+
6+
export const BlockchainNodeReturnValueSchema = WsApplPlatformReturnValueSchema.extend({
7+
serviceSubType: z.string(),
8+
network: UniqueNameSchema,
9+
endpoints: z.object({
10+
base: UrlSchema,
11+
jsonRpc: UrlSchema,
12+
jsonWs: UrlSchema,
13+
graphQl: UrlSchema,
14+
}),
15+
});
16+
export type BlockchainNodeReturnValue = z.infer<typeof BlockchainNodeReturnValueSchema>;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { z } from "zod";
2+
import { WsApplPlatformReturnValueSchema } from "../ws-appl-platform";
3+
import { UrlSchema } from "./url";
4+
5+
export const CustomDeploymentReturnValueSchema = WsApplPlatformReturnValueSchema.extend({
6+
serviceSubType: z.string(),
7+
protocol: z.string(),
8+
endpoints: z.object({
9+
base: UrlSchema,
10+
}),
11+
});
12+
export type CustomDeploymentReturnValue = z.infer<typeof CustomDeploymentReturnValueSchema>;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { z } from "zod";
2+
3+
export const EthereumAddressSchema = z.string().regex(/^0x[a-fA-F0-9]{40}$/);
4+
export type EthereumAddress = z.infer<typeof EthereumAddressSchema>;
5+
6+
export const EthereumPublicKeySchema = z.string().regex(/^0x[a-fA-F0-9]{64}$/);
7+
export type EthereumPublicKey = z.infer<typeof EthereumPublicKeySchema>;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { z } from "zod";
2+
import { WsApplPlatformReturnValueSchema } from "../ws-appl-platform";
3+
import { UrlSchema } from "./url";
4+
5+
export const InsightsReturnValueSchema = WsApplPlatformReturnValueSchema.extend({
6+
serviceSubType: z.string(),
7+
protocol: z.string(),
8+
endpoints: z.object({
9+
base: UrlSchema,
10+
}),
11+
});
12+
export type InsightsReturnValue = z.infer<typeof InsightsReturnValueSchema>;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { z } from "zod";
2+
import { WsApplPlatformReturnValueSchema } from "../ws-appl-platform";
3+
import { UrlSchema } from "./url";
4+
5+
export const BaseIntegrationToolSchema = WsApplPlatformReturnValueSchema.extend({
6+
serviceSubType: z.string(),
7+
endpoints: z.object({
8+
base: UrlSchema,
9+
}),
10+
});
11+
export type BaseIntegrationTool = z.infer<typeof BaseIntegrationToolSchema>;
12+
13+
export const HasuraIntegrationToolSchema = BaseIntegrationToolSchema.extend({
14+
serviceSubType: z.literal("HASURA"),
15+
endpoints: z.object({
16+
base: UrlSchema,
17+
graphQl: UrlSchema,
18+
}),
19+
secrets: z.object({
20+
adminSecret: z.string(),
21+
}),
22+
});
23+
export type HasuraIntegrationTool = z.infer<typeof HasuraIntegrationToolSchema>;
24+
25+
export const IntegrationToolReturnValueSchema = z.union([HasuraIntegrationToolSchema, BaseIntegrationToolSchema]);
26+
export type IntegrationToolReturnValue = z.infer<typeof IntegrationToolReturnValueSchema>;

0 commit comments

Comments
 (0)