diff --git a/lexicons-generated/community/lexicon/calendar/rsvp/getRecord.json b/lexicons-generated/community/lexicon/calendar/rsvp/getRecord.json index 8e79377..a56272b 100644 --- a/lexicons-generated/community/lexicon/calendar/rsvp/getRecord.json +++ b/lexicons-generated/community/lexicon/calendar/rsvp/getRecord.json @@ -63,6 +63,10 @@ "time_us": { "type": "integer" }, + "event": { + "type": "ref", + "ref": "#refEventRecord" + }, "profiles": { "type": "array", "items": { @@ -74,6 +78,43 @@ } } }, + "refEventRecord": { + "type": "object", + "required": [ + "uri", + "did", + "collection", + "rkey", + "time_us" + ], + "properties": { + "uri": { + "type": "string", + "format": "at-uri" + }, + "did": { + "type": "string", + "format": "did" + }, + "collection": { + "type": "string", + "format": "nsid" + }, + "rkey": { + "type": "string" + }, + "cid": { + "type": "string" + }, + "record": { + "type": "ref", + "ref": "community.lexicon.calendar.event#main" + }, + "time_us": { + "type": "integer" + } + } + }, "profileEntry": { "type": "object", "required": [ diff --git a/lexicons-generated/community/lexicon/calendar/rsvp/listRecords.json b/lexicons-generated/community/lexicon/calendar/rsvp/listRecords.json index 45379dc..1c9efbb 100644 --- a/lexicons-generated/community/lexicon/calendar/rsvp/listRecords.json +++ b/lexicons-generated/community/lexicon/calendar/rsvp/listRecords.json @@ -117,6 +117,47 @@ "type": "ref", "ref": "community.lexicon.calendar.rsvp#main" }, + "time_us": { + "type": "integer" + }, + "event": { + "type": "ref", + "ref": "#refEventRecord" + } + } + }, + "refEventRecord": { + "type": "object", + "required": [ + "uri", + "did", + "collection", + "rkey", + "time_us" + ], + "properties": { + "uri": { + "type": "string", + "format": "at-uri" + }, + "did": { + "type": "string", + "format": "did" + }, + "collection": { + "type": "string", + "format": "nsid" + }, + "rkey": { + "type": "string" + }, + "cid": { + "type": "string" + }, + "record": { + "type": "ref", + "ref": "community.lexicon.calendar.event#main" + }, "time_us": { "type": "integer" } diff --git a/scripts/generate-lexicons.ts b/scripts/generate-lexicons.ts index ef84818..4414422 100644 --- a/scripts/generate-lexicons.ts +++ b/scripts/generate-lexicons.ts @@ -162,10 +162,16 @@ interface RelationDef { groups: Record; // shortName → full token } +interface ReferenceDef { + refName: string; + collection: string; +} + function buildRecordDef( collectionRef: string | null, countFields?: CountField[], - relationDefs?: RelationDef[] + relationDefs?: RelationDef[], + referenceDefs?: ReferenceDef[] ) { const properties: Record = { uri: { type: "string", format: "at-uri" }, @@ -202,6 +208,16 @@ function buildRecordDef( } } + if (referenceDefs && referenceDefs.length > 0) { + for (const rd of referenceDefs) { + const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1); + properties[rd.refName] = { + type: "ref", + ref: `#ref${capitalize(rd.refName)}Record`, + }; + } + } + return { type: "object", required: ["uri", "did", "collection", "rkey", "time_us"], @@ -209,6 +225,33 @@ function buildRecordDef( }; } +function buildReferenceDefs(referenceDefs: ReferenceDef[]): Record { + const defs: Record = {}; + const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1); + + for (const rd of referenceDefs) { + const refCollectionRef = getCollectionLexiconRef(rd.collection); + const recordDefName = `ref${capitalize(rd.refName)}Record`; + defs[recordDefName] = { + type: "object", + required: ["uri", "did", "collection", "rkey", "time_us"], + properties: { + uri: { type: "string", format: "at-uri" }, + did: { type: "string", format: "did" }, + collection: { type: "string", format: "nsid" }, + rkey: { type: "string" }, + cid: { type: "string" }, + record: refCollectionRef + ? { type: "ref", ref: refCollectionRef } + : { type: "unknown" }, + time_us: { type: "integer" }, + }, + }; + } + + return defs; +} + function buildHydrateDefs(relationDefs: RelationDef[]): Record { const defs: Record = {}; const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1); @@ -575,6 +618,12 @@ for (const [collection, colConfig] of Object.entries(config.collections)) { }); } + // Build reference defs + const referenceDefs: ReferenceDef[] = []; + for (const [refName, ref] of Object.entries(colConfig.references ?? {})) { + referenceDefs.push({ refName, collection: ref.collection }); + } + // Add per-reference hydrate params (e.g. hydrateEvent=true) for (const refName of Object.keys(colConfig.references ?? {})) { const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1); @@ -607,6 +656,7 @@ for (const [collection, colConfig] of Object.entries(config.collections)) { } const hydrateDefs = buildHydrateDefs(relationDefs); + const refDefs = buildReferenceDefs(referenceDefs); writeLexicon(`${collection}.listRecords`, { lexicon: 1, @@ -632,8 +682,9 @@ for (const [collection, colConfig] of Object.entries(config.collections)) { }, }, }, - record: buildRecordDef(collectionRef, countFields, relationDefs), + record: buildRecordDef(collectionRef, countFields, relationDefs, referenceDefs), ...hydrateDefs, + ...refDefs, ...profileDefs(), }, }); @@ -682,13 +733,14 @@ for (const [collection, colConfig] of Object.entries(config.collections)) { type: "object", required: ["uri", "did", "collection", "rkey", "time_us"], properties: { - ...buildRecordDef(collectionRef, countFields, relationDefs).properties, + ...buildRecordDef(collectionRef, countFields, relationDefs, referenceDefs).properties, profiles: { type: "array", items: { type: "ref", ref: "#profileEntry" } }, }, }, }, }, ...hydrateDefs, + ...refDefs, ...profileDefs(), }, });