@atproto/lexicon 0.3.1 → 0.3.2
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/CHANGELOG.md +7 -0
- package/LICENSE.txt +1 -1
- package/dist/blob-refs.d.ts +3 -3
- package/dist/index.js.map +2 -2
- package/dist/lexicons.d.ts +3 -1
- package/dist/serialize.d.ts +2 -2
- package/dist/types.d.ts +425 -425
- package/package.json +2 -2
- package/src/lexicons.ts +13 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/lexicon",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "atproto Lexicon schema language library",
|
|
6
6
|
"keywords": [
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"multiformats": "^9.9.0",
|
|
20
20
|
"zod": "^3.21.4",
|
|
21
21
|
"@atproto/common-web": "^0.2.3",
|
|
22
|
-
"@atproto/syntax": "^0.
|
|
22
|
+
"@atproto/syntax": "^0.2.0"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"test": "jest",
|
package/src/lexicons.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
LexiconDoc,
|
|
3
3
|
LexRecord,
|
|
4
|
-
LexXrpcProcedure,
|
|
5
|
-
LexXrpcQuery,
|
|
6
4
|
LexUserType,
|
|
7
5
|
LexiconDefNotFoundError,
|
|
8
6
|
InvalidLexiconError,
|
|
@@ -10,7 +8,6 @@ import {
|
|
|
10
8
|
ValidationError,
|
|
11
9
|
isObj,
|
|
12
10
|
hasProp,
|
|
13
|
-
LexXrpcSubscription,
|
|
14
11
|
} from './types'
|
|
15
12
|
import {
|
|
16
13
|
assertValidRecord,
|
|
@@ -91,7 +88,14 @@ export class Lexicons {
|
|
|
91
88
|
/**
|
|
92
89
|
* Get a def, throw if not found. Throws on not found.
|
|
93
90
|
*/
|
|
94
|
-
getDefOrThrow
|
|
91
|
+
getDefOrThrow<T extends LexUserType['type'] = LexUserType['type']>(
|
|
92
|
+
uri: string,
|
|
93
|
+
types?: readonly T[],
|
|
94
|
+
): Extract<LexUserType, { type: T }>
|
|
95
|
+
getDefOrThrow(
|
|
96
|
+
uri: string,
|
|
97
|
+
types?: readonly LexUserType['type'][],
|
|
98
|
+
): LexUserType {
|
|
95
99
|
const def = this.getDef(uri)
|
|
96
100
|
if (!def) {
|
|
97
101
|
throw new LexiconDefNotFoundError(`Lexicon not found: ${uri}`)
|
|
@@ -118,7 +122,7 @@ export class Lexicons {
|
|
|
118
122
|
} else if (def.type === 'object') {
|
|
119
123
|
return ComplexValidators.object(this, 'Object', def, value)
|
|
120
124
|
} else {
|
|
121
|
-
//
|
|
125
|
+
// shouldn't happen
|
|
122
126
|
throw new InvalidLexiconError('Definition must be a record or object')
|
|
123
127
|
}
|
|
124
128
|
}
|
|
@@ -154,11 +158,7 @@ export class Lexicons {
|
|
|
154
158
|
'procedure',
|
|
155
159
|
'subscription',
|
|
156
160
|
])
|
|
157
|
-
return assertValidXrpcParams(
|
|
158
|
-
this,
|
|
159
|
-
def as LexXrpcProcedure | LexXrpcQuery | LexXrpcSubscription,
|
|
160
|
-
value,
|
|
161
|
-
)
|
|
161
|
+
return assertValidXrpcParams(this, def, value)
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
/**
|
|
@@ -167,7 +167,7 @@ export class Lexicons {
|
|
|
167
167
|
assertValidXrpcInput(lexUri: string, value: unknown) {
|
|
168
168
|
lexUri = toLexUri(lexUri)
|
|
169
169
|
const def = this.getDefOrThrow(lexUri, ['procedure'])
|
|
170
|
-
return assertValidXrpcInput(this, def
|
|
170
|
+
return assertValidXrpcInput(this, def, value)
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
/**
|
|
@@ -176,11 +176,7 @@ export class Lexicons {
|
|
|
176
176
|
assertValidXrpcOutput(lexUri: string, value: unknown) {
|
|
177
177
|
lexUri = toLexUri(lexUri)
|
|
178
178
|
const def = this.getDefOrThrow(lexUri, ['query', 'procedure'])
|
|
179
|
-
return assertValidXrpcOutput(
|
|
180
|
-
this,
|
|
181
|
-
def as LexXrpcProcedure | LexXrpcQuery,
|
|
182
|
-
value,
|
|
183
|
-
)
|
|
179
|
+
return assertValidXrpcOutput(this, def, value)
|
|
184
180
|
}
|
|
185
181
|
|
|
186
182
|
/**
|
|
@@ -189,7 +185,7 @@ export class Lexicons {
|
|
|
189
185
|
assertValidXrpcMessage<T = unknown>(lexUri: string, value: unknown): T {
|
|
190
186
|
lexUri = toLexUri(lexUri)
|
|
191
187
|
const def = this.getDefOrThrow(lexUri, ['subscription'])
|
|
192
|
-
return assertValidXrpcMessage(this, def
|
|
188
|
+
return assertValidXrpcMessage(this, def, value) as T
|
|
193
189
|
}
|
|
194
190
|
|
|
195
191
|
/**
|