@atproto/lex-client 0.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.
- package/dist/agent.d.ts +33 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +21 -0
- package/dist/agent.js.map +1 -0
- package/dist/client.d.ts +456 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +236 -0
- package/dist/client.js.map +1 -0
- package/dist/error.d.ts +70 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +98 -0
- package/dist/error.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/lexicons/com/atproto/repo/createRecord.d.ts +3 -0
- package/dist/lexicons/com/atproto/repo/createRecord.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts +100 -0
- package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/repo/createRecord.defs.js +42 -0
- package/dist/lexicons/com/atproto/repo/createRecord.defs.js.map +1 -0
- package/dist/lexicons/com/atproto/repo/createRecord.js +10 -0
- package/dist/lexicons/com/atproto/repo/createRecord.js.map +1 -0
- package/dist/lexicons/com/atproto/repo/defs.d.ts +3 -0
- package/dist/lexicons/com/atproto/repo/defs.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/repo/defs.defs.d.ts +12 -0
- package/dist/lexicons/com/atproto/repo/defs.defs.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/repo/defs.defs.js +16 -0
- package/dist/lexicons/com/atproto/repo/defs.defs.js.map +1 -0
- package/dist/lexicons/com/atproto/repo/defs.js +10 -0
- package/dist/lexicons/com/atproto/repo/defs.js.map +1 -0
- package/dist/lexicons/com/atproto/repo/deleteRecord.d.ts +3 -0
- package/dist/lexicons/com/atproto/repo/deleteRecord.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts +70 -0
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js +33 -0
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js.map +1 -0
- package/dist/lexicons/com/atproto/repo/deleteRecord.js +10 -0
- package/dist/lexicons/com/atproto/repo/deleteRecord.js.map +1 -0
- package/dist/lexicons/com/atproto/repo/getRecord.d.ts +3 -0
- package/dist/lexicons/com/atproto/repo/getRecord.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts +82 -0
- package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/repo/getRecord.defs.js +30 -0
- package/dist/lexicons/com/atproto/repo/getRecord.defs.js.map +1 -0
- package/dist/lexicons/com/atproto/repo/getRecord.js +10 -0
- package/dist/lexicons/com/atproto/repo/getRecord.js.map +1 -0
- package/dist/lexicons/com/atproto/repo/listRecords.d.ts +3 -0
- package/dist/lexicons/com/atproto/repo/listRecords.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts +75 -0
- package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/repo/listRecords.defs.js +42 -0
- package/dist/lexicons/com/atproto/repo/listRecords.defs.js.map +1 -0
- package/dist/lexicons/com/atproto/repo/listRecords.js +10 -0
- package/dist/lexicons/com/atproto/repo/listRecords.js.map +1 -0
- package/dist/lexicons/com/atproto/repo/putRecord.d.ts +3 -0
- package/dist/lexicons/com/atproto/repo/putRecord.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts +110 -0
- package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/repo/putRecord.defs.js +46 -0
- package/dist/lexicons/com/atproto/repo/putRecord.defs.js.map +1 -0
- package/dist/lexicons/com/atproto/repo/putRecord.js +10 -0
- package/dist/lexicons/com/atproto/repo/putRecord.js.map +1 -0
- package/dist/lexicons/com/atproto/repo/uploadBlob.d.ts +3 -0
- package/dist/lexicons/com/atproto/repo/uploadBlob.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts +25 -0
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js +22 -0
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js.map +1 -0
- package/dist/lexicons/com/atproto/repo/uploadBlob.js +10 -0
- package/dist/lexicons/com/atproto/repo/uploadBlob.js.map +1 -0
- package/dist/lexicons/com/atproto/repo.d.ts +8 -0
- package/dist/lexicons/com/atproto/repo.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/repo.js +15 -0
- package/dist/lexicons/com/atproto/repo.js.map +1 -0
- package/dist/lexicons/com/atproto.d.ts +2 -0
- package/dist/lexicons/com/atproto.d.ts.map +1 -0
- package/dist/lexicons/com/atproto.js +9 -0
- package/dist/lexicons/com/atproto.js.map +1 -0
- package/dist/lexicons/com.d.ts +2 -0
- package/dist/lexicons/com.d.ts.map +1 -0
- package/dist/lexicons/com.js +9 -0
- package/dist/lexicons/com.js.map +1 -0
- package/dist/response.d.ts +21 -0
- package/dist/response.d.ts.map +1 -0
- package/dist/response.js +31 -0
- package/dist/response.js.map +1 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/xrpc.d.ts +37 -0
- package/dist/xrpc.d.ts.map +1 -0
- package/dist/xrpc.js +185 -0
- package/dist/xrpc.js.map +1 -0
- package/jest.config.js +5 -0
- package/package.json +46 -0
- package/scripts/lex-build.mjs +40 -0
- package/src/agent.ts +63 -0
- package/src/client.ts +513 -0
- package/src/error.ts +154 -0
- package/src/index.ts +6 -0
- package/src/response.ts +42 -0
- package/src/types.ts +21 -0
- package/src/xrpc.ts +335 -0
- package/tests/client.test.ts +370 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +7 -0
- package/tsconfig.tests.json +12 -0
package/dist/client.js
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Client = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const lex_schema_1 = require("@atproto/lex-schema");
|
|
6
|
+
const agent_js_1 = require("./agent.js");
|
|
7
|
+
const error_js_1 = require("./error.js");
|
|
8
|
+
const com = tslib_1.__importStar(require("./lexicons/com.js"));
|
|
9
|
+
const types_js_1 = require("./types.js");
|
|
10
|
+
const xrpc_js_1 = require("./xrpc.js");
|
|
11
|
+
class Client {
|
|
12
|
+
static appLabelers = [];
|
|
13
|
+
/**
|
|
14
|
+
* Configures the Client (or its sub classes) globally.
|
|
15
|
+
*/
|
|
16
|
+
static configure(opts) {
|
|
17
|
+
if (opts.appLabelers)
|
|
18
|
+
this.appLabelers = [...opts.appLabelers];
|
|
19
|
+
}
|
|
20
|
+
agent;
|
|
21
|
+
headers;
|
|
22
|
+
service;
|
|
23
|
+
labelers;
|
|
24
|
+
constructor(agent, options = {}) {
|
|
25
|
+
this.agent =
|
|
26
|
+
typeof agent === 'object' && 'fetchHandler' in agent
|
|
27
|
+
? agent
|
|
28
|
+
: (0, agent_js_1.buildAgent)(agent);
|
|
29
|
+
this.service = options.service;
|
|
30
|
+
this.labelers = new Set(options.labelers);
|
|
31
|
+
this.headers = new Headers(options.headers);
|
|
32
|
+
}
|
|
33
|
+
get did() {
|
|
34
|
+
return this.agent.did;
|
|
35
|
+
}
|
|
36
|
+
get assertDid() {
|
|
37
|
+
this.assertAuthenticated();
|
|
38
|
+
return this.did;
|
|
39
|
+
}
|
|
40
|
+
assertAuthenticated() {
|
|
41
|
+
if (!this.did)
|
|
42
|
+
throw new error_js_1.XrpcError(error_js_1.KnownError.AuthenticationRequired);
|
|
43
|
+
}
|
|
44
|
+
setLabelers(labelers = []) {
|
|
45
|
+
this.clearLabelers();
|
|
46
|
+
this.addLabelers(labelers);
|
|
47
|
+
}
|
|
48
|
+
addLabelers(labelers) {
|
|
49
|
+
for (const labeler of labelers)
|
|
50
|
+
this.labelers.add(labeler);
|
|
51
|
+
}
|
|
52
|
+
clearLabelers() {
|
|
53
|
+
this.labelers.clear();
|
|
54
|
+
}
|
|
55
|
+
fetchHandler(path, init) {
|
|
56
|
+
const headers = (0, xrpc_js_1.xrpcRequestHeaders)({
|
|
57
|
+
headers: init.headers,
|
|
58
|
+
service: this.service,
|
|
59
|
+
labelers: [
|
|
60
|
+
...this.constructor.appLabelers.map((l) => `${l};redact`),
|
|
61
|
+
...this.labelers,
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
// Incoming headers take precedence
|
|
65
|
+
for (const [key, value] of this.headers) {
|
|
66
|
+
if (!headers.has(key))
|
|
67
|
+
headers.set(key, value);
|
|
68
|
+
}
|
|
69
|
+
return this.agent.fetchHandler(path, { ...init, headers });
|
|
70
|
+
}
|
|
71
|
+
async xrpc(ns, options = {}) {
|
|
72
|
+
return (0, xrpc_js_1.xrpc)(this, ns, options);
|
|
73
|
+
}
|
|
74
|
+
async xrpcSafe(ns, options = {}) {
|
|
75
|
+
const schema = (0, types_js_1.getMain)(ns);
|
|
76
|
+
return this.xrpc(schema, options).catch((0, error_js_1.asXrpcRequestFailureFor)(schema));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @param rkey Leave `undefined` to have the server generate a TID.
|
|
80
|
+
*/
|
|
81
|
+
async createRecord(record, rkey, options) {
|
|
82
|
+
return this.xrpc(com.atproto.repo.createRecord.main, {
|
|
83
|
+
...options,
|
|
84
|
+
body: {
|
|
85
|
+
repo: options?.repo ?? this.assertDid,
|
|
86
|
+
collection: record.$type,
|
|
87
|
+
record,
|
|
88
|
+
rkey,
|
|
89
|
+
validate: options?.validate,
|
|
90
|
+
swapCommit: options?.swapCommit,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async createRecordsSafe(...args) {
|
|
95
|
+
return this.createRecord(...args).catch((0, error_js_1.asXrpcRequestFailureFor)(com.atproto.repo.createRecord.main));
|
|
96
|
+
}
|
|
97
|
+
async deleteRecord(collection, rkey, options) {
|
|
98
|
+
return this.xrpc(com.atproto.repo.deleteRecord.main, {
|
|
99
|
+
...options,
|
|
100
|
+
body: {
|
|
101
|
+
repo: options?.repo ?? this.assertDid,
|
|
102
|
+
collection,
|
|
103
|
+
rkey,
|
|
104
|
+
swapCommit: options?.swapCommit,
|
|
105
|
+
swapRecord: options?.swapRecord,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
async deleteRecordsSafe(...args) {
|
|
110
|
+
return this.deleteRecord(...args).catch((0, error_js_1.asXrpcRequestFailureFor)(com.atproto.repo.deleteRecord.main));
|
|
111
|
+
}
|
|
112
|
+
async getRecord(collection, rkey, options) {
|
|
113
|
+
return this.xrpc(com.atproto.repo.getRecord.main, {
|
|
114
|
+
...options,
|
|
115
|
+
params: {
|
|
116
|
+
repo: options?.repo ?? this.assertDid,
|
|
117
|
+
collection,
|
|
118
|
+
rkey,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
async getRecordsSafe(...args) {
|
|
123
|
+
return this.getRecord(...args).catch((0, error_js_1.asXrpcRequestFailureFor)(com.atproto.repo.getRecord.main));
|
|
124
|
+
}
|
|
125
|
+
async putRecord(record, rkey, options) {
|
|
126
|
+
return this.xrpc(com.atproto.repo.putRecord.main, {
|
|
127
|
+
...options,
|
|
128
|
+
body: {
|
|
129
|
+
repo: options?.repo ?? this.assertDid,
|
|
130
|
+
collection: record.$type,
|
|
131
|
+
rkey,
|
|
132
|
+
record,
|
|
133
|
+
validate: options?.validate,
|
|
134
|
+
swapCommit: options?.swapCommit,
|
|
135
|
+
swapRecord: options?.swapRecord,
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
async putRecordsSafe(...args) {
|
|
140
|
+
return this.putRecord(...args).catch((0, error_js_1.asXrpcRequestFailureFor)(com.atproto.repo.putRecord.main));
|
|
141
|
+
}
|
|
142
|
+
async listRecords(nsid, options) {
|
|
143
|
+
return this.xrpc(com.atproto.repo.listRecords.main, {
|
|
144
|
+
...options,
|
|
145
|
+
params: {
|
|
146
|
+
repo: options?.repo ?? this.assertDid,
|
|
147
|
+
collection: nsid,
|
|
148
|
+
cursor: options?.cursor,
|
|
149
|
+
limit: options?.limit,
|
|
150
|
+
reverse: options?.reverse,
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
async call(ns, arg, options = {}) {
|
|
155
|
+
const method = (0, types_js_1.getMain)(ns);
|
|
156
|
+
if (typeof method === 'function') {
|
|
157
|
+
return method(this, arg, options);
|
|
158
|
+
}
|
|
159
|
+
if (method instanceof lex_schema_1.Procedure) {
|
|
160
|
+
const body = arg;
|
|
161
|
+
const result = await this.xrpc(method, { ...options, body });
|
|
162
|
+
return result.body;
|
|
163
|
+
}
|
|
164
|
+
else if (method instanceof lex_schema_1.Query) {
|
|
165
|
+
const params = arg;
|
|
166
|
+
const result = await this.xrpc(method, { ...options, params });
|
|
167
|
+
return result.body;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
throw new TypeError('Invalid lexicon');
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async create(ns, input, options = {}) {
|
|
174
|
+
const schema = (0, types_js_1.getMain)(ns);
|
|
175
|
+
const record = options.validate
|
|
176
|
+
? schema.parse(schema.build(input))
|
|
177
|
+
: schema.build(input);
|
|
178
|
+
const rkey = options.rkey ?? getDefaultRecordKey(schema);
|
|
179
|
+
if (rkey !== undefined)
|
|
180
|
+
schema.keySchema.assert(rkey);
|
|
181
|
+
const response = await this.createRecord(record, rkey, options);
|
|
182
|
+
return response.body;
|
|
183
|
+
}
|
|
184
|
+
async delete(ns, options = {}) {
|
|
185
|
+
const schema = (0, types_js_1.getMain)(ns);
|
|
186
|
+
const rkey = schema.keySchema.parse(options.rkey ?? getLiteralRecordKey(schema));
|
|
187
|
+
const response = await this.deleteRecord(schema.$type, rkey, options);
|
|
188
|
+
return response.body;
|
|
189
|
+
}
|
|
190
|
+
async get(ns, options = {}) {
|
|
191
|
+
const schema = (0, types_js_1.getMain)(ns);
|
|
192
|
+
const rkey = schema.keySchema.parse(options.rkey ?? getLiteralRecordKey(schema));
|
|
193
|
+
const response = await this.getRecord(schema.$type, rkey, options);
|
|
194
|
+
const value = schema.parse(response.body.value);
|
|
195
|
+
return { ...response.body, value };
|
|
196
|
+
}
|
|
197
|
+
async put(ns, input, options = {}) {
|
|
198
|
+
const schema = (0, types_js_1.getMain)(ns);
|
|
199
|
+
const record = schema.build(input);
|
|
200
|
+
const rkey = options.rkey ?? getLiteralRecordKey(schema);
|
|
201
|
+
const response = await this.putRecord(record, rkey, options);
|
|
202
|
+
return response.body;
|
|
203
|
+
}
|
|
204
|
+
async list(ns, options) {
|
|
205
|
+
const schema = (0, types_js_1.getMain)(ns);
|
|
206
|
+
const { body } = await this.listRecords(schema.$type, options);
|
|
207
|
+
const records = [];
|
|
208
|
+
const invalid = [];
|
|
209
|
+
for (const record of body.records) {
|
|
210
|
+
const parsed = schema.validate(record.value);
|
|
211
|
+
if (parsed.success) {
|
|
212
|
+
records.push({ ...record, value: parsed.value });
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
invalid.push(record.value);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return { ...body, records, invalid };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.Client = Client;
|
|
222
|
+
function getDefaultRecordKey(schema) {
|
|
223
|
+
// Let the server generate the TID
|
|
224
|
+
if (schema.key === 'tid')
|
|
225
|
+
return undefined;
|
|
226
|
+
if (schema.key === 'any')
|
|
227
|
+
return undefined;
|
|
228
|
+
return getLiteralRecordKey(schema);
|
|
229
|
+
}
|
|
230
|
+
function getLiteralRecordKey(schema) {
|
|
231
|
+
if (schema.key.startsWith('literal:')) {
|
|
232
|
+
return schema.key.slice(8);
|
|
233
|
+
}
|
|
234
|
+
throw new TypeError(`An "rkey" must be provided for record key type "${schema.key}" (${schema.$type})`);
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;;AACA,oDAiB4B;AAC5B,yCAA4D;AAC5D,yCAKmB;AACnB,+DAAwC;AAExC,yCAAqE;AACrE,uCAAiE;AA2FjE,MAAa,MAAM;IACjB,MAAM,CAAC,WAAW,GAAmB,EAAE,CAAA;IAEvC;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,IAAqC;QACpD,IAAI,IAAI,CAAC,WAAW;YAAE,IAAI,CAAC,WAAW,GAAG,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAA;IAChE,CAAC;IAEe,KAAK,CAAO;IACZ,OAAO,CAAS;IAChB,OAAO,CAAU;IACjB,QAAQ,CAAU;IAElC,YAAY,KAA2B,EAAE,UAAyB,EAAE;QAClE,IAAI,CAAC,KAAK;YACR,OAAO,KAAK,KAAK,QAAQ,IAAI,cAAc,IAAI,KAAK;gBAClD,CAAC,CAAC,KAAK;gBACP,CAAC,CAAC,IAAA,qBAAU,EAAC,KAAK,CAAC,CAAA;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC9B,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;QACzC,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC7C,CAAC;IAED,IAAI,GAAG;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,KAAK,CAAC,CAAC,CAAC,CAAA;IAC5B,CAAC;IAED,MAAM,IAAI,SAAS,CACjB,mDAAmD,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,KAAK,GAAG,CACnF,CAAA;AACH,CAAC","sourcesContent":["import { LexMap, LexValue } from '@atproto/lex-data'\nimport {\n AtIdentifier,\n Did,\n Infer,\n InferProcedureInputBody,\n InferProcedureOutputBody,\n InferQueryOutputBody,\n InferQueryParameters,\n InferRecordKey,\n Nsid,\n Params,\n Procedure,\n Query,\n RecordKey,\n RecordSchema,\n Restricted,\n ValidationResult,\n} from '@atproto/lex-schema'\nimport { Agent, AgentOptions, buildAgent } from './agent.js'\nimport {\n KnownError,\n XrpcError,\n XrpcRequestFailure,\n asXrpcRequestFailureFor,\n} from './error.js'\nimport * as com from './lexicons/com.js'\nimport { XrpcResponse, XrpcResponseBody } from './response.js'\nimport { CallOptions, Namespace, Service, getMain } from './types.js'\nimport { XrpcOptions, xrpc, xrpcRequestHeaders } from './xrpc.js'\n\nexport type ClientOptions = {\n labelers?: Iterable<Did>\n headers?: HeadersInit\n service?: Service\n}\n\nexport type Action<I = any, O = any> = (\n client: Client,\n input: I,\n options: CallOptions,\n) => O | Promise<O>\nexport type InferActionInput<A extends Action> =\n A extends Action<infer I, any> ? I : never\nexport type InferActionOutput<A extends Action> =\n A extends Action<any, infer O> ? O : never\n\nexport type CreateRecordOptions = CallOptions & {\n repo?: AtIdentifier\n swapCommit?: string\n validate?: boolean\n}\n\nexport type DeleteRecordOptions = CallOptions & {\n repo?: AtIdentifier\n swapCommit?: string\n swapRecord?: string\n}\n\nexport type GetRecordOptions = CallOptions & {\n repo?: AtIdentifier\n}\n\nexport type PutRecordOptions = CallOptions & {\n repo?: AtIdentifier\n swapCommit?: string\n swapRecord?: string\n validate?: boolean\n}\n\nexport type ListRecordsOptions = CallOptions & {\n repo?: AtIdentifier\n limit?: number\n cursor?: string\n reverse?: boolean\n}\n\nexport type RecordKeyOptions<\n T extends RecordSchema,\n AlsoOptionalWhenRecordKeyIs extends RecordKey = never,\n> = T['key'] extends `literal:${string}` | AlsoOptionalWhenRecordKeyIs\n ? { rkey?: InferRecordKey<T> }\n : { rkey: InferRecordKey<T> }\n\nexport type CreateOptions<T extends RecordSchema> = CreateRecordOptions &\n RecordKeyOptions<T, 'tid'>\nexport type CreateOutput = XrpcResponseBody<\n typeof com.atproto.repo.createRecord.main\n>\n\nexport type DeleteOptions<T extends RecordSchema> = DeleteRecordOptions &\n RecordKeyOptions<T>\nexport type DeleteOutput = XrpcResponseBody<\n typeof com.atproto.repo.deleteRecord.main\n>\nexport type GetOptions<T extends RecordSchema> = GetRecordOptions &\n RecordKeyOptions<T>\nexport type GetOutput<T extends RecordSchema> = Omit<\n XrpcResponseBody<typeof com.atproto.repo.getRecord.main>,\n 'value'\n> & { value: Infer<T> }\n\nexport type PutOptions<T extends RecordSchema> = PutRecordOptions &\n RecordKeyOptions<T>\nexport type PutOutput = XrpcResponseBody<typeof com.atproto.repo.putRecord.main>\n\nexport type ListOptions = ListRecordsOptions\nexport type ListOutput<T extends RecordSchema> = XrpcResponseBody<\n typeof com.atproto.repo.listRecords.main\n> & {\n records: ListRecord<T>[]\n // @NOTE Because the schema uses \"type\": \"unknown\" instead of an open union,\n // we have to use LexMap instead of TypedObject here.\n invalid: LexMap[]\n}\nexport type ListRecord<T extends RecordSchema> =\n com.atproto.repo.listRecords.DefRecord & {\n value: Infer<T>\n }\n\nexport class Client implements Agent {\n static appLabelers: readonly Did[] = []\n\n /**\n * Configures the Client (or its sub classes) globally.\n */\n static configure(opts: { appLabelers?: Iterable<Did> }) {\n if (opts.appLabelers) this.appLabelers = [...opts.appLabelers]\n }\n\n public readonly agent: Agent\n public readonly headers: Headers\n public readonly service?: Service\n public readonly labelers: Set<Did>\n\n constructor(agent: Agent | AgentOptions, options: ClientOptions = {}) {\n this.agent =\n typeof agent === 'object' && 'fetchHandler' in agent\n ? agent\n : buildAgent(agent)\n this.service = options.service\n this.labelers = new Set(options.labelers)\n this.headers = new Headers(options.headers)\n }\n\n get did(): Did | undefined {\n return this.agent.did\n }\n\n get assertDid(): Did {\n this.assertAuthenticated()\n return this.did\n }\n\n public assertAuthenticated(): asserts this is { did: Did } {\n if (!this.did) throw new XrpcError(KnownError.AuthenticationRequired)\n }\n\n public setLabelers(labelers: Iterable<Did> = []) {\n this.clearLabelers()\n this.addLabelers(labelers)\n }\n\n public addLabelers(labelers: Iterable<Did>) {\n for (const labeler of labelers) this.labelers.add(labeler)\n }\n\n public clearLabelers() {\n this.labelers.clear()\n }\n\n public fetchHandler(path: string, init: RequestInit): Promise<Response> {\n const headers = xrpcRequestHeaders({\n headers: init.headers,\n service: this.service,\n labelers: [\n ...(this.constructor as typeof Client).appLabelers.map(\n (l) => `${l};redact` as const,\n ),\n ...this.labelers,\n ],\n })\n\n // Incoming headers take precedence\n for (const [key, value] of this.headers) {\n if (!headers.has(key)) headers.set(key, value)\n }\n\n return this.agent.fetchHandler(path, { ...init, headers })\n }\n\n async xrpc<const M extends Query | Procedure>(\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Namespace<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n ): Promise<XrpcResponse<M>>\n async xrpc<const M extends Query | Procedure>(\n ns: Namespace<M>,\n options: XrpcOptions<M>,\n ): Promise<XrpcResponse<M>>\n async xrpc<const M extends Query | Procedure>(\n ns: Namespace<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n ): Promise<XrpcResponse<M>> {\n return xrpc(this, ns, options)\n }\n\n async xrpcSafe<const M extends Query | Procedure>(\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Namespace<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n ): Promise<XrpcResponse<M> | XrpcRequestFailure<M>>\n async xrpcSafe<const M extends Query | Procedure>(\n ns: Namespace<M>,\n options: XrpcOptions<M>,\n ): Promise<XrpcResponse<M> | XrpcRequestFailure<M>>\n async xrpcSafe<const M extends Query | Procedure>(\n ns: Namespace<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n ): Promise<unknown> {\n const schema = getMain(ns)\n return this.xrpc(schema, options).catch(asXrpcRequestFailureFor(schema))\n }\n\n /**\n * @param rkey Leave `undefined` to have the server generate a TID.\n */\n public async createRecord(\n record: { $type: Nsid } & LexMap,\n rkey?: string,\n options?: CreateRecordOptions,\n ) {\n return this.xrpc(com.atproto.repo.createRecord.main, {\n ...options,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection: record.$type,\n record,\n rkey,\n validate: options?.validate,\n swapCommit: options?.swapCommit,\n },\n })\n }\n\n async createRecordsSafe(...args: Parameters<Client['createRecord']>) {\n return this.createRecord(...args).catch(\n asXrpcRequestFailureFor(com.atproto.repo.createRecord.main),\n )\n }\n\n async deleteRecord(\n collection: Nsid,\n rkey: string,\n options?: DeleteRecordOptions,\n ) {\n return this.xrpc(com.atproto.repo.deleteRecord.main, {\n ...options,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection,\n rkey,\n swapCommit: options?.swapCommit,\n swapRecord: options?.swapRecord,\n },\n })\n }\n\n async deleteRecordsSafe(...args: Parameters<Client['deleteRecord']>) {\n return this.deleteRecord(...args).catch(\n asXrpcRequestFailureFor(com.atproto.repo.deleteRecord.main),\n )\n }\n\n public async getRecord(\n collection: Nsid,\n rkey: string,\n options?: GetRecordOptions,\n ) {\n return this.xrpc(com.atproto.repo.getRecord.main, {\n ...options,\n params: {\n repo: options?.repo ?? this.assertDid,\n collection,\n rkey,\n },\n })\n }\n\n async getRecordsSafe(...args: Parameters<Client['getRecord']>) {\n return this.getRecord(...args).catch(\n asXrpcRequestFailureFor(com.atproto.repo.getRecord.main),\n )\n }\n\n async putRecord(\n record: { $type: Nsid } & LexMap,\n rkey: string,\n options?: PutRecordOptions,\n ) {\n return this.xrpc(com.atproto.repo.putRecord.main, {\n ...options,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection: record.$type,\n rkey,\n record,\n validate: options?.validate,\n swapCommit: options?.swapCommit,\n swapRecord: options?.swapRecord,\n },\n })\n }\n\n async putRecordsSafe(...args: Parameters<Client['putRecord']>) {\n return this.putRecord(...args).catch(\n asXrpcRequestFailureFor(com.atproto.repo.putRecord.main),\n )\n }\n\n async listRecords(nsid: Nsid, options?: ListRecordsOptions) {\n return this.xrpc(com.atproto.repo.listRecords.main, {\n ...options,\n params: {\n repo: options?.repo ?? this.assertDid,\n collection: nsid,\n cursor: options?.cursor,\n limit: options?.limit,\n reverse: options?.reverse,\n },\n })\n }\n\n public async call<const T extends Action>(\n ns: Namespace<T>,\n input: InferActionInput<T>,\n options?: CallOptions,\n ): Promise<InferActionOutput<T>>\n public async call<const T extends Procedure>(\n ns: Namespace<T>,\n body: InferProcedureInputBody<T>,\n options?: CallOptions,\n ): Promise<InferProcedureOutputBody<T>>\n public async call<const T extends Query>(\n ns: NonNullable<unknown> extends InferQueryParameters<T>\n ? Namespace<T>\n : Restricted<'This query type requires a \"params\" argument'>,\n ): Promise<InferQueryOutputBody<T>>\n public async call<const T extends Query>(\n ns: Namespace<T>,\n params: InferQueryParameters<T>,\n options?: CallOptions,\n ): Promise<InferQueryOutputBody<T>>\n public async call(\n ns: Namespace<Action> | Namespace<Procedure> | Namespace<Query>,\n arg?: LexValue | Params,\n options: CallOptions = {},\n ): Promise<unknown> {\n const method = getMain(ns)\n\n if (typeof method === 'function') {\n return method(this, arg, options)\n }\n\n if (method instanceof Procedure) {\n const body = arg as LexValue | undefined\n const result = await this.xrpc(method, { ...options, body })\n return result.body\n } else if (method instanceof Query) {\n const params = arg as Params | undefined\n const result = await this.xrpc(method, { ...options, params })\n return result.body\n } else {\n throw new TypeError('Invalid lexicon')\n }\n }\n\n public async create<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends CreateOptions<T>\n ? Namespace<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n input: Omit<Infer<T>, '$type'>,\n ): Promise<CreateOutput>\n public async create<const T extends RecordSchema>(\n ns: Namespace<T>,\n input: Omit<Infer<T>, '$type'>,\n options: CreateOptions<T>,\n ): Promise<CreateOutput>\n public async create<const T extends RecordSchema>(\n ns: Namespace<T>,\n input: Omit<Infer<T>, '$type'>,\n options: CreateOptions<T> = {} as CreateOptions<T>,\n ): Promise<CreateOutput> {\n const schema: T = getMain(ns)\n const record = options.validate\n ? schema.parse(schema.build(input))\n : schema.build(input)\n const rkey = options.rkey ?? getDefaultRecordKey(schema)\n if (rkey !== undefined) schema.keySchema.assert(rkey)\n const response = await this.createRecord(record, rkey, options)\n return response.body\n }\n\n public async delete<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends DeleteOptions<T>\n ? Namespace<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n ): Promise<DeleteOutput>\n public async delete<const T extends RecordSchema>(\n ns: Namespace<T>,\n options?: DeleteOptions<T>,\n ): Promise<DeleteOutput>\n public async delete<const T extends RecordSchema>(\n ns: Namespace<T>,\n options: DeleteOptions<T> = {} as DeleteOptions<T>,\n ): Promise<DeleteOutput> {\n const schema = getMain(ns)\n const rkey = schema.keySchema.parse(\n options.rkey ?? getLiteralRecordKey(schema),\n )\n const response = await this.deleteRecord(schema.$type, rkey, options)\n return response.body\n }\n\n public async get<const T extends RecordSchema>(\n ns: T['key'] extends `literal:${string}`\n ? Namespace<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n ): Promise<GetOutput<T>>\n public async get<const T extends RecordSchema>(\n ns: Namespace<T>,\n options?: GetOptions<T>,\n ): Promise<GetOutput<T>>\n public async get<const T extends RecordSchema>(\n ns: Namespace<T>,\n options: GetOptions<T> = {} as GetOptions<T>,\n ): Promise<GetOutput<T>> {\n const schema = getMain(ns)\n const rkey = schema.keySchema.parse(\n options.rkey ?? getLiteralRecordKey(schema),\n )\n const response = await this.getRecord(schema.$type, rkey, options)\n const value = schema.parse(response.body.value) as Infer<T>\n return { ...response.body, value }\n }\n\n public async put<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends PutOptions<T>\n ? Namespace<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n input: Omit<Infer<T>, '$type'>,\n ): Promise<PutOutput>\n public async put<const T extends RecordSchema>(\n ns: Namespace<T>,\n input: Omit<Infer<T>, '$type'>,\n options: PutOptions<T>,\n ): Promise<PutOutput>\n public async put<const T extends RecordSchema>(\n ns: Namespace<T>,\n input: Omit<Infer<T>, '$type'>,\n options: PutOptions<T> = {} as PutOptions<T>,\n ): Promise<PutOutput> {\n const schema = getMain(ns)\n const record = schema.build(input)\n const rkey = options.rkey ?? getLiteralRecordKey(schema)\n const response = await this.putRecord(record, rkey, options)\n return response.body\n }\n\n async list<const T extends RecordSchema>(\n ns: Namespace<T>,\n options?: ListOptions,\n ): Promise<ListOutput<T>> {\n const schema = getMain(ns)\n const { body } = await this.listRecords(schema.$type, options)\n\n const records: ListRecord<T>[] = []\n const invalid: LexMap[] = []\n\n for (const record of body.records) {\n const parsed = schema.validate(record.value) as ValidationResult<Infer<T>>\n if (parsed.success) {\n records.push({ ...record, value: parsed.value })\n } else {\n invalid.push(record.value)\n }\n }\n\n return { ...body, records, invalid }\n }\n}\n\nfunction getDefaultRecordKey<const T extends RecordSchema>(\n schema: T,\n): undefined | InferRecordKey<T> {\n // Let the server generate the TID\n if (schema.key === 'tid') return undefined\n if (schema.key === 'any') return undefined\n\n return getLiteralRecordKey(schema)\n}\n\nfunction getLiteralRecordKey<const T extends RecordSchema>(\n schema: T,\n): InferRecordKey<T> {\n if (schema.key.startsWith('literal:')) {\n return schema.key.slice(8)\n }\n\n throw new TypeError(\n `An \"rkey\" must be provided for record key type \"${schema.key}\" (${schema.$type})`,\n )\n}\n"]}
|
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { LexValue } from '@atproto/lex-data';
|
|
2
|
+
import { Infer, ObjectSchema, Procedure, Query, ResultFailure, StringSchema } from '@atproto/lex-schema';
|
|
3
|
+
export declare enum KnownError {
|
|
4
|
+
Unknown = "Unknown",
|
|
5
|
+
AuthenticationRequired = "AuthenticationRequired",
|
|
6
|
+
Forbidden = "Forbidden",
|
|
7
|
+
InternalServerError = "InternalServerError",
|
|
8
|
+
InvalidRequest = "InvalidRequest",
|
|
9
|
+
InvalidResponse = "InvalidResponse",
|
|
10
|
+
MethodNotImplemented = "MethodNotImplemented",
|
|
11
|
+
NotAcceptable = "NotAcceptable",
|
|
12
|
+
NotEnoughResources = "NotEnoughResources",
|
|
13
|
+
PayloadTooLarge = "PayloadTooLarge",
|
|
14
|
+
RateLimitExceeded = "RateLimitExceeded",
|
|
15
|
+
UnsupportedMediaType = "UnsupportedMediaType",
|
|
16
|
+
UpstreamFailure = "UpstreamFailure",
|
|
17
|
+
UpstreamTimeout = "UpstreamTimeout",
|
|
18
|
+
XRPCNotSupported = "XRPCNotSupported"
|
|
19
|
+
}
|
|
20
|
+
export type XrpcFailure<N extends string, E> = ResultFailure<E> & {
|
|
21
|
+
name: N;
|
|
22
|
+
};
|
|
23
|
+
export type XrpcErrorName = Infer<typeof xrpcErrorNameSchema>;
|
|
24
|
+
export declare const xrpcErrorNameSchema: StringSchema<{
|
|
25
|
+
readonly minLength: 1;
|
|
26
|
+
readonly knownValues: KnownError[];
|
|
27
|
+
}>;
|
|
28
|
+
export type XrpcErrorBody<N extends XrpcErrorName = XrpcErrorName> = {
|
|
29
|
+
error: N;
|
|
30
|
+
message?: string;
|
|
31
|
+
};
|
|
32
|
+
export declare const xrpcErrorBodySchema: ObjectSchema<{
|
|
33
|
+
readonly error: StringSchema<{
|
|
34
|
+
readonly minLength: 1;
|
|
35
|
+
readonly knownValues: KnownError[];
|
|
36
|
+
}>;
|
|
37
|
+
readonly message: StringSchema<{}>;
|
|
38
|
+
}, {
|
|
39
|
+
readonly required: readonly ["error"];
|
|
40
|
+
}, XrpcErrorBody<KnownError | import("@atproto/lex-schema").UnknownString>>;
|
|
41
|
+
/**
|
|
42
|
+
* @implements {XrpcFailure<N, XrpcError<N>>} for convenience in result handling contexts.
|
|
43
|
+
*/
|
|
44
|
+
export declare class XrpcError<N extends XrpcErrorName = XrpcErrorName> extends Error implements XrpcFailure<N, XrpcError<N>> {
|
|
45
|
+
readonly name: N;
|
|
46
|
+
constructor(name: N, message?: string, options?: ErrorOptions);
|
|
47
|
+
/** @see {@link ResultFailure.success} */
|
|
48
|
+
readonly success: false;
|
|
49
|
+
/** @see {@link ResultFailure.error} */
|
|
50
|
+
get error(): this;
|
|
51
|
+
static from(cause: unknown, message?: string): XrpcError;
|
|
52
|
+
}
|
|
53
|
+
export declare class XrpcServiceError<N extends XrpcErrorName = XrpcErrorName> extends XrpcError<N> {
|
|
54
|
+
readonly status: number;
|
|
55
|
+
readonly headers: Headers;
|
|
56
|
+
readonly body: undefined | LexValue;
|
|
57
|
+
constructor(name: N, status: number, headers: Headers, body: undefined | LexValue, message?: string, options?: ErrorOptions);
|
|
58
|
+
}
|
|
59
|
+
export declare class XrpcResponseError<N extends XrpcErrorName = XrpcErrorName, B extends XrpcErrorBody<N> = XrpcErrorBody<N>> extends XrpcError<N> {
|
|
60
|
+
readonly status: number;
|
|
61
|
+
readonly headers: Headers;
|
|
62
|
+
readonly encoding: undefined | string;
|
|
63
|
+
readonly body: B;
|
|
64
|
+
constructor(status: number, headers: Headers, encoding: undefined | string, body: B, options?: ErrorOptions);
|
|
65
|
+
}
|
|
66
|
+
export type XrpcRequestFailure<M extends Procedure | Query> = (M extends {
|
|
67
|
+
errors: readonly (infer N extends string)[];
|
|
68
|
+
} ? XrpcResponseError<N> : never) | XrpcFailure<'Unknown', XrpcResponseError<string>> | XrpcFailure<'UnexpectedError', unknown>;
|
|
69
|
+
export declare function asXrpcRequestFailureFor<M extends Procedure | Query>(schema: M): (error: unknown) => XrpcRequestFailure<M>;
|
|
70
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,m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C,GAEjD,WAAW,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAA;AAE3C,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,SAAS,GAAG,KAAK,EACjE,MAAM,EAAE,CAAC,GAGmC,CAC1C,KAAK,EAAE,OAAO,KACX,kBAAkB,CAAC,CAAC,CAAC,CAC3B"}
|
package/dist/error.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XrpcResponseError = exports.XrpcServiceError = exports.XrpcError = exports.xrpcErrorBodySchema = exports.xrpcErrorNameSchema = exports.KnownError = void 0;
|
|
4
|
+
exports.asXrpcRequestFailureFor = asXrpcRequestFailureFor;
|
|
5
|
+
const lex_schema_1 = require("@atproto/lex-schema");
|
|
6
|
+
var KnownError;
|
|
7
|
+
(function (KnownError) {
|
|
8
|
+
KnownError["Unknown"] = "Unknown";
|
|
9
|
+
KnownError["AuthenticationRequired"] = "AuthenticationRequired";
|
|
10
|
+
KnownError["Forbidden"] = "Forbidden";
|
|
11
|
+
KnownError["InternalServerError"] = "InternalServerError";
|
|
12
|
+
KnownError["InvalidRequest"] = "InvalidRequest";
|
|
13
|
+
KnownError["InvalidResponse"] = "InvalidResponse";
|
|
14
|
+
KnownError["MethodNotImplemented"] = "MethodNotImplemented";
|
|
15
|
+
KnownError["NotAcceptable"] = "NotAcceptable";
|
|
16
|
+
KnownError["NotEnoughResources"] = "NotEnoughResources";
|
|
17
|
+
KnownError["PayloadTooLarge"] = "PayloadTooLarge";
|
|
18
|
+
KnownError["RateLimitExceeded"] = "RateLimitExceeded";
|
|
19
|
+
KnownError["UnsupportedMediaType"] = "UnsupportedMediaType";
|
|
20
|
+
KnownError["UpstreamFailure"] = "UpstreamFailure";
|
|
21
|
+
KnownError["UpstreamTimeout"] = "UpstreamTimeout";
|
|
22
|
+
KnownError["XRPCNotSupported"] = "XRPCNotSupported";
|
|
23
|
+
})(KnownError || (exports.KnownError = KnownError = {}));
|
|
24
|
+
exports.xrpcErrorNameSchema = new lex_schema_1.StringSchema({
|
|
25
|
+
minLength: 1,
|
|
26
|
+
knownValues: Object.keys(KnownError),
|
|
27
|
+
});
|
|
28
|
+
exports.xrpcErrorBodySchema = new lex_schema_1.ObjectSchema({ error: exports.xrpcErrorNameSchema, message: new lex_schema_1.StringSchema({}) }, { required: ['error'] });
|
|
29
|
+
/**
|
|
30
|
+
* @implements {XrpcFailure<N, XrpcError<N>>} for convenience in result handling contexts.
|
|
31
|
+
*/
|
|
32
|
+
class XrpcError extends Error {
|
|
33
|
+
name;
|
|
34
|
+
constructor(name, message = name === KnownError.InvalidResponse
|
|
35
|
+
? `XRPC service returned an invalid response`
|
|
36
|
+
: name === KnownError.InternalServerError
|
|
37
|
+
? `XRPC service encountered an internal error`
|
|
38
|
+
: name === KnownError.UpstreamFailure ||
|
|
39
|
+
name === KnownError.UpstreamTimeout
|
|
40
|
+
? `XRPC service upstream error`
|
|
41
|
+
: `XRPC ${name} error`, options) {
|
|
42
|
+
super(message, options);
|
|
43
|
+
this.name = name;
|
|
44
|
+
}
|
|
45
|
+
/** @see {@link ResultFailure.success} */
|
|
46
|
+
success = false;
|
|
47
|
+
/** @see {@link ResultFailure.error} */
|
|
48
|
+
get error() {
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
static from(cause, message) {
|
|
52
|
+
if (cause instanceof XrpcError) {
|
|
53
|
+
return cause;
|
|
54
|
+
}
|
|
55
|
+
return new XrpcError('Unknown', message ?? (cause instanceof Error ? cause.message : undefined), { cause });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.XrpcError = XrpcError;
|
|
59
|
+
class XrpcServiceError extends XrpcError {
|
|
60
|
+
status;
|
|
61
|
+
headers;
|
|
62
|
+
body;
|
|
63
|
+
constructor(name, status, headers, body, message, options) {
|
|
64
|
+
super(name, message, options);
|
|
65
|
+
this.status = status;
|
|
66
|
+
this.headers = headers;
|
|
67
|
+
this.body = body;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.XrpcServiceError = XrpcServiceError;
|
|
71
|
+
class XrpcResponseError extends XrpcError {
|
|
72
|
+
status;
|
|
73
|
+
headers;
|
|
74
|
+
encoding;
|
|
75
|
+
body;
|
|
76
|
+
constructor(status, headers, encoding, body, options) {
|
|
77
|
+
super(body.error, body.message, options);
|
|
78
|
+
this.status = status;
|
|
79
|
+
this.headers = headers;
|
|
80
|
+
this.encoding = encoding;
|
|
81
|
+
this.body = body;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.XrpcResponseError = XrpcResponseError;
|
|
85
|
+
function asXrpcRequestFailureFor(schema) {
|
|
86
|
+
// Performance: Using .bind instead of arrow function to avoid creating a closure
|
|
87
|
+
return asXrpcRequestFailure.bind(schema);
|
|
88
|
+
}
|
|
89
|
+
function asXrpcRequestFailure(error) {
|
|
90
|
+
if (!(error instanceof XrpcResponseError)) {
|
|
91
|
+
return { success: false, error, name: 'UnexpectedError' };
|
|
92
|
+
}
|
|
93
|
+
if (!this.errors.includes(error.name)) {
|
|
94
|
+
return { success: false, error, name: 'Unknown' };
|
|
95
|
+
}
|
|
96
|
+
return error;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAmIA,0DAOC;AAzID,oDAQ4B;AAE5B,IAAY,UAgBX;AAhBD,WAAY,UAAU;IACpB,iCAAmB,CAAA;IACnB,+DAAiD,CAAA;IACjD,qCAAuB,CAAA;IACvB,yDAA2C,CAAA;IAC3C,+CAAiC,CAAA;IACjC,iDAAmC,CAAA;IACnC,2DAA6C,CAAA;IAC7C,6CAA+B,CAAA;IAC/B,uDAAyC,CAAA;IACzC,iDAAmC,CAAA;IACnC,qDAAuC,CAAA;IACvC,2DAA6C,CAAA;IAC7C,iDAA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E,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,CAAA;IACnD,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import { LexValue } from '@atproto/lex-data'\nimport {\n Infer,\n ObjectSchema,\n Procedure,\n Query,\n ResultFailure,\n StringSchema,\n Validator,\n} from '@atproto/lex-schema'\n\nexport enum KnownError {\n Unknown = 'Unknown',\n AuthenticationRequired = 'AuthenticationRequired',\n Forbidden = 'Forbidden',\n InternalServerError = 'InternalServerError',\n InvalidRequest = 'InvalidRequest',\n InvalidResponse = 'InvalidResponse',\n MethodNotImplemented = 'MethodNotImplemented',\n NotAcceptable = 'NotAcceptable',\n NotEnoughResources = 'NotEnoughResources',\n PayloadTooLarge = 'PayloadTooLarge',\n RateLimitExceeded = 'RateLimitExceeded',\n UnsupportedMediaType = 'UnsupportedMediaType',\n UpstreamFailure = 'UpstreamFailure',\n UpstreamTimeout = 'UpstreamTimeout',\n XRPCNotSupported = 'XRPCNotSupported',\n}\n\nexport type XrpcFailure<N extends string, E> = ResultFailure<E> & {\n name: N\n}\n\nexport type XrpcErrorName = Infer<typeof xrpcErrorNameSchema>\nexport const xrpcErrorNameSchema = new StringSchema({\n minLength: 1,\n knownValues: Object.keys(KnownError) as KnownError[],\n})\n\nexport type XrpcErrorBody<N extends XrpcErrorName = XrpcErrorName> = {\n error: N\n message?: string\n}\nexport const xrpcErrorBodySchema = new ObjectSchema(\n { error: xrpcErrorNameSchema, message: new StringSchema({}) },\n { required: ['error'] },\n) satisfies Validator<XrpcErrorBody>\n\n/**\n * @implements {XrpcFailure<N, XrpcError<N>>} for convenience in result handling contexts.\n */\nexport class XrpcError<N extends XrpcErrorName = XrpcErrorName>\n extends Error\n implements XrpcFailure<N, XrpcError<N>>\n{\n constructor(\n public readonly name: N,\n message: string = name === KnownError.InvalidResponse\n ? `XRPC service returned an invalid response`\n : name === KnownError.InternalServerError\n ? `XRPC service encountered an internal error`\n : name === KnownError.UpstreamFailure ||\n name === KnownError.UpstreamTimeout\n ? `XRPC service upstream error`\n : `XRPC ${name} error`,\n options?: ErrorOptions,\n ) {\n super(message, options)\n }\n\n /** @see {@link ResultFailure.success} */\n readonly success = false as const\n\n /** @see {@link ResultFailure.error} */\n get error(): this {\n return this\n }\n\n static from(cause: unknown, message?: string): XrpcError {\n if (cause instanceof XrpcError) {\n return cause\n }\n return new XrpcError(\n 'Unknown',\n message ?? (cause instanceof Error ? cause.message : undefined),\n { cause },\n )\n }\n}\n\nexport class XrpcServiceError<\n N extends XrpcErrorName = XrpcErrorName,\n> extends XrpcError<N> {\n constructor(\n name: N,\n public readonly status: number,\n public readonly headers: Headers,\n public readonly body: undefined | LexValue,\n message?: string,\n options?: ErrorOptions,\n ) {\n super(name, message, options)\n }\n}\n\nexport class XrpcResponseError<\n N extends XrpcErrorName = XrpcErrorName,\n B extends XrpcErrorBody<N> = XrpcErrorBody<N>,\n> extends XrpcError<N> {\n constructor(\n public readonly status: number,\n public readonly headers: Headers,\n public readonly encoding: undefined | string,\n public readonly body: B,\n options?: ErrorOptions,\n ) {\n super(body.error, body.message, options)\n }\n}\n\nexport type XrpcRequestFailure<M extends Procedure | Query> =\n // The server responded with a declared error.\n | (M extends { errors: readonly (infer N extends string)[] }\n ? XrpcResponseError<N> // implements XrpcRequestFailure<N, XrpcResponseError<N>>\n : never)\n // The server responded with an error that is not declared in the method's\n // `errors` list.\n | XrpcFailure<'Unknown', XrpcResponseError<string>>\n // An unexpected error occurred (e.g., network error, invalid response, etc.)\n | XrpcFailure<'UnexpectedError', unknown>\n\nexport function asXrpcRequestFailureFor<M extends Procedure | Query>(\n schema: M,\n) {\n // Performance: Using .bind instead of arrow function to avoid creating a closure\n return asXrpcRequestFailure.bind(schema) as (\n error: unknown,\n ) => XrpcRequestFailure<M>\n}\n\nfunction asXrpcRequestFailure<M extends Procedure | Query>(\n this: M,\n error: unknown,\n): XrpcRequestFailure<M> {\n if (!(error instanceof XrpcResponseError)) {\n return { success: false, error, name: 'UnexpectedError' }\n }\n\n if (!this.errors.includes(error.name)) {\n return { success: false, error, name: 'Unknown' }\n }\n\n return error\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./agent.js"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./client.js"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./error.js"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./response.js"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./types.js"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./xrpc.js"), exports);
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAA0B;AAC1B,sDAA2B;AAC3B,qDAA0B;AAC1B,wDAA6B;AAC7B,qDAA0B;AAC1B,oDAAyB","sourcesContent":["export * from './agent.js'\nexport * from './client.js'\nexport * from './error.js'\nexport * from './response.js'\nexport * from './types.js'\nexport * from './xrpc.js'\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRecord.d.ts","sourceRoot":"","sources":["../../../../../src/lexicons/com/atproto/repo/createRecord.ts"],"names":[],"mappings":"AAIA,cAAc,wBAAwB,CAAA;AACtC,OAAO,KAAK,KAAK,MAAM,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { l } from '@atproto/lex-schema';
|
|
2
|
+
import * as RepoDefs from './defs.defs.js';
|
|
3
|
+
declare const $nsid = "com.atproto.repo.createRecord";
|
|
4
|
+
export { $nsid };
|
|
5
|
+
/**
|
|
6
|
+
* Create a single new repository record. Requires auth, implemented by PDS.
|
|
7
|
+
*/
|
|
8
|
+
declare const main: l.Procedure<"com.atproto.repo.createRecord", l.ParamsSchema<{}, l.ParamsSchemaOptions, {}>, l.Payload<"application/json", l.ObjectSchema<{
|
|
9
|
+
readonly repo: l.StringSchema<{
|
|
10
|
+
readonly format: "at-identifier";
|
|
11
|
+
}>;
|
|
12
|
+
readonly collection: l.StringSchema<{
|
|
13
|
+
readonly format: "nsid";
|
|
14
|
+
}>;
|
|
15
|
+
readonly rkey: l.StringSchema<{
|
|
16
|
+
readonly format: "record-key";
|
|
17
|
+
readonly maxLength: 512;
|
|
18
|
+
}>;
|
|
19
|
+
readonly validate: l.BooleanSchema;
|
|
20
|
+
readonly record: l.UnknownObjectSchema;
|
|
21
|
+
readonly swapCommit: l.StringSchema<{
|
|
22
|
+
readonly format: "cid";
|
|
23
|
+
}>;
|
|
24
|
+
}, {
|
|
25
|
+
readonly required: readonly ["repo", "collection", "record"];
|
|
26
|
+
}, {
|
|
27
|
+
repo: l.AtIdentifier;
|
|
28
|
+
collection: `${string}.${string}.${string}`;
|
|
29
|
+
record: l.LexMap;
|
|
30
|
+
rkey?: string | undefined;
|
|
31
|
+
swapCommit?: string | undefined;
|
|
32
|
+
validate?: boolean | undefined;
|
|
33
|
+
}>>, l.Payload<"application/json", l.ObjectSchema<{
|
|
34
|
+
readonly uri: l.StringSchema<{
|
|
35
|
+
readonly format: "at-uri";
|
|
36
|
+
}>;
|
|
37
|
+
readonly cid: l.StringSchema<{
|
|
38
|
+
readonly format: "cid";
|
|
39
|
+
}>;
|
|
40
|
+
readonly commit: l.RefSchema<RepoDefs.CommitMeta>;
|
|
41
|
+
readonly validationStatus: l.StringSchema<{
|
|
42
|
+
readonly knownValues: readonly ["valid", "unknown"];
|
|
43
|
+
}>;
|
|
44
|
+
}, {
|
|
45
|
+
readonly required: readonly ["uri", "cid"];
|
|
46
|
+
}, {
|
|
47
|
+
uri: `at://did:${string}:${string}/${string}.${string}.${string}/${string}` | `at://${string}.${string}/${string}.${string}.${string}/${string}`;
|
|
48
|
+
cid: string;
|
|
49
|
+
validationStatus?: l.UnknownString | "unknown" | "valid" | undefined;
|
|
50
|
+
commit?: RepoDefs.CommitMeta | undefined;
|
|
51
|
+
}>>, readonly ["InvalidSwap"]>;
|
|
52
|
+
export { main };
|
|
53
|
+
export declare const $params: l.ParamsSchema<{}, l.ParamsSchemaOptions, {}>, $input: l.Payload<"application/json", l.ObjectSchema<{
|
|
54
|
+
readonly repo: l.StringSchema<{
|
|
55
|
+
readonly format: "at-identifier";
|
|
56
|
+
}>;
|
|
57
|
+
readonly collection: l.StringSchema<{
|
|
58
|
+
readonly format: "nsid";
|
|
59
|
+
}>;
|
|
60
|
+
readonly rkey: l.StringSchema<{
|
|
61
|
+
readonly format: "record-key";
|
|
62
|
+
readonly maxLength: 512;
|
|
63
|
+
}>;
|
|
64
|
+
readonly validate: l.BooleanSchema;
|
|
65
|
+
readonly record: l.UnknownObjectSchema;
|
|
66
|
+
readonly swapCommit: l.StringSchema<{
|
|
67
|
+
readonly format: "cid";
|
|
68
|
+
}>;
|
|
69
|
+
}, {
|
|
70
|
+
readonly required: readonly ["repo", "collection", "record"];
|
|
71
|
+
}, {
|
|
72
|
+
repo: l.AtIdentifier;
|
|
73
|
+
collection: `${string}.${string}.${string}`;
|
|
74
|
+
record: l.LexMap;
|
|
75
|
+
rkey?: string | undefined;
|
|
76
|
+
swapCommit?: string | undefined;
|
|
77
|
+
validate?: boolean | undefined;
|
|
78
|
+
}>>, $output: l.Payload<"application/json", l.ObjectSchema<{
|
|
79
|
+
readonly uri: l.StringSchema<{
|
|
80
|
+
readonly format: "at-uri";
|
|
81
|
+
}>;
|
|
82
|
+
readonly cid: l.StringSchema<{
|
|
83
|
+
readonly format: "cid";
|
|
84
|
+
}>;
|
|
85
|
+
readonly commit: l.RefSchema<RepoDefs.CommitMeta>;
|
|
86
|
+
readonly validationStatus: l.StringSchema<{
|
|
87
|
+
readonly knownValues: readonly ["valid", "unknown"];
|
|
88
|
+
}>;
|
|
89
|
+
}, {
|
|
90
|
+
readonly required: readonly ["uri", "cid"];
|
|
91
|
+
}, {
|
|
92
|
+
uri: `at://did:${string}:${string}/${string}.${string}.${string}/${string}` | `at://${string}.${string}/${string}.${string}.${string}/${string}`;
|
|
93
|
+
cid: string;
|
|
94
|
+
validationStatus?: l.UnknownString | "unknown" | "valid" | undefined;
|
|
95
|
+
commit?: RepoDefs.CommitMeta | undefined;
|
|
96
|
+
}>>;
|
|
97
|
+
export type Params = l.InferProcedureParameters<typeof main>;
|
|
98
|
+
export type Input = l.InferProcedureInputBody<typeof main>;
|
|
99
|
+
export type Output = l.InferProcedureOutputBody<typeof main>;
|
|
100
|
+
//# sourceMappingURL=createRecord.defs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRecord.defs.d.ts","sourceRoot":"","sources":["../../../../../src/lexicons/com/atproto/repo/createRecord.defs.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAA;AACvC,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;AAE1C,QAAA,MAAM,KAAK,kCAAkC,CAAA;AAE7C,OAAO,EAAE,KAAK,EAAE,CAAA;AAEhB;;GAEG;AACH,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8BAuCP,CAAA;AACH,OAAO,EAAE,IAAI,EAAE,CAAA;AAEf,eAAO,MAAM,OAAO,+CAAgC,EAClD,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;GAA2B,EACjC,OAAO;;;;;;;;;;;;;;;;;;GAA4B,CAAA;AAErC,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,wBAAwB,CAAC,OAAO,IAAI,CAAC,CAAA;AAC5D,MAAM,MAAM,KAAK,GAAG,CAAC,CAAC,uBAAuB,CAAC,OAAO,IAAI,CAAC,CAAA;AAC1D,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,wBAAwB,CAAC,OAAO,IAAI,CAAC,CAAA"}
|