diff --git a/deno.lock b/deno.lock index 04492e1..f86a0a3 100644 --- a/deno.lock +++ b/deno.lock @@ -14,6 +14,9 @@ "jsr:@std/expect@^1.0.17": "1.0.17", "jsr:@std/internal@^1.0.10": "1.0.12", "jsr:@std/internal@^1.0.12": "1.0.12", + "npm:@atcute/lex-cli@*": "2.3.1", + "npm:@atcute/lex-cli@^2.3.1": "2.3.1", + "npm:@atcute/lexicons@^1.2.2": "1.2.2", "npm:@atproto/lexicon@~0.5.1": "0.5.1" }, "jsr": { @@ -54,6 +57,31 @@ } }, "npm": { + "@atcute/lex-cli@2.3.1": { + "integrity": "sha512-HrHD91CFSFd/p0UFe3akFA1HXiboQwd5LbYiU0srKdLxGX+NLTX/EdCdhbLV6M7LsXdmxk7PB6BMcprsX4rbvg==", + "dependencies": [ + "@atcute/lexicon-doc", + "@badrap/valita", + "@optique/core", + "@optique/run", + "picocolors", + "prettier" + ], + "bin": true + }, + "@atcute/lexicon-doc@1.1.4": { + "integrity": "sha512-OL0fsXtbnN/KwCq/L3nWGvOCdSHV0NWTatgLUIPt+T9AhcziFNaXAbbjvVHdflr3ZaLh3ksleHK0J789UBhlWQ==", + "dependencies": [ + "@badrap/valita" + ] + }, + "@atcute/lexicons@1.2.2": { + "integrity": "sha512-bgEhJq5Z70/0TbK5sx+tAkrR8FsCODNiL2gUEvS5PuJfPxmFmRYNWaMGehxSPaXWpU2+Oa9ckceHiYbrItDTkA==", + "dependencies": [ + "@standard-schema/spec", + "esm-env" + ] + }, "@atproto/common-web@0.4.3": { "integrity": "sha512-nRDINmSe4VycJzPo6fP/hEltBcULFxt9Kw7fQk6405FyAWZiTluYHlXOnU7GkQfeUK44OENG1qFTBcmCJ7e8pg==", "dependencies": [ @@ -76,6 +104,24 @@ "@atproto/syntax@0.4.1": { "integrity": "sha512-CJdImtLAiFO+0z3BWTtxwk6aY5w4t8orHTMVJgkf++QRJWTxPbIFko/0hrkADB7n2EruDxDSeAgfUGehpH6ngw==" }, + "@badrap/valita@0.4.6": { + "integrity": "sha512-4kdqcjyxo/8RQ8ayjms47HCWZIF5981oE5nIenbfThKDxWXtEHKipAOWlflpPJzZx9y/JWYQkp18Awr7VuepFg==" + }, + "@optique/core@0.6.2": { + "integrity": "sha512-HTxIHJ8xLOSZotiU6Zc5BCJv+SJ8DMYmuiQM+7tjF7RolJn/pdZNe7M78G3+DgXL9lIf82l8aGcilmgVYRQnGQ==" + }, + "@optique/run@0.6.2": { + "integrity": "sha512-ERksB5bHozwEUVlTPToIc8UjZZBOgLeBhFZYh2lgldUbNDt7LItzgcErsPq5au5i5IBmmyCti4+2A3x+MRI4Xw==", + "dependencies": [ + "@optique/core" + ] + }, + "@standard-schema/spec@1.0.0": { + "integrity": "sha512-m2bOd0f2RT9k8QJx1JN85cZYyH1RqFBdlwtkSlf4tBDYLCiiZnv1fIIwacK6cqwXavOydf0NPToMQgpKq+dVlA==" + }, + "esm-env@1.2.2": { + "integrity": "sha512-Epxrv+Nr/CaL4ZcFGPJIYLWFom+YeV1DqMLHJoEd9SYRxNbaFruBwfEX/kkHUJf55j2+TUbmDcmuilbP1TmXHA==" + }, "graphemer@1.4.0": { "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==" }, @@ -85,6 +131,13 @@ "multiformats@9.9.0": { "integrity": "sha512-HoMUjhH9T8DDBNT+6xzkrd9ga/XiBI4xLr58LJACwK6G3HTOPeMz4nB4KJs33L2BelrIJa7P0VuNaVF3hMYfjg==" }, + "picocolors@1.1.1": { + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==" + }, + "prettier@3.6.2": { + "integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==", + "bin": true + }, "uint8arrays@3.0.0": { "integrity": "sha512-HRCx0q6O9Bfbp+HHSfQQKD7wU70+lydKVt4EghkdOvlK/NlrF90z+eXV34mUd48rNvVJXwkrMSPpCATkct8fJA==", "dependencies": [ @@ -107,6 +160,8 @@ }, "packages/lexicon": { "dependencies": [ + "npm:@atcute/lex-cli@^2.3.1", + "npm:@atcute/lexicons@^1.2.2", "npm:@atproto/lexicon@~0.5.1" ] } diff --git a/packages/lexicon/deno.jsonc b/packages/lexicon/deno.jsonc index cb88406..4a5f0fd 100644 --- a/packages/lexicon/deno.jsonc +++ b/packages/lexicon/deno.jsonc @@ -3,7 +3,12 @@ "exports": { ".": "./mod.ts" }, + "tasks": { + "generate": "deno run --allow-env --allow-sys --allow-read --allow-write npm:@atcute/lex-cli generate -c lex.config.ts" + }, "imports": { + "@atcute/lex-cli": "npm:@atcute/lex-cli@^2.3.1", + "@atcute/lexicons": "npm:@atcute/lexicons@^1.2.2", "@atproto/lexicon": "npm:@atproto/lexicon@^0.5.1" } } diff --git a/packages/lexicon/lex.config.ts b/packages/lexicon/lex.config.ts new file mode 100644 index 0000000..cfa96f4 --- /dev/null +++ b/packages/lexicon/lex.config.ts @@ -0,0 +1,9 @@ +import { defineLexiconConfig } from "@atcute/lex-cli"; + +export default defineLexiconConfig({ + files: ["lexicons/**/*.json"], + outdir: "./src", + modules: { + importSuffix: ".ts", + }, +}); diff --git a/packages/lexicon/schemas/item.json b/packages/lexicon/lexicons/app/cistern/lexicon/item.json similarity index 100% rename from packages/lexicon/schemas/item.json rename to packages/lexicon/lexicons/app/cistern/lexicon/item.json diff --git a/packages/lexicon/schemas/pubkey.json b/packages/lexicon/lexicons/app/cistern/lexicon/pubkey.json similarity index 100% rename from packages/lexicon/schemas/pubkey.json rename to packages/lexicon/lexicons/app/cistern/lexicon/pubkey.json diff --git a/packages/lexicon/mod.ts b/packages/lexicon/mod.ts index a44bb04..401c73a 100644 --- a/packages/lexicon/mod.ts +++ b/packages/lexicon/mod.ts @@ -1,11 +1 @@ -import item from "./schemas/item.json" with { type: "json" }; -import pubkey from "./schemas/pubkey.json" with { type: "json" }; - -import { type LexiconDoc, Lexicons } from "@atproto/lexicon"; - -const lexicons: Lexicons = new Lexicons(); - -lexicons.add(item as LexiconDoc); -lexicons.add(pubkey as LexiconDoc); - -export { item, lexicons, pubkey }; +export * from "./src/index.ts"; diff --git a/packages/lexicon/src/index.ts b/packages/lexicon/src/index.ts new file mode 100644 index 0000000..6942c64 --- /dev/null +++ b/packages/lexicon/src/index.ts @@ -0,0 +1,2 @@ +export * as AppCisternLexiconItem from "./types/app/cistern/lexicon/item.ts"; +export * as AppCisternLexiconPubkey from "./types/app/cistern/lexicon/pubkey.ts"; diff --git a/packages/lexicon/src/types/app/cistern/lexicon/item.ts b/packages/lexicon/src/types/app/cistern/lexicon/item.ts new file mode 100644 index 0000000..022a6a8 --- /dev/null +++ b/packages/lexicon/src/types/app/cistern/lexicon/item.ts @@ -0,0 +1,64 @@ +import type {} from "@atcute/lexicons"; +import * as v from "@atcute/lexicons/validations"; +import type {} from "@atcute/lexicons/ambient"; + +const _mainSchema = /*#__PURE__*/ v.record( + /*#__PURE__*/ v.string(), + /*#__PURE__*/ v.object({ + $type: /*#__PURE__*/ v.literal("app.cistern.lexicon.item"), + /** + * Algorithm used for encryption, in -- format. + */ + algorithm: /*#__PURE__*/ v.string< + "x_wing-xchacha20_poly1305-sha3_512" | (string & {}) + >(), + /** + * Encapsulated shared ciphertext + * @maxLength 2000 + */ + ciphertext: /*#__PURE__*/ v.constrain(/*#__PURE__*/ v.string(), [ + /*#__PURE__*/ v.stringLength(0, 2000), + ]), + /** + * Base64-encoded hash of the decrypted contents. Verify this before accepting the decrypted message. The algorithm is identified under `algorithm` + */ + contentHash: /*#__PURE__*/ v.string(), + /** + * Original content length in bytes + */ + contentLength: /*#__PURE__*/ v.integer(), + /** + * Base64-encoded nonce used for content encryption + * @maxLength 32 + */ + nonce: /*#__PURE__*/ v.constrain(/*#__PURE__*/ v.string(), [ + /*#__PURE__*/ v.stringLength(0, 32), + ]), + /** + * Base64-encoded encrypted item contents + */ + payload: /*#__PURE__*/ v.string(), + /** + * URI to the public key used to encrypt this item + */ + pubkey: /*#__PURE__*/ v.resourceUriString(), + /** + * TID representing when this item was created + */ + tid: /*#__PURE__*/ v.tidString(), + }), +); + +type main$schematype = typeof _mainSchema; + +export interface mainSchema extends main$schematype {} + +export const mainSchema = _mainSchema as mainSchema; + +export interface Main extends v.InferInput {} + +declare module "@atcute/lexicons/ambient" { + interface Records { + "app.cistern.lexicon.item": mainSchema; + } +} diff --git a/packages/lexicon/src/types/app/cistern/lexicon/pubkey.ts b/packages/lexicon/src/types/app/cistern/lexicon/pubkey.ts new file mode 100644 index 0000000..07ba924 --- /dev/null +++ b/packages/lexicon/src/types/app/cistern/lexicon/pubkey.ts @@ -0,0 +1,40 @@ +import type {} from "@atcute/lexicons"; +import * as v from "@atcute/lexicons/validations"; +import type {} from "@atcute/lexicons/ambient"; + +const _mainSchema = /*#__PURE__*/ v.record( + /*#__PURE__*/ v.string(), + /*#__PURE__*/ v.object({ + $type: /*#__PURE__*/ v.literal("app.cistern.lexicon.pubkey"), + /** + * KEM algorithm used to generate this key + */ + algorithm: /*#__PURE__*/ v.string<"x_wing" | (string & {})>(), + /** + * Contents of the public key, encoded in base64 + */ + content: /*#__PURE__*/ v.string(), + createdAt: /*#__PURE__*/ v.datetimeString(), + /** + * A memorable name for this public key. Avoid using revealing names, such as "Graham's Macbook" + * @minGraphemes 1 + */ + name: /*#__PURE__*/ v.constrain(/*#__PURE__*/ v.string(), [ + /*#__PURE__*/ v.stringGraphemes(1), + ]), + }), +); + +type main$schematype = typeof _mainSchema; + +export interface mainSchema extends main$schematype {} + +export const mainSchema = _mainSchema as mainSchema; + +export interface Main extends v.InferInput {} + +declare module "@atcute/lexicons/ambient" { + interface Records { + "app.cistern.lexicon.pubkey": mainSchema; + } +}