@atcute/jetstream 1.1.2 → 2.0.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.
@@ -1,16 +1,182 @@
1
- import * as v from '@badrap/valita';
2
- import type * as t from './types.js';
3
- export declare const createCommitSchema: v.Type<t.CreateCommit>;
4
- export declare const updateCommitSchema: v.Type<t.UpdateCommit>;
5
- export declare const deleteCommitSchema: v.Type<t.DeleteCommit>;
6
- export declare const commitOperationSchema: v.Type<t.CommitOperation>;
7
- export declare const commitEventSchema: v.Type<t.CommitEvent>;
8
- export declare const identityDataSchema: v.Type<t.IdentityData>;
9
- export declare const identityEventSchema: v.Type<t.IdentityEvent>;
10
- export declare const accountDataSchema: v.Type<t.AccountData>;
11
- export declare const accountEventSchema: v.Type<t.AccountEvent>;
12
- export declare const jetstreamEventSchema: v.Type<t.JetstreamEvent>;
13
- export declare const optionsUpdatePayloadSchema: v.Type<t.OptionsUpdatePayload>;
14
- export declare const optionsUpdateProcedureSchema: v.Type<t.OptionsUpdateProcedure>;
15
- export declare const jetstreamProcedureSchema: v.Type<t.JetstreamProcedure>;
1
+ import * as v from 'valibot';
2
+ export declare const createCommitSchema: v.LooseObjectSchema<{
3
+ readonly rev: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
4
+ readonly collection: v.CustomSchema<`${string}.${string}.${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
5
+ readonly rkey: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
6
+ readonly operation: v.LiteralSchema<"create", undefined>;
7
+ readonly cid: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
8
+ readonly record: v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>;
9
+ }, undefined>;
10
+ export declare const updateCommitSchema: v.LooseObjectSchema<{
11
+ readonly rev: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
12
+ readonly collection: v.CustomSchema<`${string}.${string}.${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
13
+ readonly rkey: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
14
+ readonly operation: v.LiteralSchema<"update", undefined>;
15
+ readonly cid: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
16
+ readonly record: v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>;
17
+ }, undefined>;
18
+ export declare const deleteCommitSchema: v.LooseObjectSchema<{
19
+ readonly rev: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
20
+ readonly collection: v.CustomSchema<`${string}.${string}.${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
21
+ readonly rkey: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
22
+ readonly operation: v.LiteralSchema<"delete", undefined>;
23
+ }, undefined>;
24
+ export declare const commitOperationSchema: v.VariantSchema<"operation", [v.LooseObjectSchema<{
25
+ readonly rev: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
26
+ readonly collection: v.CustomSchema<`${string}.${string}.${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
27
+ readonly rkey: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
28
+ readonly operation: v.LiteralSchema<"create", undefined>;
29
+ readonly cid: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
30
+ readonly record: v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>;
31
+ }, undefined>, v.LooseObjectSchema<{
32
+ readonly rev: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
33
+ readonly collection: v.CustomSchema<`${string}.${string}.${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
34
+ readonly rkey: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
35
+ readonly operation: v.LiteralSchema<"update", undefined>;
36
+ readonly cid: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
37
+ readonly record: v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>;
38
+ }, undefined>, v.LooseObjectSchema<{
39
+ readonly rev: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
40
+ readonly collection: v.CustomSchema<`${string}.${string}.${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
41
+ readonly rkey: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
42
+ readonly operation: v.LiteralSchema<"delete", undefined>;
43
+ }, undefined>], undefined>;
44
+ export declare const commitEventSchema: v.LooseObjectSchema<{
45
+ readonly did: v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
46
+ readonly time_us: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
47
+ readonly kind: v.LiteralSchema<"commit", undefined>;
48
+ readonly commit: v.VariantSchema<"operation", [v.LooseObjectSchema<{
49
+ readonly rev: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
50
+ readonly collection: v.CustomSchema<`${string}.${string}.${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
51
+ readonly rkey: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
52
+ readonly operation: v.LiteralSchema<"create", undefined>;
53
+ readonly cid: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
54
+ readonly record: v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>;
55
+ }, undefined>, v.LooseObjectSchema<{
56
+ readonly rev: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
57
+ readonly collection: v.CustomSchema<`${string}.${string}.${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
58
+ readonly rkey: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
59
+ readonly operation: v.LiteralSchema<"update", undefined>;
60
+ readonly cid: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
61
+ readonly record: v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>;
62
+ }, undefined>, v.LooseObjectSchema<{
63
+ readonly rev: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
64
+ readonly collection: v.CustomSchema<`${string}.${string}.${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
65
+ readonly rkey: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
66
+ readonly operation: v.LiteralSchema<"delete", undefined>;
67
+ }, undefined>], undefined>;
68
+ }, undefined>;
69
+ export declare const identityDataSchema: v.LooseObjectSchema<{
70
+ readonly did: v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
71
+ readonly handle: v.CustomSchema<`${string}.${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
72
+ readonly seq: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
73
+ readonly time: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
74
+ }, undefined>;
75
+ export declare const identityEventSchema: v.LooseObjectSchema<{
76
+ readonly did: v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
77
+ readonly time_us: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
78
+ readonly kind: v.LiteralSchema<"identity", undefined>;
79
+ readonly identity: v.LooseObjectSchema<{
80
+ readonly did: v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
81
+ readonly handle: v.CustomSchema<`${string}.${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
82
+ readonly seq: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
83
+ readonly time: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
84
+ }, undefined>;
85
+ }, undefined>;
86
+ export declare const accountDataSchema: v.LooseObjectSchema<{
87
+ readonly did: v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
88
+ readonly active: v.BooleanSchema<undefined>;
89
+ readonly seq: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
90
+ readonly time: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
91
+ }, undefined>;
92
+ export declare const accountEventSchema: v.LooseObjectSchema<{
93
+ readonly did: v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
94
+ readonly time_us: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
95
+ readonly kind: v.LiteralSchema<"account", undefined>;
96
+ readonly account: v.LooseObjectSchema<{
97
+ readonly did: v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
98
+ readonly active: v.BooleanSchema<undefined>;
99
+ readonly seq: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
100
+ readonly time: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
101
+ }, undefined>;
102
+ }, undefined>;
103
+ export declare const jetstreamEventSchema: v.VariantSchema<"kind", [v.LooseObjectSchema<{
104
+ readonly did: v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
105
+ readonly time_us: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
106
+ readonly kind: v.LiteralSchema<"commit", undefined>;
107
+ readonly commit: v.VariantSchema<"operation", [v.LooseObjectSchema<{
108
+ readonly rev: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
109
+ readonly collection: v.CustomSchema<`${string}.${string}.${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
110
+ readonly rkey: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
111
+ readonly operation: v.LiteralSchema<"create", undefined>;
112
+ readonly cid: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
113
+ readonly record: v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>;
114
+ }, undefined>, v.LooseObjectSchema<{
115
+ readonly rev: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
116
+ readonly collection: v.CustomSchema<`${string}.${string}.${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
117
+ readonly rkey: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
118
+ readonly operation: v.LiteralSchema<"update", undefined>;
119
+ readonly cid: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
120
+ readonly record: v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>;
121
+ }, undefined>, v.LooseObjectSchema<{
122
+ readonly rev: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
123
+ readonly collection: v.CustomSchema<`${string}.${string}.${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
124
+ readonly rkey: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
125
+ readonly operation: v.LiteralSchema<"delete", undefined>;
126
+ }, undefined>], undefined>;
127
+ }, undefined>, v.LooseObjectSchema<{
128
+ readonly did: v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
129
+ readonly time_us: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
130
+ readonly kind: v.LiteralSchema<"identity", undefined>;
131
+ readonly identity: v.LooseObjectSchema<{
132
+ readonly did: v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
133
+ readonly handle: v.CustomSchema<`${string}.${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
134
+ readonly seq: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
135
+ readonly time: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
136
+ }, undefined>;
137
+ }, undefined>, v.LooseObjectSchema<{
138
+ readonly did: v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
139
+ readonly time_us: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
140
+ readonly kind: v.LiteralSchema<"account", undefined>;
141
+ readonly account: v.LooseObjectSchema<{
142
+ readonly did: v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
143
+ readonly active: v.BooleanSchema<undefined>;
144
+ readonly seq: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
145
+ readonly time: v.CustomSchema<string, v.ErrorMessage<v.CustomIssue> | undefined>;
146
+ }, undefined>;
147
+ }, undefined>], undefined>;
148
+ export declare const optionsUpdatePayloadSchema: v.LooseObjectSchema<{
149
+ readonly wantedCollections: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
150
+ readonly wantedDids: v.OptionalSchema<v.ArraySchema<v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>, undefined>, undefined>;
151
+ readonly maxMessageSizeBytes: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
152
+ }, undefined>;
153
+ export declare const optionsUpdateProcedureSchema: v.LooseObjectSchema<{
154
+ readonly type: v.LiteralSchema<"options_update", undefined>;
155
+ readonly payload: v.LooseObjectSchema<{
156
+ readonly wantedCollections: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
157
+ readonly wantedDids: v.OptionalSchema<v.ArraySchema<v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>, undefined>, undefined>;
158
+ readonly maxMessageSizeBytes: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
159
+ }, undefined>;
160
+ }, undefined>;
161
+ export declare const jetstreamProcedureSchema: v.VariantSchema<"type", [v.LooseObjectSchema<{
162
+ readonly type: v.LiteralSchema<"options_update", undefined>;
163
+ readonly payload: v.LooseObjectSchema<{
164
+ readonly wantedCollections: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
165
+ readonly wantedDids: v.OptionalSchema<v.ArraySchema<v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>, undefined>, undefined>;
166
+ readonly maxMessageSizeBytes: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
167
+ }, undefined>;
168
+ }, undefined>], undefined>;
169
+ export type CreateCommit = v.InferOutput<typeof createCommitSchema>;
170
+ export type UpdateCommit = v.InferOutput<typeof updateCommitSchema>;
171
+ export type DeleteCommit = v.InferOutput<typeof deleteCommitSchema>;
172
+ export type CommitOperation = v.InferOutput<typeof commitOperationSchema>;
173
+ export type CommitEvent = v.InferOutput<typeof commitEventSchema>;
174
+ export type IdentityData = v.InferOutput<typeof identityDataSchema>;
175
+ export type IdentityEvent = v.InferOutput<typeof identityEventSchema>;
176
+ export type AccountData = v.InferOutput<typeof accountDataSchema>;
177
+ export type AccountEvent = v.InferOutput<typeof accountEventSchema>;
178
+ export type JetstreamEvent = v.InferOutput<typeof jetstreamEventSchema>;
179
+ export type OptionsUpdatePayload = v.InferOutput<typeof optionsUpdatePayloadSchema>;
180
+ export type OptionsUpdateProcedure = v.InferOutput<typeof optionsUpdateProcedureSchema>;
181
+ export type JetstreamProcedure = v.InferOutput<typeof jetstreamProcedureSchema>;
16
182
  //# sourceMappingURL=typedefs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"typedefs.d.ts","sourceRoot":"","sources":["../lib/typedefs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,gBAAgB,CAAC;AAIpC,OAAO,KAAK,KAAK,CAAC,MAAM,YAAY,CAAC;AAoBrC,eAAO,MAAM,kBAAkB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAIpD,CAAC;AAEH,eAAO,MAAM,kBAAkB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAIpD,CAAC;AAEH,eAAO,MAAM,kBAAkB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAEpD,CAAC;AAEH,eAAO,MAAM,qBAAqB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,CAI3D,CAAC;AAOF,eAAO,MAAM,iBAAiB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAGlD,CAAC;AAEH,eAAO,MAAM,kBAAkB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAKpD,CAAC;AAEH,eAAO,MAAM,mBAAmB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAGtD,CAAC;AAEH,eAAO,MAAM,iBAAiB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAKlD,CAAC;AAEH,eAAO,MAAM,kBAAkB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAGpD,CAAC;AAEH,eAAO,MAAM,oBAAoB,EAAE,CAAC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YAAY,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,kBAAkB,CAAC,CAAC;AACpE,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,kBAAkB,CAAC,CAAC;AACpE,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAE1E,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAClE,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,kBAAkB,CAAC,CAAC;AACpE,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,mBAAmB,CAAC,CAAC;AACtE,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAClE,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,kBAAkB,CAAC,CAAC;AACpE,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAExE,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,0BAA0B,CAAC,CAAC;AACpF,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,4BAA4B,CAAC,CAAC;AACxF,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,wBAAwB,CAAC,CAAC"}
package/dist/typedefs.js CHANGED
@@ -1,71 +1,83 @@
1
- import * as v from '@badrap/valita';
2
- import { isCid, isDatetime, isDid, isHandle, isNsid, isRecordKey, isTid } from '@atcute/lexicons/syntax';
3
- const cidString = v.string().assert(isCid, `must be a cid`);
4
- const datetimeString = v.string().assert(isDatetime, `must be a datetime`);
5
- const didString = v.string().assert(isDid, `must be a did`);
6
- const handleString = v.string().assert(isHandle, `must be a handle`);
7
- const nsidString = v.string().assert(isNsid, `must be an nsid`);
8
- const rkeyString = v.string().assert(isRecordKey, `must be a rkey`);
9
- const tidString = v.string().assert(isTid, `must be a tid`);
10
- const integer = v
11
- .number()
12
- .assert((input) => input >= 0 && Number.isSafeInteger(input), `must be a nonnegative integer`);
13
- const baseCommit = v.object({
1
+ import { isCid, isDatetime, isDid, isHandle, isNsid, isRecordKey, isTid, } from '@atcute/lexicons/syntax';
2
+ import * as v from 'valibot';
3
+ const cidString = v.custom(isCid, `must be a cid`);
4
+ const datetimeString = v.custom(isDatetime, `must be a datetime`);
5
+ const didString = v.custom(isDid, `must be a did`);
6
+ const handleString = v.custom(isHandle, `must be a handle`);
7
+ const nsidString = v.custom(isNsid, `must be an nsid`);
8
+ const rkeyString = v.custom(isRecordKey, `must be a rkey`);
9
+ const tidString = v.custom(isTid, `must be a tid`);
10
+ const integer = v.pipe(v.number(), v.safeInteger(), v.minValue(0));
11
+ const baseCommitEntries = {
14
12
  rev: tidString,
15
13
  collection: nsidString,
16
14
  rkey: rkeyString,
17
- });
18
- export const createCommitSchema = baseCommit.extend({
15
+ };
16
+ export const createCommitSchema = v.looseObject({
17
+ ...baseCommitEntries,
19
18
  operation: v.literal('create'),
20
19
  cid: cidString,
21
- record: v.record(v.unknown()),
20
+ record: v.record(v.string(), v.unknown()),
22
21
  });
23
- export const updateCommitSchema = baseCommit.extend({
22
+ export const updateCommitSchema = v.looseObject({
23
+ ...baseCommitEntries,
24
24
  operation: v.literal('update'),
25
25
  cid: cidString,
26
- record: v.record(v.unknown()),
26
+ record: v.record(v.string(), v.unknown()),
27
27
  });
28
- export const deleteCommitSchema = baseCommit.extend({
28
+ export const deleteCommitSchema = v.looseObject({
29
+ ...baseCommitEntries,
29
30
  operation: v.literal('delete'),
30
31
  });
31
- export const commitOperationSchema = v.union(createCommitSchema, updateCommitSchema, deleteCommitSchema);
32
- const baseEvent = v.object({
32
+ export const commitOperationSchema = v.variant('operation', [
33
+ createCommitSchema,
34
+ updateCommitSchema,
35
+ deleteCommitSchema,
36
+ ]);
37
+ const baseEventEntries = {
33
38
  did: didString,
34
39
  time_us: integer,
35
- });
36
- export const commitEventSchema = baseEvent.extend({
40
+ };
41
+ export const commitEventSchema = v.looseObject({
42
+ ...baseEventEntries,
37
43
  kind: v.literal('commit'),
38
44
  commit: commitOperationSchema,
39
45
  });
40
- export const identityDataSchema = v.object({
46
+ export const identityDataSchema = v.looseObject({
41
47
  did: didString,
42
48
  handle: handleString,
43
49
  seq: integer,
44
50
  time: datetimeString,
45
51
  });
46
- export const identityEventSchema = baseEvent.extend({
52
+ export const identityEventSchema = v.looseObject({
53
+ ...baseEventEntries,
47
54
  kind: v.literal('identity'),
48
55
  identity: identityDataSchema,
49
56
  });
50
- export const accountDataSchema = v.object({
57
+ export const accountDataSchema = v.looseObject({
51
58
  did: didString,
52
59
  active: v.boolean(),
53
60
  seq: integer,
54
61
  time: datetimeString,
55
62
  });
56
- export const accountEventSchema = baseEvent.extend({
63
+ export const accountEventSchema = v.looseObject({
64
+ ...baseEventEntries,
57
65
  kind: v.literal('account'),
58
66
  account: accountDataSchema,
59
67
  });
60
- export const jetstreamEventSchema = v.union(commitEventSchema, identityEventSchema, accountEventSchema);
61
- export const optionsUpdatePayloadSchema = v.object({
62
- wantedCollections: v.array(v.string()).optional(),
63
- wantedDids: v.array(didString).optional(),
64
- maxMessageSizeBytes: integer.optional(),
68
+ export const jetstreamEventSchema = v.variant('kind', [
69
+ commitEventSchema,
70
+ identityEventSchema,
71
+ accountEventSchema,
72
+ ]);
73
+ export const optionsUpdatePayloadSchema = v.looseObject({
74
+ wantedCollections: v.optional(v.array(v.string())),
75
+ wantedDids: v.optional(v.array(didString)),
76
+ maxMessageSizeBytes: v.optional(integer),
65
77
  });
66
- export const optionsUpdateProcedureSchema = v.object({
78
+ export const optionsUpdateProcedureSchema = v.looseObject({
67
79
  type: v.literal('options_update'),
68
80
  payload: optionsUpdatePayloadSchema,
69
81
  });
70
- export const jetstreamProcedureSchema = v.union(optionsUpdateProcedureSchema);
82
+ export const jetstreamProcedureSchema = v.variant('type', [optionsUpdateProcedureSchema]);
71
83
  //# sourceMappingURL=typedefs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typedefs.js","sourceRoot":"","sources":["../lib/typedefs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,gBAAgB,CAAC;AAEpC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAIzG,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;AAC5D,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,oBAAoB,CAAC,CAAC;AAC3E,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;AAC5D,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;AACrE,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AAChE,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC;AACpE,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;AAE5D,MAAM,OAAO,GAAG,CAAC;KACf,MAAM,EAAE;KACR,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,+BAA+B,CAAC,CAAC;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B,CAAC,CAAC,CAAC"}
package/lib/index.ts CHANGED
@@ -1,3 +1,2 @@
1
- export * from './subscription.js';
2
- export * from './types.js';
3
- export * from './typedefs.js';
1
+ export * from './subscription.ts';
2
+ export * from './typedefs.ts';
@@ -2,14 +2,12 @@ import type { Did } from '@atcute/lexicons';
2
2
 
3
3
  import { EventIterator } from '@mary-ext/event-iterator';
4
4
  import { SimpleEventEmitter } from '@mary-ext/simple-event-emitter';
5
-
6
5
  import { WebSocket as ReconnectingWebSocket } from 'partysocket';
7
6
  import type { CloseEvent, ErrorEvent, Options } from 'partysocket/ws';
8
-
9
7
  import type { ReadonlyDeep } from 'type-fest';
8
+ import * as v from 'valibot';
10
9
 
11
- import type { JetstreamEvent, JetstreamProcedure } from './types.js';
12
- import { jetstreamEventSchema } from './typedefs.js';
10
+ import { jetstreamEventSchema, type JetstreamEvent, type JetstreamProcedure } from './typedefs.ts';
13
11
 
14
12
  export interface JetstreamSubscriptionOptions {
15
13
  url: string | string[];
@@ -36,6 +34,11 @@ export interface JetstreamSubscriptionOptions {
36
34
  onConnectionOpen?: (event: Event) => void;
37
35
  onConnectionClose?: (event: CloseEvent) => void;
38
36
  onConnectionError?: (event: ErrorEvent) => void;
37
+ /**
38
+ * called when an event fails schema validation. the error is a valibot `ValiError` carrying
39
+ * the validation issues. without a handler, invalid events are silently dropped.
40
+ */
41
+ onError?: (err: unknown) => void;
39
42
 
40
43
  /**
41
44
  * WebSocket connection options
@@ -43,8 +46,6 @@ export interface JetstreamSubscriptionOptions {
43
46
  ws?: Options;
44
47
  }
45
48
 
46
- const PARSE_OPTIONS = { mode: 'passthrough' } as const;
47
-
48
49
  export class JetstreamSubscription {
49
50
  #listening = 0;
50
51
  #ws?: ReconnectingWebSocket;
@@ -94,6 +95,7 @@ export class JetstreamSubscription {
94
95
  onConnectionClose,
95
96
  onConnectionError,
96
97
  onConnectionOpen,
98
+ onError,
97
99
  } = this.#options;
98
100
  const emitter = this.#emitter;
99
101
 
@@ -138,12 +140,13 @@ export class JetstreamSubscription {
138
140
 
139
141
  let event: JetstreamEvent;
140
142
  if (validateEvents) {
141
- const result = jetstreamEventSchema.try(raw, PARSE_OPTIONS);
142
- if (!result.ok) {
143
+ const result = v.safeParse(jetstreamEventSchema, raw);
144
+ if (!result.success) {
145
+ onError?.(new v.ValiError(result.issues));
143
146
  return;
144
147
  }
145
148
 
146
- event = result.value;
149
+ event = result.output;
147
150
  } else {
148
151
  event = raw;
149
152
  }
@@ -200,21 +203,25 @@ export class JetstreamSubscription {
200
203
  }
201
204
 
202
205
  updateOptions(options: Partial<JetstreamSubscriptionOptions>): void {
206
+ const previousCursor = this.#cursor;
207
+
203
208
  this.#options = { ...this.#options, ...options };
204
209
  if (options.cursor !== undefined) {
205
210
  this.#cursor = options.cursor;
206
211
  }
207
212
 
208
213
  if (this.#ws !== undefined) {
209
- const isOptionsUpdate = Object.keys(options).every((key) => {
210
- return key === 'wantedCollections' || key === 'wantedDids';
214
+ const cursorChanged = this.#cursor !== previousCursor;
215
+ const filtersChanged = 'wantedCollections' in options || 'wantedDids' in options;
216
+ const otherKeys = Object.keys(options).some((key) => {
217
+ return key !== 'wantedCollections' && key !== 'wantedDids' && key !== 'cursor';
211
218
  });
212
219
 
213
- if (isOptionsUpdate) {
214
- this.#sendOptionsUpdate();
215
- } else {
220
+ if (cursorChanged || otherKeys) {
216
221
  this.#destroy();
217
222
  this.#create();
223
+ } else if (filtersChanged) {
224
+ this.#sendOptionsUpdate();
218
225
  }
219
226
  }
220
227
  }
package/lib/typedefs.ts CHANGED
@@ -1,98 +1,131 @@
1
- import * as v from '@badrap/valita';
2
-
3
- import { isCid, isDatetime, isDid, isHandle, isNsid, isRecordKey, isTid } from '@atcute/lexicons/syntax';
4
-
5
- import type * as t from './types.js';
6
-
7
- const cidString = v.string().assert(isCid, `must be a cid`);
8
- const datetimeString = v.string().assert(isDatetime, `must be a datetime`);
9
- const didString = v.string().assert(isDid, `must be a did`);
10
- const handleString = v.string().assert(isHandle, `must be a handle`);
11
- const nsidString = v.string().assert(isNsid, `must be an nsid`);
12
- const rkeyString = v.string().assert(isRecordKey, `must be a rkey`);
13
- const tidString = v.string().assert(isTid, `must be a tid`);
14
-
15
- const integer = v
16
- .number()
17
- .assert((input) => input >= 0 && Number.isSafeInteger(input), `must be a nonnegative integer`);
18
-
19
- const baseCommit = v.object({
1
+ import {
2
+ isCid,
3
+ isDatetime,
4
+ isDid,
5
+ isHandle,
6
+ isNsid,
7
+ isRecordKey,
8
+ isTid,
9
+ type Cid,
10
+ type Datetime,
11
+ type Did,
12
+ type Handle,
13
+ type Nsid,
14
+ type RecordKey,
15
+ type Tid,
16
+ } from '@atcute/lexicons/syntax';
17
+
18
+ import * as v from 'valibot';
19
+
20
+ const cidString = v.custom<Cid>(isCid, `must be a cid`);
21
+ const datetimeString = v.custom<Datetime>(isDatetime, `must be a datetime`);
22
+ const didString = v.custom<Did>(isDid, `must be a did`);
23
+ const handleString = v.custom<Handle>(isHandle, `must be a handle`);
24
+ const nsidString = v.custom<Nsid>(isNsid, `must be an nsid`);
25
+ const rkeyString = v.custom<RecordKey>(isRecordKey, `must be a rkey`);
26
+ const tidString = v.custom<Tid>(isTid, `must be a tid`);
27
+
28
+ const integer = v.pipe(v.number(), v.safeInteger(), v.minValue(0));
29
+
30
+ const baseCommitEntries = {
20
31
  rev: tidString,
21
32
  collection: nsidString,
22
33
  rkey: rkeyString,
23
- });
34
+ };
24
35
 
25
- export const createCommitSchema: v.Type<t.CreateCommit> = baseCommit.extend({
36
+ export const createCommitSchema = v.looseObject({
37
+ ...baseCommitEntries,
26
38
  operation: v.literal('create'),
27
39
  cid: cidString,
28
- record: v.record(v.unknown()),
40
+ record: v.record(v.string(), v.unknown()),
29
41
  });
30
42
 
31
- export const updateCommitSchema: v.Type<t.UpdateCommit> = baseCommit.extend({
43
+ export const updateCommitSchema = v.looseObject({
44
+ ...baseCommitEntries,
32
45
  operation: v.literal('update'),
33
46
  cid: cidString,
34
- record: v.record(v.unknown()),
47
+ record: v.record(v.string(), v.unknown()),
35
48
  });
36
49
 
37
- export const deleteCommitSchema: v.Type<t.DeleteCommit> = baseCommit.extend({
50
+ export const deleteCommitSchema = v.looseObject({
51
+ ...baseCommitEntries,
38
52
  operation: v.literal('delete'),
39
53
  });
40
54
 
41
- export const commitOperationSchema: v.Type<t.CommitOperation> = v.union(
55
+ export const commitOperationSchema = v.variant('operation', [
42
56
  createCommitSchema,
43
57
  updateCommitSchema,
44
58
  deleteCommitSchema,
45
- );
59
+ ]);
46
60
 
47
- const baseEvent = v.object({
61
+ const baseEventEntries = {
48
62
  did: didString,
49
63
  time_us: integer,
50
- });
64
+ };
51
65
 
52
- export const commitEventSchema: v.Type<t.CommitEvent> = baseEvent.extend({
66
+ export const commitEventSchema = v.looseObject({
67
+ ...baseEventEntries,
53
68
  kind: v.literal('commit'),
54
69
  commit: commitOperationSchema,
55
70
  });
56
71
 
57
- export const identityDataSchema: v.Type<t.IdentityData> = v.object({
72
+ export const identityDataSchema = v.looseObject({
58
73
  did: didString,
59
74
  handle: handleString,
60
75
  seq: integer,
61
76
  time: datetimeString,
62
77
  });
63
78
 
64
- export const identityEventSchema: v.Type<t.IdentityEvent> = baseEvent.extend({
79
+ export const identityEventSchema = v.looseObject({
80
+ ...baseEventEntries,
65
81
  kind: v.literal('identity'),
66
82
  identity: identityDataSchema,
67
83
  });
68
84
 
69
- export const accountDataSchema: v.Type<t.AccountData> = v.object({
85
+ export const accountDataSchema = v.looseObject({
70
86
  did: didString,
71
87
  active: v.boolean(),
72
88
  seq: integer,
73
89
  time: datetimeString,
74
90
  });
75
91
 
76
- export const accountEventSchema: v.Type<t.AccountEvent> = baseEvent.extend({
92
+ export const accountEventSchema = v.looseObject({
93
+ ...baseEventEntries,
77
94
  kind: v.literal('account'),
78
95
  account: accountDataSchema,
79
96
  });
80
97
 
81
- export const jetstreamEventSchema: v.Type<t.JetstreamEvent> = v.union(
98
+ export const jetstreamEventSchema = v.variant('kind', [
82
99
  commitEventSchema,
83
100
  identityEventSchema,
84
101
  accountEventSchema,
85
- );
102
+ ]);
86
103
 
87
- export const optionsUpdatePayloadSchema: v.Type<t.OptionsUpdatePayload> = v.object({
88
- wantedCollections: v.array(v.string()).optional(),
89
- wantedDids: v.array(didString).optional(),
90
- maxMessageSizeBytes: integer.optional(),
104
+ export const optionsUpdatePayloadSchema = v.looseObject({
105
+ wantedCollections: v.optional(v.array(v.string())),
106
+ wantedDids: v.optional(v.array(didString)),
107
+ maxMessageSizeBytes: v.optional(integer),
91
108
  });
92
109
 
93
- export const optionsUpdateProcedureSchema: v.Type<t.OptionsUpdateProcedure> = v.object({
110
+ export const optionsUpdateProcedureSchema = v.looseObject({
94
111
  type: v.literal('options_update'),
95
112
  payload: optionsUpdatePayloadSchema,
96
113
  });
97
114
 
98
- export const jetstreamProcedureSchema: v.Type<t.JetstreamProcedure> = v.union(optionsUpdateProcedureSchema);
115
+ export const jetstreamProcedureSchema = v.variant('type', [optionsUpdateProcedureSchema]);
116
+
117
+ export type CreateCommit = v.InferOutput<typeof createCommitSchema>;
118
+ export type UpdateCommit = v.InferOutput<typeof updateCommitSchema>;
119
+ export type DeleteCommit = v.InferOutput<typeof deleteCommitSchema>;
120
+ export type CommitOperation = v.InferOutput<typeof commitOperationSchema>;
121
+
122
+ export type CommitEvent = v.InferOutput<typeof commitEventSchema>;
123
+ export type IdentityData = v.InferOutput<typeof identityDataSchema>;
124
+ export type IdentityEvent = v.InferOutput<typeof identityEventSchema>;
125
+ export type AccountData = v.InferOutput<typeof accountDataSchema>;
126
+ export type AccountEvent = v.InferOutput<typeof accountEventSchema>;
127
+ export type JetstreamEvent = v.InferOutput<typeof jetstreamEventSchema>;
128
+
129
+ export type OptionsUpdatePayload = v.InferOutput<typeof optionsUpdatePayloadSchema>;
130
+ export type OptionsUpdateProcedure = v.InferOutput<typeof optionsUpdateProcedureSchema>;
131
+ export type JetstreamProcedure = v.InferOutput<typeof jetstreamProcedureSchema>;