@atproto/lex-schema 0.0.11 → 0.0.13
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 +54 -0
- package/dist/core/$type.d.ts +149 -0
- package/dist/core/$type.d.ts.map +1 -1
- package/dist/core/$type.js +44 -0
- package/dist/core/$type.js.map +1 -1
- package/dist/core/record-key.d.ts +44 -0
- package/dist/core/record-key.d.ts.map +1 -1
- package/dist/core/record-key.js +30 -0
- package/dist/core/record-key.js.map +1 -1
- package/dist/core/result.d.ts +85 -4
- package/dist/core/result.d.ts.map +1 -1
- package/dist/core/result.js +60 -4
- package/dist/core/result.js.map +1 -1
- package/dist/core/schema.d.ts +232 -5
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/schema.js +197 -4
- package/dist/core/schema.js.map +1 -1
- package/dist/core/string-format.d.ts +244 -11
- package/dist/core/string-format.d.ts.map +1 -1
- package/dist/core/string-format.js +150 -0
- package/dist/core/string-format.js.map +1 -1
- package/dist/core/types.d.ts +90 -3
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/core/validation-error.d.ts +60 -0
- package/dist/core/validation-error.d.ts.map +1 -1
- package/dist/core/validation-error.js +60 -0
- package/dist/core/validation-error.js.map +1 -1
- package/dist/core/validation-issue.d.ts +61 -0
- package/dist/core/validation-issue.d.ts.map +1 -1
- package/dist/core/validation-issue.js +54 -1
- package/dist/core/validation-issue.js.map +1 -1
- package/dist/core/validator.d.ts +356 -11
- package/dist/core/validator.d.ts.map +1 -1
- package/dist/core/validator.js +203 -4
- package/dist/core/validator.js.map +1 -1
- package/dist/helpers.d.ts +12 -28
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js.map +1 -1
- package/dist/schema/array.d.ts +46 -0
- package/dist/schema/array.d.ts.map +1 -1
- package/dist/schema/array.js +16 -1
- package/dist/schema/array.js.map +1 -1
- package/dist/schema/blob.d.ts +50 -2
- package/dist/schema/blob.d.ts.map +1 -1
- package/dist/schema/blob.js +44 -2
- package/dist/schema/blob.js.map +1 -1
- package/dist/schema/boolean.d.ts +29 -0
- package/dist/schema/boolean.d.ts.map +1 -1
- package/dist/schema/boolean.js +30 -1
- package/dist/schema/boolean.js.map +1 -1
- package/dist/schema/bytes.d.ts +39 -0
- package/dist/schema/bytes.d.ts.map +1 -1
- package/dist/schema/bytes.js +34 -1
- package/dist/schema/bytes.js.map +1 -1
- package/dist/schema/cid.d.ts +39 -0
- package/dist/schema/cid.d.ts.map +1 -1
- package/dist/schema/cid.js +35 -1
- package/dist/schema/cid.js.map +1 -1
- package/dist/schema/custom.d.ts +67 -1
- package/dist/schema/custom.d.ts.map +1 -1
- package/dist/schema/custom.js +55 -0
- package/dist/schema/custom.js.map +1 -1
- package/dist/schema/dict.d.ts +45 -0
- package/dist/schema/dict.d.ts.map +1 -1
- package/dist/schema/dict.js +46 -1
- package/dist/schema/dict.js.map +1 -1
- package/dist/schema/discriminated-union.d.ts +59 -0
- package/dist/schema/discriminated-union.d.ts.map +1 -1
- package/dist/schema/discriminated-union.js +47 -1
- package/dist/schema/discriminated-union.js.map +1 -1
- package/dist/schema/enum.d.ts +49 -0
- package/dist/schema/enum.d.ts.map +1 -1
- package/dist/schema/enum.js +49 -0
- package/dist/schema/enum.js.map +1 -1
- package/dist/schema/integer.d.ts +43 -0
- package/dist/schema/integer.d.ts.map +1 -1
- package/dist/schema/integer.js +38 -1
- package/dist/schema/integer.js.map +1 -1
- package/dist/schema/intersection.d.ts +55 -0
- package/dist/schema/intersection.d.ts.map +1 -1
- package/dist/schema/intersection.js +50 -0
- package/dist/schema/intersection.js.map +1 -1
- package/dist/schema/lex-map.d.ts +37 -0
- package/dist/schema/lex-map.d.ts.map +1 -0
- package/dist/schema/lex-map.js +60 -0
- package/dist/schema/lex-map.js.map +1 -0
- package/dist/schema/lex-value.d.ts +35 -0
- package/dist/schema/lex-value.d.ts.map +1 -0
- package/dist/schema/lex-value.js +87 -0
- package/dist/schema/lex-value.js.map +1 -0
- package/dist/schema/literal.d.ts +45 -0
- package/dist/schema/literal.d.ts.map +1 -1
- package/dist/schema/literal.js +45 -0
- package/dist/schema/literal.js.map +1 -1
- package/dist/schema/never.d.ts +43 -0
- package/dist/schema/never.d.ts.map +1 -1
- package/dist/schema/never.js +44 -1
- package/dist/schema/never.js.map +1 -1
- package/dist/schema/null.d.ts +30 -0
- package/dist/schema/null.d.ts.map +1 -1
- package/dist/schema/null.js +31 -1
- package/dist/schema/null.js.map +1 -1
- package/dist/schema/nullable.d.ts +42 -0
- package/dist/schema/nullable.d.ts.map +1 -1
- package/dist/schema/nullable.js +42 -0
- package/dist/schema/nullable.js.map +1 -1
- package/dist/schema/object.d.ts +57 -0
- package/dist/schema/object.d.ts.map +1 -1
- package/dist/schema/object.js +53 -1
- package/dist/schema/object.js.map +1 -1
- package/dist/schema/optional.d.ts +43 -0
- package/dist/schema/optional.d.ts.map +1 -1
- package/dist/schema/optional.js +43 -0
- package/dist/schema/optional.js.map +1 -1
- package/dist/schema/params.d.ts +96 -12
- package/dist/schema/params.d.ts.map +1 -1
- package/dist/schema/params.js +155 -21
- package/dist/schema/params.js.map +1 -1
- package/dist/schema/payload.d.ts +111 -15
- package/dist/schema/payload.d.ts.map +1 -1
- package/dist/schema/payload.js +73 -3
- package/dist/schema/payload.js.map +1 -1
- package/dist/schema/permission-set.d.ts +58 -0
- package/dist/schema/permission-set.d.ts.map +1 -1
- package/dist/schema/permission-set.js +50 -0
- package/dist/schema/permission-set.js.map +1 -1
- package/dist/schema/permission.d.ts +42 -0
- package/dist/schema/permission.d.ts.map +1 -1
- package/dist/schema/permission.js +39 -0
- package/dist/schema/permission.js.map +1 -1
- package/dist/schema/procedure.d.ts +64 -0
- package/dist/schema/procedure.d.ts.map +1 -1
- package/dist/schema/procedure.js +64 -0
- package/dist/schema/procedure.js.map +1 -1
- package/dist/schema/query.d.ts +55 -0
- package/dist/schema/query.d.ts.map +1 -1
- package/dist/schema/query.js +55 -0
- package/dist/schema/query.js.map +1 -1
- package/dist/schema/record.d.ts +76 -25
- package/dist/schema/record.d.ts.map +1 -1
- package/dist/schema/record.js +21 -0
- package/dist/schema/record.js.map +1 -1
- package/dist/schema/ref.d.ts +51 -0
- package/dist/schema/ref.d.ts.map +1 -1
- package/dist/schema/ref.js +18 -0
- package/dist/schema/ref.js.map +1 -1
- package/dist/schema/refine.d.ts +58 -9
- package/dist/schema/refine.d.ts.map +1 -1
- package/dist/schema/refine.js.map +1 -1
- package/dist/schema/regexp.d.ts +45 -0
- package/dist/schema/regexp.d.ts.map +1 -1
- package/dist/schema/regexp.js +46 -1
- package/dist/schema/regexp.js.map +1 -1
- package/dist/schema/string.d.ts +72 -6
- package/dist/schema/string.d.ts.map +1 -1
- package/dist/schema/string.js +56 -8
- package/dist/schema/string.js.map +1 -1
- package/dist/schema/subscription.d.ts +72 -2
- package/dist/schema/subscription.d.ts.map +1 -1
- package/dist/schema/subscription.js +59 -0
- package/dist/schema/subscription.js.map +1 -1
- package/dist/schema/token.d.ts +48 -0
- package/dist/schema/token.d.ts.map +1 -1
- package/dist/schema/token.js +49 -1
- package/dist/schema/token.js.map +1 -1
- package/dist/schema/typed-object.d.ts +73 -23
- package/dist/schema/typed-object.d.ts.map +1 -1
- package/dist/schema/typed-object.js +20 -1
- package/dist/schema/typed-object.js.map +1 -1
- package/dist/schema/typed-ref.d.ts +54 -0
- package/dist/schema/typed-ref.d.ts.map +1 -1
- package/dist/schema/typed-ref.js +16 -0
- package/dist/schema/typed-ref.js.map +1 -1
- package/dist/schema/typed-union.d.ts +51 -1
- package/dist/schema/typed-union.d.ts.map +1 -1
- package/dist/schema/typed-union.js +52 -2
- package/dist/schema/typed-union.js.map +1 -1
- package/dist/schema/union.d.ts +46 -0
- package/dist/schema/union.d.ts.map +1 -1
- package/dist/schema/union.js +41 -0
- package/dist/schema/union.js.map +1 -1
- package/dist/schema/unknown.d.ts +34 -0
- package/dist/schema/unknown.d.ts.map +1 -1
- package/dist/schema/unknown.js +34 -0
- package/dist/schema/unknown.js.map +1 -1
- package/dist/schema/with-default.d.ts +45 -0
- package/dist/schema/with-default.d.ts.map +1 -1
- package/dist/schema/with-default.js +45 -0
- package/dist/schema/with-default.js.map +1 -1
- package/dist/schema.d.ts +2 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +2 -1
- package/dist/schema.js.map +1 -1
- package/dist/util/if-any.d.ts +2 -0
- package/dist/util/if-any.d.ts.map +1 -0
- package/dist/util/if-any.js +3 -0
- package/dist/util/if-any.js.map +1 -0
- package/package.json +3 -3
- package/src/core/$type.ts +150 -18
- package/src/core/record-key.ts +44 -0
- package/src/core/result.ts +86 -4
- package/src/core/schema.ts +244 -9
- package/src/core/string-format.ts +259 -13
- package/src/core/types.ts +91 -3
- package/src/core/validation-error.ts +60 -0
- package/src/core/validation-issue.ts +68 -2
- package/src/core/validator.ts +373 -12
- package/src/helpers.test.ts +110 -29
- package/src/helpers.ts +54 -25
- package/src/schema/array.test.ts +94 -79
- package/src/schema/array.ts +48 -1
- package/src/schema/blob.ts +50 -1
- package/src/schema/boolean.ts +31 -1
- package/src/schema/bytes.ts +41 -1
- package/src/schema/cid.ts +41 -1
- package/src/schema/custom.ts +68 -1
- package/src/schema/dict.ts +47 -1
- package/src/schema/discriminated-union.ts +61 -1
- package/src/schema/enum.ts +50 -0
- package/src/schema/integer.ts +45 -1
- package/src/schema/intersection.ts +56 -0
- package/src/schema/{unknown-object.test.ts → lex-map.test.ts} +9 -9
- package/src/schema/lex-map.ts +63 -0
- package/src/schema/lex-value.test.ts +81 -0
- package/src/schema/lex-value.ts +86 -0
- package/src/schema/literal.ts +46 -0
- package/src/schema/never.ts +45 -1
- package/src/schema/null.ts +32 -1
- package/src/schema/nullable.ts +43 -0
- package/src/schema/object.ts +59 -1
- package/src/schema/optional.ts +44 -0
- package/src/schema/params.test.ts +133 -38
- package/src/schema/params.ts +237 -37
- package/src/schema/payload.test.ts +3 -3
- package/src/schema/payload.ts +145 -42
- package/src/schema/permission-set.ts +58 -0
- package/src/schema/permission.ts +42 -0
- package/src/schema/procedure.ts +64 -0
- package/src/schema/query.ts +55 -0
- package/src/schema/record.ts +82 -16
- package/src/schema/ref.ts +52 -0
- package/src/schema/refine.ts +58 -9
- package/src/schema/regexp.ts +47 -1
- package/src/schema/string.test.ts +99 -2
- package/src/schema/string.ts +108 -15
- package/src/schema/subscription.ts +72 -2
- package/src/schema/token.ts +50 -1
- package/src/schema/typed-object.ts +81 -16
- package/src/schema/typed-ref.ts +55 -0
- package/src/schema/typed-union.ts +58 -3
- package/src/schema/union.ts +47 -0
- package/src/schema/unknown.ts +35 -0
- package/src/schema/with-default.ts +46 -0
- package/src/schema.ts +2 -1
- package/src/util/if-any.ts +3 -0
- package/dist/schema/unknown-object.d.ts +0 -8
- package/dist/schema/unknown-object.d.ts.map +0 -1
- package/dist/schema/unknown-object.js +0 -19
- package/dist/schema/unknown-object.js.map +0 -1
- package/src/schema/unknown-object.ts +0 -19
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
import { NsidString } from '../core.js';
|
|
2
2
|
import { ParamsSchema } from './params.js';
|
|
3
3
|
import { Payload } from './payload.js';
|
|
4
|
+
/**
|
|
5
|
+
* Represents a Lexicon procedure (HTTP POST) endpoint definition.
|
|
6
|
+
*
|
|
7
|
+
* Procedures are operations that may modify state on the server.
|
|
8
|
+
* They have parameters, an input payload (request body), an output
|
|
9
|
+
* payload (response body), and optional error types.
|
|
10
|
+
*
|
|
11
|
+
* @template TNsid - The NSID identifying this procedure
|
|
12
|
+
* @template TParameters - The parameters schema type
|
|
13
|
+
* @template TInputPayload - The request body payload type
|
|
14
|
+
* @template TOutputPayload - The response body payload type
|
|
15
|
+
* @template TErrors - Array of error type strings, or undefined
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const createPost = new Procedure(
|
|
20
|
+
* 'app.bsky.feed.post',
|
|
21
|
+
* l.params({}),
|
|
22
|
+
* l.jsonPayload({ text: l.string() }),
|
|
23
|
+
* l.jsonPayload({ uri: l.string(), cid: l.string() }),
|
|
24
|
+
* ['InvalidRecord']
|
|
25
|
+
* )
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
4
28
|
export declare class Procedure<const TNsid extends NsidString = NsidString, const TParameters extends ParamsSchema = ParamsSchema, const TInputPayload extends Payload = Payload, const TOutputPayload extends Payload = Payload, const TErrors extends undefined | readonly string[] = undefined | readonly string[]> {
|
|
5
29
|
readonly nsid: TNsid;
|
|
6
30
|
readonly parameters: TParameters;
|
|
@@ -10,5 +34,45 @@ export declare class Procedure<const TNsid extends NsidString = NsidString, cons
|
|
|
10
34
|
readonly type: "procedure";
|
|
11
35
|
constructor(nsid: TNsid, parameters: TParameters, input: TInputPayload, output: TOutputPayload, errors: TErrors);
|
|
12
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a procedure definition for a Lexicon POST endpoint.
|
|
39
|
+
*
|
|
40
|
+
* Procedures can modify server state. They accept both URL parameters
|
|
41
|
+
* and a request body (input payload).
|
|
42
|
+
*
|
|
43
|
+
* @param nsid - The NSID identifying this procedure endpoint
|
|
44
|
+
* @param parameters - Schema for URL query parameters
|
|
45
|
+
* @param input - Schema for request body payload
|
|
46
|
+
* @param output - Schema for response body payload
|
|
47
|
+
* @param errors - Optional array of error type strings
|
|
48
|
+
* @returns A new {@link Procedure} instance
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* // Create record procedure
|
|
53
|
+
* const createRecord = l.procedure(
|
|
54
|
+
* 'com.atproto.repo.createRecord',
|
|
55
|
+
* l.params({}),
|
|
56
|
+
* l.jsonPayload({
|
|
57
|
+
* repo: l.string({ format: 'at-identifier' }),
|
|
58
|
+
* collection: l.string({ format: 'nsid' }),
|
|
59
|
+
* record: l.unknown(),
|
|
60
|
+
* }),
|
|
61
|
+
* l.jsonPayload({
|
|
62
|
+
* uri: l.string({ format: 'at-uri' }),
|
|
63
|
+
* cid: l.string({ format: 'cid' }),
|
|
64
|
+
* }),
|
|
65
|
+
* ['InvalidRecord', 'RepoNotFound'],
|
|
66
|
+
* )
|
|
67
|
+
*
|
|
68
|
+
* // Procedure with binary input
|
|
69
|
+
* const uploadBlob = l.procedure(
|
|
70
|
+
* 'com.atproto.repo.uploadBlob',
|
|
71
|
+
* l.params({}),
|
|
72
|
+
* l.payload('*\/*', undefined), // Accept any content type
|
|
73
|
+
* l.jsonPayload({ blob: l.blob() }),
|
|
74
|
+
* )
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
13
77
|
export declare function procedure<const N extends NsidString, const P extends ParamsSchema, const I extends Payload, const O extends Payload, const E extends undefined | readonly string[] = undefined>(nsid: N, parameters: P, input: I, output: O, errors?: E): Procedure<N, P, I, O, E>;
|
|
14
78
|
//# sourceMappingURL=procedure.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"procedure.d.ts","sourceRoot":"","sources":["../../src/schema/procedure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,qBAAa,SAAS,CACpB,KAAK,CAAC,KAAK,SAAS,UAAU,GAAG,UAAU,EAC3C,KAAK,CAAC,WAAW,SAAS,YAAY,GAAG,YAAY,EACrD,KAAK,CAAC,aAAa,SAAS,OAAO,GAAG,OAAO,EAC7C,KAAK,CAAC,cAAc,SAAS,OAAO,GAAG,OAAO,EAC9C,KAAK,CAAC,OAAO,SAAS,SAAS,GAAG,SAAS,MAAM,EAAE,GAC/C,SAAS,GACT,SAAS,MAAM,EAAE;IAKnB,QAAQ,CAAC,IAAI,EAAE,KAAK;IACpB,QAAQ,CAAC,UAAU,EAAE,WAAW;IAChC,QAAQ,CAAC,KAAK,EAAE,aAAa;IAC7B,QAAQ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GAuCG;AAEH,wBAAgB,SAAS,CACvB,KAAK,CAAC,CAAC,SAAS,UAAU,EAC1B,KAAK,CAAC,CAAC,SAAS,YAAY,EAC5B,KAAK,CAAC,CAAC,SAAS,OAAO,EACvB,KAAK,CAAC,CAAC,SAAS,OAAO,EACvB,KAAK,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,EACzD,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAE,CAAkB,4BAExE"}
|
package/dist/schema/procedure.js
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Procedure = void 0;
|
|
4
4
|
exports.procedure = procedure;
|
|
5
|
+
/**
|
|
6
|
+
* Represents a Lexicon procedure (HTTP POST) endpoint definition.
|
|
7
|
+
*
|
|
8
|
+
* Procedures are operations that may modify state on the server.
|
|
9
|
+
* They have parameters, an input payload (request body), an output
|
|
10
|
+
* payload (response body), and optional error types.
|
|
11
|
+
*
|
|
12
|
+
* @template TNsid - The NSID identifying this procedure
|
|
13
|
+
* @template TParameters - The parameters schema type
|
|
14
|
+
* @template TInputPayload - The request body payload type
|
|
15
|
+
* @template TOutputPayload - The response body payload type
|
|
16
|
+
* @template TErrors - Array of error type strings, or undefined
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const createPost = new Procedure(
|
|
21
|
+
* 'app.bsky.feed.post',
|
|
22
|
+
* l.params({}),
|
|
23
|
+
* l.jsonPayload({ text: l.string() }),
|
|
24
|
+
* l.jsonPayload({ uri: l.string(), cid: l.string() }),
|
|
25
|
+
* ['InvalidRecord']
|
|
26
|
+
* )
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
5
29
|
class Procedure {
|
|
6
30
|
nsid;
|
|
7
31
|
parameters;
|
|
@@ -18,6 +42,46 @@ class Procedure {
|
|
|
18
42
|
}
|
|
19
43
|
}
|
|
20
44
|
exports.Procedure = Procedure;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a procedure definition for a Lexicon POST endpoint.
|
|
47
|
+
*
|
|
48
|
+
* Procedures can modify server state. They accept both URL parameters
|
|
49
|
+
* and a request body (input payload).
|
|
50
|
+
*
|
|
51
|
+
* @param nsid - The NSID identifying this procedure endpoint
|
|
52
|
+
* @param parameters - Schema for URL query parameters
|
|
53
|
+
* @param input - Schema for request body payload
|
|
54
|
+
* @param output - Schema for response body payload
|
|
55
|
+
* @param errors - Optional array of error type strings
|
|
56
|
+
* @returns A new {@link Procedure} instance
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* // Create record procedure
|
|
61
|
+
* const createRecord = l.procedure(
|
|
62
|
+
* 'com.atproto.repo.createRecord',
|
|
63
|
+
* l.params({}),
|
|
64
|
+
* l.jsonPayload({
|
|
65
|
+
* repo: l.string({ format: 'at-identifier' }),
|
|
66
|
+
* collection: l.string({ format: 'nsid' }),
|
|
67
|
+
* record: l.unknown(),
|
|
68
|
+
* }),
|
|
69
|
+
* l.jsonPayload({
|
|
70
|
+
* uri: l.string({ format: 'at-uri' }),
|
|
71
|
+
* cid: l.string({ format: 'cid' }),
|
|
72
|
+
* }),
|
|
73
|
+
* ['InvalidRecord', 'RepoNotFound'],
|
|
74
|
+
* )
|
|
75
|
+
*
|
|
76
|
+
* // Procedure with binary input
|
|
77
|
+
* const uploadBlob = l.procedure(
|
|
78
|
+
* 'com.atproto.repo.uploadBlob',
|
|
79
|
+
* l.params({}),
|
|
80
|
+
* l.payload('*\/*', undefined), // Accept any content type
|
|
81
|
+
* l.jsonPayload({ blob: l.blob() }),
|
|
82
|
+
* )
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
21
85
|
/*@__NO_SIDE_EFFECTS__*/
|
|
22
86
|
function procedure(nsid, parameters, input, output, errors = undefined) {
|
|
23
87
|
return new Procedure(nsid, parameters, input, output, errors);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"procedure.js","sourceRoot":"","sources":["../../src/schema/procedure.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"procedure.js","sourceRoot":"","sources":["../../src/schema/procedure.ts"],"names":[],"mappings":";;;AAyFA,8BAQC;AA7FD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAa,SAAS;IAYT;IACA;IACA;IACA;IACA;IAPF,IAAI,GAAG,WAAoB,CAAA;IAEpC,YACW,IAAW,EACX,UAAuB,EACvB,KAAoB,EACpB,MAAsB,EACtB,MAAe;QAJf,SAAI,GAAJ,IAAI,CAAO;QACX,eAAU,GAAV,UAAU,CAAa;QACvB,UAAK,GAAL,KAAK,CAAe;QACpB,WAAM,GAAN,MAAM,CAAgB;QACtB,WAAM,GAAN,MAAM,CAAS;IACvB,CAAC;CACL;AAlBD,8BAkBC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAwB;AACxB,SAAgB,SAAS,CAMvB,IAAO,EAAE,UAAa,EAAE,KAAQ,EAAE,MAAS,EAAE,SAAY,SAAc;IACvE,OAAO,IAAI,SAAS,CAAgB,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAC9E,CAAC","sourcesContent":["import { NsidString } from '../core.js'\nimport { ParamsSchema } from './params.js'\nimport { Payload } from './payload.js'\n\n/**\n * Represents a Lexicon procedure (HTTP POST) endpoint definition.\n *\n * Procedures are operations that may modify state on the server.\n * They have parameters, an input payload (request body), an output\n * payload (response body), and optional error types.\n *\n * @template TNsid - The NSID identifying this procedure\n * @template TParameters - The parameters schema type\n * @template TInputPayload - The request body payload type\n * @template TOutputPayload - The response body payload type\n * @template TErrors - Array of error type strings, or undefined\n *\n * @example\n * ```ts\n * const createPost = new Procedure(\n * 'app.bsky.feed.post',\n * l.params({}),\n * l.jsonPayload({ text: l.string() }),\n * l.jsonPayload({ uri: l.string(), cid: l.string() }),\n * ['InvalidRecord']\n * )\n * ```\n */\nexport class Procedure<\n const TNsid extends NsidString = NsidString,\n const TParameters extends ParamsSchema = ParamsSchema,\n const TInputPayload extends Payload = Payload,\n const TOutputPayload extends Payload = Payload,\n const TErrors extends undefined | readonly string[] =\n | undefined\n | readonly string[],\n> {\n readonly type = 'procedure' as const\n\n constructor(\n readonly nsid: TNsid,\n readonly parameters: TParameters,\n readonly input: TInputPayload,\n readonly output: TOutputPayload,\n readonly errors: TErrors,\n ) {}\n}\n\n/**\n * Creates a procedure definition for a Lexicon POST endpoint.\n *\n * Procedures can modify server state. They accept both URL parameters\n * and a request body (input payload).\n *\n * @param nsid - The NSID identifying this procedure endpoint\n * @param parameters - Schema for URL query parameters\n * @param input - Schema for request body payload\n * @param output - Schema for response body payload\n * @param errors - Optional array of error type strings\n * @returns A new {@link Procedure} instance\n *\n * @example\n * ```ts\n * // Create record procedure\n * const createRecord = l.procedure(\n * 'com.atproto.repo.createRecord',\n * l.params({}),\n * l.jsonPayload({\n * repo: l.string({ format: 'at-identifier' }),\n * collection: l.string({ format: 'nsid' }),\n * record: l.unknown(),\n * }),\n * l.jsonPayload({\n * uri: l.string({ format: 'at-uri' }),\n * cid: l.string({ format: 'cid' }),\n * }),\n * ['InvalidRecord', 'RepoNotFound'],\n * )\n *\n * // Procedure with binary input\n * const uploadBlob = l.procedure(\n * 'com.atproto.repo.uploadBlob',\n * l.params({}),\n * l.payload('*\\/*', undefined), // Accept any content type\n * l.jsonPayload({ blob: l.blob() }),\n * )\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function procedure<\n const N extends NsidString,\n const P extends ParamsSchema,\n const I extends Payload,\n const O extends Payload,\n const E extends undefined | readonly string[] = undefined,\n>(nsid: N, parameters: P, input: I, output: O, errors: E = undefined as E) {\n return new Procedure<N, P, I, O, E>(nsid, parameters, input, output, errors)\n}\n"]}
|
package/dist/schema/query.d.ts
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import { NsidString } from '../core.js';
|
|
2
2
|
import { ParamsSchema } from './params.js';
|
|
3
3
|
import { Payload } from './payload.js';
|
|
4
|
+
/**
|
|
5
|
+
* Represents a Lexicon query (HTTP GET) endpoint definition.
|
|
6
|
+
*
|
|
7
|
+
* Queries are read-only operations that retrieve data from a server.
|
|
8
|
+
* They have parameters (passed as URL query parameters), an output
|
|
9
|
+
* payload, and optional error types.
|
|
10
|
+
*
|
|
11
|
+
* @template TNsid - The NSID identifying this query
|
|
12
|
+
* @template TParameters - The parameters schema type
|
|
13
|
+
* @template TOutputPayload - The output payload type
|
|
14
|
+
* @template TErrors - Array of error type strings, or undefined
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const getPostQuery = new Query(
|
|
19
|
+
* 'app.bsky.feed.getPost',
|
|
20
|
+
* l.params({ uri: l.string({ format: 'at-uri' }) }),
|
|
21
|
+
* l.payload('application/json', postSchema),
|
|
22
|
+
* ['NotFound']
|
|
23
|
+
* )
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
4
26
|
export declare class Query<const TNsid extends NsidString = NsidString, const TParameters extends ParamsSchema = ParamsSchema, const TOutputPayload extends Payload = Payload, const TErrors extends undefined | readonly string[] = undefined | readonly string[]> {
|
|
5
27
|
readonly nsid: TNsid;
|
|
6
28
|
readonly parameters: TParameters;
|
|
@@ -9,5 +31,38 @@ export declare class Query<const TNsid extends NsidString = NsidString, const TP
|
|
|
9
31
|
readonly type: "query";
|
|
10
32
|
constructor(nsid: TNsid, parameters: TParameters, output: TOutputPayload, errors: TErrors);
|
|
11
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Creates a query definition for a Lexicon GET endpoint.
|
|
36
|
+
*
|
|
37
|
+
* Queries retrieve data without side effects. Parameters are sent as
|
|
38
|
+
* URL query string parameters.
|
|
39
|
+
*
|
|
40
|
+
* @param nsid - The NSID identifying this query endpoint
|
|
41
|
+
* @param parameters - Schema for URL query parameters
|
|
42
|
+
* @param output - Expected response payload schema
|
|
43
|
+
* @param errors - Optional array of error type strings
|
|
44
|
+
* @returns A new {@link Query} instance
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* // Simple query with JSON output
|
|
49
|
+
* const getProfile = l.query(
|
|
50
|
+
* 'app.bsky.actor.getProfile',
|
|
51
|
+
* l.params({ actor: l.string({ format: 'at-identifier' }) }),
|
|
52
|
+
* l.jsonPayload({ displayName: l.string(), handle: l.string() }),
|
|
53
|
+
* )
|
|
54
|
+
*
|
|
55
|
+
* // Query with pagination and errors
|
|
56
|
+
* const getTimeline = l.query(
|
|
57
|
+
* 'app.bsky.feed.getTimeline',
|
|
58
|
+
* l.params({
|
|
59
|
+
* limit: l.optional(l.integer({ minimum: 1, maximum: 100 })),
|
|
60
|
+
* cursor: l.optional(l.string()),
|
|
61
|
+
* }),
|
|
62
|
+
* l.jsonPayload({ feed: l.array(feedItemSchema), cursor: l.optional(l.string()) }),
|
|
63
|
+
* ['BlockedActor', 'BlockedByActor'],
|
|
64
|
+
* )
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
12
67
|
export declare function query<const N extends NsidString, const P extends ParamsSchema, const O extends Payload, const E extends undefined | readonly string[] = undefined>(nsid: N, parameters: P, output: O, errors?: E): Query<N, P, O, E>;
|
|
13
68
|
//# sourceMappingURL=query.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/schema/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,qBAAa,KAAK,CAChB,KAAK,CAAC,KAAK,SAAS,UAAU,GAAG,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AI,EAAE,KAAK,EACX,UAAU,EAAE,WAAW,EACvB,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,OAAO;CAE3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,wBAAgB,KAAK,CACnB,KAAK,CAAC,CAAC,SAAS,UAAU,EAC1B,KAAK,CAAC,CAAC,SAAS,YAAY,EAC5B,KAAK,CAAC,CAAC,SAAS,OAAO,EACvB,KAAK,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,EACzD,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAE,CAAkB,qBAE9D"}
|
package/dist/schema/query.js
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Query = void 0;
|
|
4
4
|
exports.query = query;
|
|
5
|
+
/**
|
|
6
|
+
* Represents a Lexicon query (HTTP GET) endpoint definition.
|
|
7
|
+
*
|
|
8
|
+
* Queries are read-only operations that retrieve data from a server.
|
|
9
|
+
* They have parameters (passed as URL query parameters), an output
|
|
10
|
+
* payload, and optional error types.
|
|
11
|
+
*
|
|
12
|
+
* @template TNsid - The NSID identifying this query
|
|
13
|
+
* @template TParameters - The parameters schema type
|
|
14
|
+
* @template TOutputPayload - The output payload type
|
|
15
|
+
* @template TErrors - Array of error type strings, or undefined
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const getPostQuery = new Query(
|
|
20
|
+
* 'app.bsky.feed.getPost',
|
|
21
|
+
* l.params({ uri: l.string({ format: 'at-uri' }) }),
|
|
22
|
+
* l.payload('application/json', postSchema),
|
|
23
|
+
* ['NotFound']
|
|
24
|
+
* )
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
5
27
|
class Query {
|
|
6
28
|
nsid;
|
|
7
29
|
parameters;
|
|
@@ -16,6 +38,39 @@ class Query {
|
|
|
16
38
|
}
|
|
17
39
|
}
|
|
18
40
|
exports.Query = Query;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a query definition for a Lexicon GET endpoint.
|
|
43
|
+
*
|
|
44
|
+
* Queries retrieve data without side effects. Parameters are sent as
|
|
45
|
+
* URL query string parameters.
|
|
46
|
+
*
|
|
47
|
+
* @param nsid - The NSID identifying this query endpoint
|
|
48
|
+
* @param parameters - Schema for URL query parameters
|
|
49
|
+
* @param output - Expected response payload schema
|
|
50
|
+
* @param errors - Optional array of error type strings
|
|
51
|
+
* @returns A new {@link Query} instance
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* // Simple query with JSON output
|
|
56
|
+
* const getProfile = l.query(
|
|
57
|
+
* 'app.bsky.actor.getProfile',
|
|
58
|
+
* l.params({ actor: l.string({ format: 'at-identifier' }) }),
|
|
59
|
+
* l.jsonPayload({ displayName: l.string(), handle: l.string() }),
|
|
60
|
+
* )
|
|
61
|
+
*
|
|
62
|
+
* // Query with pagination and errors
|
|
63
|
+
* const getTimeline = l.query(
|
|
64
|
+
* 'app.bsky.feed.getTimeline',
|
|
65
|
+
* l.params({
|
|
66
|
+
* limit: l.optional(l.integer({ minimum: 1, maximum: 100 })),
|
|
67
|
+
* cursor: l.optional(l.string()),
|
|
68
|
+
* }),
|
|
69
|
+
* l.jsonPayload({ feed: l.array(feedItemSchema), cursor: l.optional(l.string()) }),
|
|
70
|
+
* ['BlockedActor', 'BlockedByActor'],
|
|
71
|
+
* )
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
19
74
|
/*@__NO_SIDE_EFFECTS__*/
|
|
20
75
|
function query(nsid, parameters, output, errors = undefined) {
|
|
21
76
|
return new Query(nsid, parameters, output, errors);
|
package/dist/schema/query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/schema/query.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/schema/query.ts"],"names":[],"mappings":";;;AA8EA,sBAOC;AAjFD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAa,KAAK;IAWL;IACA;IACA;IACA;IANF,IAAI,GAAG,OAAgB,CAAA;IAEhC,YACW,IAAW,EACX,UAAuB,EACvB,MAAsB,EACtB,MAAe;QAHf,SAAI,GAAJ,IAAI,CAAO;QACX,eAAU,GAAV,UAAU,CAAa;QACvB,WAAM,GAAN,MAAM,CAAgB;QACtB,WAAM,GAAN,MAAM,CAAS;IACvB,CAAC;CACL;AAhBD,sBAgBC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAwB;AACxB,SAAgB,KAAK,CAKnB,IAAO,EAAE,UAAa,EAAE,MAAS,EAAE,SAAY,SAAc;IAC7D,OAAO,IAAI,KAAK,CAAa,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAChE,CAAC","sourcesContent":["import { NsidString } from '../core.js'\nimport { ParamsSchema } from './params.js'\nimport { Payload } from './payload.js'\n\n/**\n * Represents a Lexicon query (HTTP GET) endpoint definition.\n *\n * Queries are read-only operations that retrieve data from a server.\n * They have parameters (passed as URL query parameters), an output\n * payload, and optional error types.\n *\n * @template TNsid - The NSID identifying this query\n * @template TParameters - The parameters schema type\n * @template TOutputPayload - The output payload type\n * @template TErrors - Array of error type strings, or undefined\n *\n * @example\n * ```ts\n * const getPostQuery = new Query(\n * 'app.bsky.feed.getPost',\n * l.params({ uri: l.string({ format: 'at-uri' }) }),\n * l.payload('application/json', postSchema),\n * ['NotFound']\n * )\n * ```\n */\nexport class Query<\n const TNsid extends NsidString = NsidString,\n const TParameters extends ParamsSchema = ParamsSchema,\n const TOutputPayload extends Payload = Payload,\n const TErrors extends undefined | readonly string[] =\n | undefined\n | readonly string[],\n> {\n readonly type = 'query' as const\n\n constructor(\n readonly nsid: TNsid,\n readonly parameters: TParameters,\n readonly output: TOutputPayload,\n readonly errors: TErrors,\n ) {}\n}\n\n/**\n * Creates a query definition for a Lexicon GET endpoint.\n *\n * Queries retrieve data without side effects. Parameters are sent as\n * URL query string parameters.\n *\n * @param nsid - The NSID identifying this query endpoint\n * @param parameters - Schema for URL query parameters\n * @param output - Expected response payload schema\n * @param errors - Optional array of error type strings\n * @returns A new {@link Query} instance\n *\n * @example\n * ```ts\n * // Simple query with JSON output\n * const getProfile = l.query(\n * 'app.bsky.actor.getProfile',\n * l.params({ actor: l.string({ format: 'at-identifier' }) }),\n * l.jsonPayload({ displayName: l.string(), handle: l.string() }),\n * )\n *\n * // Query with pagination and errors\n * const getTimeline = l.query(\n * 'app.bsky.feed.getTimeline',\n * l.params({\n * limit: l.optional(l.integer({ minimum: 1, maximum: 100 })),\n * cursor: l.optional(l.string()),\n * }),\n * l.jsonPayload({ feed: l.array(feedItemSchema), cursor: l.optional(l.string()) }),\n * ['BlockedActor', 'BlockedByActor'],\n * )\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function query<\n const N extends NsidString,\n const P extends ParamsSchema,\n const O extends Payload,\n const E extends undefined | readonly string[] = undefined,\n>(nsid: N, parameters: P, output: O, errors: E = undefined as E) {\n return new Query<N, P, O, E>(nsid, parameters, output, errors)\n}\n"]}
|
package/dist/schema/record.d.ts
CHANGED
|
@@ -1,33 +1,54 @@
|
|
|
1
1
|
import { $Typed, InferInput, InferOutput, LexiconRecordKey, NsidString, Schema, TidString, Unknown$TypedObject, ValidationContext, Validator } from '../core.js';
|
|
2
|
+
/**
|
|
3
|
+
* Infers the record key type from a RecordSchema.
|
|
4
|
+
*
|
|
5
|
+
* @template R - The RecordSchema type
|
|
6
|
+
*/
|
|
2
7
|
export type InferRecordKey<R extends RecordSchema> = R extends RecordSchema<infer TKey> ? RecordKeySchemaOutput<TKey> : never;
|
|
8
|
+
export type TypedRecord<TType extends NsidString, TValue extends {
|
|
9
|
+
$type?: unknown;
|
|
10
|
+
} = {
|
|
11
|
+
$type?: unknown;
|
|
12
|
+
}> = TValue extends {
|
|
13
|
+
$type: TType;
|
|
14
|
+
} ? TValue : $Typed<Exclude<TValue, Unknown$TypedObject>, TType>;
|
|
15
|
+
/**
|
|
16
|
+
* Schema for AT Protocol records with a type identifier and key constraints.
|
|
17
|
+
*
|
|
18
|
+
* Records are the primary data unit in AT Protocol. Each record has a `$type`
|
|
19
|
+
* field identifying its Lexicon schema, and is stored at a specific key
|
|
20
|
+
* (TID, NSID, or other format) in a repository.
|
|
21
|
+
*
|
|
22
|
+
* @template TKey - The record key type ('tid', 'nsid', 'any', or 'literal:...')
|
|
23
|
+
* @template TType - The NSID string identifying this record type
|
|
24
|
+
* @template TShape - The validator type for the record's data shape
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const postSchema = new RecordSchema(
|
|
29
|
+
* 'tid',
|
|
30
|
+
* 'app.bsky.feed.post',
|
|
31
|
+
* l.object({ text: l.string(), createdAt: l.string() })
|
|
32
|
+
* )
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
3
35
|
export declare class RecordSchema<const TKey extends LexiconRecordKey = any, const TType extends NsidString = any, const TShape extends Validator<{
|
|
4
36
|
[k: string]: unknown;
|
|
5
37
|
}> = any> extends Schema<$Typed<InferInput<TShape>, TType>, $Typed<InferOutput<TShape>, TType>> {
|
|
6
38
|
readonly key: TKey;
|
|
7
39
|
readonly $type: TType;
|
|
8
40
|
readonly schema: TShape;
|
|
41
|
+
readonly type: "record";
|
|
9
42
|
keySchema: RecordKeySchema<TKey>;
|
|
10
43
|
constructor(key: TKey, $type: TType, schema: TShape);
|
|
11
|
-
isTypeOf<
|
|
44
|
+
isTypeOf<TValue extends {
|
|
12
45
|
$type?: unknown;
|
|
13
|
-
}>(value:
|
|
14
|
-
$type: TType;
|
|
15
|
-
} ? X : $Typed<Exclude<X, Unknown$TypedObject>, TType>;
|
|
46
|
+
}>(value: TValue): value is TypedRecord<TType, TValue>;
|
|
16
47
|
build(input: Omit<InferInput<this>, '$type'>): $Typed<InferOutput<this>, TType>;
|
|
17
|
-
$isTypeOf<
|
|
48
|
+
$isTypeOf<TValue extends {
|
|
18
49
|
$type?: unknown;
|
|
19
|
-
}>(value:
|
|
20
|
-
|
|
21
|
-
} ? X : Exclude<X, Unknown$TypedObject> & {
|
|
22
|
-
$type: TType;
|
|
23
|
-
} extends infer T ? { [K in keyof T]: (Exclude<X, Unknown$TypedObject> & {
|
|
24
|
-
$type: TType;
|
|
25
|
-
})[K]; } : never;
|
|
26
|
-
$build(input: Omit<InferInput<this>, '$type'>): InferOutput<this> & {
|
|
27
|
-
$type: TType;
|
|
28
|
-
} extends infer T ? { [K in keyof T]: (InferOutput<this> & {
|
|
29
|
-
$type: TType;
|
|
30
|
-
})[K]; } : never;
|
|
50
|
+
}>(value: TValue): value is TypedRecord<TType, TValue>;
|
|
51
|
+
$build(input: Omit<InferInput<this>, '$type'>): $Typed<InferOutput<this>, TType>;
|
|
31
52
|
validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationFailure | import("../core.js").ValidationSuccess<InferInput<TShape>>;
|
|
32
53
|
}
|
|
33
54
|
export type RecordKeySchemaOutput<Key extends LexiconRecordKey> = Key extends 'any' ? string : Key extends 'tid' ? TidString : Key extends 'nsid' ? NsidString : Key extends `literal:${infer L extends string}` ? L : never;
|
|
@@ -37,15 +58,45 @@ export type RecordKeySchema<Key extends LexiconRecordKey> = Schema<RecordKeySche
|
|
|
37
58
|
*/
|
|
38
59
|
type AsNsid<T> = T extends `${string}#${string}` ? never : T;
|
|
39
60
|
/**
|
|
61
|
+
* Creates a record schema for AT Protocol records.
|
|
62
|
+
*
|
|
63
|
+
* Records are the primary data unit in AT Protocol repositories. They have
|
|
64
|
+
* a `$type` field identifying their Lexicon schema, and are stored at keys
|
|
65
|
+
* following a specific format (TID, NSID, etc.).
|
|
66
|
+
*
|
|
40
67
|
* This function offers two overloads:
|
|
41
|
-
* - One that
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* -
|
|
47
|
-
*
|
|
48
|
-
*
|
|
68
|
+
* - One that infers the output type from the provided arguments (does not
|
|
69
|
+
* support circular references)
|
|
70
|
+
* - One with an explicitly defined interface for use with codegen and
|
|
71
|
+
* circular references
|
|
72
|
+
*
|
|
73
|
+
* @param key - The record key type: 'tid', 'nsid', 'any', or 'literal:value'
|
|
74
|
+
* @param type - The NSID identifying this record type (e.g., 'app.bsky.feed.post')
|
|
75
|
+
* @param validator - Schema validator for the record's properties
|
|
76
|
+
* @returns A new {@link RecordSchema} instance
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* // Post record with TID key
|
|
81
|
+
* const postSchema = l.record('tid', 'app.bsky.feed.post', l.object({
|
|
82
|
+
* text: l.string({ maxGraphemes: 300 }),
|
|
83
|
+
* createdAt: l.string({ format: 'datetime' }),
|
|
84
|
+
* reply: l.optional(l.object({
|
|
85
|
+
* root: l.ref(() => strongRefSchema),
|
|
86
|
+
* parent: l.ref(() => strongRefSchema),
|
|
87
|
+
* })),
|
|
88
|
+
* }))
|
|
89
|
+
*
|
|
90
|
+
* // Profile record with literal 'self' key
|
|
91
|
+
* const profileSchema = l.record('literal:self', 'app.bsky.actor.profile', l.object({
|
|
92
|
+
* displayName: l.optional(l.string({ maxGraphemes: 64 })),
|
|
93
|
+
* description: l.optional(l.string({ maxGraphemes: 256 })),
|
|
94
|
+
* avatar: l.optional(l.blob({ accept: ['image/*'] })),
|
|
95
|
+
* }))
|
|
96
|
+
*
|
|
97
|
+
* // Build a record with automatic $type injection
|
|
98
|
+
* const post = postSchema.build({ text: 'Hello!', createdAt: new Date().toISOString() })
|
|
99
|
+
* ```
|
|
49
100
|
*/
|
|
50
101
|
export declare function record<const K extends LexiconRecordKey, const T extends NsidString, const S extends Validator<{
|
|
51
102
|
[k: string]: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../src/schema/record.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAEN,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,MAAM,EACN,SAAS,EACT,mBAAmB,EACnB,iBAAiB,EACjB,SAAS,EACV,MAAM,YAAY,CAAA;AAInB,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,YAAY,IAC/C,CAAC,SAAS,YAAY,CAAC,MAAM,IAAI,CAAC,GAAG,qBAAqB,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;AAE1E,qBAAa,YAAY,CACvB,KAAK,CAAC,IAAI,SAAS,gBAAgB,GAAG,GAAG,EACzC,KAAK,CAAC,KAAK,SAAS,UAAU,GAAG,GAAG,EACpC,KAAK,CAAC,MAAM,SAAS,SAAS,CAAC;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC,GAAG,GAAG,CAC9D,SAAQ,MAAM,CACd,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,EACjC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CACnC;
|
|
1
|
+
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../src/schema/record.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAEN,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,MAAM,EACN,SAAS,EACT,mBAAmB,EACnB,iBAAiB,EACjB,SAAS,EACV,MAAM,YAAY,CAAA;AAInB;;;;GAIG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,YAAY,IAC/C,CAAC,SAAS,YAAY,CAAC,MAAM,IAAI,CAAC,GAAG,qBAAqB,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;AAE1E,MAAM,MAAM,WAAW,CACrB,KAAK,SAAS,UAAU,EACxB,MA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CAAC,CAAC,CAAA;AAC/D,wBAAgB,MAAM,CACpB,KAAK,CAAC,CAAC,SAAS,gBAAgB,EAChC,KAAK,CAAC,CAAC,SAAS;IAAE,KAAK,EAAE,UAAU,CAAA;CAAE,EAErC,GAAG,EAAE,CAAC,EACN,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EACxB,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,GACrC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA"}
|
package/dist/schema/record.js
CHANGED
|
@@ -5,10 +5,31 @@ exports.record = record;
|
|
|
5
5
|
const core_js_1 = require("../core.js");
|
|
6
6
|
const literal_js_1 = require("./literal.js");
|
|
7
7
|
const string_js_1 = require("./string.js");
|
|
8
|
+
/**
|
|
9
|
+
* Schema for AT Protocol records with a type identifier and key constraints.
|
|
10
|
+
*
|
|
11
|
+
* Records are the primary data unit in AT Protocol. Each record has a `$type`
|
|
12
|
+
* field identifying its Lexicon schema, and is stored at a specific key
|
|
13
|
+
* (TID, NSID, or other format) in a repository.
|
|
14
|
+
*
|
|
15
|
+
* @template TKey - The record key type ('tid', 'nsid', 'any', or 'literal:...')
|
|
16
|
+
* @template TType - The NSID string identifying this record type
|
|
17
|
+
* @template TShape - The validator type for the record's data shape
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const postSchema = new RecordSchema(
|
|
22
|
+
* 'tid',
|
|
23
|
+
* 'app.bsky.feed.post',
|
|
24
|
+
* l.object({ text: l.string(), createdAt: l.string() })
|
|
25
|
+
* )
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
8
28
|
class RecordSchema extends core_js_1.Schema {
|
|
9
29
|
key;
|
|
10
30
|
$type;
|
|
11
31
|
schema;
|
|
32
|
+
type = 'record';
|
|
12
33
|
keySchema;
|
|
13
34
|
constructor(key, $type, schema) {
|
|
14
35
|
super();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.js","sourceRoot":"","sources":["../../src/schema/record.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"record.js","sourceRoot":"","sources":["../../src/schema/record.ts"],"names":[],"mappings":";;;AA+MA,wBAMC;AArND,wCAYmB;AACnB,6CAAsC;AACtC,2CAAoC;AAiBpC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,YAIX,SAAQ,gBAGT;IAMY;IACA;IACA;IAPF,IAAI,GAAG,QAAiB,CAAA;IAEjC,SAAS,CAAuB;IAEhC,YACW,GAAS,EACT,KAAY,EACZ,MAAc;QAEvB,KAAK,EAAE,CAAA;QAJE,QAAG,GAAH,GAAG,CAAM;QACT,UAAK,GAAL,KAAK,CAAO;QACZ,WAAM,GAAN,MAAM,CAAQ;QAGvB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,GAAG,CAAC,CAAA;IACjC,CAAC;IAED,QAAQ,CACN,KAAa;QAEb,OAAO,KAAK,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,CAAA;IACnC,CAAC;IAED,KAAK,CACH,KAAsC;QAEtC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,gBAAM,EAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;IAC9C,CAAC;IAED,SAAS,CACP,KAAa;QAEb,OAAO,IAAI,CAAC,QAAQ,CAAS,KAAK,CAAC,CAAA;IACrC,CAAC;IAED,MAAM,CACJ,KAAsC;QAEtC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAC1B,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QAE/C,IAAI,CA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GAAM,EAAE,IAAO,EAAE,SAAY;IAC7B,OAAO,IAAI,YAAY,CAAU,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;AACxD,CAAC","sourcesContent":["import {\n $Typed,\n $typed,\n InferInput,\n InferOutput,\n LexiconRecordKey,\n NsidString,\n Schema,\n TidString,\n Unknown$TypedObject,\n ValidationContext,\n Validator,\n} from '../core.js'\nimport { literal } from './literal.js'\nimport { string } from './string.js'\n\n/**\n * Infers the record key type from a RecordSchema.\n *\n * @template R - The RecordSchema type\n */\nexport type InferRecordKey<R extends RecordSchema> =\n R extends RecordSchema<infer TKey> ? RecordKeySchemaOutput<TKey> : never\n\nexport type TypedRecord<\n TType extends NsidString,\n TValue extends { $type?: unknown } = { $type?: unknown },\n> = TValue extends { $type: TType }\n ? TValue\n : $Typed<Exclude<TValue, Unknown$TypedObject>, TType>\n\n/**\n * Schema for AT Protocol records with a type identifier and key constraints.\n *\n * Records are the primary data unit in AT Protocol. Each record has a `$type`\n * field identifying its Lexicon schema, and is stored at a specific key\n * (TID, NSID, or other format) in a repository.\n *\n * @template TKey - The record key type ('tid', 'nsid', 'any', or 'literal:...')\n * @template TType - The NSID string identifying this record type\n * @template TShape - The validator type for the record's data shape\n *\n * @example\n * ```ts\n * const postSchema = new RecordSchema(\n * 'tid',\n * 'app.bsky.feed.post',\n * l.object({ text: l.string(), createdAt: l.string() })\n * )\n * ```\n */\nexport class RecordSchema<\n const TKey extends LexiconRecordKey = any,\n const TType extends NsidString = any,\n const TShape extends Validator<{ [k: string]: unknown }> = any,\n> extends Schema<\n $Typed<InferInput<TShape>, TType>,\n $Typed<InferOutput<TShape>, TType>\n> {\n readonly type = 'record' as const\n\n keySchema: RecordKeySchema<TKey>\n\n constructor(\n readonly key: TKey,\n readonly $type: TType,\n readonly schema: TShape,\n ) {\n super()\n this.keySchema = recordKey(key)\n }\n\n isTypeOf<TValue extends { $type?: unknown }>(\n value: TValue,\n ): value is TypedRecord<TType, TValue> {\n return value.$type === this.$type\n }\n\n build(\n input: Omit<InferInput<this>, '$type'>,\n ): $Typed<InferOutput<this>, TType> {\n return this.parse($typed(input, this.$type))\n }\n\n $isTypeOf<TValue extends { $type?: unknown }>(\n value: TValue,\n ): value is TypedRecord<TType, TValue> {\n return this.isTypeOf<TValue>(value)\n }\n\n $build(\n input: Omit<InferInput<this>, '$type'>,\n ): $Typed<InferOutput<this>, TType> {\n return this.build(input)\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n const result = ctx.validate(input, this.schema)\n\n if (!result.success) {\n return result\n }\n\n if (result.value.$type !== this.$type) {\n return ctx.issueInvalidPropertyValue(result.value, '$type', [this.$type])\n }\n\n return result\n }\n}\n\nexport type RecordKeySchemaOutput<Key extends LexiconRecordKey> =\n Key extends 'any'\n ? string\n : Key extends 'tid'\n ? TidString\n : Key extends 'nsid'\n ? NsidString\n : Key extends `literal:${infer L extends string}`\n ? L\n : never\n\nexport type RecordKeySchema<Key extends LexiconRecordKey> = Schema<\n RecordKeySchemaOutput<Key>\n>\n\nconst keySchema = string({ minLength: 1 })\nconst tidSchema = string({ format: 'tid' })\nconst nsidSchema = string({ format: 'nsid' })\nconst selfLiteralSchema = literal('self')\n\nfunction recordKey<Key extends LexiconRecordKey>(\n key: Key,\n): RecordKeySchema<Key> {\n // @NOTE Use cached instances for common schemas\n if (key === 'any') return keySchema as any\n if (key === 'tid') return tidSchema as any\n if (key === 'nsid') return nsidSchema as any\n if (key.startsWith('literal:')) {\n const value = key.slice(8) as RecordKeySchemaOutput<Key>\n if (value === 'self') return selfLiteralSchema as any\n return literal(value)\n }\n\n throw new Error(`Unsupported record key type: ${key}`)\n}\n\n/**\n * Ensures that a `$type` used in a record is a valid NSID (i.e. no fragment).\n */\ntype AsNsid<T> = T extends `${string}#${string}` ? never : T\n\n/**\n * Creates a record schema for AT Protocol records.\n *\n * Records are the primary data unit in AT Protocol repositories. They have\n * a `$type` field identifying their Lexicon schema, and are stored at keys\n * following a specific format (TID, NSID, etc.).\n *\n * This function offers two overloads:\n * - One that infers the output type from the provided arguments (does not\n * support circular references)\n * - One with an explicitly defined interface for use with codegen and\n * circular references\n *\n * @param key - The record key type: 'tid', 'nsid', 'any', or 'literal:value'\n * @param type - The NSID identifying this record type (e.g., 'app.bsky.feed.post')\n * @param validator - Schema validator for the record's properties\n * @returns A new {@link RecordSchema} instance\n *\n * @example\n * ```ts\n * // Post record with TID key\n * const postSchema = l.record('tid', 'app.bsky.feed.post', l.object({\n * text: l.string({ maxGraphemes: 300 }),\n * createdAt: l.string({ format: 'datetime' }),\n * reply: l.optional(l.object({\n * root: l.ref(() => strongRefSchema),\n * parent: l.ref(() => strongRefSchema),\n * })),\n * }))\n *\n * // Profile record with literal 'self' key\n * const profileSchema = l.record('literal:self', 'app.bsky.actor.profile', l.object({\n * displayName: l.optional(l.string({ maxGraphemes: 64 })),\n * description: l.optional(l.string({ maxGraphemes: 256 })),\n * avatar: l.optional(l.blob({ accept: ['image/*'] })),\n * }))\n *\n * // Build a record with automatic $type injection\n * const post = postSchema.build({ text: 'Hello!', createdAt: new Date().toISOString() })\n * ```\n */\nexport function record<\n const K extends LexiconRecordKey,\n const T extends NsidString,\n const S extends Validator<{ [k: string]: unknown }>,\n>(key: K, type: AsNsid<T>, validator: S): RecordSchema<K, T, S>\nexport function record<\n const K extends LexiconRecordKey,\n const V extends { $type: NsidString },\n>(\n key: K,\n type: AsNsid<V['$type']>,\n validator: Validator<Omit<V, '$type'>>,\n): RecordSchema<K, V['$type'], Validator<Omit<V, '$type'>>>\n/*@__NO_SIDE_EFFECTS__*/\nexport function record<\n const K extends LexiconRecordKey,\n const T extends NsidString,\n const S extends Validator<{ [k: string]: unknown }>,\n>(key: K, type: T, validator: S) {\n return new RecordSchema<K, T, S>(key, type, validator)\n}\n"]}
|
package/dist/schema/ref.d.ts
CHANGED
|
@@ -1,12 +1,63 @@
|
|
|
1
1
|
import { InferInput, InferOutput, Schema, ValidationContext, Validator, WrappedValidator } from '../core.js';
|
|
2
|
+
/**
|
|
3
|
+
* Function type that returns a validator, used for lazy schema resolution.
|
|
4
|
+
*
|
|
5
|
+
* @template TValidator - The validator type that will be returned
|
|
6
|
+
*/
|
|
2
7
|
export type RefSchemaGetter<out TValidator extends Validator> = () => TValidator;
|
|
8
|
+
/**
|
|
9
|
+
* Schema for creating references to other schemas with lazy resolution.
|
|
10
|
+
*
|
|
11
|
+
* Useful for handling circular references or breaking module dependency cycles.
|
|
12
|
+
* The referenced schema is resolved lazily when first needed for validation.
|
|
13
|
+
*
|
|
14
|
+
* @template TValidator - The referenced validator type
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* // Self-referential schema for tree structure
|
|
19
|
+
* const nodeSchema = l.object({
|
|
20
|
+
* value: l.string(),
|
|
21
|
+
* children: l.array(l.ref(() => nodeSchema)),
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
3
25
|
export declare class RefSchema<const TValidator extends Validator> extends Schema<InferInput<TValidator>, InferOutput<TValidator>, TValidator['__lex']> implements WrappedValidator<TValidator> {
|
|
4
26
|
#private;
|
|
27
|
+
readonly type: "ref";
|
|
5
28
|
constructor(getter: RefSchemaGetter<TValidator>);
|
|
6
29
|
get validator(): TValidator;
|
|
7
30
|
unwrap(): TValidator;
|
|
8
31
|
validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<InferInput<TValidator>>;
|
|
9
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a reference schema with lazy resolution.
|
|
35
|
+
*
|
|
36
|
+
* Allows referencing schemas that may not be defined yet, enabling
|
|
37
|
+
* circular references and breaking dependency cycles. The getter function
|
|
38
|
+
* is called lazily when validation is first performed.
|
|
39
|
+
*
|
|
40
|
+
* @param get - Function that returns the referenced validator
|
|
41
|
+
* @returns A new {@link RefSchema} instance
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* // Circular reference - tree node that contains children of the same type
|
|
46
|
+
* const treeNodeSchema = l.object({
|
|
47
|
+
* name: l.string(),
|
|
48
|
+
* children: l.optional(l.array(l.ref(() => treeNodeSchema))),
|
|
49
|
+
* })
|
|
50
|
+
*
|
|
51
|
+
* // Cross-module reference
|
|
52
|
+
* const commentSchema = l.object({
|
|
53
|
+
* text: l.string(),
|
|
54
|
+
* author: l.ref(() => userSchema), // userSchema defined elsewhere
|
|
55
|
+
* })
|
|
56
|
+
*
|
|
57
|
+
* // Explicitly typed reference
|
|
58
|
+
* const itemSchema = l.ref<Item>(() => complexItemSchema)
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
10
61
|
export declare function ref<const TValidator extends Validator>(get: RefSchemaGetter<TValidator>): RefSchema<TValidator>;
|
|
11
62
|
export declare function ref<TInput, TOutput extends TInput = TInput>(get: RefSchemaGetter<Validator<TInput, TOutput>>): RefSchema<Validator<TInput, TOutput>>;
|
|
12
63
|
//# sourceMappingURL=ref.d.ts.map
|
package/dist/schema/ref.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../src/schema/ref.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,WAAW,EACX,MAAM,EACN,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EACjB,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,eAAe,CAAC,GAAG,CAAC,UAAU,SAAS,SAAS,IAAI,MAAM,UAAU,CAAA;AAEhF,qBAAa,SAAS,CAAC,KAAK,CAAC,UAAU,SAAS,SAAS,CACvD,SAAQ,MAAM,CACZ,UAAU,CAAC,UAAU,CAAC,EACtB,WAAW,CAAC,UAAU,CAAC,EACvB,UAAU,CAAC,OAAO,CAAC,CAErB,YAAW,gBAAgB,CAAC,UAAU,CAAC;;
|
|
1
|
+
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../src/schema/ref.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAA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