@atproto/lexicon-resolver 0.3.6 → 0.4.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/dist/index.js +2 -18
- package/dist/index.js.map +1 -1
- package/dist/lexicon.js +22 -75
- package/dist/lexicon.js.map +1 -1
- package/dist/lexicons/com/atproto/lexicon/schema.defs.js +6 -9
- package/dist/lexicons/com/atproto/lexicon/schema.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/lexicon/schema.js +2 -41
- package/dist/lexicons/com/atproto/lexicon/schema.js.map +1 -1
- package/dist/lexicons/com/atproto/lexicon.js +1 -37
- package/dist/lexicons/com/atproto/lexicon.js.map +1 -1
- package/dist/lexicons/com/atproto/sync/getRecord.defs.js +9 -12
- package/dist/lexicons/com/atproto/sync/getRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/sync/getRecord.js +2 -41
- package/dist/lexicons/com/atproto/sync/getRecord.js.map +1 -1
- package/dist/lexicons/com/atproto/sync.js +1 -37
- package/dist/lexicons/com/atproto/sync.js.map +1 -1
- package/dist/lexicons/com/atproto.js +2 -38
- package/dist/lexicons/com/atproto.js.map +1 -1
- package/dist/lexicons/com.js +1 -37
- package/dist/lexicons/com.js.map +1 -1
- package/dist/lexicons/index.js +1 -37
- package/dist/lexicons/index.js.map +1 -1
- package/dist/record.js +25 -31
- package/dist/record.js.map +1 -1
- package/dist/util.js +3 -6
- package/dist/util.js.map +1 -1
- package/package.json +15 -14
- package/src/lexicon.ts +1 -1
- package/tests/lexicon.test.ts +4 -3
- package/tests/record.test.ts +1 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/vitest.config.ts +5 -0
- package/jest.config.js +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @atproto/lexicon-resolver
|
|
2
2
|
|
|
3
|
+
## 0.4.0-next.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#4929](https://github.com/bluesky-social/atproto/pull/4929) [`bb7491c`](https://github.com/bluesky-social/atproto/commit/bb7491c29e06181e1d2f8cf6eb454f9bb8ab961b) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Drop support for Node.js 18 and 20. Node.js 22 is now the minimum supported version. Docker images now use Node.js 24.
|
|
8
|
+
|
|
9
|
+
- [#4943](https://github.com/bluesky-social/atproto/pull/4943) [`07ae5d4`](https://github.com/bluesky-social/atproto/commit/07ae5d4452df51e045e0239da7a04cf0bc154028) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Convert to pure ESM. All packages now ship `"type": "module"` with ES module output and Node16 module resolution.
|
|
10
|
+
|
|
11
|
+
Node.js 22's `require()` compatibility layer can still load these packages in CommonJS code.
|
|
12
|
+
|
|
13
|
+
- [#4930](https://github.com/bluesky-social/atproto/pull/4930) [`042df15`](https://github.com/bluesky-social/atproto/commit/042df15087c0e62cd1e715fcbf58852fab875af9) Thanks [@devinivy](https://github.com/devinivy)! - Build with TypeScript 6.0. Emitted `.d.ts` files now use TypeScript 6's stricter `Uint8Array<ArrayBuffer>` typing in places where Web/Node APIs require buffer-backed (not shared-memory) byte arrays. Consumers compiling against these types on older TypeScript should see no runtime impact, but may need to widen or cast in spots that previously relied on `Uint8Array` defaulting to `<ArrayBufferLike>`.
|
|
14
|
+
|
|
15
|
+
Internal: tsconfig `moduleResolution: "node"` is silenced via `ignoreDeprecations: "6.0"` for now; the proper migration to `node16`/`bundler` resolution is deferred.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [[`bb7491c`](https://github.com/bluesky-social/atproto/commit/bb7491c29e06181e1d2f8cf6eb454f9bb8ab961b), [`07ae5d4`](https://github.com/bluesky-social/atproto/commit/07ae5d4452df51e045e0239da7a04cf0bc154028), [`8e40db6`](https://github.com/bluesky-social/atproto/commit/8e40db65aab7ba5f9414c26dbe1ab658e3bffeca), [`042df15`](https://github.com/bluesky-social/atproto/commit/042df15087c0e62cd1e715fcbf58852fab875af9)]:
|
|
20
|
+
- @atproto/identity@0.5.0-next.0
|
|
21
|
+
- @atproto/lex@0.1.0-next.0
|
|
22
|
+
- @atproto/lex-document@0.1.0-next.0
|
|
23
|
+
- @atproto/repo@0.10.0-next.0
|
|
24
|
+
- @atproto/syntax@0.6.0-next.0
|
|
25
|
+
- @atproto-labs/fetch-node@0.3.0-next.0
|
|
26
|
+
|
|
3
27
|
## 0.3.6
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./record.js"), exports);
|
|
18
|
-
__exportStar(require("./lexicon.js"), exports);
|
|
1
|
+
export * from './record.js';
|
|
2
|
+
export * from './lexicon.js';
|
|
19
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA","sourcesContent":["export * from './record.js'\nexport * from './lexicon.js'\n"]}
|
package/dist/lexicon.js
CHANGED
|
@@ -1,70 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.LexiconResolutionError = exports.resolveLexicon = exports.NSID = exports.AtUri = exports.LEXICON_SCHEMA_NSID = void 0;
|
|
40
|
-
exports.buildLexiconResolver = buildLexiconResolver;
|
|
41
|
-
exports.resolveLexiconDidAuthority = resolveLexiconDidAuthority;
|
|
42
|
-
const promises_1 = __importDefault(require("node:dns/promises"));
|
|
43
|
-
const lex_1 = require("@atproto/lex");
|
|
44
|
-
const lex_document_1 = require("@atproto/lex-document");
|
|
45
|
-
const syntax_1 = require("@atproto/syntax");
|
|
46
|
-
Object.defineProperty(exports, "AtUri", { enumerable: true, get: function () { return syntax_1.AtUri; } });
|
|
47
|
-
Object.defineProperty(exports, "NSID", { enumerable: true, get: function () { return syntax_1.NSID; } });
|
|
48
|
-
const lexiconsSchema = __importStar(require("./lexicons/com/atproto/lexicon/schema.js"));
|
|
49
|
-
const record_js_1 = require("./record.js");
|
|
1
|
+
import * as dns from 'node:dns/promises';
|
|
2
|
+
import { l } from '@atproto/lex';
|
|
3
|
+
import { lexiconDocumentSchema } from '@atproto/lex-document';
|
|
4
|
+
import { AtUri, NSID } from '@atproto/syntax';
|
|
5
|
+
import * as lexiconsSchema from './lexicons/com/atproto/lexicon/schema.js';
|
|
6
|
+
import { buildRecordResolver, } from './record.js';
|
|
50
7
|
const DNS_SUBDOMAIN = '_lexicon';
|
|
51
8
|
const DNS_PREFIX = 'did=';
|
|
52
|
-
|
|
9
|
+
export const LEXICON_SCHEMA_NSID = lexiconsSchema.$nsid;
|
|
10
|
+
export { AtUri, NSID };
|
|
53
11
|
/**
|
|
54
12
|
* Build a Lexicon resolver function.
|
|
55
13
|
*/
|
|
56
|
-
function buildLexiconResolver(options = {}) {
|
|
57
|
-
const resolveRecord =
|
|
14
|
+
export function buildLexiconResolver(options = {}) {
|
|
15
|
+
const resolveRecord = buildRecordResolver(options);
|
|
58
16
|
return async function (input, opts = {}) {
|
|
59
|
-
const nsid =
|
|
17
|
+
const nsid = NSID.from(input);
|
|
60
18
|
const didAuthority = await getDidAuthority(nsid, opts);
|
|
61
|
-
const verified = await resolveRecord(
|
|
19
|
+
const verified = await resolveRecord(AtUri.make(didAuthority, lexiconsSchema.$nsid, nsid.toString()), { forceRefresh: opts.forceRefresh }).catch((err) => {
|
|
62
20
|
throw new LexiconResolutionError(nsid, 'Could not resolve Lexicon schema record', { cause: err });
|
|
63
21
|
});
|
|
64
22
|
if (!lexiconsSchema.$matches(verified.record)) {
|
|
65
23
|
throw new LexiconResolutionError(nsid, 'Invalid Lexicon schema record');
|
|
66
24
|
}
|
|
67
|
-
const validationResult =
|
|
25
|
+
const validationResult = lexiconDocumentSchema.safeValidate(verified.record);
|
|
68
26
|
if (!validationResult.success) {
|
|
69
27
|
throw new LexiconResolutionError(nsid, 'Invalid Lexicon document', {
|
|
70
28
|
cause: validationResult.reason,
|
|
@@ -78,41 +36,30 @@ function buildLexiconResolver(options = {}) {
|
|
|
78
36
|
return { commit, uri, cid, nsid, lexicon };
|
|
79
37
|
};
|
|
80
38
|
}
|
|
81
|
-
|
|
39
|
+
export const resolveLexicon = buildLexiconResolver();
|
|
82
40
|
/**
|
|
83
41
|
* Resolve the DID authority for a Lexicon from the network using DNS, based on its NSID.
|
|
84
42
|
* @param input NSID or string representing one for which to lookup its Lexicon DID authority.
|
|
85
43
|
*/
|
|
86
|
-
async function resolveLexiconDidAuthority(input) {
|
|
87
|
-
const nsid =
|
|
44
|
+
export async function resolveLexiconDidAuthority(input) {
|
|
45
|
+
const nsid = NSID.from(input);
|
|
88
46
|
const did = await resolveDns(nsid.authority);
|
|
89
|
-
if (did == null || !
|
|
47
|
+
if (did == null || !l.isDidString(did))
|
|
90
48
|
return;
|
|
91
49
|
return did;
|
|
92
50
|
}
|
|
93
|
-
class LexiconResolutionError extends Error {
|
|
51
|
+
export class LexiconResolutionError extends Error {
|
|
94
52
|
constructor(nsid, description = `Could not resolve Lexicon for NSID`, options) {
|
|
95
53
|
super(`${description} (${nsid})`, options);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
configurable: true,
|
|
99
|
-
writable: true,
|
|
100
|
-
value: nsid
|
|
101
|
-
});
|
|
102
|
-
Object.defineProperty(this, "description", {
|
|
103
|
-
enumerable: true,
|
|
104
|
-
configurable: true,
|
|
105
|
-
writable: true,
|
|
106
|
-
value: description
|
|
107
|
-
});
|
|
54
|
+
this.nsid = nsid;
|
|
55
|
+
this.description = description;
|
|
108
56
|
this.name = 'LexiconResolutionError';
|
|
109
57
|
}
|
|
110
58
|
static from(input, description, options) {
|
|
111
|
-
const nsid =
|
|
59
|
+
const nsid = NSID.from(input);
|
|
112
60
|
return new LexiconResolutionError(nsid, description, options);
|
|
113
61
|
}
|
|
114
62
|
}
|
|
115
|
-
exports.LexiconResolutionError = LexiconResolutionError;
|
|
116
63
|
async function getDidAuthority(nsid, options) {
|
|
117
64
|
if (options.didAuthority) {
|
|
118
65
|
return options.didAuthority;
|
|
@@ -126,7 +73,7 @@ async function getDidAuthority(nsid, options) {
|
|
|
126
73
|
async function resolveDns(authority) {
|
|
127
74
|
let chunkedResults;
|
|
128
75
|
try {
|
|
129
|
-
chunkedResults = await
|
|
76
|
+
chunkedResults = await dns.resolveTxt(`${DNS_SUBDOMAIN}.${authority}`);
|
|
130
77
|
}
|
|
131
78
|
catch (err) {
|
|
132
79
|
return undefined;
|
package/dist/lexicon.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon.js","sourceRoot":"","sources":["../src/lexicon.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lexicon.js","sourceRoot":"","sources":["../src/lexicon.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAO,CAAC,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAmB,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAE9E,OAAO,EAAE,KAAK,EAAa,IAAI,EAAc,MAAM,iBAAiB,CAAA;AACpE,OAAO,KAAK,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D,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;AAC1C,CAAC","sourcesContent":["import * as dns from 'node:dns/promises'\nimport { Cid, l } from '@atproto/lex'\nimport { LexiconDocument, lexiconDocumentSchema } from '@atproto/lex-document'\nimport { Commit } from '@atproto/repo'\nimport { AtUri, DidString, NSID, NsidString } from '@atproto/syntax'\nimport * as lexiconsSchema from './lexicons/com/atproto/lexicon/schema.js'\nimport {\n BuildRecordResolverOptions,\n ResolveRecordOptions,\n buildRecordResolver,\n} from './record.js'\n\nconst DNS_SUBDOMAIN = '_lexicon'\nconst DNS_PREFIX = 'did='\n\nexport type LexiconDocumentRecord = lexiconsSchema.Main & LexiconDocument\nexport const LEXICON_SCHEMA_NSID = lexiconsSchema.$nsid\n\n/**\n * Resolve Lexicon from an NSID\n */\nexport type LexiconResolver = (\n nsid: NSID | NsidString,\n) => Promise<LexiconResolution>\n\n/**\n * Resolve Lexicon from an NSID using Lexicon DID authority and record resolution\n */\nexport type AtprotoLexiconResolver = (\n nsid: NSID | NsidString,\n options?: ResolveLexiconOptions,\n) => Promise<LexiconResolution>\n\nexport type BuildLexiconResolverOptions = BuildRecordResolverOptions\n\nexport type ResolveLexiconOptions = ResolveRecordOptions & {\n didAuthority?: DidString\n}\n\nexport type LexiconResolution = {\n commit: Commit\n uri: AtUri\n cid: Cid\n nsid: NSID\n lexicon: LexiconDocumentRecord\n}\n\nexport { AtUri, NSID }\nexport type { Cid, Commit, DidString, LexiconDocument, NsidString }\n\n/**\n * Build a Lexicon resolver function.\n */\nexport function buildLexiconResolver(\n options: BuildLexiconResolverOptions = {},\n): AtprotoLexiconResolver {\n const resolveRecord = buildRecordResolver(options)\n return async function (\n input: NSID | NsidString,\n opts: ResolveLexiconOptions = {},\n ): Promise<LexiconResolution> {\n const nsid = NSID.from(input)\n const didAuthority = await getDidAuthority(nsid, opts)\n const verified = await resolveRecord(\n AtUri.make(didAuthority, lexiconsSchema.$nsid, nsid.toString()),\n { forceRefresh: opts.forceRefresh },\n ).catch((err) => {\n throw new LexiconResolutionError(\n nsid,\n 'Could not resolve Lexicon schema record',\n { cause: err },\n )\n })\n\n if (!lexiconsSchema.$matches(verified.record)) {\n throw new LexiconResolutionError(nsid, 'Invalid Lexicon schema record')\n }\n\n const validationResult = lexiconDocumentSchema.safeValidate(verified.record)\n if (!validationResult.success) {\n throw new LexiconResolutionError(nsid, 'Invalid Lexicon document', {\n cause: validationResult.reason,\n })\n }\n\n const lexicon = validationResult.value\n if (lexicon.id !== nsid.toString()) {\n throw new LexiconResolutionError(\n nsid,\n `Lexicon schema record id (${lexicon.id}) does not match NSID`,\n )\n }\n const { uri, cid, commit } = verified\n return { commit, uri, cid, nsid, lexicon }\n } satisfies LexiconResolver\n}\n\nexport const resolveLexicon = buildLexiconResolver()\n\n/**\n * Resolve the DID authority for a Lexicon from the network using DNS, based on its NSID.\n * @param input NSID or string representing one for which to lookup its Lexicon DID authority.\n */\nexport async function resolveLexiconDidAuthority(\n input: NSID | NsidString,\n): Promise<DidString | undefined> {\n const nsid = NSID.from(input)\n const did = await resolveDns(nsid.authority)\n if (did == null || !l.isDidString(did)) return\n return did\n}\n\nexport class LexiconResolutionError extends Error {\n constructor(\n public readonly nsid: NSID,\n public readonly description = `Could not resolve Lexicon for NSID`,\n options?: ErrorOptions,\n ) {\n super(`${description} (${nsid})`, options)\n this.name = 'LexiconResolutionError'\n }\n\n static from(\n input: NSID | string,\n description?: string,\n options?: ErrorOptions,\n ): LexiconResolutionError {\n const nsid = NSID.from(input)\n return new LexiconResolutionError(nsid, description, options)\n }\n}\n\nasync function getDidAuthority(nsid: NSID, options: ResolveLexiconOptions) {\n if (options.didAuthority) {\n return options.didAuthority\n }\n const did = await resolveLexiconDidAuthority(nsid)\n if (!did) {\n throw new LexiconResolutionError(\n nsid,\n `Could not resolve a DID authority for NSID`,\n )\n }\n return did\n}\n\nasync function resolveDns(authority: string): Promise<string | undefined> {\n let chunkedResults: string[][]\n try {\n chunkedResults = await dns.resolveTxt(`${DNS_SUBDOMAIN}.${authority}`)\n } catch (err) {\n return undefined\n }\n return parseDnsResult(chunkedResults)\n}\n\nfunction parseDnsResult(chunkedResults: string[][]): string | undefined {\n const results = chunkedResults.map((chunks) => chunks.join(''))\n const found = results.filter((i) => i.startsWith(DNS_PREFIX))\n if (found.length !== 1) {\n return undefined\n }\n return found[0].slice(DNS_PREFIX.length)\n}\n"]}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
exports.$safeValidate = exports.$validate = exports.$safeParse = exports.$parse = exports.$matches = exports.$ifMatches = exports.$cast = exports.$check = exports.$assert = exports.$type = exports.$build = exports.$isTypeOf = exports.main = exports.$nsid = void 0;
|
|
7
|
-
const lex_1 = require("@atproto/lex");
|
|
4
|
+
import { l } from '@atproto/lex';
|
|
8
5
|
const $nsid = 'com.atproto.lexicon.schema';
|
|
9
|
-
|
|
6
|
+
export { $nsid };
|
|
10
7
|
/** 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). */
|
|
11
|
-
const main =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
const main = l.record('nsid', $nsid, l.object({ lexicon: l.integer() }));
|
|
9
|
+
export { main };
|
|
10
|
+
export const $isTypeOf = /*#__PURE__*/ main.isTypeOf.bind(main), $build = /*#__PURE__*/ main.build.bind(main), $type = /*#__PURE__*/ main.$type;
|
|
11
|
+
export const $assert = /*#__PURE__*/ main.assert.bind(main), $check = /*#__PURE__*/ main.check.bind(main), $cast = /*#__PURE__*/ main.cast.bind(main), $ifMatches = /*#__PURE__*/ main.ifMatches.bind(main), $matches = /*#__PURE__*/ main.matches.bind(main), $parse = /*#__PURE__*/ main.parse.bind(main), $safeParse = /*#__PURE__*/ main.safeParse.bind(main), $validate = /*#__PURE__*/ main.validate.bind(main), $safeValidate = /*#__PURE__*/ main.safeValidate.bind(main);
|
|
15
12
|
//# sourceMappingURL=schema.defs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.defs.js","sourceRoot":"","sources":["../../../../../src/lexicons/com/atproto/lexicon/schema.defs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.defs.js","sourceRoot":"","sources":["../../../../../src/lexicons/com/atproto/lexicon/schema.defs.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,cAAc,CAAA;AAEhC,MAAM,KAAK,GAAG,4BAA4B,CAAA;AAE1C,OAAO,EAAE,KAAK,EAAE,CAAA;AAchB,wUAAwU;AACxU,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CACnB,MAAM,EACN,KAAK,EACL,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CACnC,CAAA;AAED,OAAO,EAAE,IAAI,EAAE,CAAA;AAEf,MAAM,CAAC,MAAM,SAAS,GAAG,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAC7D,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAC5C,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,KAAK,CAAA;AAClC,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EACzD,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAC5C,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAC1C,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EACpD,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAChD,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAC5C,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EACpD,SAAS,GAAG,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAClD,aAAa,GAAG,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nimport { l } from '@atproto/lex'\n\nconst $nsid = 'com.atproto.lexicon.schema'\n\nexport { $nsid }\n\n/** 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). */\ntype Main = {\n $type: 'com.atproto.lexicon.schema'\n\n /**\n * Indicates the 'version' of the Lexicon language. Must be '1' for the current atproto/Lexicon schema system.\n */\n lexicon: number\n}\n\nexport type { Main }\n\n/** 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). */\nconst main = l.record<'nsid', Main>(\n 'nsid',\n $nsid,\n l.object({ lexicon: l.integer() }),\n)\n\nexport { main }\n\nexport const $isTypeOf = /*#__PURE__*/ main.isTypeOf.bind(main),\n $build = /*#__PURE__*/ main.build.bind(main),\n $type = /*#__PURE__*/ main.$type\nexport const $assert = /*#__PURE__*/ main.assert.bind(main),\n $check = /*#__PURE__*/ main.check.bind(main),\n $cast = /*#__PURE__*/ main.cast.bind(main),\n $ifMatches = /*#__PURE__*/ main.ifMatches.bind(main),\n $matches = /*#__PURE__*/ main.matches.bind(main),\n $parse = /*#__PURE__*/ main.parse.bind(main),\n $safeParse = /*#__PURE__*/ main.safeParse.bind(main),\n $validate = /*#__PURE__*/ main.validate.bind(main),\n $safeValidate = /*#__PURE__*/ main.safeValidate.bind(main)\n"]}
|
|
@@ -1,45 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
22
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
23
|
-
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
-
var ownKeys = function(o) {
|
|
26
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
-
var ar = [];
|
|
28
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
-
return ar;
|
|
30
|
-
};
|
|
31
|
-
return ownKeys(o);
|
|
32
|
-
};
|
|
33
|
-
return function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.$defs = void 0;
|
|
43
|
-
__exportStar(require("./schema.defs.js"), exports);
|
|
44
|
-
exports.$defs = __importStar(require("./schema.defs.js"));
|
|
4
|
+
export * from './schema.defs.js';
|
|
5
|
+
export * as $defs from './schema.defs.js';
|
|
45
6
|
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../src/lexicons/com/atproto/lexicon/schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../src/lexicons/com/atproto/lexicon/schema.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,kBAAkB,CAAA;AAChC,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAA","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * from './schema.defs.js'\nexport * as $defs from './schema.defs.js'\n"]}
|
|
@@ -1,41 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
4
3
|
*/
|
|
5
|
-
|
|
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.schema = void 0;
|
|
40
|
-
exports.schema = __importStar(require("./lexicon/schema.js"));
|
|
4
|
+
export * as schema from './lexicon/schema.js';
|
|
41
5
|
//# sourceMappingURL=lexicon.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon.js","sourceRoot":"","sources":["../../../../src/lexicons/com/atproto/lexicon.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lexicon.js","sourceRoot":"","sources":["../../../../src/lexicons/com/atproto/lexicon.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,MAAM,MAAM,qBAAqB,CAAA","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * as schema from './lexicon/schema.js'\n"]}
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
exports.$output = exports.$params = exports.$lxm = exports.main = exports.$nsid = void 0;
|
|
7
|
-
const lex_1 = require("@atproto/lex");
|
|
4
|
+
import { l } from '@atproto/lex';
|
|
8
5
|
const $nsid = 'com.atproto.sync.getRecord';
|
|
9
|
-
|
|
6
|
+
export { $nsid };
|
|
10
7
|
/** Get data blocks needed to prove the existence or non-existence of record in the current version of repo. Does not require auth. */
|
|
11
|
-
const main =
|
|
12
|
-
did:
|
|
13
|
-
collection:
|
|
14
|
-
rkey:
|
|
15
|
-
}),
|
|
8
|
+
const main = l.query($nsid, l.params({
|
|
9
|
+
did: l.string({ format: 'did' }),
|
|
10
|
+
collection: l.string({ format: 'nsid' }),
|
|
11
|
+
rkey: l.string({ format: 'record-key' }),
|
|
12
|
+
}), l.payload('application/vnd.ipld.car'), [
|
|
16
13
|
'RecordNotFound',
|
|
17
14
|
'RepoNotFound',
|
|
18
15
|
'RepoTakendown',
|
|
19
16
|
'RepoSuspended',
|
|
20
17
|
'RepoDeactivated',
|
|
21
18
|
]);
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
export { main };
|
|
20
|
+
export const $lxm = main.nsid, $params = main.parameters, $output = main.output;
|
|
24
21
|
//# sourceMappingURL=getRecord.defs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRecord.defs.js","sourceRoot":"","sources":["../../../../../src/lexicons/com/atproto/sync/getRecord.defs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getRecord.defs.js","sourceRoot":"","sources":["../../../../../src/lexicons/com/atproto/sync/getRecord.defs.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,cAAc,CAAA;AAEhC,MAAM,KAAK,GAAG,4BAA4B,CAAA;AAE1C,OAAO,EAAE,KAAK,EAAE,CAAA;AAEhB,sIAAsI;AACtI,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAClB,KAAK,EACL,CAAC,CAAC,MAAM,CAAC;IACP,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAChC,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IACxC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;CACzC,CAAC,EACF,CAAC,CAAC,OAAO,CAAC,0BAA0B,CAAC,EACrC;IACE,gBAAgB;IAChB,cAAc;IACd,eAAe;IACf,eAAe;IACf,iBAAiB;CAClB,CACF,CAAA;AACD,OAAO,EAAE,IAAI,EAAE,CAAA;AASf,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAC3B,OAAO,GAAG,IAAI,CAAC,UAAU,EACzB,OAAO,GAAG,IAAI,CAAC,MAAM,CAAA","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nimport { l } from '@atproto/lex'\n\nconst $nsid = 'com.atproto.sync.getRecord'\n\nexport { $nsid }\n\n/** Get data blocks needed to prove the existence or non-existence of record in the current version of repo. Does not require auth. */\nconst main = l.query(\n $nsid,\n l.params({\n did: l.string({ format: 'did' }),\n collection: l.string({ format: 'nsid' }),\n rkey: l.string({ format: 'record-key' }),\n }),\n l.payload('application/vnd.ipld.car'),\n [\n 'RecordNotFound',\n 'RepoNotFound',\n 'RepoTakendown',\n 'RepoSuspended',\n 'RepoDeactivated',\n ],\n)\nexport { main }\n\nexport type $Params = l.InferMethodParams<typeof main>\nexport type $Output<B = l.BinaryData> = l.InferMethodOutput<typeof main, B>\nexport type $OutputBody<B = l.BinaryData> = l.InferMethodOutputBody<\n typeof main,\n B\n>\n\nexport const $lxm = main.nsid,\n $params = main.parameters,\n $output = main.output\n"]}
|
|
@@ -1,45 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
22
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
23
|
-
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
-
var ownKeys = function(o) {
|
|
26
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
-
var ar = [];
|
|
28
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
-
return ar;
|
|
30
|
-
};
|
|
31
|
-
return ownKeys(o);
|
|
32
|
-
};
|
|
33
|
-
return function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.$defs = void 0;
|
|
43
|
-
__exportStar(require("./getRecord.defs.js"), exports);
|
|
44
|
-
exports.$defs = __importStar(require("./getRecord.defs.js"));
|
|
4
|
+
export * from './getRecord.defs.js';
|
|
5
|
+
export * as $defs from './getRecord.defs.js';
|
|
45
6
|
//# sourceMappingURL=getRecord.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRecord.js","sourceRoot":"","sources":["../../../../../src/lexicons/com/atproto/sync/getRecord.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getRecord.js","sourceRoot":"","sources":["../../../../../src/lexicons/com/atproto/sync/getRecord.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,qBAAqB,CAAA;AACnC,OAAO,KAAK,KAAK,MAAM,qBAAqB,CAAA","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * from './getRecord.defs.js'\nexport * as $defs from './getRecord.defs.js'\n"]}
|
|
@@ -1,41 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
4
3
|
*/
|
|
5
|
-
|
|
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"));
|
|
4
|
+
export * as getRecord from './sync/getRecord.js';
|
|
41
5
|
//# sourceMappingURL=sync.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../../../src/lexicons/com/atproto/sync.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../../../src/lexicons/com/atproto/sync.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,SAAS,MAAM,qBAAqB,CAAA","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * as getRecord from './sync/getRecord.js'\n"]}
|
|
@@ -1,42 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
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"));
|
|
4
|
+
export * as lexicon from './atproto/lexicon.js';
|
|
5
|
+
export * as sync from './atproto/sync.js';
|
|
42
6
|
//# sourceMappingURL=atproto.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atproto.js","sourceRoot":"","sources":["../../../src/lexicons/com/atproto.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"atproto.js","sourceRoot":"","sources":["../../../src/lexicons/com/atproto.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAA;AAC/C,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAA","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"]}
|
package/dist/lexicons/com.js
CHANGED
|
@@ -1,41 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
4
3
|
*/
|
|
5
|
-
|
|
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"));
|
|
4
|
+
export * as atproto from './com/atproto.js';
|
|
41
5
|
//# sourceMappingURL=com.js.map
|
package/dist/lexicons/com.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"com.js","sourceRoot":"","sources":["../../src/lexicons/com.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"com.js","sourceRoot":"","sources":["../../src/lexicons/com.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAA","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * as atproto from './com/atproto.js'\n"]}
|
package/dist/lexicons/index.js
CHANGED
|
@@ -1,41 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
4
3
|
*/
|
|
5
|
-
|
|
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"));
|
|
4
|
+
export * as com from './com.js';
|
|
41
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lexicons/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lexicons/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * as com from './com.js'\n"]}
|
package/dist/record.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const repo_1 = require("@atproto/repo");
|
|
9
|
-
const syntax_1 = require("@atproto/syntax");
|
|
10
|
-
Object.defineProperty(exports, "AtUri", { enumerable: true, get: function () { return syntax_1.AtUri; } });
|
|
11
|
-
const fetch_node_1 = require("@atproto-labs/fetch-node");
|
|
12
|
-
const index_js_1 = require("./lexicons/index.js");
|
|
1
|
+
import { IdResolver, parseToAtprotoDocument } from '@atproto/identity';
|
|
2
|
+
import { Client, l, } from '@atproto/lex';
|
|
3
|
+
import { MST, MemoryBlockstore, def as repoDef, readCarWithRoot, verifyCommitSig, } from '@atproto/repo';
|
|
4
|
+
import { AtUri } from '@atproto/syntax';
|
|
5
|
+
import { safeFetchWrap } from '@atproto-labs/fetch-node';
|
|
6
|
+
import { com } from './lexicons/index.js';
|
|
7
|
+
export { AtUri, IdResolver };
|
|
13
8
|
/**
|
|
14
9
|
* Build a record resolver function.
|
|
15
10
|
*/
|
|
16
|
-
function buildRecordResolver(options = {}) {
|
|
17
|
-
const { idResolver = new
|
|
11
|
+
export function buildRecordResolver(options = {}) {
|
|
12
|
+
const { idResolver = new IdResolver(), rpc } = options;
|
|
18
13
|
return async function resolveRecord(uriStr, opts = {}) {
|
|
19
|
-
const uri = typeof uriStr === 'string' ? new
|
|
14
|
+
const uri = typeof uriStr === 'string' ? new AtUri(uriStr) : uriStr;
|
|
20
15
|
const did = await getDidFromUri(uri, { idResolver });
|
|
21
16
|
const identityDoc = await idResolver.did
|
|
22
17
|
.ensureResolve(did, opts.forceRefresh)
|
|
@@ -25,22 +20,22 @@ function buildRecordResolver(options = {}) {
|
|
|
25
20
|
cause: err,
|
|
26
21
|
});
|
|
27
22
|
});
|
|
28
|
-
const { pds, signingKey } =
|
|
23
|
+
const { pds, signingKey } = parseToAtprotoDocument(identityDoc);
|
|
29
24
|
if (!pds) {
|
|
30
25
|
throw new RecordResolutionError('Incomplete DID identity data: missing pds');
|
|
31
26
|
}
|
|
32
27
|
if (!signingKey) {
|
|
33
28
|
throw new RecordResolutionError('Incomplete DID identity data: missing signing key');
|
|
34
29
|
}
|
|
35
|
-
const client = new
|
|
30
|
+
const client = new Client(typeof rpc === 'function'
|
|
36
31
|
? { fetchHandler: rpc }
|
|
37
32
|
: {
|
|
38
33
|
...rpc,
|
|
39
34
|
service: rpc?.service ?? pds,
|
|
40
|
-
fetch: rpc?.fetch ??
|
|
35
|
+
fetch: rpc?.fetch ?? safeFetch,
|
|
41
36
|
});
|
|
42
37
|
const proofBytes = await client
|
|
43
|
-
.call(
|
|
38
|
+
.call(com.atproto.sync.getRecord, {
|
|
44
39
|
did,
|
|
45
40
|
collection: uri.collection,
|
|
46
41
|
rkey: uri.rkey,
|
|
@@ -51,41 +46,40 @@ function buildRecordResolver(options = {}) {
|
|
|
51
46
|
});
|
|
52
47
|
});
|
|
53
48
|
const verified = await verifyRecordProof(proofBytes, {
|
|
54
|
-
uri:
|
|
49
|
+
uri: AtUri.make(did, uri.collection, uri.rkey),
|
|
55
50
|
signingKey,
|
|
56
51
|
});
|
|
57
52
|
return verified;
|
|
58
53
|
};
|
|
59
54
|
}
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
export const resolveRecord = buildRecordResolver();
|
|
56
|
+
export const safeFetch = safeFetchWrap({
|
|
62
57
|
allowIpHost: false,
|
|
63
58
|
allowImplicitRedirect: true,
|
|
64
59
|
responseMaxSize: (1024 + 10) * 1024, // 1MB + 10kB, just a bit larger than max record size
|
|
65
60
|
});
|
|
66
|
-
class RecordResolutionError extends Error {
|
|
61
|
+
export class RecordResolutionError extends Error {
|
|
67
62
|
constructor(message, options) {
|
|
68
63
|
super(message, options);
|
|
69
64
|
this.name = 'RecordResolutionError';
|
|
70
65
|
}
|
|
71
66
|
}
|
|
72
|
-
exports.RecordResolutionError = RecordResolutionError;
|
|
73
67
|
async function getDidFromUri(uri, { idResolver }) {
|
|
74
|
-
if (
|
|
68
|
+
if (l.isDidString(uri.host)) {
|
|
75
69
|
return uri.host;
|
|
76
70
|
}
|
|
77
71
|
const resolved = await idResolver.handle.resolve(uri.host);
|
|
78
|
-
if (!resolved || !
|
|
72
|
+
if (!resolved || !l.isDidString(resolved)) {
|
|
79
73
|
throw new RecordResolutionError('Could not resolve handle found in AT-URI');
|
|
80
74
|
}
|
|
81
75
|
return resolved;
|
|
82
76
|
}
|
|
83
77
|
async function verifyRecordProof(proofBytes, { uri, signingKey }) {
|
|
84
|
-
const { root, blocks } = await
|
|
78
|
+
const { root, blocks } = await readCarWithRoot(proofBytes).catch((err) => {
|
|
85
79
|
throw new RecordResolutionError('Malformed record proof', { cause: err });
|
|
86
80
|
});
|
|
87
|
-
const blockstore = new
|
|
88
|
-
const commit = await blockstore.readObj(root,
|
|
81
|
+
const blockstore = new MemoryBlockstore(blocks);
|
|
82
|
+
const commit = await blockstore.readObj(root, repoDef.commit).catch((err) => {
|
|
89
83
|
throw new RecordResolutionError('Invalid commit in record proof', {
|
|
90
84
|
cause: err,
|
|
91
85
|
});
|
|
@@ -93,11 +87,11 @@ async function verifyRecordProof(proofBytes, { uri, signingKey }) {
|
|
|
93
87
|
if (commit.did !== uri.host) {
|
|
94
88
|
throw new RecordResolutionError(`Invalid repo did: ${commit.did}`);
|
|
95
89
|
}
|
|
96
|
-
const validSig = await
|
|
90
|
+
const validSig = await verifyCommitSig(commit, signingKey);
|
|
97
91
|
if (!validSig) {
|
|
98
92
|
throw new RecordResolutionError(`Invalid signature on commit: ${root.toString()}`);
|
|
99
93
|
}
|
|
100
|
-
const mst =
|
|
94
|
+
const mst = MST.load(blockstore, commit.data);
|
|
101
95
|
const cid = await mst.get(`${uri.collection}/${uri.rkey}`);
|
|
102
96
|
if (!cid) {
|
|
103
97
|
throw new RecordResolutionError('Record not found in proof');
|
package/dist/record.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.js","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"record.js","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,EAGL,MAAM,EAIN,CAAC,GACF,MAAM,cAAc,CAAA;AACrB,OAAO,EAEL,GAAG,EACH,gBAAgB,EAChB,GAAG,IAAI,OAAO,EACd,eAAe,EACf,eAAe,GAChB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,KAAK,EAAe,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AAEzC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,CAAA;AA0C5B;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,UAAsC,EAAE;IAExC,MAAM,EAAE,UAAU,GAAG,IAAI,UAAU,EAAE,EAAE,GAAG,EAAE,GAAG,OAAO,CAAA;IACtD,OAAO,KAAK,UAAU,aAAa,CACjC,MAA2B,EAC3B,OAA6B,EAAE;QAE/B,MAAM,GAAG,GAAG,OA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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/dist/util.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.isValidDid = isValidDid;
|
|
4
|
-
const syntax_1 = require("@atproto/syntax");
|
|
5
|
-
function isValidDid(did) {
|
|
1
|
+
import { ensureValidDid } from '@atproto/syntax';
|
|
2
|
+
export function isValidDid(did) {
|
|
6
3
|
try {
|
|
7
|
-
|
|
4
|
+
ensureValidDid(did);
|
|
8
5
|
return true;
|
|
9
6
|
}
|
|
10
7
|
catch {
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,IAAI,CAAC;QACH,cAAc,CAAC,GAAG,CAAC,CAAA;QACnB,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC","sourcesContent":["import { ensureValidDid } from '@atproto/syntax'\n\nexport function isValidDid(did: string) {\n try {\n ensureValidDid(did)\n return true\n } catch {\n return false\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/lexicon-resolver",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.4.0-next.0",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": ">=22"
|
|
6
|
+
},
|
|
7
|
+
"type": "module",
|
|
5
8
|
"license": "MIT",
|
|
6
9
|
"description": "ATProto Lexicon resolution",
|
|
7
10
|
"keywords": [
|
|
@@ -14,8 +17,6 @@
|
|
|
14
17
|
"url": "https://github.com/bluesky-social/atproto",
|
|
15
18
|
"directory": "packages/lexicon-resolver"
|
|
16
19
|
},
|
|
17
|
-
"main": "dist/index.js",
|
|
18
|
-
"types": "dist/index.d.ts",
|
|
19
20
|
"exports": {
|
|
20
21
|
".": {
|
|
21
22
|
"types": "./dist/index.d.ts",
|
|
@@ -23,20 +24,20 @@
|
|
|
23
24
|
}
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
|
-
"@atproto
|
|
27
|
-
"@atproto/
|
|
28
|
-
"@atproto/
|
|
29
|
-
"@atproto/
|
|
30
|
-
"@atproto/repo": "^0.
|
|
31
|
-
"@atproto/
|
|
27
|
+
"@atproto/lex": "^0.1.0-next.0",
|
|
28
|
+
"@atproto/lex-document": "^0.1.0-next.0",
|
|
29
|
+
"@atproto/syntax": "^0.6.0-next.0",
|
|
30
|
+
"@atproto-labs/fetch-node": "^0.3.0-next.0",
|
|
31
|
+
"@atproto/repo": "^0.10.0-next.0",
|
|
32
|
+
"@atproto/identity": "^0.5.0-next.0"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"@atproto/lex-cbor": "^0.0.
|
|
35
|
+
"typescript": "^6.0.3",
|
|
36
|
+
"vitest": "^4.0.16",
|
|
37
|
+
"@atproto/lex-cbor": "^0.1.0-next.0"
|
|
37
38
|
},
|
|
38
39
|
"scripts": {
|
|
39
|
-
"test": "
|
|
40
|
+
"test": "vitest run",
|
|
40
41
|
"build": "tsc --build tsconfig.build.json",
|
|
41
42
|
"prebuild": "pnpm run codegen",
|
|
42
43
|
"codegen": "lex build --override --indexFile --lexicons ../../lexicons --include com.atproto.sync.getRecord --include com.atproto.lexicon.schema"
|
package/src/lexicon.ts
CHANGED
package/tests/lexicon.test.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
|
|
1
2
|
import { SeedClient, TestNetworkNoAppView, usersSeed } from '@atproto/dev-env'
|
|
2
3
|
import { DidString, NSID } from '@atproto/syntax'
|
|
3
4
|
import {
|
|
@@ -8,14 +9,15 @@ import {
|
|
|
8
9
|
|
|
9
10
|
const dnsEntries: [entry: string, ...result: string[][]][] = []
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
vi.mock('node:dns/promises', () => {
|
|
13
|
+
const mock = {
|
|
13
14
|
resolveTxt: (entry: string) => {
|
|
14
15
|
const found = dnsEntries.find(([e]) => e === entry)
|
|
15
16
|
if (found) return found.slice(1)
|
|
16
17
|
return []
|
|
17
18
|
},
|
|
18
19
|
}
|
|
20
|
+
return { default: mock, ...mock }
|
|
19
21
|
})
|
|
20
22
|
|
|
21
23
|
describe('Lexicon resolution', () => {
|
|
@@ -37,7 +39,6 @@ describe('Lexicon resolution', () => {
|
|
|
37
39
|
})
|
|
38
40
|
|
|
39
41
|
afterAll(async () => {
|
|
40
|
-
jest.unmock('node:dns/promises')
|
|
41
42
|
await network.close()
|
|
42
43
|
})
|
|
43
44
|
|
package/tests/record.test.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import assert from 'node:assert'
|
|
2
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
|
2
3
|
import { SeedClient, TestNetworkNoAppView, usersSeed } from '@atproto/dev-env'
|
|
3
4
|
import { AtUriString, l } from '@atproto/lex'
|
|
4
5
|
import { encode } from '@atproto/lex-cbor'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["./src/index.ts","./src/lexicon.ts","./src/record.ts","./src/util.ts","./src/lexicons/com.ts","./src/lexicons/index.ts","./src/lexicons/com/atproto.ts","./src/lexicons/com/atproto/lexicon.ts","./src/lexicons/com/atproto/sync.ts","./src/lexicons/com/atproto/lexicon/schema.defs.ts","./src/lexicons/com/atproto/lexicon/schema.ts","./src/lexicons/com/atproto/sync/
|
|
1
|
+
{"root":["./src/index.ts","./src/lexicon.ts","./src/record.ts","./src/util.ts","./src/lexicons/com.ts","./src/lexicons/index.ts","./src/lexicons/com/atproto.ts","./src/lexicons/com/atproto/lexicon.ts","./src/lexicons/com/atproto/sync.ts","./src/lexicons/com/atproto/lexicon/schema.defs.ts","./src/lexicons/com/atproto/lexicon/schema.ts","./src/lexicons/com/atproto/sync/getrecord.defs.ts","./src/lexicons/com/atproto/sync/getrecord.ts"],"version":"6.0.3"}
|
package/vitest.config.ts
ADDED
package/jest.config.js
DELETED