@atproto/lex-client 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/client.d.ts +79 -25
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +56 -24
  5. package/dist/client.js.map +1 -1
  6. package/dist/lexicons/com/atproto/repo/applyWrites.d.ts +3 -0
  7. package/dist/lexicons/com/atproto/repo/applyWrites.d.ts.map +1 -0
  8. package/dist/lexicons/com/atproto/repo/applyWrites.defs.d.ts +100 -0
  9. package/dist/lexicons/com/atproto/repo/applyWrites.defs.d.ts.map +1 -0
  10. package/dist/lexicons/com/atproto/repo/applyWrites.defs.js +81 -0
  11. package/dist/lexicons/com/atproto/repo/applyWrites.defs.js.map +1 -0
  12. package/dist/lexicons/com/atproto/repo/applyWrites.js +6 -0
  13. package/dist/lexicons/com/atproto/repo/applyWrites.js.map +1 -0
  14. package/dist/lexicons/com/atproto/repo/createRecord.d.ts +1 -1
  15. package/dist/lexicons/com/atproto/repo/createRecord.d.ts.map +1 -1
  16. package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts +16 -13
  17. package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts.map +1 -1
  18. package/dist/lexicons/com/atproto/repo/createRecord.defs.js +10 -10
  19. package/dist/lexicons/com/atproto/repo/createRecord.defs.js.map +1 -1
  20. package/dist/lexicons/com/atproto/repo/createRecord.js +1 -1
  21. package/dist/lexicons/com/atproto/repo/createRecord.js.map +1 -1
  22. package/dist/lexicons/com/atproto/repo/defs.d.ts +0 -1
  23. package/dist/lexicons/com/atproto/repo/defs.d.ts.map +1 -1
  24. package/dist/lexicons/com/atproto/repo/defs.js +0 -1
  25. package/dist/lexicons/com/atproto/repo/defs.js.map +1 -1
  26. package/dist/lexicons/com/atproto/repo/deleteRecord.d.ts +1 -1
  27. package/dist/lexicons/com/atproto/repo/deleteRecord.d.ts.map +1 -1
  28. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts +16 -13
  29. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts.map +1 -1
  30. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js +10 -10
  31. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js.map +1 -1
  32. package/dist/lexicons/com/atproto/repo/deleteRecord.js +1 -1
  33. package/dist/lexicons/com/atproto/repo/deleteRecord.js.map +1 -1
  34. package/dist/lexicons/com/atproto/repo/getRecord.d.ts +1 -1
  35. package/dist/lexicons/com/atproto/repo/getRecord.d.ts.map +1 -1
  36. package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts +13 -11
  37. package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts.map +1 -1
  38. package/dist/lexicons/com/atproto/repo/getRecord.defs.js +7 -9
  39. package/dist/lexicons/com/atproto/repo/getRecord.defs.js.map +1 -1
  40. package/dist/lexicons/com/atproto/repo/getRecord.js +1 -1
  41. package/dist/lexicons/com/atproto/repo/getRecord.js.map +1 -1
  42. package/dist/lexicons/com/atproto/repo/listRecords.d.ts +1 -1
  43. package/dist/lexicons/com/atproto/repo/listRecords.d.ts.map +1 -1
  44. package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts +13 -11
  45. package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts.map +1 -1
  46. package/dist/lexicons/com/atproto/repo/listRecords.defs.js +7 -9
  47. package/dist/lexicons/com/atproto/repo/listRecords.defs.js.map +1 -1
  48. package/dist/lexicons/com/atproto/repo/listRecords.js +1 -1
  49. package/dist/lexicons/com/atproto/repo/listRecords.js.map +1 -1
  50. package/dist/lexicons/com/atproto/repo/putRecord.d.ts +1 -1
  51. package/dist/lexicons/com/atproto/repo/putRecord.d.ts.map +1 -1
  52. package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts +16 -13
  53. package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts.map +1 -1
  54. package/dist/lexicons/com/atproto/repo/putRecord.defs.js +10 -10
  55. package/dist/lexicons/com/atproto/repo/putRecord.defs.js.map +1 -1
  56. package/dist/lexicons/com/atproto/repo/putRecord.js +1 -1
  57. package/dist/lexicons/com/atproto/repo/putRecord.js.map +1 -1
  58. package/dist/lexicons/com/atproto/repo/uploadBlob.d.ts +1 -1
  59. package/dist/lexicons/com/atproto/repo/uploadBlob.d.ts.map +1 -1
  60. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts +11 -8
  61. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts.map +1 -1
  62. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js +7 -7
  63. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js.map +1 -1
  64. package/dist/lexicons/com/atproto/repo/uploadBlob.js +1 -1
  65. package/dist/lexicons/com/atproto/repo/uploadBlob.js.map +1 -1
  66. package/dist/lexicons/com/atproto/repo.d.ts +2 -1
  67. package/dist/lexicons/com/atproto/repo.d.ts.map +1 -1
  68. package/dist/lexicons/com/atproto/repo.js +2 -1
  69. package/dist/lexicons/com/atproto/repo.js.map +1 -1
  70. package/dist/lexicons/com/atproto/sync/getBlob.d.ts +1 -1
  71. package/dist/lexicons/com/atproto/sync/getBlob.d.ts.map +1 -1
  72. package/dist/lexicons/com/atproto/sync/getBlob.defs.d.ts +11 -9
  73. package/dist/lexicons/com/atproto/sync/getBlob.defs.d.ts.map +1 -1
  74. package/dist/lexicons/com/atproto/sync/getBlob.defs.js +6 -8
  75. package/dist/lexicons/com/atproto/sync/getBlob.defs.js.map +1 -1
  76. package/dist/lexicons/com/atproto/sync/getBlob.js +1 -1
  77. package/dist/lexicons/com/atproto/sync/getBlob.js.map +1 -1
  78. package/dist/types.d.ts +2 -6
  79. package/dist/types.d.ts.map +1 -1
  80. package/dist/types.js.map +1 -1
  81. package/dist/util.d.ts +9 -0
  82. package/dist/util.d.ts.map +1 -1
  83. package/dist/util.js +23 -0
  84. package/dist/util.js.map +1 -1
  85. package/dist/write-operation-builder.d.ts +19 -0
  86. package/dist/write-operation-builder.d.ts.map +1 -0
  87. package/dist/write-operation-builder.js +35 -0
  88. package/dist/write-operation-builder.js.map +1 -0
  89. package/dist/xrpc.d.ts.map +1 -1
  90. package/dist/xrpc.js +5 -2
  91. package/dist/xrpc.js.map +1 -1
  92. package/package.json +4 -4
  93. package/src/client.ts +122 -82
  94. package/src/lexicons/com/atproto/repo/applyWrites.defs.ts +201 -0
  95. package/src/lexicons/com/atproto/repo/applyWrites.ts +6 -0
  96. package/src/lexicons/com/atproto/repo/createRecord.defs.ts +43 -46
  97. package/src/lexicons/com/atproto/repo/createRecord.ts +1 -1
  98. package/src/lexicons/com/atproto/repo/defs.ts +0 -1
  99. package/src/lexicons/com/atproto/repo/deleteRecord.defs.ts +37 -40
  100. package/src/lexicons/com/atproto/repo/deleteRecord.ts +1 -1
  101. package/src/lexicons/com/atproto/repo/getRecord.defs.ts +23 -26
  102. package/src/lexicons/com/atproto/repo/getRecord.ts +1 -1
  103. package/src/lexicons/com/atproto/repo/listRecords.defs.ts +30 -32
  104. package/src/lexicons/com/atproto/repo/listRecords.ts +1 -1
  105. package/src/lexicons/com/atproto/repo/putRecord.defs.ts +44 -47
  106. package/src/lexicons/com/atproto/repo/putRecord.ts +1 -1
  107. package/src/lexicons/com/atproto/repo/uploadBlob.defs.ts +21 -23
  108. package/src/lexicons/com/atproto/repo/uploadBlob.ts +1 -1
  109. package/src/lexicons/com/atproto/repo.ts +2 -1
  110. package/src/lexicons/com/atproto/sync/getBlob.defs.ts +23 -26
  111. package/src/lexicons/com/atproto/sync/getBlob.ts +1 -1
  112. package/src/types.ts +6 -10
  113. package/src/util.ts +48 -1
  114. package/src/write-operation-builder.ts +110 -0
  115. package/src/xrpc.ts +5 -5
@@ -8,30 +8,28 @@ const $nsid = 'com.atproto.repo.uploadBlob'
8
8
 
9
9
  export { $nsid }
10
10
 
11
- /** 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
- /*#__PURE__*/
14
- l.procedure(
15
- $nsid,
16
- /*#__PURE__*/ l.params(),
17
- /*#__PURE__*/ l.payload('*/*'),
18
- /*#__PURE__*/ l.jsonPayload({ blob: /*#__PURE__*/ l.blob() }),
19
- )
20
- export { main }
11
+ export const $params = /*#__PURE__*/ l.params()
21
12
 
22
- export type $Params = l.InferMethodParams<typeof main>
23
- export type $Input<B = l.BinaryData> = l.InferMethodInput<typeof main, B>
24
- export type $InputBody<B = l.BinaryData> = l.InferMethodInputBody<
25
- typeof main,
26
- B
27
- >
28
- export type $Output<B = l.BinaryData> = l.InferMethodOutput<typeof main, B>
29
- export type $OutputBody<B = l.BinaryData> = l.InferMethodOutputBody<
30
- typeof main,
13
+ export type $Params = l.InferOutput<typeof $params>
14
+
15
+ export const $input = /*#__PURE__*/ l.payload('*/*')
16
+
17
+ export type $Input<B = l.BinaryData> = l.InferPayload<typeof $input, B>
18
+ export type $InputBody<B = l.BinaryData> = l.InferPayloadBody<typeof $input, B>
19
+
20
+ export const $output = /*#__PURE__*/ l.jsonPayload({
21
+ blob: /*#__PURE__*/ l.blob(),
22
+ })
23
+
24
+ export type $Output<B = l.BinaryData> = l.InferPayload<typeof $output, B>
25
+ export type $OutputBody<B = l.BinaryData> = l.InferPayloadBody<
26
+ typeof $output,
31
27
  B
32
28
  >
33
29
 
34
- export const $lxm = /*#__PURE__*/ main.nsid,
35
- $params = /*#__PURE__*/ main.parameters,
36
- $input = /*#__PURE__*/ main.input,
37
- $output = /*#__PURE__*/ main.output
30
+ /** 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. */
31
+ const main = /*#__PURE__*/ l.procedure($nsid, $params, $input, $output)
32
+
33
+ export { main }
34
+
35
+ export const $lxm = $nsid
@@ -3,4 +3,4 @@
3
3
  */
4
4
 
5
5
  export * from './uploadBlob.defs.js'
6
- export * as $defs from './uploadBlob.defs.js'
6
+ export { main as default } from './uploadBlob.defs.js'
@@ -2,10 +2,11 @@
2
2
  * THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
3
3
  */
4
4
 
5
- export * as createRecord from './repo/createRecord.js'
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,33 +8,30 @@ const $nsid = 'com.atproto.sync.getBlob'
8
8
 
9
9
  export { $nsid }
10
10
 
11
- /** 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
- /*#__PURE__*/
14
- l.query(
15
- $nsid,
16
- /*#__PURE__*/ l.params({
17
- did: /*#__PURE__*/ l.string({ format: 'did' }),
18
- cid: /*#__PURE__*/ l.string({ format: 'cid' }),
19
- }),
20
- /*#__PURE__*/ l.payload('*/*'),
21
- [
22
- 'BlobNotFound',
23
- 'RepoNotFound',
24
- 'RepoTakendown',
25
- 'RepoSuspended',
26
- 'RepoDeactivated',
27
- ],
28
- )
29
- export { main }
11
+ export const $params = /*#__PURE__*/ l.params({
12
+ did: /*#__PURE__*/ l.string({ format: 'did' }),
13
+ cid: /*#__PURE__*/ l.string({ format: 'cid' }),
14
+ })
15
+
16
+ export type $Params = l.InferOutput<typeof $params>
17
+
18
+ export const $output = /*#__PURE__*/ l.payload('*/*')
30
19
 
31
- export type $Params = l.InferMethodParams<typeof main>
32
- export type $Output<B = l.BinaryData> = l.InferMethodOutput<typeof main, B>
33
- export type $OutputBody<B = l.BinaryData> = l.InferMethodOutputBody<
34
- typeof main,
20
+ export type $Output<B = l.BinaryData> = l.InferPayload<typeof $output, B>
21
+ export type $OutputBody<B = l.BinaryData> = l.InferPayloadBody<
22
+ typeof $output,
35
23
  B
36
24
  >
37
25
 
38
- export const $lxm = /*#__PURE__*/ main.nsid,
39
- $params = main.parameters,
40
- $output = main.output
26
+ /** Get a blob associated with a given account. Returns the full blob as originally uploaded. Does not require auth; implemented by PDS. */
27
+ const main = /*#__PURE__*/ l.query($nsid, $params, $output, [
28
+ 'BlobNotFound',
29
+ 'RepoNotFound',
30
+ 'RepoTakendown',
31
+ 'RepoSuspended',
32
+ 'RepoDeactivated',
33
+ ])
34
+
35
+ export { main }
36
+
37
+ export const $lxm = $nsid
@@ -3,4 +3,4 @@
3
3
  */
4
4
 
5
5
  export * from './getBlob.defs.js'
6
- export * as $defs from './getBlob.defs.js'
6
+ export { main as default } from './getBlob.defs.js'
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<ArrayBuffer>,
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)