@atproto/lexicon-resolver 0.2.5 → 0.3.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.
Files changed (82) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/LICENSE.txt +1 -1
  3. package/dist/lexicon.d.ts +13 -13
  4. package/dist/lexicon.d.ts.map +1 -1
  5. package/dist/lexicon.js +46 -20
  6. package/dist/lexicon.js.map +1 -1
  7. package/dist/lexicons/com/atproto/lexicon/schema.d.ts +3 -0
  8. package/dist/lexicons/com/atproto/lexicon/schema.d.ts.map +1 -0
  9. package/dist/lexicons/com/atproto/lexicon/schema.defs.d.ts +50 -0
  10. package/dist/lexicons/com/atproto/lexicon/schema.defs.d.ts.map +1 -0
  11. package/dist/lexicons/com/atproto/lexicon/schema.defs.js +15 -0
  12. package/dist/lexicons/com/atproto/lexicon/schema.defs.js.map +1 -0
  13. package/dist/lexicons/com/atproto/lexicon/schema.js +45 -0
  14. package/dist/lexicons/com/atproto/lexicon/schema.js.map +1 -0
  15. package/dist/lexicons/com/atproto/lexicon.d.ts +2 -0
  16. package/dist/lexicons/com/atproto/lexicon.d.ts.map +1 -0
  17. package/dist/lexicons/com/atproto/lexicon.js +41 -0
  18. package/dist/lexicons/com/atproto/lexicon.js.map +1 -0
  19. package/dist/lexicons/com/atproto/sync/getRecord.d.ts +3 -0
  20. package/dist/lexicons/com/atproto/sync/getRecord.d.ts.map +1 -0
  21. package/dist/lexicons/com/atproto/sync/getRecord.defs.d.ts +31 -0
  22. package/dist/lexicons/com/atproto/sync/getRecord.defs.d.ts.map +1 -0
  23. package/dist/lexicons/com/atproto/sync/getRecord.defs.js +24 -0
  24. package/dist/lexicons/com/atproto/sync/getRecord.defs.js.map +1 -0
  25. package/dist/lexicons/com/atproto/sync/getRecord.js +45 -0
  26. package/dist/lexicons/com/atproto/sync/getRecord.js.map +1 -0
  27. package/dist/lexicons/com/atproto/sync.d.ts +2 -0
  28. package/dist/lexicons/com/atproto/sync.d.ts.map +1 -0
  29. package/dist/lexicons/com/atproto/sync.js +41 -0
  30. package/dist/lexicons/com/atproto/sync.js.map +1 -0
  31. package/dist/lexicons/com/atproto.d.ts +3 -0
  32. package/dist/lexicons/com/atproto.d.ts.map +1 -0
  33. package/dist/lexicons/com/atproto.js +42 -0
  34. package/dist/lexicons/com/atproto.js.map +1 -0
  35. package/dist/lexicons/com.d.ts +2 -0
  36. package/dist/lexicons/com.d.ts.map +1 -0
  37. package/dist/lexicons/com.js +41 -0
  38. package/dist/lexicons/com.js.map +1 -0
  39. package/dist/lexicons/index.d.ts +2 -0
  40. package/dist/lexicons/index.d.ts.map +1 -0
  41. package/dist/lexicons/index.js +41 -0
  42. package/dist/lexicons/index.js.map +1 -0
  43. package/dist/record.d.ts +9 -10
  44. package/dist/record.d.ts.map +1 -1
  45. package/dist/record.js +21 -18
  46. package/dist/record.js.map +1 -1
  47. package/package.json +7 -9
  48. package/src/lexicon.ts +29 -37
  49. package/src/lexicons/com/atproto/lexicon/schema.defs.ts +43 -0
  50. package/src/lexicons/com/atproto/lexicon/schema.ts +6 -0
  51. package/src/lexicons/com/atproto/lexicon.ts +5 -0
  52. package/src/lexicons/com/atproto/sync/getRecord.defs.ts +39 -0
  53. package/src/lexicons/com/atproto/sync/getRecord.ts +6 -0
  54. package/src/lexicons/com/atproto/sync.ts +5 -0
  55. package/src/lexicons/com/atproto.ts +6 -0
  56. package/src/lexicons/com.ts +5 -0
  57. package/src/lexicons/index.ts +5 -0
  58. package/src/record.ts +58 -32
  59. package/tests/lexicon.test.ts +4 -3
  60. package/tests/record.test.ts +99 -6
  61. package/tsconfig.build.tsbuildinfo +1 -1
  62. package/dist/client/index.d.ts +0 -28
  63. package/dist/client/index.d.ts.map +0 -1
  64. package/dist/client/index.js +0 -118
  65. package/dist/client/index.js.map +0 -1
  66. package/dist/client/lexicons.d.ts +0 -105
  67. package/dist/client/lexicons.d.ts.map +0 -1
  68. package/dist/client/lexicons.js +0 -75
  69. package/dist/client/lexicons.js.map +0 -1
  70. package/dist/client/types/com/atproto/sync/getRecord.d.ts +0 -38
  71. package/dist/client/types/com/atproto/sync/getRecord.d.ts.map +0 -1
  72. package/dist/client/types/com/atproto/sync/getRecord.js +0 -58
  73. package/dist/client/types/com/atproto/sync/getRecord.js.map +0 -1
  74. package/dist/client/util.d.ts +0 -37
  75. package/dist/client/util.d.ts.map +0 -1
  76. package/dist/client/util.js +0 -38
  77. package/dist/client/util.js.map +0 -1
  78. package/src/client/index.ts +0 -67
  79. package/src/client/lexicons.ts +0 -98
  80. package/src/client/types/com/atproto/sync/getRecord.ts +0 -78
  81. package/src/client/util.ts +0 -82
  82. package/tsconfig.tests.tsbuildinfo +0 -1
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /*
3
+ * THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getRecord = void 0;
40
+ exports.getRecord = __importStar(require("./sync/getRecord.js"));
41
+ //# sourceMappingURL=sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.js","sourceRoot":"","sources":["../../../../src/lexicons/com/atproto/sync.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,iEAAgD","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * as getRecord from './sync/getRecord.js'\n"]}
@@ -0,0 +1,3 @@
1
+ export * as lexicon from './atproto/lexicon.js';
2
+ export * as sync from './atproto/sync.js';
3
+ //# sourceMappingURL=atproto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atproto.d.ts","sourceRoot":"","sources":["../../../src/lexicons/com/atproto.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAA;AAC/C,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAA"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ /*
3
+ * THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.sync = exports.lexicon = void 0;
40
+ exports.lexicon = __importStar(require("./atproto/lexicon.js"));
41
+ exports.sync = __importStar(require("./atproto/sync.js"));
42
+ //# sourceMappingURL=atproto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atproto.js","sourceRoot":"","sources":["../../../src/lexicons/com/atproto.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,gEAA+C;AAC/C,0DAAyC","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * as lexicon from './atproto/lexicon.js'\nexport * as sync from './atproto/sync.js'\n"]}
@@ -0,0 +1,2 @@
1
+ export * as atproto from './com/atproto.js';
2
+ //# sourceMappingURL=com.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"com.d.ts","sourceRoot":"","sources":["../../src/lexicons/com.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAA"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /*
3
+ * THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.atproto = void 0;
40
+ exports.atproto = __importStar(require("./com/atproto.js"));
41
+ //# sourceMappingURL=com.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"com.js","sourceRoot":"","sources":["../../src/lexicons/com.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,4DAA2C","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * as atproto from './com/atproto.js'\n"]}
@@ -0,0 +1,2 @@
1
+ export * as com from './com.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lexicons/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /*
3
+ * THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.com = void 0;
40
+ exports.com = __importStar(require("./com.js"));
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lexicons/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,gDAA+B","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * as com from './com.js'\n"]}
package/dist/record.d.ts CHANGED
@@ -1,20 +1,20 @@
1
- import { CID } from 'multiformats/cid';
2
1
  import { IdResolver } from '@atproto/identity';
3
- import { RepoRecord } from '@atproto/lexicon';
2
+ import { AgentConfig, Cid, DidString, FetchHandler, LexMap } from '@atproto/lex';
4
3
  import { Commit } from '@atproto/repo';
5
- import { AtUri } from '@atproto/syntax';
6
- import { BuildFetchHandlerOptions, FetchHandler } from '@atproto/xrpc';
4
+ import { AtUri, AtUriString } from '@atproto/syntax';
5
+ export { AtUri, IdResolver };
6
+ export type { AgentConfig, AtUriString, Cid, Commit, DidString, FetchHandler, LexMap, };
7
7
  /**
8
8
  * Resolve a record from the network.
9
9
  */
10
- export type RecordResolver = (uri: AtUri | string) => Promise<RecordResolution>;
10
+ export type RecordResolver = (uri: AtUri | AtUriString) => Promise<RecordResolution>;
11
11
  /**
12
12
  * Resolve a record from the network, verifying its authenticity.
13
13
  */
14
- export type AtprotoRecordResolver = (uri: AtUri | string, options?: ResolveRecordOptions) => Promise<RecordResolution>;
14
+ export type AtprotoRecordResolver = (uri: AtUri | AtUriString, options?: ResolveRecordOptions) => Promise<RecordResolution>;
15
15
  export type BuildRecordResolverOptions = {
16
16
  idResolver?: IdResolver;
17
- rpc?: Partial<BuildFetchHandlerOptions> | FetchHandler;
17
+ rpc?: Partial<AgentConfig> | FetchHandler;
18
18
  };
19
19
  export type ResolveRecordOptions = {
20
20
  forceRefresh?: boolean;
@@ -22,10 +22,9 @@ export type ResolveRecordOptions = {
22
22
  export type RecordResolution = {
23
23
  commit: Commit;
24
24
  uri: AtUri;
25
- cid: CID;
26
- record: RepoRecord;
25
+ cid: Cid;
26
+ record: LexMap;
27
27
  };
28
- export { AtUri, CID, type Commit, IdResolver, type RepoRecord };
29
28
  /**
30
29
  * Build a record resolver function.
31
30
  */
@@ -1 +1 @@
1
- {"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EACL,MAAM,EAMP,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,KAAK,EAAkB,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAKtE;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,KAAK,GAAG,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAA;AAE/E;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAClC,GAAG,EAAE,KAAK,GAAG,MAAM,EACnB,OAAO,CAAC,EAAE,oBAAoB,KAC3B,OAAO,CAAC,gBAAgB,CAAC,CAAA;AAE9B,MAAM,MAAM,0BAA0B,GAAG;IACvC,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,GAAG,CAAC,EAAE,OAAO,CAAC,wBAAwB,CAAC,GAAG,YAAY,CAAA;CACvD,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,KAAK,CAAA;IACV,GAAG,EAAE,GAAG,CAAA;IACR,MAAM,EAAE,UAAU,CAAA;CACnB,CAAA;AAED,OAAO,EAAE,KAAK,EAAE,GAAG,EAA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AAoB,GAAG;IACjC,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,KAAK,CAAA;IACV,GAAG,EAAE,GAAG,CAAA;IACR,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,0BAA+B,GACvC,qBAAqB,CAoDvB;AAED,eAAO,MAAM,aAAa,uBAAwB,CAAA;AAElD,eAAO,MAAM,SAAS,sFAIpB,CAAA;AAEF,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIrD"}
package/dist/record.js CHANGED
@@ -1,18 +1,15 @@
1
1
  "use strict";
2
- /* eslint-disable import/no-deprecated */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.RecordResolutionError = exports.safeFetch = exports.resolveRecord = exports.IdResolver = exports.CID = exports.AtUri = void 0;
3
+ exports.RecordResolutionError = exports.safeFetch = exports.resolveRecord = exports.IdResolver = exports.AtUri = void 0;
5
4
  exports.buildRecordResolver = buildRecordResolver;
6
- const cid_1 = require("multiformats/cid");
7
- Object.defineProperty(exports, "CID", { enumerable: true, get: function () { return cid_1.CID; } });
8
5
  const identity_1 = require("@atproto/identity");
9
6
  Object.defineProperty(exports, "IdResolver", { enumerable: true, get: function () { return identity_1.IdResolver; } });
7
+ const lex_1 = require("@atproto/lex");
10
8
  const repo_1 = require("@atproto/repo");
11
9
  const syntax_1 = require("@atproto/syntax");
12
10
  Object.defineProperty(exports, "AtUri", { enumerable: true, get: function () { return syntax_1.AtUri; } });
13
11
  const fetch_node_1 = require("@atproto-labs/fetch-node");
14
- const index_js_1 = require("./client/index.js");
15
- const util_js_1 = require("./util.js");
12
+ const index_js_1 = require("./lexicons/index.js");
16
13
  /**
17
14
  * Build a record resolver function.
18
15
  */
@@ -21,22 +18,29 @@ function buildRecordResolver(options = {}) {
21
18
  return async function resolveRecord(uriStr, opts = {}) {
22
19
  const uri = typeof uriStr === 'string' ? new syntax_1.AtUri(uriStr) : uriStr;
23
20
  const did = await getDidFromUri(uri, { idResolver });
24
- const identity = await idResolver.did
25
- .resolveAtprotoData(did, opts.forceRefresh)
21
+ const identityDoc = await idResolver.did
22
+ .ensureResolve(did, opts.forceRefresh)
26
23
  .catch((err) => {
27
24
  throw new RecordResolutionError('Could not resolve DID identity data', {
28
25
  cause: err,
29
26
  });
30
27
  });
31
- const client = new index_js_1.AtpBaseClient(typeof rpc === 'function'
32
- ? rpc
28
+ const { pds, signingKey } = (0, identity_1.parseToAtprotoDocument)(identityDoc);
29
+ if (!pds) {
30
+ throw new RecordResolutionError('Incomplete DID identity data: missing pds');
31
+ }
32
+ if (!signingKey) {
33
+ throw new RecordResolutionError('Incomplete DID identity data: missing signing key');
34
+ }
35
+ const client = new lex_1.Client(typeof rpc === 'function'
36
+ ? { fetchHandler: rpc }
33
37
  : {
34
38
  ...rpc,
35
- service: rpc?.service ?? identity.pds,
39
+ service: rpc?.service ?? pds,
36
40
  fetch: rpc?.fetch ?? exports.safeFetch,
37
41
  });
38
- const { data: proofBytes } = await client.com.atproto.sync
39
- .getRecord({
42
+ const proofBytes = await client
43
+ .call(index_js_1.com.atproto.sync.getRecord, {
40
44
  did,
41
45
  collection: uri.collection,
42
46
  rkey: uri.rkey,
@@ -48,7 +52,7 @@ function buildRecordResolver(options = {}) {
48
52
  });
49
53
  const verified = await verifyRecordProof(proofBytes, {
50
54
  uri: syntax_1.AtUri.make(did, uri.collection, uri.rkey),
51
- signingKey: identity.signingKey,
55
+ signingKey,
52
56
  });
53
57
  return verified;
54
58
  };
@@ -67,12 +71,11 @@ class RecordResolutionError extends Error {
67
71
  }
68
72
  exports.RecordResolutionError = RecordResolutionError;
69
73
  async function getDidFromUri(uri, { idResolver }) {
70
- if (uri.host.startsWith('did:')) {
71
- (0, syntax_1.ensureValidDid)(uri.host);
74
+ if (lex_1.l.isDidString(uri.host)) {
72
75
  return uri.host;
73
76
  }
74
77
  const resolved = await idResolver.handle.resolve(uri.host);
75
- if (!resolved || !(0, util_js_1.isValidDid)(resolved)) {
78
+ if (!resolved || !lex_1.l.isDidString(resolved)) {
76
79
  throw new RecordResolutionError('Could not resolve handle found in AT-URI');
77
80
  }
78
81
  return resolved;
@@ -99,7 +102,7 @@ async function verifyRecordProof(proofBytes, { uri, signingKey }) {
99
102
  if (!cid) {
100
103
  throw new RecordResolutionError('Record not found in proof');
101
104
  }
102
- const record = await blockstore.readRecord(cid);
105
+ const record = (await blockstore.readRecord(cid));
103
106
  return { commit, uri, cid, record };
104
107
  }
105
108
  //# sourceMappingURL=record.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"record.js","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":";AAAA,yCAAyC;;;AAqDzC,kDA2CC;AA9FD,0CAAsC;AA8CtB,oFA9CP,SAAG,OA8CO;AA7CnB,gDAA8C;AA6CZ,2FA7CzB,qBAAU,OA6CyB;AA3C5C,wCAOsB;AACtB,4CAAuD;AAmC9C,sFAnCA,cAAK,OAmCA;AAjCd,yDAAwD;AACxD,gDAA2D;AAC3D,uCAAsC;AAiCtC;;GAEG;AACH,SAAgB,mBAAmB,CACjC,UAAsC,EAAE;IAExC,MAAM,EAAE,UAAU,GAAG,IAAI,qBAAU,EAAE,EAAE,GAAG,EAAE,GAAG,OAAO,CAAA;IACtD,OAAO,KAAK,UAAU,aAAa,CACjC,MAAsB,EACtB,OAA6B,EAAE;QAE/B,MAAM,GAAG,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,cAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;QACnE,MAAM,GAAG,GAAG,MAAM,aAAa,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;QACpD,MAAM,QAAQ,GAAG,MAA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G,MAAM,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,UAAO,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QAC1E,MAAM,IAAI,qBAAqB,CAAC,gCAAgC,EAAE;YAChE,KAAK,EAAE,GAAG;SACX,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IACF,IAAI,MAAM,CAAC,GAAG,KAAK,GAAG,CAAC,IAAI,EAAE,CAAC;QAC5B,MAAM,IAAI,qBAAqB,CAAC,qBAAqB,MAAM,CAAC,GAAG,EAAE,CAAC,CAAA;IACpE,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,IAAA,sBAAe,EAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAC1D,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,qBAAqB,CAC7B,gCAAgC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAClD,CAAA;IACH,CAAC;IACD,MAAM,GAAG,GAAG,UAAG,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;IAC7C,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;IAC1D,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,qBAAqB,CAAC,2BAA2B,CAAC,CAAA;IAC9D,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;IAC/C,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,CAAA;AACrC,CAAC","sourcesContent":["/* eslint-disable import/no-deprecated */\n\nimport { CID } from 'multiformats/cid'\nimport { IdResolver } from '@atproto/identity'\nimport { RepoRecord } from '@atproto/lexicon'\nimport {\n Commit,\n MST,\n MemoryBlockstore,\n def as repoDef,\n readCarWithRoot,\n verifyCommitSig,\n} from '@atproto/repo'\nimport { AtUri, ensureValidDid } from '@atproto/syntax'\nimport { BuildFetchHandlerOptions, FetchHandler } from '@atproto/xrpc'\nimport { safeFetchWrap } from '@atproto-labs/fetch-node'\nimport { AtpBaseClient as Client } from './client/index.js'\nimport { isValidDid } from './util.js'\n\n/**\n * Resolve a record from the network.\n */\nexport type RecordResolver = (uri: AtUri | string) => Promise<RecordResolution>\n\n/**\n * Resolve a record from the network, verifying its authenticity.\n */\nexport type AtprotoRecordResolver = (\n uri: AtUri | string,\n options?: ResolveRecordOptions,\n) => Promise<RecordResolution>\n\nexport type BuildRecordResolverOptions = {\n idResolver?: IdResolver\n rpc?: Partial<BuildFetchHandlerOptions> | FetchHandler\n}\n\nexport type ResolveRecordOptions = {\n forceRefresh?: boolean\n}\n\nexport type RecordResolution = {\n commit: Commit\n uri: AtUri\n cid: CID\n record: RepoRecord\n}\n\nexport { AtUri, CID, type Commit, IdResolver, type RepoRecord }\n\n/**\n * Build a record resolver function.\n */\nexport function buildRecordResolver(\n options: BuildRecordResolverOptions = {},\n): AtprotoRecordResolver {\n const { idResolver = new IdResolver(), rpc } = options\n return async function resolveRecord(\n uriStr: AtUri | string,\n opts: ResolveRecordOptions = {},\n ): Promise<RecordResolution> {\n const uri = typeof uriStr === 'string' ? new AtUri(uriStr) : uriStr\n const did = await getDidFromUri(uri, { idResolver })\n const identity = await idResolver.did\n .resolveAtprotoData(did, opts.forceRefresh)\n .catch((err) => {\n throw new RecordResolutionError('Could not resolve DID identity data', {\n cause: err,\n })\n })\n const client = new Client(\n typeof rpc === 'function'\n ? rpc\n : {\n ...rpc,\n service: rpc?.service ?? identity.pds,\n fetch: rpc?.fetch ?? safeFetch,\n },\n )\n const { data: proofBytes } = await client.com.atproto.sync\n .getRecord({\n did,\n collection: uri.collection,\n rkey: uri.rkey,\n })\n .catch((err) => {\n throw new RecordResolutionError('Could not fetch record proof', {\n cause: err,\n })\n })\n const verified = await verifyRecordProof(proofBytes, {\n uri: AtUri.make(did, uri.collection, uri.rkey),\n signingKey: identity.signingKey,\n })\n return verified\n }\n}\n\nexport const resolveRecord = buildRecordResolver()\n\nexport const safeFetch = safeFetchWrap({\n allowIpHost: false,\n allowImplicitRedirect: true,\n responseMaxSize: (1024 + 10) * 1024, // 1MB + 10kB, just a bit larger than max record size\n})\n\nexport class RecordResolutionError extends Error {\n constructor(message?: string, options?: ErrorOptions) {\n super(message, options)\n this.name = 'RecordResolutionError'\n }\n}\n\nasync function getDidFromUri(\n uri: AtUri,\n { idResolver }: { idResolver: IdResolver },\n) {\n if (uri.host.startsWith('did:')) {\n ensureValidDid(uri.host)\n return uri.host\n }\n const resolved = await idResolver.handle.resolve(uri.host)\n if (!resolved || !isValidDid(resolved)) {\n throw new RecordResolutionError('Could not resolve handle found in AT-URI')\n }\n return resolved\n}\n\nasync function verifyRecordProof(\n proofBytes: Uint8Array,\n { uri, signingKey }: { uri: AtUri; signingKey: string },\n) {\n const { root, blocks } = await readCarWithRoot(proofBytes).catch((err) => {\n throw new RecordResolutionError('Malformed record proof', { cause: err })\n })\n const blockstore = new MemoryBlockstore(blocks)\n const commit = await blockstore.readObj(root, repoDef.commit).catch((err) => {\n throw new RecordResolutionError('Invalid commit in record proof', {\n cause: err,\n })\n })\n if (commit.did !== uri.host) {\n throw new RecordResolutionError(`Invalid repo did: ${commit.did}`)\n }\n const validSig = await verifyCommitSig(commit, signingKey)\n if (!validSig) {\n throw new RecordResolutionError(\n `Invalid signature on commit: ${root.toString()}`,\n )\n }\n const mst = MST.load(blockstore, commit.data)\n const cid = await mst.get(`${uri.collection}/${uri.rkey}`)\n if (!cid) {\n throw new RecordResolutionError('Record not found in proof')\n }\n const record = await blockstore.readRecord(cid)\n return { commit, uri, cid, record }\n}\n"]}
1
+ {"version":3,"file":"record.js","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":";;;AAmEA,kDAsDC;AAzHD,gDAAsE;AAsBtD,2FAtBP,qBAAU,OAsBO;AArB1B,sCAQ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,EAAE,CAAC;QACd,MAAM,IAAI,qBAAqB,CAC7B,gCAAgC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAClD,CAAA;IACH,CAAC;IACD,MAAM,GAAG,GAAG,UAAG,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;IAC7C,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;IAC1D,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,qBAAqB,CAAC,2BAA2B,CAAC,CAAA;IAC9D,CAAC;IACD,MAAM,MAAM,GAAG,CAAC,MAAM,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAW,CAAA;IAC3D,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,CAAA;AACrC,CAAC","sourcesContent":["import { IdResolver, parseToAtprotoDocument } from '@atproto/identity'\nimport {\n AgentConfig,\n Cid,\n Client,\n DidString,\n FetchHandler,\n LexMap,\n l,\n} from '@atproto/lex'\nimport {\n Commit,\n MST,\n MemoryBlockstore,\n def as repoDef,\n readCarWithRoot,\n verifyCommitSig,\n} from '@atproto/repo'\nimport { AtUri, AtUriString } from '@atproto/syntax'\nimport { safeFetchWrap } from '@atproto-labs/fetch-node'\nimport { com } from './lexicons/index.js'\n\nexport { AtUri, IdResolver }\nexport type {\n AgentConfig,\n AtUriString,\n Cid,\n Commit,\n DidString,\n FetchHandler,\n LexMap,\n}\n\n/**\n * Resolve a record from the network.\n */\nexport type RecordResolver = (\n uri: AtUri | AtUriString,\n) => Promise<RecordResolution>\n\n/**\n * Resolve a record from the network, verifying its authenticity.\n */\nexport type AtprotoRecordResolver = (\n uri: AtUri | AtUriString,\n options?: ResolveRecordOptions,\n) => Promise<RecordResolution>\n\nexport type BuildRecordResolverOptions = {\n idResolver?: IdResolver\n rpc?: Partial<AgentConfig> | FetchHandler\n}\n\nexport type ResolveRecordOptions = {\n forceRefresh?: boolean\n}\n\nexport type RecordResolution = {\n commit: Commit\n uri: AtUri\n cid: Cid\n record: LexMap\n}\n\n/**\n * Build a record resolver function.\n */\nexport function buildRecordResolver(\n options: BuildRecordResolverOptions = {},\n): AtprotoRecordResolver {\n const { idResolver = new IdResolver(), rpc } = options\n return async function resolveRecord(\n uriStr: AtUri | AtUriString,\n opts: ResolveRecordOptions = {},\n ): Promise<RecordResolution> {\n const uri = typeof uriStr === 'string' ? new AtUri(uriStr) : uriStr\n const did = await getDidFromUri(uri, { idResolver })\n const identityDoc = await idResolver.did\n .ensureResolve(did, opts.forceRefresh)\n .catch((err) => {\n throw new RecordResolutionError('Could not resolve DID identity data', {\n cause: err,\n })\n })\n const { pds, signingKey } = parseToAtprotoDocument(identityDoc)\n if (!pds) {\n throw new RecordResolutionError(\n 'Incomplete DID identity data: missing pds',\n )\n }\n if (!signingKey) {\n throw new RecordResolutionError(\n 'Incomplete DID identity data: missing signing key',\n )\n }\n const client = new Client(\n typeof rpc === 'function'\n ? { fetchHandler: rpc }\n : {\n ...rpc,\n service: rpc?.service ?? pds,\n fetch: rpc?.fetch ?? safeFetch,\n },\n )\n const proofBytes = await client\n .call(com.atproto.sync.getRecord, {\n did,\n collection: uri.collection as l.NsidString,\n rkey: uri.rkey as l.RecordKeyString,\n })\n .catch((err) => {\n throw new RecordResolutionError('Could not fetch record proof', {\n cause: err,\n })\n })\n const verified = await verifyRecordProof(proofBytes, {\n uri: AtUri.make(did, uri.collection, uri.rkey),\n signingKey,\n })\n return verified\n }\n}\n\nexport const resolveRecord = buildRecordResolver()\n\nexport const safeFetch = safeFetchWrap({\n allowIpHost: false,\n allowImplicitRedirect: true,\n responseMaxSize: (1024 + 10) * 1024, // 1MB + 10kB, just a bit larger than max record size\n})\n\nexport class RecordResolutionError extends Error {\n constructor(message?: string, options?: ErrorOptions) {\n super(message, options)\n this.name = 'RecordResolutionError'\n }\n}\n\nasync function getDidFromUri(\n uri: AtUri,\n { idResolver }: { idResolver: IdResolver },\n): Promise<DidString> {\n if (l.isDidString(uri.host)) {\n return uri.host\n }\n\n const resolved = await idResolver.handle.resolve(uri.host)\n if (!resolved || !l.isDidString(resolved)) {\n throw new RecordResolutionError('Could not resolve handle found in AT-URI')\n }\n\n return resolved\n}\n\nasync function verifyRecordProof(\n proofBytes: Uint8Array,\n { uri, signingKey }: { uri: AtUri; signingKey: string },\n): Promise<RecordResolution> {\n const { root, blocks } = await readCarWithRoot(proofBytes).catch((err) => {\n throw new RecordResolutionError('Malformed record proof', { cause: err })\n })\n const blockstore = new MemoryBlockstore(blocks)\n const commit = await blockstore.readObj(root, repoDef.commit).catch((err) => {\n throw new RecordResolutionError('Invalid commit in record proof', {\n cause: err,\n })\n })\n if (commit.did !== uri.host) {\n throw new RecordResolutionError(`Invalid repo did: ${commit.did}`)\n }\n const validSig = await verifyCommitSig(commit, signingKey)\n if (!validSig) {\n throw new RecordResolutionError(\n `Invalid signature on commit: ${root.toString()}`,\n )\n }\n const mst = MST.load(blockstore, commit.data)\n const cid = await mst.get(`${uri.collection}/${uri.rkey}`)\n if (!cid) {\n throw new RecordResolutionError('Record not found in proof')\n }\n const record = (await blockstore.readRecord(cid)) as LexMap\n return { commit, uri, cid, record }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/lexicon-resolver",
3
- "version": "0.2.5",
3
+ "version": "0.3.0",
4
4
  "type": "commonjs",
5
5
  "license": "MIT",
6
6
  "description": "ATProto Lexicon resolution",
@@ -23,23 +23,21 @@
23
23
  }
24
24
  },
25
25
  "dependencies": {
26
- "multiformats": "^9.9.0",
27
26
  "@atproto-labs/fetch-node": "^0.2.0",
28
- "@atproto/identity": "^0.4.10",
29
- "@atproto/lexicon": "^0.6.0",
27
+ "@atproto/lex": "^0.0.20",
28
+ "@atproto/identity": "^0.4.12",
29
+ "@atproto/lex-document": "^0.0.15",
30
30
  "@atproto/repo": "^0.8.12",
31
- "@atproto/syntax": "^0.4.2",
32
- "@atproto/xrpc": "^0.7.7"
31
+ "@atproto/syntax": "^0.5.0"
33
32
  },
34
33
  "devDependencies": {
35
34
  "jest": "^28.1.2",
36
35
  "typescript": "^5.6.3",
37
- "@atproto/common": "^0.5.3",
38
- "@atproto/lex-cli": "^0.9.8"
36
+ "@atproto/lex-cbor": "^0.0.14"
39
37
  },
40
38
  "scripts": {
41
39
  "test": "jest",
42
40
  "build": "tsc --build tsconfig.build.json",
43
- "codegen": "lex gen-api --yes ./src/client ../../lexicons/com/atproto/sync/getRecord.json"
41
+ "codegen": "lex build --indexFile --lexicons ../../lexicons --clear --include com.atproto.sync.getRecord --include com.atproto.lexicon.schema"
44
42
  }
45
43
  }
package/src/lexicon.ts CHANGED
@@ -1,56 +1,52 @@
1
1
  import dns from 'node:dns/promises'
2
- import { CID } from 'multiformats/cid'
3
- import { LexiconDoc, parseLexiconDoc } from '@atproto/lexicon'
2
+ import { Cid, l } from '@atproto/lex'
3
+ import { LexiconDocument, lexiconDocumentSchema } from '@atproto/lex-document'
4
4
  import { Commit } from '@atproto/repo'
5
- import { AtUri, NSID, ensureValidDid } from '@atproto/syntax'
5
+ import { AtUri, DidString, NSID, NsidString } from '@atproto/syntax'
6
+ import * as lexiconsSchema from './lexicons/com/atproto/lexicon/schema.js'
6
7
  import {
7
8
  BuildRecordResolverOptions,
8
9
  ResolveRecordOptions,
9
10
  buildRecordResolver,
10
11
  } from './record.js'
11
- import { isValidDid } from './util.js'
12
12
 
13
13
  const DNS_SUBDOMAIN = '_lexicon'
14
14
  const DNS_PREFIX = 'did='
15
- export const LEXICON_SCHEMA_NSID = 'com.atproto.lexicon.schema'
15
+
16
+ export type LexiconDocumentRecord = lexiconsSchema.Main & LexiconDocument
17
+ export const LEXICON_SCHEMA_NSID = lexiconsSchema.$nsid
16
18
 
17
19
  /**
18
20
  * Resolve Lexicon from an NSID
19
21
  */
20
22
  export type LexiconResolver = (
21
- nsid: NSID | string,
23
+ nsid: NSID | NsidString,
22
24
  ) => Promise<LexiconResolution>
23
25
 
24
26
  /**
25
27
  * Resolve Lexicon from an NSID using Lexicon DID authority and record resolution
26
28
  */
27
29
  export type AtprotoLexiconResolver = (
28
- nsid: NSID | string,
30
+ nsid: NSID | NsidString,
29
31
  options?: ResolveLexiconOptions,
30
32
  ) => Promise<LexiconResolution>
31
33
 
32
34
  export type BuildLexiconResolverOptions = BuildRecordResolverOptions
33
35
 
34
36
  export type ResolveLexiconOptions = ResolveRecordOptions & {
35
- didAuthority?: string
37
+ didAuthority?: DidString
36
38
  }
37
39
 
38
40
  export type LexiconResolution = {
39
41
  commit: Commit
40
42
  uri: AtUri
41
- cid: CID
43
+ cid: Cid
42
44
  nsid: NSID
43
- lexicon: LexiconDoc & LexiconSchemaRecord
45
+ lexicon: LexiconDocumentRecord
44
46
  }
45
47
 
46
- export {
47
- AtUri,
48
- CID,
49
- type Commit,
50
- type LexiconDoc,
51
- type LexiconSchemaRecord,
52
- NSID,
53
- }
48
+ export { AtUri, NSID }
49
+ export type { Cid, Commit, DidString, LexiconDocument, NsidString }
54
50
 
55
51
  /**
56
52
  * Build a Lexicon resolver function.
@@ -60,13 +56,13 @@ export function buildLexiconResolver(
60
56
  ): AtprotoLexiconResolver {
61
57
  const resolveRecord = buildRecordResolver(options)
62
58
  return async function (
63
- input: NSID | string,
59
+ input: NSID | NsidString,
64
60
  opts: ResolveLexiconOptions = {},
65
61
  ): Promise<LexiconResolution> {
66
62
  const nsid = NSID.from(input)
67
63
  const didAuthority = await getDidAuthority(nsid, opts)
68
64
  const verified = await resolveRecord(
69
- AtUri.make(didAuthority, LEXICON_SCHEMA_NSID, nsid.toString()),
65
+ AtUri.make(didAuthority, lexiconsSchema.$nsid, nsid.toString()),
70
66
  { forceRefresh: opts.forceRefresh },
71
67
  ).catch((err) => {
72
68
  throw new LexiconResolutionError(
@@ -75,17 +71,19 @@ export function buildLexiconResolver(
75
71
  { cause: err },
76
72
  )
77
73
  })
78
- let lexicon: LexiconDoc
79
- try {
80
- lexicon = parseLexiconDoc(verified.record)
81
- } catch (err) {
74
+
75
+ if (!lexiconsSchema.$matches(verified.record)) {
76
+ throw new LexiconResolutionError(nsid, 'Invalid Lexicon schema record')
77
+ }
78
+
79
+ const validationResult = lexiconDocumentSchema.safeValidate(verified.record)
80
+ if (!validationResult.success) {
82
81
  throw new LexiconResolutionError(nsid, 'Invalid Lexicon document', {
83
- cause: err,
82
+ cause: validationResult.reason,
84
83
  })
85
84
  }
86
- if (!isLexiconSchemaRecord(lexicon)) {
87
- throw new LexiconResolutionError(nsid, 'Invalid Lexicon schema record')
88
- }
85
+
86
+ const lexicon = validationResult.value
89
87
  if (lexicon.id !== nsid.toString()) {
90
88
  throw new LexiconResolutionError(
91
89
  nsid,
@@ -104,11 +102,11 @@ export const resolveLexicon = buildLexiconResolver()
104
102
  * @param input NSID or string representing one for which to lookup its Lexicon DID authority.
105
103
  */
106
104
  export async function resolveLexiconDidAuthority(
107
- input: NSID | string,
108
- ): Promise<string | undefined> {
105
+ input: NSID | NsidString,
106
+ ): Promise<DidString | undefined> {
109
107
  const nsid = NSID.from(input)
110
108
  const did = await resolveDns(nsid.authority)
111
- if (did == null || !isValidDid(did)) return
109
+ if (did == null || !l.isDidString(did)) return
112
110
  return did
113
111
  }
114
112
 
@@ -134,7 +132,6 @@ export class LexiconResolutionError extends Error {
134
132
 
135
133
  async function getDidAuthority(nsid: NSID, options: ResolveLexiconOptions) {
136
134
  if (options.didAuthority) {
137
- ensureValidDid(options.didAuthority)
138
135
  return options.didAuthority
139
136
  }
140
137
  const did = await resolveLexiconDidAuthority(nsid)
@@ -165,8 +162,3 @@ function parseDnsResult(chunkedResults: string[][]): string | undefined {
165
162
  }
166
163
  return found[0].slice(DNS_PREFIX.length)
167
164
  }
168
-
169
- type LexiconSchemaRecord = { $type: typeof LEXICON_SCHEMA_NSID }
170
- function isLexiconSchemaRecord(v: unknown): v is LexiconSchemaRecord {
171
- return v?.['$type'] === LEXICON_SCHEMA_NSID
172
- }
@@ -0,0 +1,43 @@
1
+ /*
2
+ * THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
3
+ */
4
+
5
+ import { l } from '@atproto/lex'
6
+
7
+ const $nsid = 'com.atproto.lexicon.schema'
8
+
9
+ export { $nsid }
10
+
11
+ /** Representation of Lexicon schemas themselves, when published as atproto records. Note that the schema language is not defined in Lexicon; this meta schema currently only includes a single version field ('lexicon'). See the atproto specifications for description of the other expected top-level fields ('id', 'defs', etc). */
12
+ type Main = {
13
+ $type: 'com.atproto.lexicon.schema'
14
+
15
+ /**
16
+ * Indicates the 'version' of the Lexicon language. Must be '1' for the current atproto/Lexicon schema system.
17
+ */
18
+ lexicon: number
19
+ }
20
+
21
+ export type { Main }
22
+
23
+ /** Representation of Lexicon schemas themselves, when published as atproto records. Note that the schema language is not defined in Lexicon; this meta schema currently only includes a single version field ('lexicon'). See the atproto specifications for description of the other expected top-level fields ('id', 'defs', etc). */
24
+ const main = l.record<'nsid', Main>(
25
+ 'nsid',
26
+ $nsid,
27
+ l.object({ lexicon: l.integer() }),
28
+ )
29
+
30
+ export { main }
31
+
32
+ export const $isTypeOf = /*#__PURE__*/ main.isTypeOf.bind(main),
33
+ $build = /*#__PURE__*/ main.build.bind(main),
34
+ $type = /*#__PURE__*/ main.$type
35
+ export const $assert = /*#__PURE__*/ main.assert.bind(main),
36
+ $check = /*#__PURE__*/ main.check.bind(main),
37
+ $cast = /*#__PURE__*/ main.cast.bind(main),
38
+ $ifMatches = /*#__PURE__*/ main.ifMatches.bind(main),
39
+ $matches = /*#__PURE__*/ main.matches.bind(main),
40
+ $parse = /*#__PURE__*/ main.parse.bind(main),
41
+ $safeParse = /*#__PURE__*/ main.safeParse.bind(main),
42
+ $validate = /*#__PURE__*/ main.validate.bind(main),
43
+ $safeValidate = /*#__PURE__*/ main.safeValidate.bind(main)
@@ -0,0 +1,6 @@
1
+ /*
2
+ * THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
3
+ */
4
+
5
+ export * from './schema.defs.js'
6
+ export * as $defs from './schema.defs.js'
@@ -0,0 +1,5 @@
1
+ /*
2
+ * THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
3
+ */
4
+
5
+ export * as schema from './lexicon/schema.js'