Skip to content

Commit 82315e6

Browse files
authored
Merge pull request #12 from windingtree/develop
Bump beta.11
2 parents 0504f60 + 71a734a commit 82315e6

File tree

10 files changed

+93
-101
lines changed

10 files changed

+93
-101
lines changed

examples/client/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"typescript": "^5.0.3",
2020
"vite": "^4.2.1",
2121
"zod": "^3.21.4",
22-
"@windingtree/sdk": "0.1.0-beta.9"
22+
"@windingtree/sdk": "0.1.0-beta.10"
2323
},
2424
"eslintConfig": {
2525
"extends": [

examples/client/src/App.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const defaultExpire = '30s';
1616
/** Default topic to publish requests the same as for the supplier node */
1717
const defaultTopic = 'hello';
1818

19+
type RequestsRegistryRecord = Required<RequestRecord<RequestQuery, OfferOptions>>;
20+
1921
interface FormValues {
2022
topic: string;
2123
message: string;
@@ -27,7 +29,7 @@ interface RequestFormProps {
2729
}
2830

2931
interface RequestsProps {
30-
requests: Required<RequestRecord<RequestQuery, OfferOptions>>[];
32+
requests: RequestsRegistryRecord[];
3133
subscribed?: (id: string) => boolean;
3234
onClear(): void;
3335
onCancel(id: string): void;
@@ -147,7 +149,7 @@ export const Requests = ({ requests, subscribed, onClear, onCancel }: RequestsPr
147149
export const App = () => {
148150
const client = useRef<Client<RequestQuery, OfferOptions> | undefined>();
149151
const [connected, setConnected] = useState<boolean>(false);
150-
const [requests, setRequests] = useState<Required<RequestRecord<RequestQuery, OfferOptions>>[]>(
152+
const [requests, setRequests] = useState<RequestsRegistryRecord[]>(
151153
[],
152154
);
153155
const [error, setError] = useState<string | undefined>();

examples/client/yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -2177,10 +2177,10 @@
21772177
magic-string "^0.27.0"
21782178
react-refresh "^0.14.0"
21792179

2180-
"@windingtree/[email protected].9":
2181-
version "0.1.0-beta.9"
2182-
resolved "https://registry.yarnpkg.com/@windingtree/sdk/-/sdk-0.1.0-beta.9.tgz#215fe4729d0bb7b777de449d9e3d4ce56241b432"
2183-
integrity sha512-L2RuVtCGcCuSAEcUjE25k2BaDx3SbZQJos/ncU9ncmilKFNuPbt+QAmxgveZVZRXCb5fInJyWa+V9bD9NvPAaw==
2180+
"@windingtree/[email protected].10":
2181+
version "0.1.0-beta.10"
2182+
resolved "https://registry.yarnpkg.com/@windingtree/sdk/-/sdk-0.1.0-beta.10.tgz#f2092903077a597ffb3c46a6af1fda25b8586bea"
2183+
integrity sha512-9CsUr+njuL71L0eHX9GmNuaTgauGHqJzsky/annmW7WDa/GJ5cFI6mowGSMRHeCIAhtOZEtMQUAlWrHRgk1TBQ==
21842184
dependencies:
21852185
"@chainsafe/libp2p-gossipsub" "^6.2.0"
21862186
"@chainsafe/libp2p-noise" "^11.0.4"

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
],
2424
"license": "MIT",
2525
"type": "module",
26-
"types": "./lib/src/index.d.ts",
27-
"main": "./lib/src/index.js",
26+
"types": "./lib/index.d.ts",
27+
"main": "./lib/index.js",
2828
"files": [
2929
"lib/**/*",
3030
"!**/*.tsbuildinfo"

src/client/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,10 @@ export class Client<
329329
}
330330

331331
/** Check is the message is an offer */
332-
const offer = createOfferDataSchema<
333-
z.ZodType<CustomRequestQuery>,
334-
z.ZodType<CustomOfferOptions>
335-
>(this.querySchema, this.offerOptionsSchema).parse(JSON.parse(decodeText(detail.data)));
332+
const offer = createOfferDataSchema<CustomRequestQuery, CustomOfferOptions>(
333+
this.querySchema,
334+
this.offerOptionsSchema,
335+
).parse(JSON.parse(decodeText(detail.data)));
336336
logger.trace('Offer received:', offer);
337337

338338
// Verify the offer

src/client/requestsRegistry.ts

+26-27
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,29 @@ const logger = createLogger('RequestsRegistry');
1919
/**
2020
* Creates request record schema
2121
*
22-
* @param {z.ZodType} querySchema Custom request query schema
23-
* @param {z.ZodType} offerOptionsSchema
22+
* @template {CustomRequestQuery}
23+
* @template {CustomOfferOptions}
24+
* @param {z.ZodType<CustomRequestQuery>} querySchema Custom request query schema
25+
* @param {z.ZodType<CustomOfferOptions>} offerOptionsSchema
2426
* @returns {z.ZodType} Request record schema
2527
*/
2628
export const createRequestRecordSchema = <
27-
TQuery extends z.ZodTypeAny,
28-
TOfferOptions extends z.ZodTypeAny,
29+
CustomRequestQuery extends GenericQuery,
30+
CustomOfferOptions extends GenericOfferOptions,
2931
>(
30-
querySchema: TQuery,
31-
offerOptionsSchema: TOfferOptions,
32+
querySchema: z.ZodType<CustomRequestQuery>,
33+
offerOptionsSchema: z.ZodType<CustomOfferOptions>,
3234
) =>
3335
z
3436
.object({
3537
/** Raw request data */
36-
data: createRequestDataSchema<TQuery>(querySchema),
38+
data: createRequestDataSchema<CustomRequestQuery>(querySchema),
3739
/** Offers associated with a request*/
3840
offers: z.array(
39-
createOfferDataSchema<TQuery, TOfferOptions>(querySchema, offerOptionsSchema),
41+
createOfferDataSchema<CustomRequestQuery, CustomOfferOptions>(
42+
querySchema,
43+
offerOptionsSchema,
44+
),
4045
),
4146
/** Request cancelation flag */
4247
cancelled: z.boolean().default(false),
@@ -84,11 +89,7 @@ export type RequestsRegistryOptions<
8489
export type RequestRecord<
8590
CustomRequestQuery extends GenericQuery,
8691
CustomOfferOptions extends GenericOfferOptions,
87-
> = z.infer<
88-
ReturnType<
89-
typeof createRequestRecordSchema<z.ZodType<CustomRequestQuery>, z.ZodType<CustomOfferOptions>>
90-
>
91-
>;
92+
> = z.infer<ReturnType<typeof createRequestRecordSchema<CustomRequestQuery, CustomOfferOptions>>>;
9293

9394
/**
9495
* Request manager events interface
@@ -260,10 +261,10 @@ export class RequestsRegistry<
260261

261262
for (let requestRecord of rawRecords) {
262263
try {
263-
requestRecord = createRequestRecordSchema<
264-
z.ZodType<CustomRequestQuery>,
265-
z.ZodType<CustomOfferOptions>
266-
>(this.client.querySchema, this.client.offerOptionsSchema).parse(requestRecord);
264+
requestRecord = createRequestRecordSchema<CustomRequestQuery, CustomOfferOptions>(
265+
this.client.querySchema,
266+
this.client.offerOptionsSchema,
267+
).parse(requestRecord);
267268

268269
// `record.data` marked as optional because of Zod generics issue
269270
this.requests.set(
@@ -379,13 +380,11 @@ export class RequestsRegistry<
379380
throw new Error('Client not connected to the coordination server yet');
380381
}
381382

382-
request = createRequestDataSchema<z.ZodType<CustomRequestQuery>>(this.client.querySchema).parse(
383-
request,
384-
);
385-
const requestRecord = createRequestRecordSchema<
386-
z.ZodType<CustomRequestQuery>,
387-
z.ZodType<CustomOfferOptions>
388-
>(this.client.querySchema, this.client.offerOptionsSchema).parse({
383+
request = createRequestDataSchema<CustomRequestQuery>(this.client.querySchema).parse(request);
384+
const requestRecord = createRequestRecordSchema<CustomRequestQuery, CustomOfferOptions>(
385+
this.client.querySchema,
386+
this.client.offerOptionsSchema,
387+
).parse({
389388
data: request,
390389
offers: [],
391390
});
@@ -452,7 +451,7 @@ export class RequestsRegistry<
452451

453452
this.requests.set(
454453
id,
455-
createRequestRecordSchema<z.ZodType<CustomRequestQuery>, z.ZodType<CustomOfferOptions>>(
454+
createRequestRecordSchema<CustomRequestQuery, CustomOfferOptions>(
456455
this.client.querySchema,
457456
this.client.offerOptionsSchema,
458457
).parse(record),
@@ -512,7 +511,7 @@ export class RequestsRegistry<
512511
* @memberof RequestsRegistry
513512
*/
514513
addOffer(offer: OfferData<CustomRequestQuery, CustomOfferOptions>) {
515-
offer = createOfferDataSchema<z.ZodType<CustomRequestQuery>, z.ZodType<CustomOfferOptions>>(
514+
offer = createOfferDataSchema<CustomRequestQuery, CustomOfferOptions>(
516515
this.client.querySchema,
517516
this.client.offerOptionsSchema,
518517
).parse(offer);
@@ -529,7 +528,7 @@ export class RequestsRegistry<
529528

530529
this.requests.set(
531530
requestId,
532-
createRequestRecordSchema<z.ZodType<CustomRequestQuery>, z.ZodType<CustomOfferOptions>>(
531+
createRequestRecordSchema<CustomRequestQuery, CustomOfferOptions>(
533532
this.client.querySchema,
534533
this.client.offerOptionsSchema,
535534
).parse({

src/node/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export class Node<
249249
}
250250

251251
const offer = await buildOffer<CustomRequestQuery, CustomOfferOptions>(
252-
createBuildOfferOptions<z.ZodType<CustomRequestQuery>, z.ZodType<CustomOfferOptions>>(
252+
createBuildOfferOptions<CustomRequestQuery, CustomOfferOptions>(
253253
this.querySchema,
254254
this.offerOptionsSchema,
255255
).parse({

src/node/requestManager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class RequestManager<CustomRequestQuery extends GenericQuery> extends Eve
4545
}
4646

4747
add(topic: string, data: string) {
48-
const requestData = createRequestDataSchema<typeof this.querySchema>(this.querySchema).parse(
48+
const requestData = createRequestDataSchema<CustomRequestQuery>(this.querySchema).parse(
4949
JSON.parse(data),
5050
);
5151

0 commit comments

Comments
 (0)