@atproto/lex-schema 0.0.20 → 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/CHANGELOG.md +18 -0
- package/dist/core/$type.js +2 -6
- package/dist/core/$type.js.map +1 -1
- package/dist/core/record-key.js +4 -8
- package/dist/core/record-key.js.map +1 -1
- package/dist/core/result.js +6 -14
- package/dist/core/result.js.map +1 -1
- package/dist/core/schema.js +16 -20
- package/dist/core/schema.js.map +1 -1
- package/dist/core/standard-schema.js +5 -10
- package/dist/core/standard-schema.js.map +1 -1
- package/dist/core/string-format.d.ts.map +1 -1
- package/dist/core/string-format.js +37 -61
- package/dist/core/string-format.js.map +1 -1
- package/dist/core/types.js +1 -2
- package/dist/core/validation-error.js +14 -25
- package/dist/core/validation-error.js.map +1 -1
- package/dist/core/validation-issue.js +12 -40
- package/dist/core/validation-issue.js.map +1 -1
- package/dist/core/validator.js +19 -28
- package/dist/core/validator.js.map +1 -1
- package/dist/core.js +9 -12
- package/dist/core.js.map +1 -1
- package/dist/external.js +3 -6
- package/dist/external.js.map +1 -1
- package/dist/helpers.js +5 -9
- package/dist/helpers.js.map +1 -1
- package/dist/index.js +3 -7
- package/dist/index.js.map +1 -1
- package/dist/schema/array.js +5 -11
- package/dist/schema/array.js.map +1 -1
- package/dist/schema/blob.js +10 -17
- package/dist/schema/blob.js.map +1 -1
- package/dist/schema/boolean.js +8 -9
- package/dist/schema/boolean.js.map +1 -1
- package/dist/schema/bytes.js +7 -12
- package/dist/schema/bytes.js.map +1 -1
- package/dist/schema/cid.js +7 -12
- package/dist/schema/cid.js.map +1 -1
- package/dist/schema/custom.js +5 -13
- package/dist/schema/custom.js.map +1 -1
- package/dist/schema/dict.js +6 -13
- package/dist/schema/dict.js.map +1 -1
- package/dist/schema/discriminated-union.js +10 -18
- package/dist/schema/discriminated-union.js.map +1 -1
- package/dist/schema/enum.js +6 -11
- package/dist/schema/enum.js.map +1 -1
- package/dist/schema/integer.js +5 -10
- package/dist/schema/integer.js.map +1 -1
- package/dist/schema/intersection.js +4 -11
- package/dist/schema/intersection.js.map +1 -1
- package/dist/schema/lex-map.js +13 -14
- package/dist/schema/lex-map.js.map +1 -1
- package/dist/schema/lex-value.js +11 -12
- package/dist/schema/lex-value.js.map +1 -1
- package/dist/schema/literal.js +4 -10
- package/dist/schema/literal.js.map +1 -1
- package/dist/schema/never.js +8 -9
- package/dist/schema/never.js.map +1 -1
- package/dist/schema/null.js +9 -10
- package/dist/schema/null.js.map +1 -1
- package/dist/schema/nullable.js +5 -10
- package/dist/schema/nullable.js.map +1 -1
- package/dist/schema/object.js +8 -14
- package/dist/schema/object.js.map +1 -1
- package/dist/schema/optional.js +5 -10
- package/dist/schema/optional.js.map +1 -1
- package/dist/schema/params.js +39 -44
- package/dist/schema/params.js.map +1 -1
- package/dist/schema/payload.js +5 -13
- package/dist/schema/payload.js.map +1 -1
- package/dist/schema/permission-set.js +2 -10
- package/dist/schema/permission-set.js.map +1 -1
- package/dist/schema/permission.js +2 -9
- package/dist/schema/permission.js.map +1 -1
- package/dist/schema/procedure.js +3 -13
- package/dist/schema/procedure.js.map +1 -1
- package/dist/schema/query.js +3 -12
- package/dist/schema/query.js.map +1 -1
- package/dist/schema/record.js +15 -24
- package/dist/schema/record.js.map +1 -1
- package/dist/schema/ref.js +4 -9
- package/dist/schema/ref.js.map +1 -1
- package/dist/schema/refine.js +3 -6
- package/dist/schema/refine.js.map +1 -1
- package/dist/schema/regexp.js +4 -11
- package/dist/schema/regexp.js.map +1 -1
- package/dist/schema/string.js +15 -26
- package/dist/schema/string.js.map +1 -1
- package/dist/schema/subscription.js +3 -12
- package/dist/schema/subscription.js.map +1 -1
- package/dist/schema/token.js +5 -11
- package/dist/schema/token.js.map +1 -1
- package/dist/schema/typed-object.js +11 -18
- package/dist/schema/typed-object.js.map +1 -1
- package/dist/schema/typed-ref.js +4 -9
- package/dist/schema/typed-ref.js.map +1 -1
- package/dist/schema/typed-union.js +8 -15
- package/dist/schema/typed-union.js.map +1 -1
- package/dist/schema/union.js +5 -11
- package/dist/schema/union.js.map +1 -1
- package/dist/schema/unknown.js +8 -9
- package/dist/schema/unknown.js.map +1 -1
- package/dist/schema/with-default.js +4 -11
- package/dist/schema/with-default.js.map +1 -1
- package/dist/schema.js +38 -41
- package/dist/schema.js.map +1 -1
- package/dist/util/array-agg.js +1 -4
- package/dist/util/array-agg.js.map +1 -1
- package/dist/util/assertion-util.js +1 -2
- package/dist/util/if-any.js +1 -2
- package/dist/util/lazy-property.js +1 -4
- package/dist/util/lazy-property.js.map +1 -1
- package/dist/util/memoize.js +2 -6
- package/dist/util/memoize.js.map +1 -1
- package/package.json +7 -8
- package/src/core/string-format.ts +2 -1
- package/src/helpers.test.ts +52 -52
- package/src/schema/record.test.ts +2 -2
- package/src/schema/ref.test.ts +1 -1
- package/src/schema/string.test.ts +6 -6
- package/src/schema/subscription.test.ts +4 -4
- package/src/schema/typed-object.test.ts +2 -2
package/dist/util/memoize.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.memoizedOptions = memoizedOptions;
|
|
4
|
-
exports.memoizedTransformer = memoizedTransformer;
|
|
5
1
|
/*@__NO_SIDE_EFFECTS__*/
|
|
6
|
-
function memoizedOptions(fn) {
|
|
2
|
+
export function memoizedOptions(fn) {
|
|
7
3
|
let cache = null;
|
|
8
4
|
return function cached(...args) {
|
|
9
5
|
// Not using the cache if there are args
|
|
@@ -19,7 +15,7 @@ function memoizedOptions(fn) {
|
|
|
19
15
|
};
|
|
20
16
|
}
|
|
21
17
|
/*@__NO_SIDE_EFFECTS__*/
|
|
22
|
-
function memoizedTransformer(fn) {
|
|
18
|
+
export function memoizedTransformer(fn) {
|
|
23
19
|
let cache;
|
|
24
20
|
return function cached(key, ...args) {
|
|
25
21
|
if (args.length > 0)
|
package/dist/util/memoize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/util/memoize.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/util/memoize.ts"],"names":[],"mappings":"AAAA,wBAAwB;AACxB,MAAM,UAAU,eAAe,CAAoC,EAAK;IACtE,IAAI,KAAK,GAAoC,IAAI,CAAA;IAEjD,OAAO,SAAS,MAAM,CAAC,GAAG,IAAW;QACnC,wCAAwC;QACxC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpB,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,CAAA;QACpB,CAAC;QAED,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,OAAO,KAAK,CAAC,KAAK,CAAA;QACpB,CAAC;QAED,MAAM,KAAK,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAA;QACzB,KAAK,GAAG,EAAE,KAAK,EAAE,CAAA;QACjB,OAAO,KAAK,CAAA;IACd,CAAM,CAAA;AACR,CAAC;AAED,wBAAwB;AACxB,MAAM,UAAU,mBAAmB,CAEjC,EAAK;IACL,IAAI,KAAqC,CAAA;IAEzC,OAAO,SAAS,MAAM,CAAC,GAAQ,EAAE,GAAG,IAAW;QAC7C,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;QAE5C,KAAK,KAAK,IAAI,OAAO,EAAE,CAAA;QACvB,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC7B,IAAI,MAAM;YAAE,OAAO,MAAM,CAAA;QACzB,MAAM,MAAM,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,CAAkB,CAAA;QAChD,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QACtB,OAAO,MAAM,CAAA;IACf,CAAM,CAAA;AACR,CAAC","sourcesContent":["/*@__NO_SIDE_EFFECTS__*/\nexport function memoizedOptions<F extends (...args: any[]) => any>(fn: F): F {\n let cache: null | { value: ReturnType<F> } = null\n\n return function cached(...args: any[]): ReturnType<F> {\n // Not using the cache if there are args\n if (args.length > 0) {\n return fn(...args)\n }\n\n if (cache != null) {\n return cache.value\n }\n\n const value = fn(...args)\n cache = { value }\n return value\n } as F\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nexport function memoizedTransformer<\n F extends (key: any, ...args: any[]) => unknown,\n>(fn: F): F {\n let cache: WeakMap<object, ReturnType<F>>\n\n return function cached(key: any, ...args: any[]): any {\n if (args.length > 0) return fn(key, ...args)\n\n cache ??= new WeakMap()\n const cached = cache.get(key)\n if (cached) return cached\n const result = fn(key, ...args) as ReturnType<F>\n cache.set(key, result)\n return result\n } as F\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/lex-schema",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": ">=22"
|
|
6
|
+
},
|
|
4
7
|
"license": "MIT",
|
|
5
8
|
"description": "Lexicon schema system for AT Lexicons",
|
|
6
9
|
"keywords": [
|
|
@@ -23,14 +26,10 @@
|
|
|
23
26
|
"./CHANGELOG.md"
|
|
24
27
|
],
|
|
25
28
|
"sideEffects": false,
|
|
26
|
-
"type": "
|
|
27
|
-
"main": "./dist/index.js",
|
|
28
|
-
"types": "./dist/index.d.ts",
|
|
29
|
+
"type": "module",
|
|
29
30
|
"exports": {
|
|
30
31
|
".": {
|
|
31
32
|
"types": "./dist/index.d.ts",
|
|
32
|
-
"browser": "./dist/index.js",
|
|
33
|
-
"import": "./dist/index.js",
|
|
34
33
|
"default": "./dist/index.js"
|
|
35
34
|
}
|
|
36
35
|
},
|
|
@@ -38,8 +37,8 @@
|
|
|
38
37
|
"@standard-schema/spec": "^1.1.0",
|
|
39
38
|
"iso-datestring-validator": "^2.2.2",
|
|
40
39
|
"tslib": "^2.8.1",
|
|
41
|
-
"@atproto/
|
|
42
|
-
"@atproto/
|
|
40
|
+
"@atproto/lex-data": "^0.1.0",
|
|
41
|
+
"@atproto/syntax": "^0.6.0"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
44
|
"vitest": "^4.0.16"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import isoDatestringValidator from 'iso-datestring-validator'
|
|
2
|
+
const { isValidISODateString } = isoDatestringValidator
|
|
2
3
|
import { validateCidString } from '@atproto/lex-data'
|
|
3
4
|
import {
|
|
4
5
|
AtIdentifierString,
|
package/src/helpers.test.ts
CHANGED
|
@@ -11,7 +11,7 @@ const binaryValue = new BinaryValue()
|
|
|
11
11
|
describe('InferMethodParams', () => {
|
|
12
12
|
describe('query', () => {
|
|
13
13
|
test('infers parameter types', () => {
|
|
14
|
-
const
|
|
14
|
+
const _query = l.query(
|
|
15
15
|
'com.example.query',
|
|
16
16
|
l.params({
|
|
17
17
|
feed: l.string({ format: 'at-uri' }),
|
|
@@ -20,7 +20,7 @@ describe('InferMethodParams', () => {
|
|
|
20
20
|
l.payload('application/json', undefined),
|
|
21
21
|
)
|
|
22
22
|
|
|
23
|
-
type Params = l.InferMethodParams<typeof
|
|
23
|
+
type Params = l.InferMethodParams<typeof _query>
|
|
24
24
|
|
|
25
25
|
expectType<Params>({
|
|
26
26
|
feed: 'at://did:plc:abc123/app.bsky.feed.post/xyz',
|
|
@@ -35,14 +35,14 @@ describe('InferMethodParams', () => {
|
|
|
35
35
|
|
|
36
36
|
describe('procedure', () => {
|
|
37
37
|
test('infers parameter types', () => {
|
|
38
|
-
const
|
|
38
|
+
const _procedure = l.procedure(
|
|
39
39
|
'com.example.list',
|
|
40
40
|
l.params({ limit: l.string() }),
|
|
41
41
|
l.payload(),
|
|
42
42
|
l.payload(),
|
|
43
43
|
)
|
|
44
44
|
|
|
45
|
-
type Params = l.InferMethodParams<typeof
|
|
45
|
+
type Params = l.InferMethodParams<typeof _procedure>
|
|
46
46
|
|
|
47
47
|
expectType<Params>({ limit: '10' })
|
|
48
48
|
// @ts-expect-error
|
|
@@ -56,7 +56,7 @@ describe('InferMethodParams', () => {
|
|
|
56
56
|
|
|
57
57
|
describe('subscription', () => {
|
|
58
58
|
test('infers parameter types', () => {
|
|
59
|
-
const
|
|
59
|
+
const _subscription = l.subscription(
|
|
60
60
|
'com.example.subscribe',
|
|
61
61
|
l.params({
|
|
62
62
|
cursor: l.optional(l.integer()),
|
|
@@ -64,7 +64,7 @@ describe('InferMethodParams', () => {
|
|
|
64
64
|
l.lexMap(),
|
|
65
65
|
)
|
|
66
66
|
|
|
67
|
-
type Params = l.InferMethodParams<typeof
|
|
67
|
+
type Params = l.InferMethodParams<typeof _subscription>
|
|
68
68
|
|
|
69
69
|
expectType<Params>({ cursor: 100 })
|
|
70
70
|
// @ts-expect-error
|
|
@@ -78,14 +78,14 @@ describe('InferMethodParams', () => {
|
|
|
78
78
|
describe('InferMethodInput', () => {
|
|
79
79
|
describe('procedure', () => {
|
|
80
80
|
test('with payload schema', () => {
|
|
81
|
-
const
|
|
81
|
+
const _procedure = l.procedure(
|
|
82
82
|
'com.example.create',
|
|
83
83
|
l.params(),
|
|
84
84
|
l.jsonPayload({ text: l.string() }),
|
|
85
85
|
l.payload(),
|
|
86
86
|
)
|
|
87
87
|
|
|
88
|
-
type Input = l.InferMethodInput<typeof
|
|
88
|
+
type Input = l.InferMethodInput<typeof _procedure, BinaryValue>
|
|
89
89
|
|
|
90
90
|
expectType<Input>({ encoding: 'application/json', body: { text: 'hi' } })
|
|
91
91
|
// @ts-expect-error
|
|
@@ -101,14 +101,14 @@ describe('InferMethodInput', () => {
|
|
|
101
101
|
})
|
|
102
102
|
|
|
103
103
|
test('without payload schema', () => {
|
|
104
|
-
const
|
|
104
|
+
const _procedure = l.procedure(
|
|
105
105
|
'com.example.create',
|
|
106
106
|
l.params(),
|
|
107
107
|
l.payload('*/*', undefined),
|
|
108
108
|
l.payload(),
|
|
109
109
|
)
|
|
110
110
|
|
|
111
|
-
type Input = l.InferMethodInput<typeof
|
|
111
|
+
type Input = l.InferMethodInput<typeof _procedure, BinaryValue>
|
|
112
112
|
|
|
113
113
|
expectType<Input>({ encoding: 'image/png', body: binaryValue })
|
|
114
114
|
// @ts-expect-error
|
|
@@ -124,14 +124,14 @@ describe('InferMethodInput', () => {
|
|
|
124
124
|
describe('InferMethodInputBody', () => {
|
|
125
125
|
describe('procedure', () => {
|
|
126
126
|
test('with payload schema', () => {
|
|
127
|
-
const
|
|
127
|
+
const _procedure = l.procedure(
|
|
128
128
|
'com.example.create',
|
|
129
129
|
l.params(),
|
|
130
130
|
l.jsonPayload({ text: l.string() }),
|
|
131
131
|
l.payload(),
|
|
132
132
|
)
|
|
133
133
|
|
|
134
|
-
type InputBody = l.InferMethodInputBody<typeof
|
|
134
|
+
type InputBody = l.InferMethodInputBody<typeof _procedure, BinaryValue>
|
|
135
135
|
|
|
136
136
|
expectType<InputBody>({ text: 'hello' })
|
|
137
137
|
// @ts-expect-error
|
|
@@ -141,14 +141,14 @@ describe('InferMethodInputBody', () => {
|
|
|
141
141
|
})
|
|
142
142
|
|
|
143
143
|
test('without payload schema', () => {
|
|
144
|
-
const
|
|
144
|
+
const _procedure = l.procedure(
|
|
145
145
|
'com.example.upload',
|
|
146
146
|
l.params(),
|
|
147
147
|
l.payload('*/*', undefined),
|
|
148
148
|
l.payload(),
|
|
149
149
|
)
|
|
150
150
|
|
|
151
|
-
type InputBody = l.InferMethodInputBody<typeof
|
|
151
|
+
type InputBody = l.InferMethodInputBody<typeof _procedure, BinaryValue>
|
|
152
152
|
|
|
153
153
|
expectType<InputBody>(binaryValue)
|
|
154
154
|
// @ts-expect-error
|
|
@@ -162,14 +162,14 @@ describe('InferMethodInputBody', () => {
|
|
|
162
162
|
describe('InferMethodInputEncoding', () => {
|
|
163
163
|
describe('procedure', () => {
|
|
164
164
|
test('with payload schema', () => {
|
|
165
|
-
const
|
|
165
|
+
const _procedure = l.procedure(
|
|
166
166
|
'com.example.create',
|
|
167
167
|
l.params(),
|
|
168
168
|
l.jsonPayload({ text: l.string() }),
|
|
169
169
|
l.payload(),
|
|
170
170
|
)
|
|
171
171
|
|
|
172
|
-
type InputEncoding = l.InferMethodInputEncoding<typeof
|
|
172
|
+
type InputEncoding = l.InferMethodInputEncoding<typeof _procedure>
|
|
173
173
|
|
|
174
174
|
expectType<InputEncoding>('application/json')
|
|
175
175
|
// @ts-expect-error
|
|
@@ -179,14 +179,14 @@ describe('InferMethodInputEncoding', () => {
|
|
|
179
179
|
})
|
|
180
180
|
|
|
181
181
|
test('without payload schema', () => {
|
|
182
|
-
const
|
|
182
|
+
const _procedure = l.procedure(
|
|
183
183
|
'com.example.upload',
|
|
184
184
|
l.params(),
|
|
185
185
|
l.payload('*/*', undefined),
|
|
186
186
|
l.payload(),
|
|
187
187
|
)
|
|
188
188
|
|
|
189
|
-
type InputEncoding = l.InferMethodInputEncoding<typeof
|
|
189
|
+
type InputEncoding = l.InferMethodInputEncoding<typeof _procedure>
|
|
190
190
|
|
|
191
191
|
expectType<InputEncoding>('image/png')
|
|
192
192
|
expectType<InputEncoding>('application/octet-stream')
|
|
@@ -199,7 +199,7 @@ describe('InferMethodInputEncoding', () => {
|
|
|
199
199
|
describe('InferMethodOutput', () => {
|
|
200
200
|
describe('query', () => {
|
|
201
201
|
test('generic output', () => {
|
|
202
|
-
const
|
|
202
|
+
const _query = l.query(
|
|
203
203
|
'com.example.query',
|
|
204
204
|
l.params(),
|
|
205
205
|
l.payload(),
|
|
@@ -207,7 +207,7 @@ describe('InferMethodOutput', () => {
|
|
|
207
207
|
const unknownValue = {} as unknown
|
|
208
208
|
const lexValue = {} as l.LexValue
|
|
209
209
|
|
|
210
|
-
type Output = l.InferMethodOutput<typeof
|
|
210
|
+
type Output = l.InferMethodOutput<typeof _query, BinaryValue>
|
|
211
211
|
|
|
212
212
|
expectType<Output>(undefined)
|
|
213
213
|
expectType<Output>({ body: binaryValue, encoding: 'text/plain' })
|
|
@@ -230,13 +230,13 @@ describe('InferMethodOutput', () => {
|
|
|
230
230
|
})
|
|
231
231
|
|
|
232
232
|
test('with payload schema', () => {
|
|
233
|
-
const
|
|
233
|
+
const _query = l.query(
|
|
234
234
|
'com.example.query',
|
|
235
235
|
l.params(),
|
|
236
236
|
l.jsonPayload({ items: l.array(l.string()) }),
|
|
237
237
|
)
|
|
238
238
|
|
|
239
|
-
type Output = l.InferMethodOutput<typeof
|
|
239
|
+
type Output = l.InferMethodOutput<typeof _query, BinaryValue>
|
|
240
240
|
|
|
241
241
|
expectType<Output>({ encoding: 'application/json', body: { items: [] } })
|
|
242
242
|
// @ts-expect-error
|
|
@@ -246,13 +246,13 @@ describe('InferMethodOutput', () => {
|
|
|
246
246
|
})
|
|
247
247
|
|
|
248
248
|
test('without payload schema', () => {
|
|
249
|
-
const
|
|
249
|
+
const _query = l.query(
|
|
250
250
|
'com.example.query',
|
|
251
251
|
l.params(),
|
|
252
252
|
l.payload('*/*', undefined),
|
|
253
253
|
)
|
|
254
254
|
|
|
255
|
-
type Output = l.InferMethodOutput<typeof
|
|
255
|
+
type Output = l.InferMethodOutput<typeof _query, BinaryValue>
|
|
256
256
|
|
|
257
257
|
expectType<Output>({ encoding: 'image/png', body: binaryValue })
|
|
258
258
|
// @ts-expect-error
|
|
@@ -264,7 +264,7 @@ describe('InferMethodOutput', () => {
|
|
|
264
264
|
|
|
265
265
|
describe('procedure', () => {
|
|
266
266
|
test('generic output', () => {
|
|
267
|
-
const
|
|
267
|
+
const _procedure = l.procedure(
|
|
268
268
|
'com.example.procedure',
|
|
269
269
|
l.params(),
|
|
270
270
|
l.payload(),
|
|
@@ -273,7 +273,7 @@ describe('InferMethodOutput', () => {
|
|
|
273
273
|
const unknownValue = {} as unknown
|
|
274
274
|
const lexValue = {} as l.LexValue
|
|
275
275
|
|
|
276
|
-
type Output = l.InferMethodOutput<typeof
|
|
276
|
+
type Output = l.InferMethodOutput<typeof _procedure, BinaryValue>
|
|
277
277
|
|
|
278
278
|
expectType<Output>(undefined)
|
|
279
279
|
expectType<Output>({ body: binaryValue, encoding: 'text/plain' })
|
|
@@ -297,7 +297,7 @@ describe('InferMethodOutput', () => {
|
|
|
297
297
|
})
|
|
298
298
|
|
|
299
299
|
test('with payload schema', () => {
|
|
300
|
-
const
|
|
300
|
+
const _procedure = l.procedure(
|
|
301
301
|
'com.example.create',
|
|
302
302
|
l.params(),
|
|
303
303
|
l.payload(),
|
|
@@ -308,7 +308,7 @@ describe('InferMethodOutput', () => {
|
|
|
308
308
|
undefined,
|
|
309
309
|
)
|
|
310
310
|
|
|
311
|
-
type Output = l.InferMethodOutput<typeof
|
|
311
|
+
type Output = l.InferMethodOutput<typeof _procedure, BinaryValue>
|
|
312
312
|
|
|
313
313
|
expectType<Output>({
|
|
314
314
|
encoding: 'application/json',
|
|
@@ -323,7 +323,7 @@ describe('InferMethodOutput', () => {
|
|
|
323
323
|
})
|
|
324
324
|
|
|
325
325
|
test('without payload schema', () => {
|
|
326
|
-
const
|
|
326
|
+
const _procedure = l.procedure(
|
|
327
327
|
'com.example.export',
|
|
328
328
|
l.params(),
|
|
329
329
|
l.payload(),
|
|
@@ -331,7 +331,7 @@ describe('InferMethodOutput', () => {
|
|
|
331
331
|
undefined,
|
|
332
332
|
)
|
|
333
333
|
|
|
334
|
-
type Output = l.InferMethodOutput<typeof
|
|
334
|
+
type Output = l.InferMethodOutput<typeof _procedure, BinaryValue>
|
|
335
335
|
|
|
336
336
|
expectType<Output>({
|
|
337
337
|
encoding: 'application/zip',
|
|
@@ -351,14 +351,14 @@ describe('InferMethodOutput', () => {
|
|
|
351
351
|
describe('InferMethodOutputBody', () => {
|
|
352
352
|
describe('query', () => {
|
|
353
353
|
test('generic output', () => {
|
|
354
|
-
const
|
|
354
|
+
const _query = l.query(
|
|
355
355
|
'com.example.query',
|
|
356
356
|
l.params(),
|
|
357
357
|
l.payload(),
|
|
358
358
|
) as unknown as l.Query
|
|
359
359
|
const lexValue = {} as l.LexValue
|
|
360
360
|
|
|
361
|
-
type OutputBody = l.InferMethodOutputBody<typeof
|
|
361
|
+
type OutputBody = l.InferMethodOutputBody<typeof _query, BinaryValue>
|
|
362
362
|
|
|
363
363
|
expectType<OutputBody>(undefined)
|
|
364
364
|
expectType<OutputBody>(binaryValue)
|
|
@@ -372,7 +372,7 @@ describe('InferMethodOutputBody', () => {
|
|
|
372
372
|
})
|
|
373
373
|
|
|
374
374
|
test('with payload schema', () => {
|
|
375
|
-
const
|
|
375
|
+
const _query = l.query(
|
|
376
376
|
'com.example.query',
|
|
377
377
|
l.params(),
|
|
378
378
|
l.payload(
|
|
@@ -384,7 +384,7 @@ describe('InferMethodOutputBody', () => {
|
|
|
384
384
|
),
|
|
385
385
|
)
|
|
386
386
|
|
|
387
|
-
type OutputBody = l.InferMethodOutputBody<typeof
|
|
387
|
+
type OutputBody = l.InferMethodOutputBody<typeof _query, BinaryValue>
|
|
388
388
|
|
|
389
389
|
expectType<OutputBody>({
|
|
390
390
|
cursor: 'abc123',
|
|
@@ -397,13 +397,13 @@ describe('InferMethodOutputBody', () => {
|
|
|
397
397
|
})
|
|
398
398
|
|
|
399
399
|
test('without payload schema', () => {
|
|
400
|
-
const
|
|
400
|
+
const _query = l.query(
|
|
401
401
|
'com.example.query',
|
|
402
402
|
l.params(),
|
|
403
403
|
l.payload('*/*', undefined),
|
|
404
404
|
)
|
|
405
405
|
|
|
406
|
-
type OutputBody = l.InferMethodOutputBody<typeof
|
|
406
|
+
type OutputBody = l.InferMethodOutputBody<typeof _query, BinaryValue>
|
|
407
407
|
|
|
408
408
|
expectType<OutputBody>(binaryValue)
|
|
409
409
|
// @ts-expect-error
|
|
@@ -415,7 +415,7 @@ describe('InferMethodOutputBody', () => {
|
|
|
415
415
|
|
|
416
416
|
describe('procedure', () => {
|
|
417
417
|
test('with payload schema', () => {
|
|
418
|
-
const
|
|
418
|
+
const _procedure = l.procedure(
|
|
419
419
|
'com.example.get',
|
|
420
420
|
l.params(),
|
|
421
421
|
l.payload(),
|
|
@@ -426,7 +426,7 @@ describe('InferMethodOutputBody', () => {
|
|
|
426
426
|
undefined,
|
|
427
427
|
)
|
|
428
428
|
|
|
429
|
-
type OutputBody = l.InferMethodOutputBody<typeof
|
|
429
|
+
type OutputBody = l.InferMethodOutputBody<typeof _procedure, BinaryValue>
|
|
430
430
|
|
|
431
431
|
expectType<OutputBody>({ uri: 'at://did:plc:abc/post/123' })
|
|
432
432
|
// @ts-expect-error
|
|
@@ -436,7 +436,7 @@ describe('InferMethodOutputBody', () => {
|
|
|
436
436
|
})
|
|
437
437
|
|
|
438
438
|
test('without payload schema', () => {
|
|
439
|
-
const
|
|
439
|
+
const _procedure = l.procedure(
|
|
440
440
|
'com.example.export',
|
|
441
441
|
l.params(),
|
|
442
442
|
l.payload(),
|
|
@@ -444,7 +444,7 @@ describe('InferMethodOutputBody', () => {
|
|
|
444
444
|
undefined,
|
|
445
445
|
)
|
|
446
446
|
|
|
447
|
-
type OutputBody = l.InferMethodOutputBody<typeof
|
|
447
|
+
type OutputBody = l.InferMethodOutputBody<typeof _procedure, BinaryValue>
|
|
448
448
|
|
|
449
449
|
expectType<OutputBody>(binaryValue)
|
|
450
450
|
// @ts-expect-error
|
|
@@ -458,13 +458,13 @@ describe('InferMethodOutputBody', () => {
|
|
|
458
458
|
describe('InferMethodOutputEncoding', () => {
|
|
459
459
|
describe('query', () => {
|
|
460
460
|
test('with payload schema', () => {
|
|
461
|
-
const
|
|
461
|
+
const _query = l.query(
|
|
462
462
|
'com.example.query',
|
|
463
463
|
l.params(),
|
|
464
464
|
l.jsonPayload({ data: l.string() }),
|
|
465
465
|
)
|
|
466
466
|
|
|
467
|
-
type OutputEncoding = l.InferMethodOutputEncoding<typeof
|
|
467
|
+
type OutputEncoding = l.InferMethodOutputEncoding<typeof _query>
|
|
468
468
|
|
|
469
469
|
expectType<OutputEncoding>('application/json')
|
|
470
470
|
// @ts-expect-error
|
|
@@ -474,13 +474,13 @@ describe('InferMethodOutputEncoding', () => {
|
|
|
474
474
|
})
|
|
475
475
|
|
|
476
476
|
test('without payload schema', () => {
|
|
477
|
-
const
|
|
477
|
+
const _query = l.query(
|
|
478
478
|
'com.example.query',
|
|
479
479
|
l.params(),
|
|
480
480
|
l.payload('*/*', undefined),
|
|
481
481
|
)
|
|
482
482
|
|
|
483
|
-
type OutputEncoding = l.InferMethodOutputEncoding<typeof
|
|
483
|
+
type OutputEncoding = l.InferMethodOutputEncoding<typeof _query>
|
|
484
484
|
|
|
485
485
|
expectType<OutputEncoding>('image/png')
|
|
486
486
|
expectType<OutputEncoding>('application/octet-stream')
|
|
@@ -491,7 +491,7 @@ describe('InferMethodOutputEncoding', () => {
|
|
|
491
491
|
|
|
492
492
|
describe('procedure', () => {
|
|
493
493
|
test('with payload schema', () => {
|
|
494
|
-
const
|
|
494
|
+
const _procedure = l.procedure(
|
|
495
495
|
'com.example.create',
|
|
496
496
|
l.params(),
|
|
497
497
|
l.payload(),
|
|
@@ -499,7 +499,7 @@ describe('InferMethodOutputEncoding', () => {
|
|
|
499
499
|
undefined,
|
|
500
500
|
)
|
|
501
501
|
|
|
502
|
-
type OutputEncoding = l.InferMethodOutputEncoding<typeof
|
|
502
|
+
type OutputEncoding = l.InferMethodOutputEncoding<typeof _procedure>
|
|
503
503
|
|
|
504
504
|
expectType<OutputEncoding>('application/json')
|
|
505
505
|
// @ts-expect-error
|
|
@@ -509,7 +509,7 @@ describe('InferMethodOutputEncoding', () => {
|
|
|
509
509
|
})
|
|
510
510
|
|
|
511
511
|
test('without payload schema', () => {
|
|
512
|
-
const
|
|
512
|
+
const _procedure = l.procedure(
|
|
513
513
|
'com.example.export',
|
|
514
514
|
l.params(),
|
|
515
515
|
l.payload(),
|
|
@@ -517,7 +517,7 @@ describe('InferMethodOutputEncoding', () => {
|
|
|
517
517
|
undefined,
|
|
518
518
|
)
|
|
519
519
|
|
|
520
|
-
type OutputEncoding = l.InferMethodOutputEncoding<typeof
|
|
520
|
+
type OutputEncoding = l.InferMethodOutputEncoding<typeof _procedure>
|
|
521
521
|
|
|
522
522
|
expectType<OutputEncoding>('application/zip')
|
|
523
523
|
expectType<OutputEncoding>('application/octet-stream')
|
|
@@ -530,7 +530,7 @@ describe('InferMethodOutputEncoding', () => {
|
|
|
530
530
|
describe('InferMethodMessage', () => {
|
|
531
531
|
describe('subscription', () => {
|
|
532
532
|
test('with message schema', () => {
|
|
533
|
-
const
|
|
533
|
+
const _subscription = l.subscription(
|
|
534
534
|
'com.example.subscribe',
|
|
535
535
|
l.params(),
|
|
536
536
|
l.object({
|
|
@@ -539,7 +539,7 @@ describe('InferMethodMessage', () => {
|
|
|
539
539
|
}),
|
|
540
540
|
)
|
|
541
541
|
|
|
542
|
-
type Message = l.InferMethodMessage<typeof
|
|
542
|
+
type Message = l.InferMethodMessage<typeof _subscription>
|
|
543
543
|
|
|
544
544
|
expectType<Message>({ seq: 1, event: 'create' })
|
|
545
545
|
// @ts-expect-error
|
|
@@ -551,13 +551,13 @@ describe('InferMethodMessage', () => {
|
|
|
551
551
|
})
|
|
552
552
|
|
|
553
553
|
test('without message schema', () => {
|
|
554
|
-
const
|
|
554
|
+
const _subscription = l.subscription(
|
|
555
555
|
'com.example.subscribe',
|
|
556
556
|
l.params(),
|
|
557
557
|
l.integer(),
|
|
558
558
|
)
|
|
559
559
|
|
|
560
|
-
type Message = l.InferMethodMessage<typeof
|
|
560
|
+
type Message = l.InferMethodMessage<typeof _subscription>
|
|
561
561
|
|
|
562
562
|
// @ts-expect-error "unknown" is turned into LexValue
|
|
563
563
|
expectType<Message>(undefined)
|
|
@@ -103,10 +103,10 @@ describe('RecordSchema', () => {
|
|
|
103
103
|
it('properly discriminates Unknown$TypeObject', () => {
|
|
104
104
|
function foo(value: Unknown$TypedObject | Schema) {
|
|
105
105
|
if (schema.isTypeOf(value)) {
|
|
106
|
-
value.text
|
|
106
|
+
void value.text
|
|
107
107
|
} else {
|
|
108
108
|
// @ts-expect-error
|
|
109
|
-
value.text
|
|
109
|
+
void value.text
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
|
package/src/schema/ref.test.ts
CHANGED
|
@@ -62,7 +62,7 @@ describe('RefSchema', () => {
|
|
|
62
62
|
const innerSchema = string()
|
|
63
63
|
|
|
64
64
|
// Access schema property to resolve it
|
|
65
|
-
schema.validator
|
|
65
|
+
void schema.validator
|
|
66
66
|
|
|
67
67
|
// Try to access the original getter again (which should throw)
|
|
68
68
|
// This is internal behavior, but we're testing the protection mechanism
|
|
@@ -725,10 +725,10 @@ describe('StringSchema', () => {
|
|
|
725
725
|
})
|
|
726
726
|
|
|
727
727
|
it('properly types knownValues in parameters', () => {
|
|
728
|
-
const
|
|
728
|
+
const _schema = string({
|
|
729
729
|
knownValues: ['active', 'inactive'],
|
|
730
730
|
})
|
|
731
|
-
type SchemaType = Infer<typeof
|
|
731
|
+
type SchemaType = Infer<typeof _schema>
|
|
732
732
|
expectTypeOf<{
|
|
733
733
|
foo: SchemaType
|
|
734
734
|
}>().toMatchObjectType<{
|
|
@@ -752,8 +752,8 @@ describe('StringSchema', () => {
|
|
|
752
752
|
})
|
|
753
753
|
|
|
754
754
|
it('type string<any>() as string', () => {
|
|
755
|
-
const
|
|
756
|
-
type SchemaType = Infer<typeof
|
|
755
|
+
const _schema = string<any>()
|
|
756
|
+
type SchemaType = Infer<typeof _schema>
|
|
757
757
|
expectTypeOf<{
|
|
758
758
|
foo: SchemaType
|
|
759
759
|
}>().toMatchObjectType<{
|
|
@@ -762,8 +762,8 @@ describe('StringSchema', () => {
|
|
|
762
762
|
})
|
|
763
763
|
|
|
764
764
|
it('type string<StringSchemaOptions>({}) as string', () => {
|
|
765
|
-
const
|
|
766
|
-
type SchemaType = Infer<typeof
|
|
765
|
+
const _schema = string<StringSchemaOptions>({})
|
|
766
|
+
type SchemaType = Infer<typeof _schema>
|
|
767
767
|
expectTypeOf<{
|
|
768
768
|
foo: SchemaType
|
|
769
769
|
}>().toMatchObjectType<{
|
|
@@ -245,7 +245,7 @@ describe('Subscription', () => {
|
|
|
245
245
|
|
|
246
246
|
describe('type inference', () => {
|
|
247
247
|
it('InferSubscriptionParameters correctly infers parameter types', () => {
|
|
248
|
-
const
|
|
248
|
+
const _mySub = subscription(
|
|
249
249
|
'com.atproto.sync.subscribeRepos',
|
|
250
250
|
params({
|
|
251
251
|
cursor: optional(integer()),
|
|
@@ -255,7 +255,7 @@ describe('Subscription', () => {
|
|
|
255
255
|
}),
|
|
256
256
|
)
|
|
257
257
|
|
|
258
|
-
type Params = InferSubscriptionParameters<typeof
|
|
258
|
+
type Params = InferSubscriptionParameters<typeof _mySub>
|
|
259
259
|
|
|
260
260
|
expectTypeOf<Params>({
|
|
261
261
|
cursor: 12345,
|
|
@@ -270,9 +270,9 @@ describe('Subscription', () => {
|
|
|
270
270
|
data: string(),
|
|
271
271
|
})
|
|
272
272
|
|
|
273
|
-
const
|
|
273
|
+
const _mySub = subscription(nsid, parameters, message, undefined)
|
|
274
274
|
|
|
275
|
-
type Message = InferSubscriptionMessage<typeof
|
|
275
|
+
type Message = InferSubscriptionMessage<typeof _mySub>
|
|
276
276
|
|
|
277
277
|
expectTypeOf<Message>({
|
|
278
278
|
seq: 12345,
|
|
@@ -210,10 +210,10 @@ describe('TypedObjectSchema', () => {
|
|
|
210
210
|
it('properly discriminates Unknown$TypeObject', () => {
|
|
211
211
|
function foo(value: Unknown$TypedObject | Schema) {
|
|
212
212
|
if (schema.isTypeOf(value)) {
|
|
213
|
-
value.text
|
|
213
|
+
void value.text
|
|
214
214
|
} else {
|
|
215
215
|
// @ts-expect-error
|
|
216
|
-
value.text
|
|
216
|
+
void value.text
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
|