diff --git a/SYNTAX.md b/SYNTAX.md index 64107ce..9676950 100644 --- a/SYNTAX.md +++ b/SYNTAX.md @@ -736,12 +736,46 @@ model FollowerRule {} } ``` +### Empty Union (No Refs) + +**Pattern:** Use `never | unknown` for unions with no model references + +In rare cases, you need an empty union that accepts any type with a `$type` discriminator but has no known refs. Use the `never | unknown` pattern: + +**TypeSpec:** +```typespec +model SubjectView { + @required type: string; + @required subject: string; + profile?: never | unknown; // Empty union +} +``` + +**JSON:** +```json +{ + "profile": { + "type": "union", + "refs": [] + } +} +``` + +**Why `never | unknown`?** +- `never` creates a union type in TypeSpec (single `unknown` is just intrinsic, not a union) +- `never` contributes no refs (it's an empty type) +- `unknown` marks the union as open/extensible +- Result: empty refs array with open union semantics + +**When to use:** Fields that may contain any discriminated type in the future but have no current known types. + ### Syntax Summary | Pattern | Syntax | JSON `closed` field | Use Case | |---------|--------|---------------------|----------| | **Open union (inline)** | `(A \| B \| unknown)` | omitted (false) | Default - allows future variants | | **Open union (named)** | `union { A, B, unknown }` | omitted (false) | Named def, reusable | +| **Empty union** | `never \| unknown` | omitted (false) | No current refs, open to future types | | **Closed union (named)** | `@closed union { A, B }` | `true` | Fixed set, named def | | **Closed union (inline)** | `Closed` | `true` | Fixed set, inline usage | | **Single reference** | `SomeType` | N/A (not a union) | Exactly one type, no variants | diff --git a/package.json b/package.json index 6af496d..25dc674 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "test": "pnpm --filter @tlex/emitter test", "test:watch": "pnpm --filter @tlex/emitter test:watch", "example": "pnpm --filter @tlex/example build", - "validate": "pnpm build && pnpm test" + "validate": "pnpm build && pnpm run validate-lexicons && pnpm test", + "validate-lexicons": "node scripts/validate-lexicons.js" }, "repository": { "type": "git", @@ -26,4 +27,4 @@ "devDependencies": { "typescript": "^5.0.0" } -} \ No newline at end of file +} diff --git a/packages/emitter/src/emitter.ts b/packages/emitter/src/emitter.ts index 5a8f684..8d03286 100644 --- a/packages/emitter/src/emitter.ts +++ b/packages/emitter/src/emitter.ts @@ -412,13 +412,13 @@ export class TlexEmitter { return this.createStringEnumDef(unionType, variants.stringLiterals, prop); } - // Case 2: Model reference union - if (variants.unionRefs.length > 0) { + // Case 2: Model reference union (including empty union with unknown) + if (variants.unionRefs.length > 0 || variants.hasUnknown) { return this.createUnionRefDef(unionType, variants, prop); } - // Case 3: Empty or invalid union - if (variants.stringLiterals.length === 0 && !variants.hasUnknown) { + // Case 3: Empty union without unknown + if (variants.stringLiterals.length === 0) { this.program.reportDiagnostic({ code: "union-empty", severity: "error", diff --git a/packages/emitter/test/scenarios/atproto/input/app/bsky/labeler/defs.tsp b/packages/emitter/test/scenarios/atproto/input/app/bsky/labeler/defs.tsp index 6ca9766..6a56a53 100644 --- a/packages/emitter/test/scenarios/atproto/input/app/bsky/labeler/defs.tsp +++ b/packages/emitter/test/scenarios/atproto/input/app/bsky/labeler/defs.tsp @@ -32,10 +32,10 @@ namespace app.bsky.labeler.defs { labels?: com.atproto.label.defs.Label[]; @doc("The set of report reason 'codes' which are in-scope for this service to review and action. These usually align to policy categories. If not defined (distinct from empty array), all reason types are allowed.") - reasonTypes?: com.atproto.moderation.defs.reasonType[]; + reasonTypes?: com.atproto.moderation.defs.ReasonType[]; @doc("The set of subject types (account, record, etc) this service accepts reports on.") - subjectTypes?: com.atproto.moderation.defs.subjectType[]; + subjectTypes?: com.atproto.moderation.defs.SubjectType[]; @doc("Set of record types (collection NSIDs) which can be reported to this service. If not defined (distinct from empty array), default is any record type.") subjectCollections?: nsid[]; diff --git a/packages/emitter/test/scenarios/atproto/input/app/bsky/labeler/service.tsp b/packages/emitter/test/scenarios/atproto/input/app/bsky/labeler/service.tsp index 0ba366c..c40056b 100644 --- a/packages/emitter/test/scenarios/atproto/input/app/bsky/labeler/service.tsp +++ b/packages/emitter/test/scenarios/atproto/input/app/bsky/labeler/service.tsp @@ -11,10 +11,10 @@ namespace app.bsky.labeler.service { @required createdAt: datetime; @doc("The set of report reason 'codes' which are in-scope for this service to review and action. These usually align to policy categories. If not defined (distinct from empty array), all reason types are allowed.") - reasonTypes?: com.atproto.moderation.defs.reasonType[]; + reasonTypes?: com.atproto.moderation.defs.ReasonType[]; @doc("The set of subject types (account, record, etc) this service accepts reports on.") - subjectTypes?: com.atproto.moderation.defs.subjectType[]; + subjectTypes?: com.atproto.moderation.defs.SubjectType[]; @doc("Set of record types (collection NSIDs) which can be reported to this service. If not defined (distinct from empty array), default is any record type.") subjectCollections?: nsid[]; diff --git a/packages/emitter/test/scenarios/atproto/input/app/bsky/richtext/facet.tsp b/packages/emitter/test/scenarios/atproto/input/app/bsky/richtext/facet.tsp index 21b866e..1dbd1a3 100644 --- a/packages/emitter/test/scenarios/atproto/input/app/bsky/richtext/facet.tsp +++ b/packages/emitter/test/scenarios/atproto/input/app/bsky/richtext/facet.tsp @@ -30,10 +30,10 @@ namespace app.bsky.richtext.facet { model ByteSlice { @minValue(0) @required - byteStart: int32; + byteStart: integer; @minValue(0) @required - byteEnd: int32; + byteEnd: integer; } } diff --git a/packages/emitter/test/scenarios/atproto/input/app/bsky/unspecced/searchActorsSkeleton.tsp b/packages/emitter/test/scenarios/atproto/input/app/bsky/unspecced/searchActorsSkeleton.tsp new file mode 100644 index 0000000..2f7d3ce --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/app/bsky/unspecced/searchActorsSkeleton.tsp @@ -0,0 +1,33 @@ +import "@tlex/emitter"; + +namespace app.bsky.unspecced.searchActorsSkeleton { + model BadQueryString {} + + @doc("Backend Actors (profile) search, returns only skeleton.") + @query + @errors(BadQueryString) + op main( + @doc("Search query string; syntax, phrase, boolean, and faceting is unspecified, but Lucene query syntax is recommended. For typeahead search, only simple term match is supported, not full syntax.") + q: string, + + @doc("DID of the account making the request (not included for public/unauthenticated queries). Used to boost followed accounts in ranking.") + viewer?: did, + + @doc("If true, acts as fast/simple 'typeahead' query.") + typeahead?: boolean, + + @minValue(1) + @maxValue(100) + limit?: integer = 25, + + @doc("Optional pagination mechanism; may not necessarily allow scrolling through entire result set.") + cursor?: string + ): { + cursor?: string; + + @doc("Count of search hits. Optional, may be rounded/truncated, and may not be possible to paginate through all hits.") + hitsTotal?: integer; + + @required actors: app.bsky.unspecced.defs.SkeletonSearchActor[]; + }; +} diff --git a/packages/emitter/test/scenarios/atproto/input/app/bsky/unspecced/searchPostsSkeleton.tsp b/packages/emitter/test/scenarios/atproto/input/app/bsky/unspecced/searchPostsSkeleton.tsp new file mode 100644 index 0000000..ce60e79 --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/app/bsky/unspecced/searchPostsSkeleton.tsp @@ -0,0 +1,61 @@ +import "@tlex/emitter"; + +@maxLength(640) +@maxGraphemes(64) +scalar SkeletonSearchTagString extends string; + +namespace app.bsky.unspecced.searchPostsSkeleton { + model BadQueryString {} + + @doc("Backend Posts search, returns only skeleton") + @query + @errors(BadQueryString) + op main( + @doc("Search query string; syntax, phrase, boolean, and faceting is unspecified, but Lucene query syntax is recommended.") + q: string, + + @doc("Specifies the ranking order of results.") + sort?: "top" | "latest" | string = "latest", + + @doc("Filter results for posts after the indicated datetime (inclusive). Expected to use 'sortAt' timestamp, which may not match 'createdAt'. Can be a datetime, or just an ISO date (YYYY-MM-DD).") + since?: string, + + @doc("Filter results for posts before the indicated datetime (not inclusive). Expected to use 'sortAt' timestamp, which may not match 'createdAt'. Can be a datetime, or just an ISO date (YYY-MM-DD).") + until?: string, + + @doc("Filter to posts which mention the given account. Handles are resolved to DID before query-time. Only matches rich-text facet mentions.") + mentions?: atIdentifier, + + @doc("Filter to posts by the given account. Handles are resolved to DID before query-time.") + author?: atIdentifier, + + @doc("Filter to posts in the given language. Expected to be based on post language field, though server may override language detection.") + lang?: language, + + @doc("Filter to posts with URLs (facet links or embeds) linking to the given domain (hostname). Server may apply hostname normalization.") + domain?: string, + + @doc("Filter to posts with links (facet links or embeds) pointing to this URL. Server may apply URL normalization or fuzzy matching.") + url?: uri, + + @doc("Filter to posts with the given tag (hashtag), based on rich-text facet or tag field. Do not include the hash (#) prefix. Multiple tags can be specified, with 'AND' matching.") + tag?: SkeletonSearchTagString[], + + @doc("DID of the account making the request (not included for public/unauthenticated queries). Used for 'from:me' queries.") + viewer?: did, + + @minValue(1) + @maxValue(100) + limit?: integer = 25, + + @doc("Optional pagination mechanism; may not necessarily allow scrolling through entire result set.") + cursor?: string + ): { + cursor?: string; + + @doc("Count of search hits. Optional, may be rounded/truncated, and may not be possible to paginate through all hits.") + hitsTotal?: integer; + + @required posts: app.bsky.unspecced.defs.SkeletonSearchPost[]; + }; +} diff --git a/packages/emitter/test/scenarios/atproto/input/app/bsky/unspecced/searchStarterPacksSkeleton.tsp b/packages/emitter/test/scenarios/atproto/input/app/bsky/unspecced/searchStarterPacksSkeleton.tsp new file mode 100644 index 0000000..24b7bde --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/app/bsky/unspecced/searchStarterPacksSkeleton.tsp @@ -0,0 +1,30 @@ +import "@tlex/emitter"; + +namespace app.bsky.unspecced.searchStarterPacksSkeleton { + model BadQueryString {} + + @doc("Backend Starter Pack search, returns only skeleton.") + @query + @errors(BadQueryString) + op main( + @doc("Search query string; syntax, phrase, boolean, and faceting is unspecified, but Lucene query syntax is recommended.") + q: string, + + @doc("DID of the account making the request (not included for public/unauthenticated queries).") + viewer?: did, + + @minValue(1) + @maxValue(100) + limit?: integer = 25, + + @doc("Optional pagination mechanism; may not necessarily allow scrolling through entire result set.") + cursor?: string + ): { + cursor?: string; + + @doc("Count of search hits. Optional, may be rounded/truncated, and may not be possible to paginate through all hits.") + hitsTotal?: integer; + + @required starterPacks: app.bsky.unspecced.defs.SkeletonSearchStarterPack[]; + }; +} diff --git a/packages/emitter/test/scenarios/atproto/input/app/bsky/video/defs.tsp b/packages/emitter/test/scenarios/atproto/input/app/bsky/video/defs.tsp index cbee94c..5f539d9 100644 --- a/packages/emitter/test/scenarios/atproto/input/app/bsky/video/defs.tsp +++ b/packages/emitter/test/scenarios/atproto/input/app/bsky/video/defs.tsp @@ -12,7 +12,7 @@ namespace app.bsky.video.defs { @doc("Progress within the current processing state.") @minValue(0) @maxValue(100) - progress?: int32; + progress?: integer; blob?: Blob; error?: string; diff --git a/packages/emitter/test/scenarios/atproto/input/app/bsky/video/uploadVideo.tsp b/packages/emitter/test/scenarios/atproto/input/app/bsky/video/uploadVideo.tsp new file mode 100644 index 0000000..bee4d2a --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/app/bsky/video/uploadVideo.tsp @@ -0,0 +1,12 @@ +import "@tlex/emitter"; + +namespace app.bsky.video.uploadVideo { + @doc("Upload a video to be processed then stored on the PDS.") + @procedure + op main( + @encoding("video/mp4") + input: void + ): { + @required jobStatus: app.bsky.video.defs.JobStatus; + }; +} diff --git a/packages/emitter/test/scenarios/atproto/input/com/atproto/label/subscribeLabels.tsp b/packages/emitter/test/scenarios/atproto/input/com/atproto/label/subscribeLabels.tsp new file mode 100644 index 0000000..aff1204 --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/com/atproto/label/subscribeLabels.tsp @@ -0,0 +1,23 @@ +import "@tlex/emitter"; + +namespace com.atproto.label.subscribeLabels { + model FutureCursor {} + + model Labels { + @required seq: integer; + @required labels: com.atproto.label.defs.Label[]; + } + + model Info { + @required name: "OutdatedCursor" | string; + message?: string; + } + + @doc("Subscribe to stream of labels (and negations). Public endpoint implemented by mod services. Uses same sequencing scheme as repo event stream.") + @subscription + @errors(FutureCursor) + op main( + @doc("The last known event seq number to backfill from.") + cursor?: integer + ): (Labels | Info); +} diff --git a/packages/emitter/test/scenarios/atproto/input/com/atproto/lexicon/schema.tsp b/packages/emitter/test/scenarios/atproto/input/com/atproto/lexicon/schema.tsp new file mode 100644 index 0000000..458a3ee --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/com/atproto/lexicon/schema.tsp @@ -0,0 +1,11 @@ +import "@tlex/emitter"; + +namespace com.atproto.lexicon.schema { + @doc("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).") + @record("nsid") + model Main { + @doc("Indicates the 'version' of the Lexicon language. Must be '1' for the current atproto/Lexicon schema system.") + @required + lexicon: integer; + } +} diff --git a/packages/emitter/test/scenarios/atproto/input/com/atproto/moderation/createReport.tsp b/packages/emitter/test/scenarios/atproto/input/com/atproto/moderation/createReport.tsp index 19f65c4..69f062a 100644 --- a/packages/emitter/test/scenarios/atproto/input/com/atproto/moderation/createReport.tsp +++ b/packages/emitter/test/scenarios/atproto/input/com/atproto/moderation/createReport.tsp @@ -6,7 +6,7 @@ namespace com.atproto.moderation.createReport { op main(input: { @doc("Indicates the broad category of violation the report is for.") @required - reasonType: com.atproto.moderation.defs.reasonType; + reasonType: com.atproto.moderation.defs.ReasonType; @maxGraphemes(2000) @maxLength(20000) @@ -23,7 +23,7 @@ namespace com.atproto.moderation.createReport { modTool?: ModTool; }): { @required id: integer; - @required reasonType: com.atproto.moderation.defs.reasonType; + @required reasonType: com.atproto.moderation.defs.ReasonType; @maxGraphemes(2000) @maxLength(20000) diff --git a/packages/emitter/test/scenarios/atproto/input/com/atproto/moderation/defs.tsp b/packages/emitter/test/scenarios/atproto/input/com/atproto/moderation/defs.tsp index f5ba900..5a28987 100644 --- a/packages/emitter/test/scenarios/atproto/input/com/atproto/moderation/defs.tsp +++ b/packages/emitter/test/scenarios/atproto/input/com/atproto/moderation/defs.tsp @@ -1,7 +1,7 @@ import "@tlex/emitter"; namespace com.atproto.moderation.defs { - union reasonType { + union ReasonType { string, ReasonSpam: "com.atproto.moderation.defs#reasonSpam", @@ -95,11 +95,10 @@ namespace com.atproto.moderation.defs { model ReasonAppeal {} @doc("Tag describing a type of subject that might be reported.") - union subjectType { + union SubjectType { + "account", + "record", + "chat", string, - - Account: "account", - Record: "record", - Chat: "chat", } } diff --git a/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/addReservedHandle.tsp b/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/addReservedHandle.tsp new file mode 100644 index 0000000..031e52c --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/addReservedHandle.tsp @@ -0,0 +1,11 @@ +import "@tlex/emitter"; + +namespace com.atproto.temp.addReservedHandle { + @doc("Add a handle to the set of reserved handles.") + @procedure + op main( + input: { + @required handle: string; + } + ): {}; +} diff --git a/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/checkHandleAvailability.tsp b/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/checkHandleAvailability.tsp new file mode 100644 index 0000000..a0ec41c --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/checkHandleAvailability.tsp @@ -0,0 +1,44 @@ +import "@tlex/emitter"; + +namespace com.atproto.temp.checkHandleAvailability { + @doc("An invalid email was provided.") + model InvalidEmail {} + + @doc("Indicates the provided handle is available.") + model ResultAvailable {} + + @doc("Indicates the provided handle is unavailable and gives suggestions of available handles.") + model ResultUnavailable { + @doc("List of suggested handles based on the provided inputs.") + @required + suggestions: Suggestion[]; + } + + model Suggestion { + @required handle: handle; + + @doc("Method used to build this suggestion. Should be considered opaque to clients. Can be used for metrics.") + @required + method: string; + } + + @doc("Checks whether the provided handle is available. If the handle is not available, available suggestions will be returned. Optional inputs will be used to generate suggestions.") + @query + @errors(InvalidEmail) + op main( + @doc("Tentative handle. Will be checked for availability or used to build handle suggestions.") + handle: handle, + + @doc("User-provided email. Might be used to build handle suggestions.") + email?: string, + + @doc("User-provided birth date. Might be used to build handle suggestions.") + birthDate?: datetime + ): { + @doc("Echo of the input handle.") + @required + handle: handle; + + @required result: ResultAvailable | ResultUnavailable; + }; +} diff --git a/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/checkSignupQueue.tsp b/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/checkSignupQueue.tsp new file mode 100644 index 0000000..93dd178 --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/checkSignupQueue.tsp @@ -0,0 +1,11 @@ +import "@tlex/emitter"; + +namespace com.atproto.temp.checkSignupQueue { + @doc("Check accounts location in signup queue.") + @query + op main(): { + @required activated: boolean; + placeInQueue?: integer; + estimatedTimeMs?: integer; + }; +} diff --git a/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/dereferenceScope.tsp b/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/dereferenceScope.tsp new file mode 100644 index 0000000..adbca80 --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/dereferenceScope.tsp @@ -0,0 +1,18 @@ +import "@tlex/emitter"; + +namespace com.atproto.temp.dereferenceScope { + @doc("An invalid scope reference was provided.") + model InvalidScopeReference {} + + @doc("Allows finding the oauth permission scope from a reference") + @query + @errors(InvalidScopeReference) + op main( + @doc("The scope reference (starts with 'ref:')") + scope: string + ): { + @doc("The full oauth permission scope") + @required + scope: string; + }; +} diff --git a/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/fetchLabels.tsp b/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/fetchLabels.tsp new file mode 100644 index 0000000..76da2a0 --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/fetchLabels.tsp @@ -0,0 +1,15 @@ +import "@tlex/emitter"; + +namespace com.atproto.temp.fetchLabels { + @doc("DEPRECATED: use queryLabels or subscribeLabels instead -- Fetch all labels from a labeler created after a certain date.") + @query + op main( + since?: integer, + + @minValue(1) + @maxValue(250) + limit?: integer = 50 + ): { + @required labels: com.atproto.label.defs.Label[]; + }; +} diff --git a/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/requestPhoneVerification.tsp b/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/requestPhoneVerification.tsp new file mode 100644 index 0000000..3211b7b --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/requestPhoneVerification.tsp @@ -0,0 +1,11 @@ +import "@tlex/emitter"; + +namespace com.atproto.temp.requestPhoneVerification { + @doc("Request a verification code to be sent to the supplied phone number") + @procedure + op main( + input: { + @required phoneNumber: string; + } + ): void; +} diff --git a/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/revokeAccountCredentials.tsp b/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/revokeAccountCredentials.tsp new file mode 100644 index 0000000..ac77114 --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/com/atproto/temp/revokeAccountCredentials.tsp @@ -0,0 +1,11 @@ +import "@tlex/emitter"; + +namespace com.atproto.temp.revokeAccountCredentials { + @doc("Revoke sessions, password, and app passwords associated with account. May be resolved by a password reset.") + @procedure + op main( + input: { + @required account: atIdentifier; + } + ): void; +} diff --git a/packages/emitter/test/scenarios/atproto/input/tools/ozone/communication/createTemplate.tsp b/packages/emitter/test/scenarios/atproto/input/tools/ozone/communication/createTemplate.tsp new file mode 100644 index 0000000..ce5d594 --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/tools/ozone/communication/createTemplate.tsp @@ -0,0 +1,30 @@ +import "@tlex/emitter"; + +namespace tools.ozone.communication.createTemplate { + model DuplicateTemplateName {} + + @doc("Administrative action to create a new, re-usable communication (email for now) template.") + @procedure + @errors(DuplicateTemplateName) + op main( + input: { + @doc("Subject of the message, used in emails.") + @required + subject: string; + + @doc("Content of the template, markdown supported, can contain variable placeholders.") + @required + contentMarkdown: string; + + @doc("Name of the template.") + @required + name: string; + + @doc("Message language.") + lang?: language; + + @doc("DID of the user who is creating the template.") + createdBy?: did; + } + ): tools.ozone.communication.defs.TemplateView; +} diff --git a/packages/emitter/test/scenarios/atproto/input/tools/ozone/communication/defs.tsp b/packages/emitter/test/scenarios/atproto/input/tools/ozone/communication/defs.tsp new file mode 100644 index 0000000..9d33c7c --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/tools/ozone/communication/defs.tsp @@ -0,0 +1,30 @@ +import "@tlex/emitter"; + +namespace tools.ozone.communication.defs { + model TemplateView { + @required id: string; + + @doc("Name of the template.") + @required + name: string; + + @doc("Content of the template, can contain markdown and variable placeholders.") + subject?: string; + + @doc("Subject of the message, used in emails.") + @required + contentMarkdown: string; + + @required disabled: boolean; + + @doc("Message language.") + lang?: language; + + @doc("DID of the user who last updated the template.") + @required + lastUpdatedBy: did; + + @required createdAt: datetime; + @required updatedAt: datetime; + } +} diff --git a/packages/emitter/test/scenarios/atproto/input/tools/ozone/communication/deleteTemplate.tsp b/packages/emitter/test/scenarios/atproto/input/tools/ozone/communication/deleteTemplate.tsp new file mode 100644 index 0000000..7cc457d --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/tools/ozone/communication/deleteTemplate.tsp @@ -0,0 +1,11 @@ +import "@tlex/emitter"; + +namespace tools.ozone.communication.deleteTemplate { + @doc("Delete a communication template.") + @procedure + op main( + input: { + @required id: string; + } + ): void; +} diff --git a/packages/emitter/test/scenarios/atproto/input/tools/ozone/communication/listTemplates.tsp b/packages/emitter/test/scenarios/atproto/input/tools/ozone/communication/listTemplates.tsp new file mode 100644 index 0000000..f34817d --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/tools/ozone/communication/listTemplates.tsp @@ -0,0 +1,9 @@ +import "@tlex/emitter"; + +namespace tools.ozone.communication.listTemplates { + @doc("Get list of all communication templates.") + @query + op main(): { + @required communicationTemplates: tools.ozone.communication.defs.TemplateView[]; + }; +} diff --git a/packages/emitter/test/scenarios/atproto/input/tools/ozone/communication/updateTemplate.tsp b/packages/emitter/test/scenarios/atproto/input/tools/ozone/communication/updateTemplate.tsp new file mode 100644 index 0000000..7c33d84 --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/tools/ozone/communication/updateTemplate.tsp @@ -0,0 +1,33 @@ +import "@tlex/emitter"; + +namespace tools.ozone.communication.updateTemplate { + model DuplicateTemplateName {} + + @doc("Administrative action to update an existing communication template. Allows passing partial fields to patch specific fields only.") + @procedure + @errors(DuplicateTemplateName) + op main( + input: { + @doc("ID of the template to be updated.") + @required + id: string; + + @doc("Name of the template.") + name?: string; + + @doc("Message language.") + lang?: language; + + @doc("Content of the template, markdown supported, can contain variable placeholders.") + contentMarkdown?: string; + + @doc("Subject of the message, used in emails.") + subject?: string; + + @doc("DID of the user who is updating the template.") + updatedBy?: did; + + disabled?: boolean; + } + ): tools.ozone.communication.defs.TemplateView; +} diff --git a/packages/emitter/test/scenarios/atproto/input/tools/ozone/moderation/defs.tsp b/packages/emitter/test/scenarios/atproto/input/tools/ozone/moderation/defs.tsp new file mode 100644 index 0000000..63be613 --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/tools/ozone/moderation/defs.tsp @@ -0,0 +1,540 @@ +import "@tlex/emitter"; + +namespace tools.ozone.moderation.defs { + model ModEventView { + @required id: integer; + @required event: ModEventTakedown | ModEventReverseTakedown | ModEventComment | ModEventReport | ModEventLabel | ModEventAcknowledge | ModEventEscalate | ModEventMute | ModEventUnmute | ModEventMuteReporter | ModEventUnmuteReporter | ModEventEmail | ModEventResolveAppeal | ModEventDivert | ModEventTag | AccountEvent | IdentityEvent | RecordEvent | ModEventPriorityScore | AgeAssuranceEvent | AgeAssuranceOverrideEvent | RevokeAccountCredentialsEvent; + @required subject: com.atproto.admin.defs.RepoRef | com.atproto.repo.strongRef.Main | chat.bsky.convo.defs.MessageRef; + @required subjectBlobCids: string[]; + @required createdBy: did; + @required createdAt: datetime; + creatorHandle?: string; + subjectHandle?: string; + modTool?: ModTool; + } + + model ModEventViewDetail { + @required id: integer; + @required event: ModEventTakedown | ModEventReverseTakedown | ModEventComment | ModEventReport | ModEventLabel | ModEventAcknowledge | ModEventEscalate | ModEventMute | ModEventUnmute | ModEventMuteReporter | ModEventUnmuteReporter | ModEventEmail | ModEventResolveAppeal | ModEventDivert | ModEventTag | AccountEvent | IdentityEvent | RecordEvent | ModEventPriorityScore | AgeAssuranceEvent | AgeAssuranceOverrideEvent | RevokeAccountCredentialsEvent; + @required subject: RepoView | RepoViewNotFound | RecordView | RecordViewNotFound; + @required subjectBlobs: BlobView[]; + @required createdBy: did; + @required createdAt: datetime; + modTool?: ModTool; + } + + model SubjectStatusView { + @required id: integer; + @required subject: com.atproto.admin.defs.RepoRef | com.atproto.repo.strongRef.Main | chat.bsky.convo.defs.MessageRef; + hosting?: AccountHosting | RecordHosting; + subjectBlobCids?: cid[]; + subjectRepoHandle?: string; + + @doc("Timestamp referencing the first moderation status impacting event was emitted on the subject") + @required + createdAt: datetime; + + @doc("Timestamp referencing when the last update was made to the moderation status of the subject") + @required + updatedAt: datetime; + + @required reviewState: SubjectReviewState; + + @doc("Sticky comment on the subject.") + comment?: string; + + @doc("Numeric value representing the level of priority. Higher score means higher priority.") + @minValue(0) + @maxValue(100) + priorityScore?: integer; + + muteUntil?: datetime; + muteReportingUntil?: datetime; + lastReviewedBy?: did; + lastReviewedAt?: datetime; + lastReportedAt?: datetime; + + @doc("Timestamp referencing when the author of the subject appealed a moderation action") + lastAppealedAt?: datetime; + + takendown?: boolean; + + @doc("True indicates that the a previously taken moderator action was appealed against, by the author of the content. False indicates last appeal was resolved by moderators.") + appealed?: boolean; + + suspendUntil?: datetime; + tags?: string[]; + + @doc("Statistics related to the account subject") + accountStats?: AccountStats; + + @doc("Statistics related to the record subjects authored by the subject's account") + recordsStats?: RecordsStats; + + @doc("Current age assurance state of the subject.") + ageAssuranceState?: "pending" | "assured" | "unknown" | "reset" | "blocked" | string; + + @doc("Whether or not the last successful update to age assurance was made by the user or admin.") + ageAssuranceUpdatedBy?: "admin" | "user" | string; + } + + @doc("Detailed view of a subject. For record subjects, the author's repo and profile will be returned.") + model SubjectView { + @required type: com.atproto.moderation.defs.SubjectType; + @required subject: string; + status?: SubjectStatusView; + repo?: RepoViewDetail; + profile?: (never | unknown); + record?: RecordViewDetail; + } + + @doc("Statistics about a particular account subject") + model AccountStats { + @doc("Total number of reports on the account") + reportCount?: integer; + + @doc("Total number of appeals against a moderation action on the account") + appealCount?: integer; + + @doc("Number of times the account was suspended") + suspendCount?: integer; + + @doc("Number of times the account was escalated") + escalateCount?: integer; + + @doc("Number of times the account was taken down") + takedownCount?: integer; + } + + @doc("Statistics about a set of record subject items") + model RecordsStats { + @doc("Cumulative sum of the number of reports on the items in the set") + totalReports?: integer; + + @doc("Number of items that were reported at least once") + reportedCount?: integer; + + @doc("Number of items that were escalated at least once") + escalatedCount?: integer; + + @doc("Number of items that were appealed at least once") + appealedCount?: integer; + + @doc("Total number of item in the set") + subjectCount?: integer; + + @doc("Number of item currently in \"reviewOpen\" or \"reviewEscalated\" state") + pendingCount?: integer; + + @doc("Number of item currently in \"reviewNone\" or \"reviewClosed\" state") + processedCount?: integer; + + @doc("Number of item currently taken down") + takendownCount?: integer; + } + + union SubjectReviewState { + string, + + ReviewOpen: "#reviewOpen", + ReviewEscalated: "#reviewEscalated", + ReviewClosed: "#reviewClosed", + ReviewNone: "#reviewNone", + } + + @doc("Moderator review status of a subject: Open. Indicates that the subject needs to be reviewed by a moderator") + @token + model ReviewOpen {} + + @doc("Moderator review status of a subject: Escalated. Indicates that the subject was escalated for review by a moderator") + @token + model ReviewEscalated {} + + @doc("Moderator review status of a subject: Closed. Indicates that the subject was already reviewed and resolved by a moderator") + @token + model ReviewClosed {} + + @doc("Moderator review status of a subject: Unnecessary. Indicates that the subject does not need a review at the moment but there is probably some moderation related metadata available for it") + @token + model ReviewNone {} + + @doc("Take down a subject permanently or temporarily") + model ModEventTakedown { + comment?: string; + + @doc("Indicates how long the takedown should be in effect before automatically expiring.") + durationInHours?: integer; + + @doc("If true, all other reports on content authored by this account will be resolved (acknowledged).") + acknowledgeAccountSubjects?: boolean; + + @maxItems(5) + @doc("Names/Keywords of the policies that drove the decision.") + policies?: string[]; + } + + @doc("Revert take down action on a subject") + model ModEventReverseTakedown { + @doc("Describe reasoning behind the reversal.") + comment?: string; + } + + @doc("Resolve appeal on a subject") + model ModEventResolveAppeal { + @doc("Describe resolution.") + comment?: string; + } + + @doc("Add a comment to a subject. An empty comment will clear any previously set sticky comment.") + model ModEventComment { + comment?: string; + + @doc("Make the comment persistent on the subject") + sticky?: boolean; + } + + @doc("Report a subject") + model ModEventReport { + comment?: string; + + @doc("Set to true if the reporter was muted from reporting at the time of the event. These reports won't impact the reviewState of the subject.") + isReporterMuted?: boolean; + + @required reportType: com.atproto.moderation.defs.ReasonType; + } + + @doc("Apply/Negate labels on a subject") + model ModEventLabel { + comment?: string; + @required createLabelVals: string[]; + @required negateLabelVals: string[]; + + @doc("Indicates how long the label will remain on the subject. Only applies on labels that are being added.") + durationInHours?: integer; + } + + @doc("Set priority score of the subject. Higher score means higher priority.") + model ModEventPriorityScore { + comment?: string; + + @minValue(0) + @maxValue(100) + @required + score: integer; + } + + @doc("Age assurance info coming directly from users. Only works on DID subjects.") + model AgeAssuranceEvent { + @doc("The date and time of this write operation.") + @required + createdAt: datetime; + + @doc("The status of the age assurance process.") + @required + status: "unknown" | "pending" | "assured" | string; + + @doc("The unique identifier for this instance of the age assurance flow, in UUID format.") + @required + attemptId: string; + + @doc("The IP address used when initiating the AA flow.") + initIp?: string; + + @doc("The user agent used when initiating the AA flow.") + initUa?: string; + + @doc("The IP address used when completing the AA flow.") + completeIp?: string; + + @doc("The user agent used when completing the AA flow.") + completeUa?: string; + } + + @doc("Age assurance status override by moderators. Only works on DID subjects.") + model AgeAssuranceOverrideEvent { + @doc("Comment describing the reason for the override.") + @required + comment: string; + + @doc("The status to be set for the user decided by a moderator, overriding whatever value the user had previously. Use reset to default to original state.") + @required + status: "assured" | "reset" | "blocked" | string; + } + + @doc("Account credentials revocation by moderators. Only works on DID subjects.") + model RevokeAccountCredentialsEvent { + @doc("Comment describing the reason for the revocation.") + @required + comment: string; + } + + model ModEventAcknowledge { + comment?: string; + + @doc("If true, all other reports on content authored by this account will be resolved (acknowledged).") + acknowledgeAccountSubjects?: boolean; + } + + model ModEventEscalate { + comment?: string; + } + + @doc("Mute incoming reports on a subject") + model ModEventMute { + comment?: string; + + @doc("Indicates how long the subject should remain muted.") + @required + durationInHours: integer; + } + + @doc("Unmute action on a subject") + model ModEventUnmute { + @doc("Describe reasoning behind the reversal.") + comment?: string; + } + + @doc("Mute incoming reports from an account") + model ModEventMuteReporter { + comment?: string; + + @doc("Indicates how long the account should remain muted. Falsy value here means a permanent mute.") + durationInHours?: integer; + } + + @doc("Unmute incoming reports from an account") + model ModEventUnmuteReporter { + @doc("Describe reasoning behind the reversal.") + comment?: string; + } + + @doc("Keep a log of outgoing email to a user") + model ModEventEmail { + @doc("The subject line of the email sent to the user.") + @required + subjectLine: string; + + @doc("The content of the email sent to the user.") + content?: string; + + @doc("Additional comment about the outgoing comm.") + comment?: string; + } + + @doc("Divert a record's blobs to a 3rd party service for further scanning/tagging") + model ModEventDivert { + comment?: string; + } + + @doc("Add/Remove a tag on a subject") + model ModEventTag { + @doc("Tags to be added to the subject. If already exists, won't be duplicated.") + @required + add: string[]; + + @doc("Tags to be removed to the subject. Ignores a tag If it doesn't exist, won't be duplicated.") + @required + remove: string[]; + + @doc("Additional comment about added/removed tags.") + comment?: string; + } + + @doc("Logs account status related events on a repo subject. Normally captured by automod from the firehose and emitted to ozone for historical tracking.") + model AccountEvent { + comment?: string; + @required timestamp: datetime; + + @doc("Indicates that the account has a repository which can be fetched from the host that emitted this event.") + @required + active: boolean; + + status?: "unknown" | "deactivated" | "deleted" | "takendown" | "suspended" | "tombstoned" | string; + } + + @doc("Logs identity related events on a repo subject. Normally captured by automod from the firehose and emitted to ozone for historical tracking.") + model IdentityEvent { + comment?: string; + handle?: handle; + pdsHost?: uri; + tombstone?: boolean; + @required timestamp: datetime; + } + + @doc("Logs lifecycle event on a record subject. Normally captured by automod from the firehose and emitted to ozone for historical tracking.") + model RecordEvent { + comment?: string; + @required timestamp: datetime; + + @required + `op`: "create" | "update" | "delete" | string; + + cid?: cid; + } + + model RepoView { + @required did: did; + @required handle: handle; + email?: string; + @required relatedRecords: unknown[]; + @required indexedAt: datetime; + @required moderation: Moderation; + invitedBy?: com.atproto.server.defs.InviteCode; + invitesDisabled?: boolean; + inviteNote?: string; + deactivatedAt?: datetime; + threatSignatures?: com.atproto.admin.defs.ThreatSignature[]; + } + + model RepoViewDetail { + @required did: did; + @required handle: handle; + email?: string; + @required relatedRecords: unknown[]; + @required indexedAt: datetime; + @required moderation: ModerationDetail; + labels?: com.atproto.label.defs.Label[]; + invitedBy?: com.atproto.server.defs.InviteCode; + invites?: com.atproto.server.defs.InviteCode[]; + invitesDisabled?: boolean; + inviteNote?: string; + emailConfirmedAt?: datetime; + deactivatedAt?: datetime; + threatSignatures?: com.atproto.admin.defs.ThreatSignature[]; + } + + model RepoViewNotFound { + @required did: did; + } + + model RecordView { + @required uri: atUri; + @required cid: cid; + @required value: unknown; + @required blobCids: cid[]; + @required indexedAt: datetime; + @required moderation: Moderation; + @required repo: RepoView; + } + + model RecordViewDetail { + @required uri: atUri; + @required cid: cid; + @required value: unknown; + @required blobs: BlobView[]; + labels?: com.atproto.label.defs.Label[]; + @required indexedAt: datetime; + @required moderation: ModerationDetail; + @required repo: RepoView; + } + + model RecordViewNotFound { + @required uri: atUri; + } + + model Moderation { + subjectStatus?: SubjectStatusView; + } + + model ModerationDetail { + subjectStatus?: SubjectStatusView; + } + + model BlobView { + @required cid: cid; + @required mimeType: string; + @required size: integer; + @required createdAt: datetime; + details?: ImageDetails | VideoDetails; + moderation?: Moderation; + } + + model ImageDetails { + @required width: integer; + @required height: integer; + } + + model VideoDetails { + @required width: integer; + @required height: integer; + @required length: integer; + } + + model AccountHosting { + @required + status: "takendown" | "suspended" | "deleted" | "deactivated" | "unknown" | string; + + updatedAt?: datetime; + createdAt?: datetime; + deletedAt?: datetime; + deactivatedAt?: datetime; + reactivatedAt?: datetime; + } + + model RecordHosting { + @required + status: "deleted" | "unknown" | string; + + updatedAt?: datetime; + createdAt?: datetime; + deletedAt?: datetime; + } + + model ReporterStats { + @required did: did; + + @doc("The total number of reports made by the user on accounts.") + @required + accountReportCount: integer; + + @doc("The total number of reports made by the user on records.") + @required + recordReportCount: integer; + + @doc("The total number of accounts reported by the user.") + @required + reportedAccountCount: integer; + + @doc("The total number of records reported by the user.") + @required + reportedRecordCount: integer; + + @doc("The total number of accounts taken down as a result of the user's reports.") + @required + takendownAccountCount: integer; + + @doc("The total number of records taken down as a result of the user's reports.") + @required + takendownRecordCount: integer; + + @doc("The total number of accounts labeled as a result of the user's reports.") + @required + labeledAccountCount: integer; + + @doc("The total number of records labeled as a result of the user's reports.") + @required + labeledRecordCount: integer; + } + + @doc("Moderation tool information for tracing the source of the action") + model ModTool { + @doc("Name/identifier of the source (e.g., 'automod', 'ozone/workspace')") + @required + name: string; + + @doc("Additional arbitrary metadata about the source") + meta?: unknown; + } + + @doc("Moderation event timeline event for a PLC create operation") + @token + model TimelineEventPlcCreate {} + + @doc("Moderation event timeline event for generic PLC operation") + @token + model TimelineEventPlcOperation {} + + @doc("Moderation event timeline event for a PLC tombstone operation") + @token + model TimelineEventPlcTombstone {} +} diff --git a/packages/emitter/test/scenarios/atproto/input/tools/ozone/report/defs.tsp b/packages/emitter/test/scenarios/atproto/input/tools/ozone/report/defs.tsp new file mode 100644 index 0000000..f1dc00c --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/tools/ozone/report/defs.tsp @@ -0,0 +1,240 @@ +import "@tlex/emitter"; + +namespace tools.ozone.report.defs { + union ReasonType { + string, + + ReasonAppeal: "tools.ozone.report.defs#reasonAppeal", + + ReasonViolenceAnimalWelfare: "tools.ozone.report.defs#reasonViolenceAnimalWelfare", + ReasonViolenceThreats: "tools.ozone.report.defs#reasonViolenceThreats", + ReasonViolenceGraphicContent: "tools.ozone.report.defs#reasonViolenceGraphicContent", + ReasonViolenceSelfHarm: "tools.ozone.report.defs#reasonViolenceSelfHarm", + ReasonViolenceGlorification: "tools.ozone.report.defs#reasonViolenceGlorification", + ReasonViolenceExtremistContent: "tools.ozone.report.defs#reasonViolenceExtremistContent", + ReasonViolenceTrafficking: "tools.ozone.report.defs#reasonViolenceTrafficking", + ReasonViolenceOther: "tools.ozone.report.defs#reasonViolenceOther", + + ReasonSexualAbuseContent: "tools.ozone.report.defs#reasonSexualAbuseContent", + ReasonSexualNCII: "tools.ozone.report.defs#reasonSexualNCII", + ReasonSexualSextortion: "tools.ozone.report.defs#reasonSexualSextortion", + ReasonSexualDeepfake: "tools.ozone.report.defs#reasonSexualDeepfake", + ReasonSexualAnimal: "tools.ozone.report.defs#reasonSexualAnimal", + ReasonSexualUnlabeled: "tools.ozone.report.defs#reasonSexualUnlabeled", + ReasonSexualOther: "tools.ozone.report.defs#reasonSexualOther", + + ReasonChildSafetyCSAM: "tools.ozone.report.defs#reasonChildSafetyCSAM", + ReasonChildSafetyGroom: "tools.ozone.report.defs#reasonChildSafetyGroom", + ReasonChildSafetyMinorPrivacy: "tools.ozone.report.defs#reasonChildSafetyMinorPrivacy", + ReasonChildSafetyEndangerment: "tools.ozone.report.defs#reasonChildSafetyEndangerment", + ReasonChildSafetyHarassment: "tools.ozone.report.defs#reasonChildSafetyHarassment", + ReasonChildSafetyPromotion: "tools.ozone.report.defs#reasonChildSafetyPromotion", + ReasonChildSafetyOther: "tools.ozone.report.defs#reasonChildSafetyOther", + + ReasonHarassmentTroll: "tools.ozone.report.defs#reasonHarassmentTroll", + ReasonHarassmentTargeted: "tools.ozone.report.defs#reasonHarassmentTargeted", + ReasonHarassmentHateSpeech: "tools.ozone.report.defs#reasonHarassmentHateSpeech", + ReasonHarassmentDoxxing: "tools.ozone.report.defs#reasonHarassmentDoxxing", + ReasonHarassmentOther: "tools.ozone.report.defs#reasonHarassmentOther", + + ReasonMisleadingBot: "tools.ozone.report.defs#reasonMisleadingBot", + ReasonMisleadingImpersonation: "tools.ozone.report.defs#reasonMisleadingImpersonation", + ReasonMisleadingSpam: "tools.ozone.report.defs#reasonMisleadingSpam", + ReasonMisleadingScam: "tools.ozone.report.defs#reasonMisleadingScam", + ReasonMisleadingSyntheticContent: "tools.ozone.report.defs#reasonMisleadingSyntheticContent", + ReasonMisleadingMisinformation: "tools.ozone.report.defs#reasonMisleadingMisinformation", + ReasonMisleadingOther: "tools.ozone.report.defs#reasonMisleadingOther", + + ReasonRuleSiteSecurity: "tools.ozone.report.defs#reasonRuleSiteSecurity", + ReasonRuleStolenContent: "tools.ozone.report.defs#reasonRuleStolenContent", + ReasonRuleProhibitedSales: "tools.ozone.report.defs#reasonRuleProhibitedSales", + ReasonRuleBanEvasion: "tools.ozone.report.defs#reasonRuleBanEvasion", + ReasonRuleOther: "tools.ozone.report.defs#reasonRuleOther", + + ReasonCivicElectoralProcess: "tools.ozone.report.defs#reasonCivicElectoralProcess", + ReasonCivicDisclosure: "tools.ozone.report.defs#reasonCivicDisclosure", + ReasonCivicInterference: "tools.ozone.report.defs#reasonCivicInterference", + ReasonCivicMisinformation: "tools.ozone.report.defs#reasonCivicMisinformation", + ReasonCivicImpersonation: "tools.ozone.report.defs#reasonCivicImpersonation", + } + + @doc("Appeal a previously taken moderation action") + @token + model ReasonAppeal {} + + @doc("Animal welfare violations") + @token + model ReasonViolenceAnimalWelfare {} + + @doc("Threats or incitement") + @token + model ReasonViolenceThreats {} + + @doc("Graphic violent content") + @token + model ReasonViolenceGraphicContent {} + + @doc("Self harm") + @token + model ReasonViolenceSelfHarm {} + + @doc("Glorification of violence") + @token + model ReasonViolenceGlorification {} + + @doc("Extremist content. These reports will be sent only be sent to the application's Moderation Authority.") + @token + model ReasonViolenceExtremistContent {} + + @doc("Human trafficking") + @token + model ReasonViolenceTrafficking {} + + @doc("Other violent content") + @token + model ReasonViolenceOther {} + + @doc("Adult sexual abuse content") + @token + model ReasonSexualAbuseContent {} + + @doc("Non-consensual intimate imagery") + @token + model ReasonSexualNCII {} + + @doc("Sextortion") + @token + model ReasonSexualSextortion {} + + @doc("Deepfake adult content") + @token + model ReasonSexualDeepfake {} + + @doc("Animal sexual abuse") + @token + model ReasonSexualAnimal {} + + @doc("Unlabelled adult content") + @token + model ReasonSexualUnlabeled {} + + @doc("Other sexual violence content") + @token + model ReasonSexualOther {} + + @doc("Child sexual abuse material (CSAM). These reports will be sent only be sent to the application's Moderation Authority.") + @token + model ReasonChildSafetyCSAM {} + + @doc("Grooming or predatory behavior. These reports will be sent only be sent to the application's Moderation Authority.") + @token + model ReasonChildSafetyGroom {} + + @doc("Privacy violation involving a minor") + @token + model ReasonChildSafetyMinorPrivacy {} + + @doc("Child endangerment. These reports will be sent only be sent to the application's Moderation Authority.") + @token + model ReasonChildSafetyEndangerment {} + + @doc("Harassment or bullying of minors") + @token + model ReasonChildSafetyHarassment {} + + @doc("Promotion of child exploitation. These reports will be sent only be sent to the application's Moderation Authority.") + @token + model ReasonChildSafetyPromotion {} + + @doc("Other child safety. These reports will be sent only be sent to the application's Moderation Authority.") + @token + model ReasonChildSafetyOther {} + + @doc("Trolling") + @token + model ReasonHarassmentTroll {} + + @doc("Targeted harassment") + @token + model ReasonHarassmentTargeted {} + + @doc("Hate speech") + @token + model ReasonHarassmentHateSpeech {} + + @doc("Doxxing") + @token + model ReasonHarassmentDoxxing {} + + @doc("Other harassing or hateful content") + @token + model ReasonHarassmentOther {} + + @doc("Fake account or bot") + @token + model ReasonMisleadingBot {} + + @doc("Impersonation") + @token + model ReasonMisleadingImpersonation {} + + @doc("Spam") + @token + model ReasonMisleadingSpam {} + + @doc("Scam") + @token + model ReasonMisleadingScam {} + + @doc("Unlabelled gen-AI or synthetic content") + @token + model ReasonMisleadingSyntheticContent {} + + @doc("Harmful false claims") + @token + model ReasonMisleadingMisinformation {} + + @doc("Other misleading content") + @token + model ReasonMisleadingOther {} + + @doc("Hacking or system attacks") + @token + model ReasonRuleSiteSecurity {} + + @doc("Stolen content") + @token + model ReasonRuleStolenContent {} + + @doc("Promoting or selling prohibited items or services") + @token + model ReasonRuleProhibitedSales {} + + @doc("Banned user returning") + @token + model ReasonRuleBanEvasion {} + + @doc("Other") + @token + model ReasonRuleOther {} + + @doc("Electoral process violations") + @token + model ReasonCivicElectoralProcess {} + + @doc("Disclosure & transparency violations") + @token + model ReasonCivicDisclosure {} + + @doc("Voter intimidation or interference") + @token + model ReasonCivicInterference {} + + @doc("Election misinformation") + @token + model ReasonCivicMisinformation {} + + @doc("Impersonation of electoral officials/entities") + @token + model ReasonCivicImpersonation {} +} diff --git a/packages/emitter/test/scenarios/atproto/input/tools/ozone/safelink/defs.tsp b/packages/emitter/test/scenarios/atproto/input/tools/ozone/safelink/defs.tsp new file mode 100644 index 0000000..8db5c0d --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/tools/ozone/safelink/defs.tsp @@ -0,0 +1,83 @@ +import "@tlex/emitter"; + +namespace tools.ozone.safelink.defs { + @doc("An event for URL safety decisions") + model Event { + @doc("Auto-incrementing row ID") + @required + id: integer; + + @required eventType: EventType; + + @doc("The URL that this rule applies to") + @required + url: string; + + @required pattern: PatternType; + @required action: ActionType; + @required reason: ReasonType; + + @doc("DID of the user who created this rule") + @required + createdBy: did; + + @required createdAt: datetime; + + @doc("Optional comment about the decision") + comment?: string; + } + + union EventType { + "addRule", + "updateRule", + "removeRule", + string, + } + + union PatternType { + "domain", + "url", + string, + } + + union ActionType { + "block", + "warn", + "whitelist", + string, + } + + union ReasonType { + "csam", + "spam", + "phishing", + "none", + string, + } + + @doc("Input for creating a URL safety rule") + model UrlRule { + @doc("The URL or domain to apply the rule to") + @required + url: string; + + @required pattern: PatternType; + @required action: ActionType; + @required reason: ReasonType; + + @doc("Optional comment about the decision") + comment?: string; + + @doc("DID of the user added the rule.") + @required + createdBy: did; + + @doc("Timestamp when the rule was created") + @required + createdAt: datetime; + + @doc("Timestamp when the rule was last updated") + @required + updatedAt: datetime; + } +} diff --git a/packages/emitter/test/scenarios/atproto/input/tools/ozone/server/getConfig.tsp b/packages/emitter/test/scenarios/atproto/input/tools/ozone/server/getConfig.tsp new file mode 100644 index 0000000..5cfc58d --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/tools/ozone/server/getConfig.tsp @@ -0,0 +1,24 @@ +import "@tlex/emitter"; + +namespace tools.ozone.server.getConfig { + model ServiceConfig { + url?: uri; + } + + model ViewerConfig { + role?: "tools.ozone.team.defs#roleAdmin" | "tools.ozone.team.defs#roleModerator" | "tools.ozone.team.defs#roleTriage" | "tools.ozone.team.defs#roleVerifier" | string; + } + + @doc("Get details about ozone's server configuration.") + @query + op main(): { + appview?: ServiceConfig; + pds?: ServiceConfig; + blobDivert?: ServiceConfig; + chat?: ServiceConfig; + viewer?: ViewerConfig; + + @doc("The did of the verifier used for verification.") + verifierDid?: did; + }; +} diff --git a/packages/emitter/test/scenarios/atproto/input/tools/ozone/set/defs.tsp b/packages/emitter/test/scenarios/atproto/input/tools/ozone/set/defs.tsp new file mode 100644 index 0000000..557576b --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/tools/ozone/set/defs.tsp @@ -0,0 +1,29 @@ +import "@tlex/emitter"; + +namespace tools.ozone.set.defs { + model Set { + @minLength(3) + @maxLength(128) + @required + name: string; + + @maxGraphemes(1024) + @maxLength(10240) + description?: string; + } + + model SetView { + @minLength(3) + @maxLength(128) + @required + name: string; + + @maxGraphemes(1024) + @maxLength(10240) + description?: string; + + @required setSize: integer; + @required createdAt: datetime; + @required updatedAt: datetime; + } +} diff --git a/packages/emitter/test/scenarios/atproto/input/tools/ozone/setting/defs.tsp b/packages/emitter/test/scenarios/atproto/input/tools/ozone/setting/defs.tsp new file mode 100644 index 0000000..10daaa8 --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/tools/ozone/setting/defs.tsp @@ -0,0 +1,24 @@ +import "@tlex/emitter"; + +namespace tools.ozone.setting.defs { + model Option { + @required key: nsid; + @required value: unknown; + @required did: did; + + @maxGraphemes(1024) + @maxLength(10240) + description?: string; + + createdAt?: datetime; + updatedAt?: datetime; + + managerRole?: "tools.ozone.team.defs#roleModerator" | "tools.ozone.team.defs#roleTriage" | "tools.ozone.team.defs#roleAdmin" | "tools.ozone.team.defs#roleVerifier" | string; + + @required + scope: "instance" | "personal" | string; + + @required createdBy: did; + @required lastUpdatedBy: did; + } +} diff --git a/packages/emitter/test/scenarios/atproto/input/tools/ozone/team/defs.tsp b/packages/emitter/test/scenarios/atproto/input/tools/ozone/team/defs.tsp new file mode 100644 index 0000000..d73e856 --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/tools/ozone/team/defs.tsp @@ -0,0 +1,31 @@ +import "@tlex/emitter"; + +namespace tools.ozone.team.defs { + model Member { + @required did: did; + disabled?: boolean; + profile?: app.bsky.actor.defs.ProfileViewDetailed; + createdAt?: datetime; + updatedAt?: datetime; + lastUpdatedBy?: string; + + @required + role: "#roleAdmin" | "#roleModerator" | "#roleTriage" | "#roleVerifier" | string; + } + + @doc("Admin role. Highest level of access, can perform all actions.") + @token + model RoleAdmin {} + + @doc("Moderator role. Can perform most actions.") + @token + model RoleModerator {} + + @doc("Triage role. Mostly intended for monitoring and escalating issues.") + @token + model RoleTriage {} + + @doc("Verifier role. Only allowed to issue verifications.") + @token + model RoleVerifier {} +} diff --git a/packages/emitter/test/scenarios/atproto/input/tools/ozone/verification/defs.tsp b/packages/emitter/test/scenarios/atproto/input/tools/ozone/verification/defs.tsp new file mode 100644 index 0000000..5d5afb7 --- /dev/null +++ b/packages/emitter/test/scenarios/atproto/input/tools/ozone/verification/defs.tsp @@ -0,0 +1,44 @@ +import "@tlex/emitter"; + +namespace tools.ozone.verification.defs { + @doc("Verification data for the associated subject.") + model VerificationView { + @doc("The user who issued this verification.") + @required + issuer: did; + + @doc("The AT-URI of the verification record.") + @required + uri: atUri; + + @doc("The subject of the verification.") + @required + subject: did; + + @doc("Handle of the subject the verification applies to at the moment of verifying, which might not be the same at the time of viewing. The verification is only valid if the current handle matches the one at the time of verifying.") + @required + handle: handle; + + @doc("Display name of the subject the verification applies to at the moment of verifying, which might not be the same at the time of viewing. The verification is only valid if the current displayName matches the one at the time of verifying.") + @required + displayName: string; + + @doc("Timestamp when the verification was created.") + @required + createdAt: datetime; + + @doc("Describes the reason for revocation, also indicating that the verification is no longer valid.") + revokeReason?: string; + + @doc("Timestamp when the verification was revoked.") + revokedAt?: datetime; + + @doc("The user who revoked this verification.") + revokedBy?: did; + + subjectProfile?: (never | unknown); + issuerProfile?: (never | unknown); + subjectRepo?: tools.ozone.moderation.defs.RepoViewDetail | tools.ozone.moderation.defs.RepoViewNotFound; + issuerRepo?: tools.ozone.moderation.defs.RepoViewDetail | tools.ozone.moderation.defs.RepoViewNotFound; + } +} diff --git a/packages/emitter/test/spec/README.md b/packages/emitter/test/spec/README.md new file mode 100644 index 0000000..2ce7b7d --- /dev/null +++ b/packages/emitter/test/spec/README.md @@ -0,0 +1,36 @@ +# Lexicon Spec Test Fixtures + +This directory contains test fixtures organized by ATProto Lexicon specification features, not by real-world examples. + +## Organization + +Each subdirectory focuses on a specific feature from the [Lexicon spec](https://atproto.com/specs/lexicon): + +- **union/** - Union type features (open, closed, variants) +- **string-constraints/** - String knownValues, enum, formats +- **validation/** - Constraints (min/max length/value, graphemes) +- **primary-types/** - Record, query, procedure, subscription +- **field-types/** - Primitive types and their features +- **refs/** - Reference patterns (local, cross-namespace) +- **nullable/** - Nullable field handling +- **unknown/** - Unknown type usage +- **tokens/** - Token definitions and usage +- **binary/** - Blob and bytes types +- **evolution/** - Schema evolution patterns + +## Purpose + +Unlike `test/scenarios/atproto/` which tests real ATProto lexicons, these fixtures: + +1. Test each spec feature in isolation +2. Demonstrate minimal, focused examples +3. Serve as documentation for TypeSpec → Lexicon mappings +4. Catch edge cases and corner cases in the spec + +## Example Structure + +Each feature directory contains: +- `input/*.tsp` - TypeSpec definitions for that feature +- `output/*.json` - Expected Lexicon JSON output + +Tests should be atomic and focus on one feature at a time. diff --git a/packages/emitter/test/spec/output/binary-types/blob.json b/packages/emitter/test/spec/output/binary-types/blob.json new file mode 100644 index 0000000..a83b2fd --- /dev/null +++ b/packages/emitter/test/spec/output/binary-types/blob.json @@ -0,0 +1,39 @@ +{ + "lexicon": 1, + "id": "com.example.blobs", + "defs": { + "main": { + "type": "object", + "description": "Blob type examples", + "properties": { + "simpleBlob": { + "type": "blob", + "description": "Basic blob with no constraints" + }, + "imageBlob": { + "type": "blob", + "accept": ["image/*"], + "maxSize": 5000000, + "description": "Image blob up to 5MB" + }, + "specificImages": { + "type": "blob", + "accept": ["image/png", "image/jpeg", "image/gif"], + "maxSize": 2000000, + "description": "Specific image types up to 2MB" + }, + "videoBlob": { + "type": "blob", + "accept": ["video/mp4", "video/webm"], + "maxSize": 100000000, + "description": "Video blob up to 100MB" + }, + "anyBlob": { + "type": "blob", + "accept": ["*/*"], + "description": "Accept any MIME type" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/binary-types/cid-link.json b/packages/emitter/test/spec/output/binary-types/cid-link.json new file mode 100644 index 0000000..4b9fcab --- /dev/null +++ b/packages/emitter/test/spec/output/binary-types/cid-link.json @@ -0,0 +1,20 @@ +{ + "lexicon": 1, + "id": "com.example.cidLinks", + "defs": { + "main": { + "type": "object", + "description": "CID link examples", + "properties": { + "contentCid": { + "type": "cid-link", + "description": "A CID link to content" + }, + "previousVersion": { + "type": "cid-link", + "description": "Link to previous version" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/container-types/array.json b/packages/emitter/test/spec/output/container-types/array.json new file mode 100644 index 0000000..655cf37 --- /dev/null +++ b/packages/emitter/test/spec/output/container-types/array.json @@ -0,0 +1,70 @@ +{ + "lexicon": 1, + "id": "com.example.arrays", + "defs": { + "main": { + "type": "object", + "description": "Array container types", + "properties": { + "stringArray": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Array of strings" + }, + "arrayWithLength": { + "type": "array", + "items": { + "type": "integer" + }, + "minLength": 1, + "maxLength": 10, + "description": "Array with size constraints" + }, + "arrayOfRefs": { + "type": "array", + "items": { + "type": "ref", + "ref": "#item" + }, + "description": "Array of object references" + }, + "arrayOfUnion": { + "type": "array", + "items": { + "type": "union", + "refs": ["#typeA", "#typeB"] + }, + "description": "Array of union types" + } + } + }, + "item": { + "type": "object", + "properties": { + "value": { + "type": "string" + } + } + }, + "typeA": { + "type": "object", + "required": ["a"], + "properties": { + "a": { + "type": "string" + } + } + }, + "typeB": { + "type": "object", + "required": ["b"], + "properties": { + "b": { + "type": "integer" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/container-types/object.json b/packages/emitter/test/spec/output/container-types/object.json new file mode 100644 index 0000000..e62f592 --- /dev/null +++ b/packages/emitter/test/spec/output/container-types/object.json @@ -0,0 +1,42 @@ +{ + "lexicon": 1, + "id": "com.example.objects", + "defs": { + "main": { + "type": "object", + "description": "Object with various property configurations", + "required": ["requiredField"], + "nullable": ["nullableField"], + "properties": { + "requiredField": { + "type": "string", + "description": "This field is required" + }, + "optionalField": { + "type": "string", + "description": "This field is optional" + }, + "nullableField": { + "type": "string", + "description": "This field can be null" + }, + "nestedObject": { + "type": "ref", + "ref": "#nested" + } + } + }, + "nested": { + "type": "object", + "required": ["id"], + "properties": { + "id": { + "type": "string" + }, + "label": { + "type": "string" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/container-types/params.json b/packages/emitter/test/spec/output/container-types/params.json new file mode 100644 index 0000000..8c96ced --- /dev/null +++ b/packages/emitter/test/spec/output/container-types/params.json @@ -0,0 +1,56 @@ +{ + "lexicon": 1, + "id": "com.example.queryParams", + "defs": { + "main": { + "type": "query", + "description": "Query with various parameter types", + "parameters": { + "type": "params", + "required": ["requiredParam"], + "properties": { + "requiredParam": { + "type": "string", + "description": "A required query parameter" + }, + "boolParam": { + "type": "boolean", + "description": "Optional boolean parameter" + }, + "intParam": { + "type": "integer", + "description": "Optional integer parameter" + }, + "stringParam": { + "type": "string", + "maxLength": 100, + "description": "Optional string parameter" + }, + "arrayParam": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Array of strings" + }, + "unknownParam": { + "type": "unknown", + "description": "Unknown type parameter" + } + } + }, + "output": { + "encoding": "application/json", + "schema": { + "type": "object", + "required": ["result"], + "properties": { + "result": { + "type": "string" + } + } + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/field-types/boolean-constraints.json b/packages/emitter/test/spec/output/field-types/boolean-constraints.json new file mode 100644 index 0000000..badcd71 --- /dev/null +++ b/packages/emitter/test/spec/output/field-types/boolean-constraints.json @@ -0,0 +1,32 @@ +{ + "lexicon": 1, + "id": "com.example.booleanConstraints", + "defs": { + "main": { + "type": "object", + "description": "Boolean field constraints", + "properties": { + "defaultTrue": { + "type": "boolean", + "default": true, + "description": "Boolean with default true" + }, + "defaultFalse": { + "type": "boolean", + "default": false, + "description": "Boolean with default false" + }, + "constTrue": { + "type": "boolean", + "const": true, + "description": "Constant true value" + }, + "constFalse": { + "type": "boolean", + "const": false, + "description": "Constant false value" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/field-types/bytes-constraints.json b/packages/emitter/test/spec/output/field-types/bytes-constraints.json new file mode 100644 index 0000000..161973c --- /dev/null +++ b/packages/emitter/test/spec/output/field-types/bytes-constraints.json @@ -0,0 +1,32 @@ +{ + "lexicon": 1, + "id": "com.example.bytesConstraints", + "defs": { + "main": { + "type": "object", + "description": "Bytes field constraints", + "properties": { + "simpleBytes": { + "type": "bytes", + "description": "Basic bytes field" + }, + "withLength": { + "type": "bytes", + "minLength": 1, + "maxLength": 1024, + "description": "Bytes with size constraints" + }, + "withMinOnly": { + "type": "bytes", + "minLength": 32, + "description": "Bytes with minimum size only" + }, + "withMaxOnly": { + "type": "bytes", + "maxLength": 5000000, + "description": "Bytes with maximum size only (5MB)" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/field-types/integer-constraints.json b/packages/emitter/test/spec/output/field-types/integer-constraints.json new file mode 100644 index 0000000..1350b32 --- /dev/null +++ b/packages/emitter/test/spec/output/field-types/integer-constraints.json @@ -0,0 +1,33 @@ +{ + "lexicon": 1, + "id": "com.example.integerConstraints", + "defs": { + "main": { + "type": "object", + "description": "Integer field constraints", + "properties": { + "withMinMax": { + "type": "integer", + "minimum": 1, + "maximum": 100, + "description": "Integer between 1 and 100" + }, + "withEnum": { + "type": "integer", + "enum": [1, 2, 3, 5, 8, 13], + "description": "Fibonacci numbers only" + }, + "withDefault": { + "type": "integer", + "default": 42, + "description": "Integer with default value" + }, + "withConst": { + "type": "integer", + "const": 99, + "description": "Constant integer value" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/field-types/primitives.json b/packages/emitter/test/spec/output/field-types/primitives.json new file mode 100644 index 0000000..3ce209d --- /dev/null +++ b/packages/emitter/test/spec/output/field-types/primitives.json @@ -0,0 +1,32 @@ +{ + "lexicon": 1, + "id": "com.example.primitives", + "defs": { + "main": { + "type": "object", + "description": "All primitive field types", + "properties": { + "boolField": { + "type": "boolean", + "description": "A boolean field" + }, + "intField": { + "type": "integer", + "description": "An integer field" + }, + "stringField": { + "type": "string", + "description": "A string field" + }, + "bytesField": { + "type": "bytes", + "description": "A bytes field" + }, + "cidField": { + "type": "cid-link", + "description": "A CID link field" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/field-types/string-constraints.json b/packages/emitter/test/spec/output/field-types/string-constraints.json new file mode 100644 index 0000000..070a055 --- /dev/null +++ b/packages/emitter/test/spec/output/field-types/string-constraints.json @@ -0,0 +1,52 @@ +{ + "lexicon": 1, + "id": "com.example.stringConstraints", + "defs": { + "main": { + "type": "object", + "description": "String field constraints", + "properties": { + "withLength": { + "type": "string", + "minLength": 1, + "maxLength": 100, + "description": "String with byte length constraints" + }, + "withGraphemes": { + "type": "string", + "minGraphemes": 1, + "maxGraphemes": 50, + "description": "String with grapheme cluster length constraints" + }, + "withBothLengths": { + "type": "string", + "minLength": 1, + "maxLength": 300, + "minGraphemes": 1, + "maxGraphemes": 100, + "description": "String with both byte and grapheme constraints" + }, + "withEnum": { + "type": "string", + "enum": ["draft", "published", "archived"], + "description": "Closed enum of allowed values" + }, + "withKnownValues": { + "type": "string", + "knownValues": ["en", "es", "fr", "de", "ja"], + "description": "Open set of suggested values" + }, + "withDefault": { + "type": "string", + "default": "hello", + "description": "String with default value" + }, + "withConst": { + "type": "string", + "const": "fixed-value", + "description": "Constant string value" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/meta-types/ref.json b/packages/emitter/test/spec/output/meta-types/ref.json new file mode 100644 index 0000000..31d82c0 --- /dev/null +++ b/packages/emitter/test/spec/output/meta-types/ref.json @@ -0,0 +1,36 @@ +{ + "lexicon": 1, + "id": "com.example.refs", + "defs": { + "main": { + "type": "object", + "description": "Reference examples", + "properties": { + "localRef": { + "type": "ref", + "ref": "#localDef", + "description": "Reference to local definition" + }, + "externalRef": { + "type": "ref", + "ref": "com.example.other#someDef", + "description": "Reference to external definition" + }, + "mainRef": { + "type": "ref", + "ref": "com.example.record", + "description": "Reference to main definition (no fragment)" + } + } + }, + "localDef": { + "type": "object", + "required": ["value"], + "properties": { + "value": { + "type": "string" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/meta-types/token.json b/packages/emitter/test/spec/output/meta-types/token.json new file mode 100644 index 0000000..9ba8ef3 --- /dev/null +++ b/packages/emitter/test/spec/output/meta-types/token.json @@ -0,0 +1,29 @@ +{ + "lexicon": 1, + "id": "com.example.tokens", + "defs": { + "main": { + "type": "object", + "description": "Token usage example", + "required": ["status"], + "properties": { + "status": { + "type": "ref", + "ref": "#active" + } + } + }, + "active": { + "type": "token", + "description": "Indicates an active state" + }, + "inactive": { + "type": "token", + "description": "Indicates an inactive state" + }, + "pending": { + "type": "token", + "description": "Indicates a pending state" + } + } +} diff --git a/packages/emitter/test/spec/output/meta-types/union-closed.json b/packages/emitter/test/spec/output/meta-types/union-closed.json new file mode 100644 index 0000000..ea9a974 --- /dev/null +++ b/packages/emitter/test/spec/output/meta-types/union-closed.json @@ -0,0 +1,61 @@ +{ + "lexicon": 1, + "id": "com.example.unionClosed", + "defs": { + "main": { + "type": "object", + "description": "Closed union example", + "required": ["action"], + "properties": { + "action": { + "type": "union", + "refs": ["#create", "#update", "#delete"], + "closed": true, + "description": "Closed union - no more variants allowed" + } + } + }, + "create": { + "type": "object", + "required": ["type", "data"], + "properties": { + "type": { + "type": "string", + "const": "create" + }, + "data": { + "type": "string" + } + } + }, + "update": { + "type": "object", + "required": ["type", "id", "data"], + "properties": { + "type": { + "type": "string", + "const": "update" + }, + "id": { + "type": "string" + }, + "data": { + "type": "string" + } + } + }, + "delete": { + "type": "object", + "required": ["type", "id"], + "properties": { + "type": { + "type": "string", + "const": "delete" + }, + "id": { + "type": "string" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/meta-types/union-empty.json b/packages/emitter/test/spec/output/meta-types/union-empty.json new file mode 100644 index 0000000..53a7ce9 --- /dev/null +++ b/packages/emitter/test/spec/output/meta-types/union-empty.json @@ -0,0 +1,17 @@ +{ + "lexicon": 1, + "id": "com.example.unionEmpty", + "defs": { + "main": { + "type": "object", + "description": "Empty open union (similar to unknown but requires $type)", + "properties": { + "data": { + "type": "union", + "refs": [], + "description": "Empty open union - any object with $type allowed" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/meta-types/union-open.json b/packages/emitter/test/spec/output/meta-types/union-open.json new file mode 100644 index 0000000..6ebc9ea --- /dev/null +++ b/packages/emitter/test/spec/output/meta-types/union-open.json @@ -0,0 +1,57 @@ +{ + "lexicon": 1, + "id": "com.example.unionOpen", + "defs": { + "main": { + "type": "object", + "description": "Open union example (default)", + "required": ["item"], + "properties": { + "item": { + "type": "union", + "refs": ["#typeA", "#typeB", "#typeC"], + "description": "Open union - more variants can be added in future" + } + } + }, + "typeA": { + "type": "object", + "required": ["kind", "valueA"], + "properties": { + "kind": { + "type": "string", + "const": "a" + }, + "valueA": { + "type": "string" + } + } + }, + "typeB": { + "type": "object", + "required": ["kind", "valueB"], + "properties": { + "kind": { + "type": "string", + "const": "b" + }, + "valueB": { + "type": "integer" + } + } + }, + "typeC": { + "type": "object", + "required": ["kind", "valueC"], + "properties": { + "kind": { + "type": "string", + "const": "c" + }, + "valueC": { + "type": "boolean" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/meta-types/unknown.json b/packages/emitter/test/spec/output/meta-types/unknown.json new file mode 100644 index 0000000..ce91fc9 --- /dev/null +++ b/packages/emitter/test/spec/output/meta-types/unknown.json @@ -0,0 +1,20 @@ +{ + "lexicon": 1, + "id": "com.example.unknown", + "defs": { + "main": { + "type": "object", + "description": "Unknown type usage", + "properties": { + "metadata": { + "type": "unknown", + "description": "Any object data without validation" + }, + "optionalMetadata": { + "type": "unknown", + "description": "Optional unknown field" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/primary-types/procedure-simple.json b/packages/emitter/test/spec/output/primary-types/procedure-simple.json new file mode 100644 index 0000000..268b70c --- /dev/null +++ b/packages/emitter/test/spec/output/primary-types/procedure-simple.json @@ -0,0 +1,46 @@ +{ + "lexicon": 1, + "id": "com.example.createRecord", + "defs": { + "main": { + "type": "procedure", + "description": "Create a new record", + "input": { + "encoding": "application/json", + "schema": { + "type": "object", + "required": ["text"], + "properties": { + "text": { + "type": "string", + "description": "The text content" + } + } + } + }, + "output": { + "encoding": "application/json", + "schema": { + "type": "object", + "required": ["uri", "cid"], + "properties": { + "uri": { + "type": "string", + "format": "at-uri" + }, + "cid": { + "type": "string", + "format": "cid" + } + } + } + }, + "errors": [ + { + "name": "InvalidText", + "description": "The provided text is invalid" + } + ] + } + } +} diff --git a/packages/emitter/test/spec/output/primary-types/query-simple.json b/packages/emitter/test/spec/output/primary-types/query-simple.json new file mode 100644 index 0000000..11b70b9 --- /dev/null +++ b/packages/emitter/test/spec/output/primary-types/query-simple.json @@ -0,0 +1,33 @@ +{ + "lexicon": 1, + "id": "com.example.getRecord", + "defs": { + "main": { + "type": "query", + "description": "Retrieve a record by ID", + "parameters": { + "type": "params", + "required": ["id"], + "properties": { + "id": { + "type": "string", + "description": "The record identifier" + } + } + }, + "output": { + "encoding": "application/json", + "schema": { + "type": "object", + "required": ["record"], + "properties": { + "record": { + "type": "ref", + "ref": "com.example.record" + } + } + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/primary-types/record-simple.json b/packages/emitter/test/spec/output/primary-types/record-simple.json new file mode 100644 index 0000000..24dbbcd --- /dev/null +++ b/packages/emitter/test/spec/output/primary-types/record-simple.json @@ -0,0 +1,26 @@ +{ + "lexicon": 1, + "id": "com.example.record", + "defs": { + "main": { + "type": "record", + "description": "A simple record with basic properties", + "key": "tid", + "record": { + "type": "object", + "required": ["text", "createdAt"], + "properties": { + "text": { + "type": "string", + "description": "The text content" + }, + "createdAt": { + "type": "string", + "format": "datetime", + "description": "When the record was created" + } + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/primary-types/subscription-simple.json b/packages/emitter/test/spec/output/primary-types/subscription-simple.json new file mode 100644 index 0000000..ccfaefc --- /dev/null +++ b/packages/emitter/test/spec/output/primary-types/subscription-simple.json @@ -0,0 +1,49 @@ +{ + "lexicon": 1, + "id": "com.example.subscribeRecords", + "defs": { + "main": { + "type": "subscription", + "description": "Subscribe to record updates", + "parameters": { + "type": "params", + "properties": { + "cursor": { + "type": "integer", + "description": "Optional cursor for resuming" + } + } + }, + "message": { + "schema": { + "type": "union", + "refs": ["#record", "#delete"] + } + } + }, + "record": { + "type": "object", + "required": ["uri", "record"], + "properties": { + "uri": { + "type": "string", + "format": "at-uri" + }, + "record": { + "type": "ref", + "ref": "com.example.record" + } + } + }, + "delete": { + "type": "object", + "required": ["uri"], + "properties": { + "uri": { + "type": "string", + "format": "at-uri" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/special-features/defs-lexicon.json b/packages/emitter/test/spec/output/special-features/defs-lexicon.json new file mode 100644 index 0000000..baf960f --- /dev/null +++ b/packages/emitter/test/spec/output/special-features/defs-lexicon.json @@ -0,0 +1,41 @@ +{ + "lexicon": 1, + "id": "com.example.defs", + "description": "Common definitions used by other lexicons", + "defs": { + "statusEnum": { + "type": "string", + "enum": ["active", "inactive", "pending", "deleted"] + }, + "timestamp": { + "type": "object", + "required": ["createdAt"], + "nullable": ["updatedAt"], + "properties": { + "createdAt": { + "type": "string", + "format": "datetime" + }, + "updatedAt": { + "type": "string", + "format": "datetime" + } + } + }, + "metadata": { + "type": "object", + "properties": { + "version": { + "type": "integer", + "default": 1 + }, + "tags": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/special-features/errors.json b/packages/emitter/test/spec/output/special-features/errors.json new file mode 100644 index 0000000..295f6aa --- /dev/null +++ b/packages/emitter/test/spec/output/special-features/errors.json @@ -0,0 +1,49 @@ +{ + "lexicon": 1, + "id": "com.example.withErrors", + "defs": { + "main": { + "type": "procedure", + "description": "Procedure with error definitions", + "input": { + "encoding": "application/json", + "schema": { + "type": "object", + "required": ["value"], + "properties": { + "value": { + "type": "integer", + "minimum": 1, + "maximum": 100 + } + } + } + }, + "output": { + "encoding": "application/json", + "schema": { + "type": "object", + "required": ["result"], + "properties": { + "result": { + "type": "string" + } + } + } + }, + "errors": [ + { + "name": "InvalidValue", + "description": "The provided value is invalid" + }, + { + "name": "RateLimitExceeded", + "description": "Too many requests" + }, + { + "name": "Unauthorized" + } + ] + } + } +} diff --git a/packages/emitter/test/spec/output/special-features/input-output-ref.json b/packages/emitter/test/spec/output/special-features/input-output-ref.json new file mode 100644 index 0000000..d2e8c74 --- /dev/null +++ b/packages/emitter/test/spec/output/special-features/input-output-ref.json @@ -0,0 +1,46 @@ +{ + "lexicon": 1, + "id": "com.example.refInOutput", + "defs": { + "main": { + "type": "procedure", + "description": "Procedure with ref in output schema", + "input": { + "encoding": "application/json", + "schema": { + "type": "ref", + "ref": "#inputData" + } + }, + "output": { + "encoding": "application/json", + "schema": { + "type": "ref", + "ref": "#outputData" + } + } + }, + "inputData": { + "type": "object", + "required": ["value"], + "properties": { + "value": { + "type": "string" + } + } + }, + "outputData": { + "type": "object", + "required": ["result", "timestamp"], + "properties": { + "result": { + "type": "string" + }, + "timestamp": { + "type": "string", + "format": "datetime" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/special-features/nullable-fields.json b/packages/emitter/test/spec/output/special-features/nullable-fields.json new file mode 100644 index 0000000..198ccbe --- /dev/null +++ b/packages/emitter/test/spec/output/special-features/nullable-fields.json @@ -0,0 +1,30 @@ +{ + "lexicon": 1, + "id": "com.example.nullableFields", + "defs": { + "main": { + "type": "object", + "description": "Demonstrates nullable field semantics", + "required": ["requiredField"], + "nullable": ["nullableRequired", "nullableOptional"], + "properties": { + "requiredField": { + "type": "string", + "description": "Required, cannot be null or omitted" + }, + "nullableRequired": { + "type": "string", + "description": "Must be present, but can be null" + }, + "nullableOptional": { + "type": "string", + "description": "Can be omitted, present with value, or present as null" + }, + "optionalField": { + "type": "string", + "description": "Can be omitted or present with value, but not null" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/special-features/output-without-schema.json b/packages/emitter/test/spec/output/special-features/output-without-schema.json new file mode 100644 index 0000000..8f574cb --- /dev/null +++ b/packages/emitter/test/spec/output/special-features/output-without-schema.json @@ -0,0 +1,22 @@ +{ + "lexicon": 1, + "id": "com.example.outputWithoutSchema", + "defs": { + "main": { + "type": "query", + "description": "Query with JSON output but no schema defined", + "parameters": { + "type": "params", + "properties": { + "id": { + "type": "string" + } + } + }, + "output": { + "encoding": "application/json", + "description": "Returns JSON data without a defined schema" + } + } + } +} diff --git a/packages/emitter/test/spec/output/special-features/record-key-any.json b/packages/emitter/test/spec/output/special-features/record-key-any.json new file mode 100644 index 0000000..af51fda --- /dev/null +++ b/packages/emitter/test/spec/output/special-features/record-key-any.json @@ -0,0 +1,25 @@ +{ + "lexicon": 1, + "id": "com.example.flexibleRecord", + "defs": { + "main": { + "type": "record", + "description": "Record with any key type", + "key": "any", + "record": { + "type": "object", + "properties": { + "data": { + "type": "string" + }, + "tags": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/special-features/record-key-literal.json b/packages/emitter/test/spec/output/special-features/record-key-literal.json new file mode 100644 index 0000000..a4c8ff8 --- /dev/null +++ b/packages/emitter/test/spec/output/special-features/record-key-literal.json @@ -0,0 +1,25 @@ +{ + "lexicon": 1, + "id": "com.example.profile", + "defs": { + "main": { + "type": "record", + "description": "Record with literal 'self' key", + "key": "literal:self", + "record": { + "type": "object", + "required": ["displayName"], + "properties": { + "displayName": { + "type": "string", + "maxGraphemes": 64 + }, + "description": { + "type": "string", + "maxGraphemes": 256 + } + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/special-features/record-key-tid.json b/packages/emitter/test/spec/output/special-features/record-key-tid.json new file mode 100644 index 0000000..527145e --- /dev/null +++ b/packages/emitter/test/spec/output/special-features/record-key-tid.json @@ -0,0 +1,24 @@ +{ + "lexicon": 1, + "id": "com.example.tidRecord", + "defs": { + "main": { + "type": "record", + "description": "Record with TID key type", + "key": "tid", + "record": { + "type": "object", + "required": ["content", "createdAt"], + "properties": { + "content": { + "type": "string" + }, + "createdAt": { + "type": "string", + "format": "datetime" + } + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/special-features/subscription-union-message.json b/packages/emitter/test/spec/output/special-features/subscription-union-message.json new file mode 100644 index 0000000..38d76d8 --- /dev/null +++ b/packages/emitter/test/spec/output/special-features/subscription-union-message.json @@ -0,0 +1,123 @@ +{ + "lexicon": 1, + "id": "com.example.eventStream", + "defs": { + "main": { + "type": "subscription", + "description": "Subscription with union message schema", + "parameters": { + "type": "params", + "properties": { + "cursor": { + "type": "integer" + } + } + }, + "message": { + "description": "Stream of events", + "schema": { + "type": "union", + "refs": ["#commit", "#identity", "#account", "#handle", "#tombstone"] + } + }, + "errors": [ + { + "name": "FutureCursor", + "description": "Cursor is in the future" + } + ] + }, + "commit": { + "type": "object", + "required": ["seq", "time", "repo"], + "properties": { + "seq": { + "type": "integer" + }, + "time": { + "type": "string", + "format": "datetime" + }, + "repo": { + "type": "string", + "format": "did" + } + } + }, + "identity": { + "type": "object", + "required": ["seq", "time", "did"], + "properties": { + "seq": { + "type": "integer" + }, + "time": { + "type": "string", + "format": "datetime" + }, + "did": { + "type": "string", + "format": "did" + } + } + }, + "account": { + "type": "object", + "required": ["seq", "time", "did", "active"], + "properties": { + "seq": { + "type": "integer" + }, + "time": { + "type": "string", + "format": "datetime" + }, + "did": { + "type": "string", + "format": "did" + }, + "active": { + "type": "boolean" + } + } + }, + "handle": { + "type": "object", + "required": ["seq", "time", "did", "handle"], + "properties": { + "seq": { + "type": "integer" + }, + "time": { + "type": "string", + "format": "datetime" + }, + "did": { + "type": "string", + "format": "did" + }, + "handle": { + "type": "string", + "format": "handle" + } + } + }, + "tombstone": { + "type": "object", + "required": ["seq", "time", "did"], + "properties": { + "seq": { + "type": "integer" + }, + "time": { + "type": "string", + "format": "datetime" + }, + "did": { + "type": "string", + "format": "did" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/string-formats/all-formats.json b/packages/emitter/test/spec/output/string-formats/all-formats.json new file mode 100644 index 0000000..780ea51 --- /dev/null +++ b/packages/emitter/test/spec/output/string-formats/all-formats.json @@ -0,0 +1,67 @@ +{ + "lexicon": 1, + "id": "com.example.stringFormats", + "defs": { + "main": { + "type": "object", + "description": "All string format types", + "properties": { + "atIdentifier": { + "type": "string", + "format": "at-identifier", + "description": "Handle or DID" + }, + "atUri": { + "type": "string", + "format": "at-uri", + "description": "AT-URI format" + }, + "cid": { + "type": "string", + "format": "cid", + "description": "CID in string format" + }, + "datetime": { + "type": "string", + "format": "datetime", + "description": "ISO 8601 datetime with timezone" + }, + "did": { + "type": "string", + "format": "did", + "description": "DID identifier" + }, + "handle": { + "type": "string", + "format": "handle", + "description": "Handle identifier" + }, + "nsid": { + "type": "string", + "format": "nsid", + "description": "Namespaced identifier" + }, + "tid": { + "type": "string", + "format": "tid", + "description": "Timestamp identifier" + }, + "recordKey": { + "type": "string", + "format": "record-key", + "description": "Record key (any syntax)" + }, + "uri": { + "type": "string", + "format": "uri", + "description": "Generic URI (RFC 3986)" + }, + "language": { + "type": "string", + "format": "language", + "description": "IETF BCP 47 language tag" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/string-formats/datetime-examples.json b/packages/emitter/test/spec/output/string-formats/datetime-examples.json new file mode 100644 index 0000000..e92b474 --- /dev/null +++ b/packages/emitter/test/spec/output/string-formats/datetime-examples.json @@ -0,0 +1,28 @@ +{ + "lexicon": 1, + "id": "com.example.datetimeExamples", + "defs": { + "main": { + "type": "object", + "description": "Datetime format usage examples", + "required": ["createdAt"], + "properties": { + "createdAt": { + "type": "string", + "format": "datetime", + "description": "Required datetime field" + }, + "updatedAt": { + "type": "string", + "format": "datetime", + "description": "Optional datetime field" + }, + "publishedAt": { + "type": "string", + "format": "datetime", + "description": "Optional publish time" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/string-formats/identifier-examples.json b/packages/emitter/test/spec/output/string-formats/identifier-examples.json new file mode 100644 index 0000000..cd5d526 --- /dev/null +++ b/packages/emitter/test/spec/output/string-formats/identifier-examples.json @@ -0,0 +1,37 @@ +{ + "lexicon": 1, + "id": "com.example.identifierExamples", + "defs": { + "main": { + "type": "object", + "description": "Identifier format examples", + "properties": { + "did": { + "type": "string", + "format": "did", + "description": "DID identifier (did:plc:, did:web:, etc)" + }, + "handle": { + "type": "string", + "format": "handle", + "description": "Handle identifier (username.bsky.social)" + }, + "atIdentifier": { + "type": "string", + "format": "at-identifier", + "description": "Either a DID or handle" + }, + "cidString": { + "type": "string", + "format": "cid", + "description": "CID as string" + }, + "languageCode": { + "type": "string", + "format": "language", + "description": "BCP 47 language tag" + } + } + } + } +} diff --git a/packages/emitter/test/spec/output/string-formats/uri-examples.json b/packages/emitter/test/spec/output/string-formats/uri-examples.json new file mode 100644 index 0000000..c50fb7b --- /dev/null +++ b/packages/emitter/test/spec/output/string-formats/uri-examples.json @@ -0,0 +1,37 @@ +{ + "lexicon": 1, + "id": "com.example.uriExamples", + "defs": { + "main": { + "type": "object", + "description": "Various URI format examples", + "properties": { + "atUri": { + "type": "string", + "format": "at-uri", + "description": "AT protocol URI" + }, + "genericUri": { + "type": "string", + "format": "uri", + "description": "Generic URI (https, did, ipfs, etc)" + }, + "recordKey": { + "type": "string", + "format": "record-key", + "description": "Record key identifier" + }, + "nsid": { + "type": "string", + "format": "nsid", + "description": "Namespaced identifier" + }, + "tid": { + "type": "string", + "format": "tid", + "description": "Timestamp identifier" + } + } + } + } +} diff --git a/scripts/validate-lexicons.js b/scripts/validate-lexicons.js new file mode 100755 index 0000000..ca392bd --- /dev/null +++ b/scripts/validate-lexicons.js @@ -0,0 +1,92 @@ +#!/usr/bin/env node + +const fs = require('fs'); +const path = require('path'); + +// Import validation from atproto lexicon package +const atprotoPath = path.join(__dirname, '../../atproto/packages/lexicon'); +const { Lexicons } = require(path.join(atprotoPath, 'dist/index.js')); + +function findJsonFiles(dir, fileList = []) { + const files = fs.readdirSync(dir); + + files.forEach(file => { + // Skip node_modules, tsp-output, and common non-lexicon directories + if (file === 'node_modules' || file === 'tsp-output' || file === 'dist' || file === '.git') { + return; + } + + const filePath = path.join(dir, file); + const stat = fs.statSync(filePath); + + if (stat.isDirectory()) { + findJsonFiles(filePath, fileList); + } else if (file.endsWith('.json') && !file.includes('package') && !file.includes('tsconfig')) { + fileList.push(filePath); + } + }); + + return fileList; +} + +function validateLexicons() { + const packagesDir = path.join(__dirname, '..', 'packages'); + const files = findJsonFiles(packagesDir); + + if (files.length === 0) { + console.log('No lexicon files found'); + return 0; + } + + let errorCount = 0; + let validCount = 0; + let skippedCount = 0; + const seenIds = new Set(); + + for (const filePath of files) { + const relPath = path.relative(path.join(__dirname, '..'), filePath); + + try { + const content = fs.readFileSync(filePath, 'utf-8'); + const json = JSON.parse(content); + + // Skip non-lexicon JSON files (e.g., package.json, tsconfig.json) + if (!json.lexicon || typeof json.lexicon !== 'number') { + continue; + } + + // Skip duplicates (same ID already seen) + if (json.id && seenIds.has(json.id)) { + skippedCount++; + continue; + } + + // Validate individually with a fresh Lexicons instance + // This avoids duplicate ID errors when validating independent lexicons + const lexicons = new Lexicons(); + lexicons.add(json); + + if (json.id) { + seenIds.add(json.id); + } + + validCount++; + console.log(`✓ ${relPath}`); + } catch (error) { + errorCount++; + console.error(`✗ ${relPath}: ${error.message}`); + } + } + + console.log(`\nValidated ${validCount} lexicons: ${validCount} valid, ${errorCount} errors${skippedCount > 0 ? `, ${skippedCount} duplicates skipped` : ''}`); + + return errorCount > 0 ? 1 : 0; +} + +try { + const exitCode = validateLexicons(); + process.exit(exitCode); +} catch (err) { + console.error('Fatal error:', err); + process.exit(1); +}