@atproto/lex-client 0.1.0-next.0 → 0.1.1
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 +28 -9
- package/dist/client.d.ts +53 -8
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +38 -16
- package/dist/client.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/applyWrites.d.ts +3 -0
- package/dist/lexicons/com/atproto/repo/applyWrites.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/repo/applyWrites.defs.d.ts +100 -0
- package/dist/lexicons/com/atproto/repo/applyWrites.defs.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/repo/applyWrites.defs.js +81 -0
- package/dist/lexicons/com/atproto/repo/applyWrites.defs.js.map +1 -0
- package/dist/lexicons/com/atproto/repo/applyWrites.js +6 -0
- package/dist/lexicons/com/atproto/repo/applyWrites.js.map +1 -0
- package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts +16 -13
- package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/createRecord.defs.js +10 -10
- package/dist/lexicons/com/atproto/repo/createRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts +16 -13
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js +10 -10
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts +13 -11
- package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/getRecord.defs.js +7 -9
- package/dist/lexicons/com/atproto/repo/getRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts +13 -11
- package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/listRecords.defs.js +7 -9
- package/dist/lexicons/com/atproto/repo/listRecords.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts +16 -13
- package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/putRecord.defs.js +10 -10
- package/dist/lexicons/com/atproto/repo/putRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts +6 -3
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js +7 -7
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo.d.ts +2 -1
- package/dist/lexicons/com/atproto/repo.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo.js +2 -1
- package/dist/lexicons/com/atproto/repo.js.map +1 -1
- package/dist/lexicons/com/atproto/sync/getBlob.defs.d.ts +10 -8
- package/dist/lexicons/com/atproto/sync/getBlob.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/sync/getBlob.defs.js +6 -8
- package/dist/lexicons/com/atproto/sync/getBlob.defs.js.map +1 -1
- package/dist/types.d.ts +2 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/util.d.ts +9 -0
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +23 -0
- package/dist/util.js.map +1 -1
- package/dist/write-operation-builder.d.ts +19 -0
- package/dist/write-operation-builder.d.ts.map +1 -0
- package/dist/write-operation-builder.js +35 -0
- package/dist/write-operation-builder.js.map +1 -0
- package/dist/xrpc.d.ts.map +1 -1
- package/dist/xrpc.js +5 -2
- package/dist/xrpc.js.map +1 -1
- package/package.json +6 -6
- package/src/client.ts +89 -46
- package/src/lexicons/com/atproto/repo/applyWrites.defs.ts +197 -0
- package/src/lexicons/com/atproto/repo/applyWrites.ts +6 -0
- package/src/lexicons/com/atproto/repo/createRecord.defs.ts +30 -36
- package/src/lexicons/com/atproto/repo/deleteRecord.defs.ts +24 -30
- package/src/lexicons/com/atproto/repo/getRecord.defs.ts +14 -21
- package/src/lexicons/com/atproto/repo/listRecords.defs.ts +21 -28
- package/src/lexicons/com/atproto/repo/putRecord.defs.ts +31 -37
- package/src/lexicons/com/atproto/repo/uploadBlob.defs.ts +8 -13
- package/src/lexicons/com/atproto/repo.ts +2 -1
- package/src/lexicons/com/atproto/sync/getBlob.defs.ts +14 -21
- package/src/types.ts +6 -10
- package/src/util.ts +48 -1
- package/src/write-operation-builder.ts +110 -0
- package/src/xrpc.ts +5 -5
|
@@ -9,32 +9,31 @@ const $nsid = 'com.atproto.repo.deleteRecord'
|
|
|
9
9
|
|
|
10
10
|
export { $nsid }
|
|
11
11
|
|
|
12
|
+
export const $lxm = $nsid
|
|
13
|
+
export const $params = /*#__PURE__*/ l.params()
|
|
14
|
+
export const $input = /*#__PURE__*/ l.jsonPayload({
|
|
15
|
+
repo: /*#__PURE__*/ l.string({ format: 'at-identifier' }),
|
|
16
|
+
collection: /*#__PURE__*/ l.string({ format: 'nsid' }),
|
|
17
|
+
rkey: /*#__PURE__*/ l.string({ format: 'record-key' }),
|
|
18
|
+
swapRecord: /*#__PURE__*/ l.optional(
|
|
19
|
+
/*#__PURE__*/ l.string({ format: 'cid' }),
|
|
20
|
+
),
|
|
21
|
+
swapCommit: /*#__PURE__*/ l.optional(
|
|
22
|
+
/*#__PURE__*/ l.string({ format: 'cid' }),
|
|
23
|
+
),
|
|
24
|
+
})
|
|
25
|
+
export const $output = /*#__PURE__*/ l.jsonPayload({
|
|
26
|
+
commit: /*#__PURE__*/ l.optional(
|
|
27
|
+
/*#__PURE__*/ l.ref<RepoDefs.CommitMeta>(
|
|
28
|
+
(() => RepoDefs.commitMeta) as any,
|
|
29
|
+
),
|
|
30
|
+
),
|
|
31
|
+
})
|
|
12
32
|
/** Delete a repository record, or ensure it doesn't exist. Requires auth, implemented by PDS. */
|
|
13
|
-
const main =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/*#__PURE__*/ l.params(),
|
|
18
|
-
/*#__PURE__*/ l.jsonPayload({
|
|
19
|
-
repo: /*#__PURE__*/ l.string({ format: 'at-identifier' }),
|
|
20
|
-
collection: /*#__PURE__*/ l.string({ format: 'nsid' }),
|
|
21
|
-
rkey: /*#__PURE__*/ l.string({ format: 'record-key' }),
|
|
22
|
-
swapRecord: /*#__PURE__*/ l.optional(
|
|
23
|
-
/*#__PURE__*/ l.string({ format: 'cid' }),
|
|
24
|
-
),
|
|
25
|
-
swapCommit: /*#__PURE__*/ l.optional(
|
|
26
|
-
/*#__PURE__*/ l.string({ format: 'cid' }),
|
|
27
|
-
),
|
|
28
|
-
}),
|
|
29
|
-
/*#__PURE__*/ l.jsonPayload({
|
|
30
|
-
commit: /*#__PURE__*/ l.optional(
|
|
31
|
-
/*#__PURE__*/ l.ref<RepoDefs.CommitMeta>(
|
|
32
|
-
(() => RepoDefs.commitMeta) as any,
|
|
33
|
-
),
|
|
34
|
-
),
|
|
35
|
-
}),
|
|
36
|
-
['InvalidSwap'],
|
|
37
|
-
)
|
|
33
|
+
const main = /*#__PURE__*/ l.procedure($nsid, $params, $input, $output, [
|
|
34
|
+
'InvalidSwap',
|
|
35
|
+
])
|
|
36
|
+
|
|
38
37
|
export { main }
|
|
39
38
|
|
|
40
39
|
export type $Params = l.InferMethodParams<typeof main>
|
|
@@ -48,8 +47,3 @@ export type $OutputBody<B = l.BinaryData> = l.InferMethodOutputBody<
|
|
|
48
47
|
typeof main,
|
|
49
48
|
B
|
|
50
49
|
>
|
|
51
|
-
|
|
52
|
-
export const $lxm = /*#__PURE__*/ main.nsid,
|
|
53
|
-
$params = /*#__PURE__*/ main.parameters,
|
|
54
|
-
$input = /*#__PURE__*/ main.input,
|
|
55
|
-
$output = /*#__PURE__*/ main.output
|
|
@@ -8,24 +8,21 @@ const $nsid = 'com.atproto.repo.getRecord'
|
|
|
8
8
|
|
|
9
9
|
export { $nsid }
|
|
10
10
|
|
|
11
|
+
export const $lxm = $nsid
|
|
12
|
+
export const $params = /*#__PURE__*/ l.params({
|
|
13
|
+
repo: /*#__PURE__*/ l.string({ format: 'at-identifier' }),
|
|
14
|
+
collection: /*#__PURE__*/ l.string({ format: 'nsid' }),
|
|
15
|
+
rkey: /*#__PURE__*/ l.string({ format: 'record-key' }),
|
|
16
|
+
cid: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string({ format: 'cid' })),
|
|
17
|
+
})
|
|
18
|
+
export const $output = /*#__PURE__*/ l.jsonPayload({
|
|
19
|
+
uri: /*#__PURE__*/ l.string({ format: 'at-uri' }),
|
|
20
|
+
cid: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string({ format: 'cid' })),
|
|
21
|
+
value: /*#__PURE__*/ l.lexMap(),
|
|
22
|
+
})
|
|
11
23
|
/** Get a single record from a repository. Does not require auth. */
|
|
12
|
-
const main =
|
|
13
|
-
|
|
14
|
-
l.query(
|
|
15
|
-
$nsid,
|
|
16
|
-
/*#__PURE__*/ l.params({
|
|
17
|
-
repo: /*#__PURE__*/ l.string({ format: 'at-identifier' }),
|
|
18
|
-
collection: /*#__PURE__*/ l.string({ format: 'nsid' }),
|
|
19
|
-
rkey: /*#__PURE__*/ l.string({ format: 'record-key' }),
|
|
20
|
-
cid: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string({ format: 'cid' })),
|
|
21
|
-
}),
|
|
22
|
-
/*#__PURE__*/ l.jsonPayload({
|
|
23
|
-
uri: /*#__PURE__*/ l.string({ format: 'at-uri' }),
|
|
24
|
-
cid: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string({ format: 'cid' })),
|
|
25
|
-
value: /*#__PURE__*/ l.lexMap(),
|
|
26
|
-
}),
|
|
27
|
-
['RecordNotFound'],
|
|
28
|
-
)
|
|
24
|
+
const main = /*#__PURE__*/ l.query($nsid, $params, $output, ['RecordNotFound'])
|
|
25
|
+
|
|
29
26
|
export { main }
|
|
30
27
|
|
|
31
28
|
export type $Params = l.InferMethodParams<typeof main>
|
|
@@ -34,7 +31,3 @@ export type $OutputBody<B = l.BinaryData> = l.InferMethodOutputBody<
|
|
|
34
31
|
typeof main,
|
|
35
32
|
B
|
|
36
33
|
>
|
|
37
|
-
|
|
38
|
-
export const $lxm = /*#__PURE__*/ main.nsid,
|
|
39
|
-
$params = main.parameters,
|
|
40
|
-
$output = main.output
|
|
@@ -8,30 +8,28 @@ const $nsid = 'com.atproto.repo.listRecords'
|
|
|
8
8
|
|
|
9
9
|
export { $nsid }
|
|
10
10
|
|
|
11
|
+
export const $lxm = $nsid
|
|
12
|
+
export const $params = /*#__PURE__*/ l.params({
|
|
13
|
+
repo: /*#__PURE__*/ l.string({ format: 'at-identifier' }),
|
|
14
|
+
collection: /*#__PURE__*/ l.string({ format: 'nsid' }),
|
|
15
|
+
limit: /*#__PURE__*/ l.optional(
|
|
16
|
+
/*#__PURE__*/ l.withDefault(
|
|
17
|
+
/*#__PURE__*/ l.integer({ minimum: 1, maximum: 100 }),
|
|
18
|
+
50,
|
|
19
|
+
),
|
|
20
|
+
),
|
|
21
|
+
cursor: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string()),
|
|
22
|
+
reverse: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.boolean()),
|
|
23
|
+
})
|
|
24
|
+
export const $output = /*#__PURE__*/ l.jsonPayload({
|
|
25
|
+
cursor: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string()),
|
|
26
|
+
records: /*#__PURE__*/ l.array(
|
|
27
|
+
/*#__PURE__*/ l.ref<Record$0>((() => record$0) as any),
|
|
28
|
+
),
|
|
29
|
+
})
|
|
11
30
|
/** List a range of records in a repository, matching a specific collection. Does not require auth. */
|
|
12
|
-
const main =
|
|
13
|
-
|
|
14
|
-
l.query(
|
|
15
|
-
$nsid,
|
|
16
|
-
/*#__PURE__*/ l.params({
|
|
17
|
-
repo: /*#__PURE__*/ l.string({ format: 'at-identifier' }),
|
|
18
|
-
collection: /*#__PURE__*/ l.string({ format: 'nsid' }),
|
|
19
|
-
limit: /*#__PURE__*/ l.optional(
|
|
20
|
-
/*#__PURE__*/ l.withDefault(
|
|
21
|
-
/*#__PURE__*/ l.integer({ minimum: 1, maximum: 100 }),
|
|
22
|
-
50,
|
|
23
|
-
),
|
|
24
|
-
),
|
|
25
|
-
cursor: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string()),
|
|
26
|
-
reverse: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.boolean()),
|
|
27
|
-
}),
|
|
28
|
-
/*#__PURE__*/ l.jsonPayload({
|
|
29
|
-
cursor: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string()),
|
|
30
|
-
records: /*#__PURE__*/ l.array(
|
|
31
|
-
/*#__PURE__*/ l.ref<Record$0>((() => record$0) as any),
|
|
32
|
-
),
|
|
33
|
-
}),
|
|
34
|
-
)
|
|
31
|
+
const main = /*#__PURE__*/ l.query($nsid, $params, $output)
|
|
32
|
+
|
|
35
33
|
export { main }
|
|
36
34
|
|
|
37
35
|
export type $Params = l.InferMethodParams<typeof main>
|
|
@@ -40,11 +38,6 @@ export type $OutputBody<B = l.BinaryData> = l.InferMethodOutputBody<
|
|
|
40
38
|
typeof main,
|
|
41
39
|
B
|
|
42
40
|
>
|
|
43
|
-
|
|
44
|
-
export const $lxm = /*#__PURE__*/ main.nsid,
|
|
45
|
-
$params = main.parameters,
|
|
46
|
-
$output = main.output
|
|
47
|
-
|
|
48
41
|
type Record$0 = {
|
|
49
42
|
$type?: 'com.atproto.repo.listRecords#record'
|
|
50
43
|
uri: l.AtUriString
|
|
@@ -9,39 +9,38 @@ const $nsid = 'com.atproto.repo.putRecord'
|
|
|
9
9
|
|
|
10
10
|
export { $nsid }
|
|
11
11
|
|
|
12
|
+
export const $lxm = $nsid
|
|
13
|
+
export const $params = /*#__PURE__*/ l.params()
|
|
14
|
+
export const $input = /*#__PURE__*/ l.jsonPayload({
|
|
15
|
+
repo: /*#__PURE__*/ l.string({ format: 'at-identifier' }),
|
|
16
|
+
collection: /*#__PURE__*/ l.string({ format: 'nsid' }),
|
|
17
|
+
rkey: /*#__PURE__*/ l.string({ format: 'record-key', maxLength: 512 }),
|
|
18
|
+
validate: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.boolean()),
|
|
19
|
+
record: /*#__PURE__*/ l.lexMap(),
|
|
20
|
+
swapRecord: /*#__PURE__*/ l.optional(
|
|
21
|
+
/*#__PURE__*/ l.nullable(/*#__PURE__*/ l.string({ format: 'cid' })),
|
|
22
|
+
),
|
|
23
|
+
swapCommit: /*#__PURE__*/ l.optional(
|
|
24
|
+
/*#__PURE__*/ l.string({ format: 'cid' }),
|
|
25
|
+
),
|
|
26
|
+
})
|
|
27
|
+
export const $output = /*#__PURE__*/ l.jsonPayload({
|
|
28
|
+
uri: /*#__PURE__*/ l.string({ format: 'at-uri' }),
|
|
29
|
+
cid: /*#__PURE__*/ l.string({ format: 'cid' }),
|
|
30
|
+
commit: /*#__PURE__*/ l.optional(
|
|
31
|
+
/*#__PURE__*/ l.ref<RepoDefs.CommitMeta>(
|
|
32
|
+
(() => RepoDefs.commitMeta) as any,
|
|
33
|
+
),
|
|
34
|
+
),
|
|
35
|
+
validationStatus: /*#__PURE__*/ l.optional(
|
|
36
|
+
/*#__PURE__*/ l.string<{ knownValues: ['valid', 'unknown'] }>(),
|
|
37
|
+
),
|
|
38
|
+
})
|
|
12
39
|
/** Write a repository record, creating or updating it as needed. Requires auth, implemented by PDS. */
|
|
13
|
-
const main =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/*#__PURE__*/ l.params(),
|
|
18
|
-
/*#__PURE__*/ l.jsonPayload({
|
|
19
|
-
repo: /*#__PURE__*/ l.string({ format: 'at-identifier' }),
|
|
20
|
-
collection: /*#__PURE__*/ l.string({ format: 'nsid' }),
|
|
21
|
-
rkey: /*#__PURE__*/ l.string({ format: 'record-key', maxLength: 512 }),
|
|
22
|
-
validate: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.boolean()),
|
|
23
|
-
record: /*#__PURE__*/ l.lexMap(),
|
|
24
|
-
swapRecord: /*#__PURE__*/ l.optional(
|
|
25
|
-
/*#__PURE__*/ l.nullable(/*#__PURE__*/ l.string({ format: 'cid' })),
|
|
26
|
-
),
|
|
27
|
-
swapCommit: /*#__PURE__*/ l.optional(
|
|
28
|
-
/*#__PURE__*/ l.string({ format: 'cid' }),
|
|
29
|
-
),
|
|
30
|
-
}),
|
|
31
|
-
/*#__PURE__*/ l.jsonPayload({
|
|
32
|
-
uri: /*#__PURE__*/ l.string({ format: 'at-uri' }),
|
|
33
|
-
cid: /*#__PURE__*/ l.string({ format: 'cid' }),
|
|
34
|
-
commit: /*#__PURE__*/ l.optional(
|
|
35
|
-
/*#__PURE__*/ l.ref<RepoDefs.CommitMeta>(
|
|
36
|
-
(() => RepoDefs.commitMeta) as any,
|
|
37
|
-
),
|
|
38
|
-
),
|
|
39
|
-
validationStatus: /*#__PURE__*/ l.optional(
|
|
40
|
-
/*#__PURE__*/ l.string<{ knownValues: ['valid', 'unknown'] }>(),
|
|
41
|
-
),
|
|
42
|
-
}),
|
|
43
|
-
['InvalidSwap'],
|
|
44
|
-
)
|
|
40
|
+
const main = /*#__PURE__*/ l.procedure($nsid, $params, $input, $output, [
|
|
41
|
+
'InvalidSwap',
|
|
42
|
+
])
|
|
43
|
+
|
|
45
44
|
export { main }
|
|
46
45
|
|
|
47
46
|
export type $Params = l.InferMethodParams<typeof main>
|
|
@@ -55,8 +54,3 @@ export type $OutputBody<B = l.BinaryData> = l.InferMethodOutputBody<
|
|
|
55
54
|
typeof main,
|
|
56
55
|
B
|
|
57
56
|
>
|
|
58
|
-
|
|
59
|
-
export const $lxm = /*#__PURE__*/ main.nsid,
|
|
60
|
-
$params = /*#__PURE__*/ main.parameters,
|
|
61
|
-
$input = /*#__PURE__*/ main.input,
|
|
62
|
-
$output = /*#__PURE__*/ main.output
|
|
@@ -8,15 +8,15 @@ const $nsid = 'com.atproto.repo.uploadBlob'
|
|
|
8
8
|
|
|
9
9
|
export { $nsid }
|
|
10
10
|
|
|
11
|
+
export const $lxm = $nsid
|
|
12
|
+
export const $params = /*#__PURE__*/ l.params()
|
|
13
|
+
export const $input = /*#__PURE__*/ l.payload('*/*')
|
|
14
|
+
export const $output = /*#__PURE__*/ l.jsonPayload({
|
|
15
|
+
blob: /*#__PURE__*/ l.blob(),
|
|
16
|
+
})
|
|
11
17
|
/** Upload a new blob, to be referenced from a repository record. The blob will be deleted if it is not referenced within a time window (eg, minutes). Blob restrictions (mimetype, size, etc) are enforced when the reference is created. Requires auth, implemented by PDS. */
|
|
12
|
-
const main =
|
|
13
|
-
|
|
14
|
-
l.procedure(
|
|
15
|
-
$nsid,
|
|
16
|
-
/*#__PURE__*/ l.params(),
|
|
17
|
-
/*#__PURE__*/ l.payload('*/*'),
|
|
18
|
-
/*#__PURE__*/ l.jsonPayload({ blob: /*#__PURE__*/ l.blob() }),
|
|
19
|
-
)
|
|
18
|
+
const main = /*#__PURE__*/ l.procedure($nsid, $params, $input, $output)
|
|
19
|
+
|
|
20
20
|
export { main }
|
|
21
21
|
|
|
22
22
|
export type $Params = l.InferMethodParams<typeof main>
|
|
@@ -30,8 +30,3 @@ export type $OutputBody<B = l.BinaryData> = l.InferMethodOutputBody<
|
|
|
30
30
|
typeof main,
|
|
31
31
|
B
|
|
32
32
|
>
|
|
33
|
-
|
|
34
|
-
export const $lxm = /*#__PURE__*/ main.nsid,
|
|
35
|
-
$params = /*#__PURE__*/ main.parameters,
|
|
36
|
-
$input = /*#__PURE__*/ main.input,
|
|
37
|
-
$output = /*#__PURE__*/ main.output
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
export * as
|
|
5
|
+
export * as applyWrites from './repo/applyWrites.js'
|
|
6
6
|
export * as deleteRecord from './repo/deleteRecord.js'
|
|
7
7
|
export * as getRecord from './repo/getRecord.js'
|
|
8
8
|
export * as listRecords from './repo/listRecords.js'
|
|
9
9
|
export * as putRecord from './repo/putRecord.js'
|
|
10
10
|
export * as uploadBlob from './repo/uploadBlob.js'
|
|
11
|
+
export * as createRecord from './repo/createRecord.js'
|
|
11
12
|
export * as defs from './repo/defs.js'
|
|
@@ -8,24 +8,21 @@ const $nsid = 'com.atproto.sync.getBlob'
|
|
|
8
8
|
|
|
9
9
|
export { $nsid }
|
|
10
10
|
|
|
11
|
+
export const $lxm = $nsid
|
|
12
|
+
export const $params = /*#__PURE__*/ l.params({
|
|
13
|
+
did: /*#__PURE__*/ l.string({ format: 'did' }),
|
|
14
|
+
cid: /*#__PURE__*/ l.string({ format: 'cid' }),
|
|
15
|
+
})
|
|
16
|
+
export const $output = /*#__PURE__*/ l.payload('*/*')
|
|
11
17
|
/** Get a blob associated with a given account. Returns the full blob as originally uploaded. Does not require auth; implemented by PDS. */
|
|
12
|
-
const main =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/*#__PURE__*/ l.payload('*/*'),
|
|
21
|
-
[
|
|
22
|
-
'BlobNotFound',
|
|
23
|
-
'RepoNotFound',
|
|
24
|
-
'RepoTakendown',
|
|
25
|
-
'RepoSuspended',
|
|
26
|
-
'RepoDeactivated',
|
|
27
|
-
],
|
|
28
|
-
)
|
|
18
|
+
const main = /*#__PURE__*/ l.query($nsid, $params, $output, [
|
|
19
|
+
'BlobNotFound',
|
|
20
|
+
'RepoNotFound',
|
|
21
|
+
'RepoTakendown',
|
|
22
|
+
'RepoSuspended',
|
|
23
|
+
'RepoDeactivated',
|
|
24
|
+
])
|
|
25
|
+
|
|
29
26
|
export { main }
|
|
30
27
|
|
|
31
28
|
export type $Params = l.InferMethodParams<typeof main>
|
|
@@ -34,7 +31,3 @@ export type $OutputBody<B = l.BinaryData> = l.InferMethodOutputBody<
|
|
|
34
31
|
typeof main,
|
|
35
32
|
B
|
|
36
33
|
>
|
|
37
|
-
|
|
38
|
-
export const $lxm = /*#__PURE__*/ main.nsid,
|
|
39
|
-
$params = main.parameters,
|
|
40
|
-
$output = main.output
|
package/src/types.ts
CHANGED
|
@@ -46,18 +46,14 @@ export type Service = `${DidString}#${DidServiceIdentifier}`
|
|
|
46
46
|
* const file: BinaryBodyInit = fileInput.files[0]
|
|
47
47
|
* await client.xrpc(uploadMethod, { body: file })
|
|
48
48
|
* ```
|
|
49
|
-
*
|
|
50
|
-
* @note Uint8Array is parameterized with ArrayBuffer (not ArrayBufferLike)
|
|
51
|
-
* because fetch's BodyInit requires ArrayBuffer-backed views —
|
|
52
|
-
* SharedArrayBuffer is not supported for network I/O.
|
|
53
49
|
*/
|
|
54
50
|
export type BinaryBodyInit =
|
|
55
|
-
| Uint8Array<ArrayBuffer>
|
|
56
|
-
| ArrayBuffer
|
|
57
|
-
| Blob
|
|
58
|
-
| ReadableStream<Uint8Array<ArrayBuffer>>
|
|
59
|
-
| AsyncIterable<Uint8Array<ArrayBuffer>>
|
|
60
51
|
| string
|
|
52
|
+
| Blob
|
|
53
|
+
| Uint8Array
|
|
54
|
+
| ArrayBuffer
|
|
55
|
+
| ReadableStream<Uint8Array>
|
|
56
|
+
| AsyncIterable<Uint8Array>
|
|
61
57
|
|
|
62
58
|
export type EncodingString = `${string}/${string}`
|
|
63
59
|
|
|
@@ -68,7 +64,7 @@ export function isEncodingString(
|
|
|
68
64
|
}
|
|
69
65
|
|
|
70
66
|
export type XrpcUnknownResponsePayload<
|
|
71
|
-
TBinary extends BinaryBodyInit = Uint8Array
|
|
67
|
+
TBinary extends BinaryBodyInit = Uint8Array,
|
|
72
68
|
> = {
|
|
73
69
|
encoding: EncodingString
|
|
74
70
|
body: LexValue | TBinary
|
package/src/util.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
InferRecordKey,
|
|
3
|
+
LexiconRecordKey,
|
|
4
|
+
RecordSchema,
|
|
5
|
+
} from '@atproto/lex-schema'
|
|
1
6
|
import type { DidString, Service } from './types.js'
|
|
2
7
|
|
|
3
8
|
export function applyDefaults<
|
|
@@ -55,6 +60,19 @@ export function isAsyncIterable<T>(
|
|
|
55
60
|
)
|
|
56
61
|
}
|
|
57
62
|
|
|
63
|
+
export function asUint8ArrayArrayBuffer(
|
|
64
|
+
bytes: Uint8Array,
|
|
65
|
+
): Uint8Array<ArrayBuffer> {
|
|
66
|
+
// If the Uint8Array is already backed by a non-shared ArrayBuffer, we can use
|
|
67
|
+
// it directly.
|
|
68
|
+
if (bytes.buffer instanceof ArrayBuffer) {
|
|
69
|
+
return bytes as Uint8Array<ArrayBuffer>
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Otherwise, we need to create a new ArrayBuffer and copy the data.
|
|
73
|
+
return new Uint8Array(bytes)
|
|
74
|
+
}
|
|
75
|
+
|
|
58
76
|
export type XrpcRequestHeadersOptions = {
|
|
59
77
|
/** Additional HTTP headers to include in the request. */
|
|
60
78
|
headers?: HeadersInit
|
|
@@ -115,7 +133,7 @@ export function toReadableStreamPonyfill(
|
|
|
115
133
|
data: AsyncIterable<Uint8Array>,
|
|
116
134
|
): ReadableStream<Uint8Array> {
|
|
117
135
|
let iterator: AsyncIterator<Uint8Array> | undefined
|
|
118
|
-
return new ReadableStream({
|
|
136
|
+
return new ReadableStream<Uint8Array>({
|
|
119
137
|
async pull(controller) {
|
|
120
138
|
try {
|
|
121
139
|
iterator ??= data[Symbol.asyncIterator]()
|
|
@@ -133,3 +151,32 @@ export function toReadableStreamPonyfill(
|
|
|
133
151
|
},
|
|
134
152
|
})
|
|
135
153
|
}
|
|
154
|
+
|
|
155
|
+
export type RecordKeyOptions<
|
|
156
|
+
T extends RecordSchema,
|
|
157
|
+
AlsoOptionalWhenRecordKeyIs extends LexiconRecordKey = never,
|
|
158
|
+
> = T['key'] extends `literal:${string}` | AlsoOptionalWhenRecordKeyIs
|
|
159
|
+
? { rkey?: InferRecordKey<T> }
|
|
160
|
+
: { rkey: InferRecordKey<T> }
|
|
161
|
+
|
|
162
|
+
export function getDefaultRecordKey<const T extends RecordSchema>(
|
|
163
|
+
schema: T,
|
|
164
|
+
): undefined | InferRecordKey<T> {
|
|
165
|
+
// Let the server generate the TID
|
|
166
|
+
if (schema.key === 'tid') return undefined
|
|
167
|
+
if (schema.key === 'any') return undefined
|
|
168
|
+
|
|
169
|
+
return getLiteralRecordKey(schema)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function getLiteralRecordKey<const T extends RecordSchema>(
|
|
173
|
+
schema: T,
|
|
174
|
+
): InferRecordKey<T> {
|
|
175
|
+
if (schema.key.startsWith('literal:')) {
|
|
176
|
+
return schema.key.slice(8) as InferRecordKey<T>
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
throw new TypeError(
|
|
180
|
+
`An "rkey" must be provided for record key type "${schema.key}" (${schema.$type})`,
|
|
181
|
+
)
|
|
182
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
$Typed,
|
|
3
|
+
InferInput,
|
|
4
|
+
Main,
|
|
5
|
+
RecordSchema,
|
|
6
|
+
Restricted,
|
|
7
|
+
getMain,
|
|
8
|
+
} from '@atproto/lex-schema'
|
|
9
|
+
import { com } from './lexicons/index.js'
|
|
10
|
+
import {
|
|
11
|
+
RecordKeyOptions,
|
|
12
|
+
getDefaultRecordKey,
|
|
13
|
+
getLiteralRecordKey,
|
|
14
|
+
} from './util.js'
|
|
15
|
+
|
|
16
|
+
export type WriteOperation =
|
|
17
|
+
| $Typed<com.atproto.repo.applyWrites.Create>
|
|
18
|
+
| $Typed<com.atproto.repo.applyWrites.Update>
|
|
19
|
+
| $Typed<com.atproto.repo.applyWrites.Delete>
|
|
20
|
+
|
|
21
|
+
export type WriteOperationCreateOptions<T extends RecordSchema> =
|
|
22
|
+
RecordKeyOptions<T, 'tid' | 'any'>
|
|
23
|
+
|
|
24
|
+
export type WriteOperationUpdateOptions<T extends RecordSchema> =
|
|
25
|
+
RecordKeyOptions<T>
|
|
26
|
+
|
|
27
|
+
export type WriteOperationDeleteOptions<T extends RecordSchema> =
|
|
28
|
+
RecordKeyOptions<T>
|
|
29
|
+
|
|
30
|
+
export type WriteOperationsFactory = (
|
|
31
|
+
helper: WriteOperationHelper,
|
|
32
|
+
) => Iterable<WriteOperation>
|
|
33
|
+
|
|
34
|
+
export class WriteOperationHelper {
|
|
35
|
+
private constructor() {}
|
|
36
|
+
|
|
37
|
+
create<const T extends RecordSchema>(
|
|
38
|
+
ns: NonNullable<unknown> extends WriteOperationCreateOptions<T>
|
|
39
|
+
? Main<T>
|
|
40
|
+
: Restricted<'This record type requires an "options" argument'>,
|
|
41
|
+
input: Omit<InferInput<T>, '$type'>,
|
|
42
|
+
): $Typed<com.atproto.repo.applyWrites.Create>
|
|
43
|
+
create<const T extends RecordSchema>(
|
|
44
|
+
ns: Main<T>,
|
|
45
|
+
input: Omit<InferInput<T>, '$type'>,
|
|
46
|
+
options: WriteOperationCreateOptions<T>,
|
|
47
|
+
): $Typed<com.atproto.repo.applyWrites.Create>
|
|
48
|
+
create<const T extends RecordSchema>(
|
|
49
|
+
ns: Main<T>,
|
|
50
|
+
input: Omit<InferInput<T>, '$type'>,
|
|
51
|
+
options: WriteOperationCreateOptions<T> = {} as WriteOperationCreateOptions<T>,
|
|
52
|
+
): $Typed<com.atproto.repo.applyWrites.Create> {
|
|
53
|
+
const schema: T = getMain(ns)
|
|
54
|
+
const value = schema.build(input)
|
|
55
|
+
return com.atproto.repo.applyWrites.create.$build({
|
|
56
|
+
collection: schema.$type,
|
|
57
|
+
value,
|
|
58
|
+
rkey: options?.rkey ?? getDefaultRecordKey(schema),
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
update<const T extends RecordSchema>(
|
|
63
|
+
ns: NonNullable<unknown> extends WriteOperationUpdateOptions<T>
|
|
64
|
+
? Main<T>
|
|
65
|
+
: Restricted<'This record type requires an "options" argument'>,
|
|
66
|
+
input: Omit<InferInput<T>, '$type'>,
|
|
67
|
+
): $Typed<com.atproto.repo.applyWrites.Update>
|
|
68
|
+
update<const T extends RecordSchema>(
|
|
69
|
+
ns: Main<T>,
|
|
70
|
+
input: Omit<InferInput<T>, '$type'>,
|
|
71
|
+
options: WriteOperationUpdateOptions<T>,
|
|
72
|
+
): $Typed<com.atproto.repo.applyWrites.Update>
|
|
73
|
+
update<const T extends RecordSchema>(
|
|
74
|
+
ns: Main<T>,
|
|
75
|
+
input: Omit<InferInput<T>, '$type'>,
|
|
76
|
+
options: WriteOperationUpdateOptions<T> = {} as WriteOperationUpdateOptions<T>,
|
|
77
|
+
): $Typed<com.atproto.repo.applyWrites.Update> {
|
|
78
|
+
const schema: T = getMain(ns)
|
|
79
|
+
const value = schema.build(input)
|
|
80
|
+
return com.atproto.repo.applyWrites.update.$build({
|
|
81
|
+
collection: schema.$type,
|
|
82
|
+
value,
|
|
83
|
+
rkey: options?.rkey ?? getLiteralRecordKey(schema),
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
delete<const T extends RecordSchema>(
|
|
88
|
+
ns: NonNullable<unknown> extends WriteOperationDeleteOptions<T>
|
|
89
|
+
? Main<T>
|
|
90
|
+
: Restricted<'This record type requires an "options" argument'>,
|
|
91
|
+
): $Typed<com.atproto.repo.applyWrites.Delete>
|
|
92
|
+
delete<const T extends RecordSchema>(
|
|
93
|
+
ns: Main<T>,
|
|
94
|
+
options: WriteOperationDeleteOptions<T>,
|
|
95
|
+
): $Typed<com.atproto.repo.applyWrites.Delete>
|
|
96
|
+
delete<const T extends RecordSchema>(
|
|
97
|
+
ns: Main<T>,
|
|
98
|
+
options: WriteOperationDeleteOptions<T> = {} as WriteOperationDeleteOptions<T>,
|
|
99
|
+
): $Typed<com.atproto.repo.applyWrites.Delete> {
|
|
100
|
+
const schema: T = getMain(ns)
|
|
101
|
+
return com.atproto.repo.applyWrites.delete.$build({
|
|
102
|
+
collection: schema.$type,
|
|
103
|
+
rkey: options?.rkey ?? getLiteralRecordKey(schema),
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static build(factory: WriteOperationsFactory): WriteOperation[] {
|
|
108
|
+
return Array.from(factory(new WriteOperationHelper()))
|
|
109
|
+
}
|
|
110
|
+
}
|
package/src/xrpc.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { XrpcResponse, XrpcResponseOptions } from './response.js'
|
|
|
19
19
|
import { BinaryBodyInit } from './types.js'
|
|
20
20
|
import {
|
|
21
21
|
XrpcRequestHeadersOptions,
|
|
22
|
+
asUint8ArrayArrayBuffer,
|
|
22
23
|
buildXrpcRequestHeaders,
|
|
23
24
|
isAsyncIterable,
|
|
24
25
|
isBlobLike,
|
|
@@ -336,17 +337,16 @@ function xrpcProcedureInput(
|
|
|
336
337
|
case 'object': {
|
|
337
338
|
if (body === null) break
|
|
338
339
|
if (ArrayBuffer.isView(body)) {
|
|
339
|
-
return buildPayload(
|
|
340
|
-
input,
|
|
341
|
-
body as Uint8Array<ArrayBuffer>,
|
|
342
|
-
encodingHint,
|
|
343
|
-
)
|
|
340
|
+
return buildPayload(input, asUint8ArrayArrayBuffer(body), encodingHint)
|
|
344
341
|
} else if (
|
|
345
342
|
body instanceof ArrayBuffer ||
|
|
346
343
|
body instanceof ReadableStream
|
|
347
344
|
) {
|
|
348
345
|
return buildPayload(input, body, encodingHint)
|
|
349
346
|
} else if (isAsyncIterable(body)) {
|
|
347
|
+
// @NOTE While fetch() does not allow SharedArrayBuffer-backed
|
|
348
|
+
// Uint8Arrays as "body", it **does** allow using ReadableStreams made
|
|
349
|
+
// of Uint8Arrays<SharedArrayBuffer> (tested on NodeJS 22) as "body".
|
|
350
350
|
return buildPayload(input, toReadableStream(body), encodingHint)
|
|
351
351
|
} else if (isBlobLike(body)) {
|
|
352
352
|
return buildPayload(input, body, encodingHint || body.type)
|