@atproto/pds 0.4.55 → 0.4.57

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/api/com/atproto/repo/applyWrites.d.ts.map +1 -1
  3. package/dist/api/com/atproto/repo/applyWrites.js +43 -7
  4. package/dist/api/com/atproto/repo/applyWrites.js.map +1 -1
  5. package/dist/api/com/atproto/repo/createRecord.d.ts.map +1 -1
  6. package/dist/api/com/atproto/repo/createRecord.js +10 -2
  7. package/dist/api/com/atproto/repo/createRecord.js.map +1 -1
  8. package/dist/api/com/atproto/repo/deleteRecord.d.ts.map +1 -1
  9. package/dist/api/com/atproto/repo/deleteRecord.js +11 -0
  10. package/dist/api/com/atproto/repo/deleteRecord.js.map +1 -1
  11. package/dist/api/com/atproto/repo/putRecord.d.ts.map +1 -1
  12. package/dist/api/com/atproto/repo/putRecord.js +7 -0
  13. package/dist/api/com/atproto/repo/putRecord.js.map +1 -1
  14. package/dist/lexicon/index.d.ts +11 -0
  15. package/dist/lexicon/index.d.ts.map +1 -1
  16. package/dist/lexicon/index.js +32 -1
  17. package/dist/lexicon/index.js.map +1 -1
  18. package/dist/lexicon/lexicons.d.ts +367 -18
  19. package/dist/lexicon/lexicons.d.ts.map +1 -1
  20. package/dist/lexicon/lexicons.js +390 -24
  21. package/dist/lexicon/lexicons.js.map +1 -1
  22. package/dist/lexicon/types/app/bsky/embed/defs.d.ts +13 -0
  23. package/dist/lexicon/types/app/bsky/embed/defs.d.ts.map +1 -0
  24. package/dist/lexicon/types/app/bsky/embed/defs.js +16 -0
  25. package/dist/lexicon/types/app/bsky/embed/defs.js.map +1 -0
  26. package/dist/lexicon/types/app/bsky/embed/images.d.ts +3 -10
  27. package/dist/lexicon/types/app/bsky/embed/images.d.ts.map +1 -1
  28. package/dist/lexicon/types/app/bsky/embed/images.js +1 -11
  29. package/dist/lexicon/types/app/bsky/embed/images.js.map +1 -1
  30. package/dist/lexicon/types/app/bsky/embed/record.d.ts +2 -1
  31. package/dist/lexicon/types/app/bsky/embed/record.d.ts.map +1 -1
  32. package/dist/lexicon/types/app/bsky/embed/record.js.map +1 -1
  33. package/dist/lexicon/types/app/bsky/embed/recordWithMedia.d.ts +3 -2
  34. package/dist/lexicon/types/app/bsky/embed/recordWithMedia.d.ts.map +1 -1
  35. package/dist/lexicon/types/app/bsky/embed/recordWithMedia.js.map +1 -1
  36. package/dist/lexicon/types/app/bsky/embed/video.d.ts +33 -0
  37. package/dist/lexicon/types/app/bsky/embed/video.d.ts.map +1 -0
  38. package/dist/lexicon/types/app/bsky/embed/video.js +35 -0
  39. package/dist/lexicon/types/app/bsky/embed/video.js.map +1 -0
  40. package/dist/lexicon/types/app/bsky/feed/defs.d.ts +2 -1
  41. package/dist/lexicon/types/app/bsky/feed/defs.d.ts.map +1 -1
  42. package/dist/lexicon/types/app/bsky/feed/defs.js.map +1 -1
  43. package/dist/lexicon/types/app/bsky/feed/post.d.ts +2 -1
  44. package/dist/lexicon/types/app/bsky/feed/post.d.ts.map +1 -1
  45. package/dist/lexicon/types/app/bsky/feed/post.js.map +1 -1
  46. package/dist/lexicon/types/app/bsky/video/defs.d.ts +19 -0
  47. package/dist/lexicon/types/app/bsky/video/defs.d.ts.map +1 -0
  48. package/dist/lexicon/types/app/bsky/video/defs.js +16 -0
  49. package/dist/lexicon/types/app/bsky/video/defs.js.map +1 -0
  50. package/dist/lexicon/types/app/bsky/video/getJobStatus.d.ts +36 -0
  51. package/dist/lexicon/types/app/bsky/video/getJobStatus.d.ts.map +1 -0
  52. package/dist/lexicon/types/app/bsky/video/getJobStatus.js +3 -0
  53. package/dist/lexicon/types/app/bsky/video/getJobStatus.js.map +1 -0
  54. package/dist/lexicon/types/app/bsky/video/getUploadLimits.d.ts +38 -0
  55. package/dist/lexicon/types/app/bsky/video/getUploadLimits.d.ts.map +1 -0
  56. package/dist/lexicon/types/app/bsky/video/getUploadLimits.js +3 -0
  57. package/dist/lexicon/types/app/bsky/video/getUploadLimits.js.map +1 -0
  58. package/dist/lexicon/types/app/bsky/video/uploadVideo.d.ts +41 -0
  59. package/dist/lexicon/types/app/bsky/video/uploadVideo.d.ts.map +1 -0
  60. package/dist/lexicon/types/app/bsky/video/uploadVideo.js +3 -0
  61. package/dist/lexicon/types/app/bsky/video/uploadVideo.js.map +1 -0
  62. package/dist/lexicon/types/com/atproto/repo/applyWrites.d.ts +38 -4
  63. package/dist/lexicon/types/com/atproto/repo/applyWrites.d.ts.map +1 -1
  64. package/dist/lexicon/types/com/atproto/repo/applyWrites.js +31 -1
  65. package/dist/lexicon/types/com/atproto/repo/applyWrites.js.map +1 -1
  66. package/dist/lexicon/types/com/atproto/repo/createRecord.d.ts +5 -2
  67. package/dist/lexicon/types/com/atproto/repo/createRecord.d.ts.map +1 -1
  68. package/dist/lexicon/types/com/atproto/repo/defs.d.ts +12 -0
  69. package/dist/lexicon/types/com/atproto/repo/defs.d.ts.map +1 -0
  70. package/dist/lexicon/types/com/atproto/repo/defs.js +16 -0
  71. package/dist/lexicon/types/com/atproto/repo/defs.js.map +1 -0
  72. package/dist/lexicon/types/com/atproto/repo/deleteRecord.d.ts +14 -2
  73. package/dist/lexicon/types/com/atproto/repo/deleteRecord.d.ts.map +1 -1
  74. package/dist/lexicon/types/com/atproto/repo/putRecord.d.ts +5 -2
  75. package/dist/lexicon/types/com/atproto/repo/putRecord.d.ts.map +1 -1
  76. package/dist/lexicon/types/tools/ozone/communication/createTemplate.d.ts +3 -0
  77. package/dist/lexicon/types/tools/ozone/communication/createTemplate.d.ts.map +1 -1
  78. package/dist/lexicon/types/tools/ozone/communication/defs.d.ts +2 -0
  79. package/dist/lexicon/types/tools/ozone/communication/defs.d.ts.map +1 -1
  80. package/dist/lexicon/types/tools/ozone/communication/defs.js.map +1 -1
  81. package/dist/lexicon/types/tools/ozone/communication/updateTemplate.d.ts +3 -0
  82. package/dist/lexicon/types/tools/ozone/communication/updateTemplate.d.ts.map +1 -1
  83. package/dist/lexicon/types/tools/ozone/moderation/emitEvent.d.ts +1 -1
  84. package/dist/lexicon/types/tools/ozone/moderation/emitEvent.d.ts.map +1 -1
  85. package/dist/read-after-write/viewer.d.ts +4 -4
  86. package/dist/repo/prepare.d.ts +4 -2
  87. package/dist/repo/prepare.d.ts.map +1 -1
  88. package/dist/repo/prepare.js +30 -14
  89. package/dist/repo/prepare.js.map +1 -1
  90. package/dist/repo/types.d.ts +3 -0
  91. package/dist/repo/types.d.ts.map +1 -1
  92. package/dist/repo/types.js.map +1 -1
  93. package/dist/sequencer/events.d.ts +2 -2
  94. package/package.json +4 -4
  95. package/src/api/com/atproto/repo/applyWrites.ts +41 -0
  96. package/src/api/com/atproto/repo/createRecord.ts +16 -7
  97. package/src/api/com/atproto/repo/deleteRecord.ts +11 -0
  98. package/src/api/com/atproto/repo/putRecord.ts +7 -0
  99. package/src/lexicon/index.ts +46 -0
  100. package/src/lexicon/lexicons.ts +393 -25
  101. package/src/lexicon/types/app/bsky/embed/defs.ts +26 -0
  102. package/src/lexicon/types/app/bsky/embed/images.ts +3 -21
  103. package/src/lexicon/types/app/bsky/embed/record.ts +2 -0
  104. package/src/lexicon/types/app/bsky/embed/recordWithMedia.ts +3 -0
  105. package/src/lexicon/types/app/bsky/embed/video.ts +67 -0
  106. package/src/lexicon/types/app/bsky/feed/defs.ts +2 -0
  107. package/src/lexicon/types/app/bsky/feed/post.ts +2 -0
  108. package/src/lexicon/types/app/bsky/video/defs.ts +32 -0
  109. package/src/lexicon/types/app/bsky/video/getJobStatus.ts +46 -0
  110. package/src/lexicon/types/app/bsky/video/getUploadLimits.ts +47 -0
  111. package/src/lexicon/types/app/bsky/video/uploadVideo.ts +48 -0
  112. package/src/lexicon/types/com/atproto/repo/applyWrites.ts +70 -3
  113. package/src/lexicon/types/com/atproto/repo/createRecord.ts +5 -2
  114. package/src/lexicon/types/com/atproto/repo/defs.ts +25 -0
  115. package/src/lexicon/types/com/atproto/repo/deleteRecord.ts +13 -1
  116. package/src/lexicon/types/com/atproto/repo/putRecord.ts +5 -2
  117. package/src/lexicon/types/tools/ozone/communication/createTemplate.ts +3 -0
  118. package/src/lexicon/types/tools/ozone/communication/defs.ts +2 -0
  119. package/src/lexicon/types/tools/ozone/communication/updateTemplate.ts +3 -0
  120. package/src/lexicon/types/tools/ozone/moderation/emitEvent.ts +1 -0
  121. package/src/repo/prepare.ts +31 -13
  122. package/src/repo/types.ts +4 -0
  123. package/tests/crud.test.ts +131 -14
package/src/repo/types.ts CHANGED
@@ -3,6 +3,8 @@ import { AtUri } from '@atproto/syntax'
3
3
  import { WriteOpAction } from '@atproto/repo'
4
4
  import { RepoRecord } from '@atproto/lexicon'
5
5
 
6
+ export type ValidationStatus = 'valid' | 'unknown' | undefined
7
+
6
8
  export type BlobConstraint = {
7
9
  accept?: string[]
8
10
  maxSize?: number
@@ -21,6 +23,7 @@ export type PreparedCreate = {
21
23
  swapCid?: CID | null
22
24
  record: RepoRecord
23
25
  blobs: PreparedBlobRef[]
26
+ validationStatus: ValidationStatus
24
27
  }
25
28
 
26
29
  export type PreparedUpdate = {
@@ -30,6 +33,7 @@ export type PreparedUpdate = {
30
33
  swapCid?: CID | null
31
34
  record: RepoRecord
32
35
  blobs: PreparedBlobRef[]
36
+ validationStatus: ValidationStatus
33
37
  }
34
38
 
35
39
  export type PreparedDelete = {
@@ -6,7 +6,7 @@ import { TestNetworkNoAppView } from '@atproto/dev-env'
6
6
  import { cidForCbor, TID, ui8ToArrayBuffer } from '@atproto/common'
7
7
  import { BlobNotFoundError } from '@atproto/repo'
8
8
  import * as Post from '../src/lexicon/types/app/bsky/feed/post'
9
- import { paginateAll } from './_util'
9
+ import { forSnapshot, paginateAll } from './_util'
10
10
  import AppContext from '../src/context'
11
11
  import { ids, lexicons } from '../src/lexicon/lexicons'
12
12
 
@@ -565,8 +565,9 @@ describe('crud operations', () => {
565
565
  expect(got.data.value['$type']).toBe(uri.collection)
566
566
  })
567
567
 
568
- it('requires the schema to be known if validating', async () => {
568
+ it('requires the schema to be known if explicitly validating', async () => {
569
569
  const prom = aliceAgent.api.com.atproto.repo.createRecord({
570
+ validate: true,
570
571
  repo: aliceAgent.accountDid,
571
572
  collection: 'com.example.foobar',
572
573
  record: { $type: 'com.example.foobar' },
@@ -576,6 +577,16 @@ describe('crud operations', () => {
576
577
  )
577
578
  })
578
579
 
580
+ it('does not require the schema to be known if not explicitly validating', async () => {
581
+ const prom = await aliceAgent.api.com.atproto.repo.createRecord({
582
+ // validate not set
583
+ repo: aliceAgent.accountDid,
584
+ collection: 'com.example.foobar',
585
+ record: { $type: 'com.example.foobar' },
586
+ })
587
+ expect(prom.data.validationStatus).toBe('unknown')
588
+ })
589
+
579
590
  it('requires the $type to match the schema', async () => {
580
591
  await expect(
581
592
  aliceAgent.api.com.atproto.repo.createRecord({
@@ -637,6 +648,7 @@ describe('crud operations', () => {
637
648
  describe('unvalidated writes', () => {
638
649
  it('disallows creation of unknown lexicons when validate is set to true', async () => {
639
650
  const attempt = aliceAgent.api.com.atproto.repo.createRecord({
651
+ validate: true,
640
652
  repo: aliceAgent.accountDid,
641
653
  collection: 'com.example.record',
642
654
  record: {
@@ -648,52 +660,157 @@ describe('crud operations', () => {
648
660
  )
649
661
  })
650
662
 
651
- it('allows creation of unknown lexicons when validate is set to false', async () => {
652
- const res = await aliceAgent.api.com.atproto.repo.createRecord({
663
+ it('allows creation of unknown lexicons when validate is not set to true', async () => {
664
+ // validate: default
665
+ const res1 = await aliceAgent.api.com.atproto.repo.createRecord({
653
666
  repo: aliceAgent.accountDid,
654
667
  collection: 'com.example.record',
655
668
  record: {
656
- blah: 'thing',
669
+ blah: 'thing1',
657
670
  },
671
+ })
672
+ expect(res1.data.validationStatus).toBe('unknown')
673
+ const record1 = await ctx.actorStore.read(
674
+ aliceAgent.accountDid,
675
+ (store) =>
676
+ store.record.getRecord(new AtUri(res1.data.uri), res1.data.cid),
677
+ )
678
+ expect(record1?.value).toEqual({
679
+ $type: 'com.example.record',
680
+ blah: 'thing1',
681
+ })
682
+ // validate: false
683
+ const res2 = await aliceAgent.api.com.atproto.repo.createRecord({
658
684
  validate: false,
685
+ repo: aliceAgent.accountDid,
686
+ collection: 'com.example.record',
687
+ record: {
688
+ blah: 'thing2',
689
+ },
659
690
  })
660
- const record = await ctx.actorStore.read(aliceAgent.accountDid, (store) =>
661
- store.record.getRecord(new AtUri(res.data.uri), res.data.cid),
691
+ expect(res2.data.validationStatus).toBeUndefined()
692
+ const record2 = await ctx.actorStore.read(
693
+ aliceAgent.accountDid,
694
+ (store) =>
695
+ store.record.getRecord(new AtUri(res2.data.uri), res2.data.cid),
662
696
  )
663
- expect(record?.value).toEqual({
697
+ expect(record2?.value).toEqual({
664
698
  $type: 'com.example.record',
665
- blah: 'thing',
699
+ blah: 'thing2',
666
700
  })
667
701
  })
668
702
 
669
703
  it('allows update of unknown lexicons when validate is set to false', async () => {
670
704
  const createRes = await aliceAgent.api.com.atproto.repo.createRecord({
705
+ validate: false,
671
706
  repo: aliceAgent.accountDid,
672
707
  collection: 'com.example.record',
673
708
  record: {
674
709
  blah: 'thing',
675
710
  },
676
- validate: false,
677
711
  })
678
712
  const uri = new AtUri(createRes.data.uri)
679
- const updateRes = await aliceAgent.api.com.atproto.repo.putRecord({
713
+ // validate: default
714
+ const updateRes1 = await aliceAgent.api.com.atproto.repo.putRecord({
680
715
  repo: aliceAgent.accountDid,
681
716
  collection: 'com.example.record',
682
717
  rkey: uri.rkey,
683
718
  record: {
684
719
  blah: 'something else',
685
720
  },
721
+ })
722
+ const record1 = await ctx.actorStore.read(
723
+ aliceAgent.accountDid,
724
+ (store) => store.record.getRecord(uri, updateRes1.data.cid),
725
+ )
726
+ expect(record1?.value).toEqual({
727
+ $type: 'com.example.record',
728
+ blah: 'something else',
729
+ })
730
+ // validate: false
731
+ const updateRes2 = await aliceAgent.api.com.atproto.repo.putRecord({
686
732
  validate: false,
733
+ repo: aliceAgent.accountDid,
734
+ collection: 'com.example.record',
735
+ rkey: uri.rkey,
736
+ record: {
737
+ blah: 'something else',
738
+ },
687
739
  })
688
- const record = await ctx.actorStore.read(aliceAgent.accountDid, (store) =>
689
- store.record.getRecord(uri, updateRes.data.cid),
740
+ const record2 = await ctx.actorStore.read(
741
+ aliceAgent.accountDid,
742
+ (store) => store.record.getRecord(uri, updateRes2.data.cid),
690
743
  )
691
- expect(record?.value).toEqual({
744
+ expect(record2?.value).toEqual({
692
745
  $type: 'com.example.record',
693
746
  blah: 'something else',
694
747
  })
695
748
  })
696
749
 
750
+ it('applyWrites returns results with validation status', async () => {
751
+ const existing1 = await aliceAgent.api.com.atproto.repo.createRecord({
752
+ validate: false,
753
+ repo: aliceAgent.accountDid,
754
+ collection: 'com.example.record',
755
+ record: {
756
+ blah: 'thing1',
757
+ },
758
+ })
759
+ const existing2 = await aliceAgent.api.com.atproto.repo.createRecord({
760
+ validate: false,
761
+ repo: aliceAgent.accountDid,
762
+ collection: 'com.example.record',
763
+ record: {
764
+ blah: 'thing2',
765
+ },
766
+ })
767
+ const {
768
+ data: { results },
769
+ } = await aliceAgent.com.atproto.repo.applyWrites({
770
+ repo: aliceAgent.accountDid,
771
+ writes: [
772
+ {
773
+ $type: `${ids.ComAtprotoRepoApplyWrites}#create`,
774
+ action: 'create',
775
+ collection: ids.AppBskyFeedPost,
776
+ value: {
777
+ $type: ids.AppBskyFeedPost,
778
+ text: '👋',
779
+ createdAt: new Date().toISOString(),
780
+ },
781
+ },
782
+ {
783
+ $type: `${ids.ComAtprotoRepoApplyWrites}#update`,
784
+ action: 'update',
785
+ collection: 'com.example.record',
786
+ rkey: new AtUri(existing1.data.uri).rkey,
787
+ value: {},
788
+ },
789
+ {
790
+ $type: `${ids.ComAtprotoRepoApplyWrites}#delete`,
791
+ action: 'delete',
792
+ collection: 'com.example.record',
793
+ rkey: new AtUri(existing2.data.uri).rkey,
794
+ },
795
+ ],
796
+ })
797
+ expect(forSnapshot(results)).toEqual([
798
+ {
799
+ $type: `${ids.ComAtprotoRepoApplyWrites}#createResult`,
800
+ cid: 'cids(0)',
801
+ uri: 'record(0)',
802
+ validationStatus: 'valid',
803
+ },
804
+ {
805
+ $type: `${ids.ComAtprotoRepoApplyWrites}#updateResult`,
806
+ cid: 'cids(1)',
807
+ uri: 'record(1)',
808
+ validationStatus: 'unknown',
809
+ },
810
+ { $type: `${ids.ComAtprotoRepoApplyWrites}#deleteResult` },
811
+ ])
812
+ })
813
+
697
814
  it('correctly associates images with unknown record types', async () => {
698
815
  const file = await fs.readFile(
699
816
  '../dev-env/src/seed/img/key-portrait-small.jpg',