@elytracms/studio 0.0.25 → 0.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/convex/cms.ts +49 -7
- package/convex/delivery.ts +14 -16
- package/convex/references.ts +38 -2
- package/convex/schema.ts +6 -1
- package/dist/components/assets/assets-store.js +41 -30
- package/dist/components/assets/assets-store.js.map +1 -1
- package/dist/components/auth-context.d.ts +4 -2
- package/dist/components/auth-context.js +19 -19
- package/dist/components/auth-context.js.map +1 -1
- package/dist/components/cms/cms-store.js +5 -4
- package/dist/components/cms/cms-store.js.map +1 -1
- package/dist/components/cms/collection-table.js +10 -3
- package/dist/components/cms/collection-table.js.map +1 -1
- package/dist/components/cms/detail-editor.js +36 -9
- package/dist/components/cms/detail-editor.js.map +1 -1
- package/dist/components/cms/field-control.d.ts +2 -1
- package/dist/components/cms/field-control.js +161 -73
- package/dist/components/cms/field-control.js.map +1 -1
- package/dist/components/cms/versions-pane.js +28 -16
- package/dist/components/cms/versions-pane.js.map +1 -1
- package/dist/components/project-session.d.ts +11 -0
- package/dist/components/project-session.js.map +1 -1
- package/dist/components/routes/routes-shell.js +22 -22
- package/dist/components/routes/routes-shell.js.map +1 -1
- package/dist/components/studio-context.js +5 -1
- package/dist/components/studio-context.js.map +1 -1
- package/dist/lib/cms/published-documents.d.ts +6 -6
- package/dist/lib/cms/published-documents.js +21 -58
- package/dist/lib/cms/published-documents.js.map +1 -1
- package/dist/lib/cms-views/view-model.d.ts +7 -3
- package/dist/lib/cms-views/view-model.js +11 -5
- package/dist/lib/cms-views/view-model.js.map +1 -1
- package/dist/lib/data/collection-content.js +7 -5
- package/dist/lib/data/collection-content.js.map +1 -1
- package/dist/lib/data/data-store.js +34 -24
- package/dist/lib/data/data-store.js.map +1 -1
- package/dist/lib/persistence/convex-adapter.js +22 -0
- package/dist/lib/persistence/convex-adapter.js.map +1 -1
- package/dist/lib/persistence/index.js +6 -2
- package/dist/lib/persistence/index.js.map +1 -1
- package/dist/lib/query/index.d.ts +6 -0
- package/dist/lib/query/index.js +6 -0
- package/dist/lib/query/index.js.map +1 -0
- package/dist/lib/query/operations-query.d.ts +85 -0
- package/dist/lib/query/operations-query.js +124 -0
- package/dist/lib/query/operations-query.js.map +1 -0
- package/dist/lib/references/reference-model.js +7 -1
- package/dist/lib/references/reference-model.js.map +1 -1
- package/dist/lib/references/references-store.d.ts +5 -10
- package/dist/lib/references/references-store.js +55 -77
- package/dist/lib/references/references-store.js.map +1 -1
- package/dist/ui/collapsible-section.d.ts +20 -0
- package/dist/ui/collapsible-section.js +18 -0
- package/dist/ui/collapsible-section.js.map +1 -0
- package/dist/ui/index.d.ts +1 -0
- package/dist/ui/index.js +1 -0
- package/dist/ui/index.js.map +1 -1
- package/package.json +3 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convex-adapter.js","sourceRoot":"","sources":["../../../src/lib/persistence/convex-adapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAEtE,OAAO,EACL,mBAAmB,EACnB,0BAA0B,EAC1B,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,6BAA6B,CAAA;AAgCpC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAIzD,MAAM,SAAS,GAAU,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;AAEvD,SAAS,KAAK,CAAC,MAAc;IAC3B,MAAM,IAAI,GACR,OAAO,UAAU,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU;QACjD,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE;QAChC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CA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CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;QAC7D,IAAI,CAAC,SAAS,GAAG,IAAI,wBAAwB,CAAC,MAAM,CAAC,CAAA;QACrD,IAAI,CAAC,KAAK,GAAG,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAA;IAC5C,CAAC;IAED,KAAK,CAAC,MAAM;QACV,IAAI,CAAC;YACH,+EAA+E;YAC/E,uEAAuE;YACvE,6EAA6E;YAC7E,0EAA0E;YAC1E,sCAAsC;YACtC,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC,CAAA;YACrD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,CAAA;QAC/C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YACrE,mEAAmE;YACnE,oEAAoE;YACpE,4EAA4E;YAC5E,4EAA4E;YAC5E,2EAA2E;YAC3E,IAAI,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC;gBAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,CAAA;YAC/E,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA;QACxD,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,KAA6B;QACpC,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAA;IACtC,CAAC;CACF","sourcesContent":["import type { ConvexHttpClient } from 'convex/browser'\nimport { documentKey, documentSchema } from '@elytracms/core/cms-core'\nimport type { CmsDocument, CollectionDef, DocumentRef } from '@elytracms/core/cms-core'\nimport {\n RecordNotFoundError,\n PersistenceValidationError,\n compareReferenceEntries,\n validateForPersistence,\n} from '@elytracms/core/persistence'\nimport type {\n AssetRecord,\n AssetRepository,\n BackendStatus,\n BackendValidationInput,\n BackendValidationResult,\n BlobStorageAdapter,\n CliTokenRecord,\n CliTokenRepository,\n CmsRepository,\n CmsSchemaRecord,\n CmsDocumentRecord,\n DocumentVersionRecord,\n SaveDocumentVersionOptions,\n MembersRepository,\n NewAssetInput,\n NewCliTokenInput,\n PersistenceAdapter,\n OutboundReference,\n ProjectMemberRecord,\n ProjectRole,\n ReferenceEntry,\n ReferenceEntryRecord,\n ReferenceIndexBuildMarker,\n ReferenceIndexRepository,\n ReferenceLookupOptions,\n ReferenceSource,\n ReferenceSourceType,\n ReferenceTarget,\n ReferenceVariant,\n} from '@elytracms/core/persistence'\nimport { queryRef, mutationRef } from './convex-client'\nimport { ConvexBlobStorage } from './convex-blob-storage'\n\n/** Wall-clock for runtime writes (deterministic seeds use a fixed clock instead). */\ntype Clock = () => string\nconst realClock: Clock = () => new Date().toISOString()\n\nfunction newId(prefix: string): string {\n const rand =\n typeof globalThis.crypto?.randomUUID === 'function'\n ? globalThis.crypto.randomUUID()\n : Math.abs(Date.parse(new Date().toISOString())).toString(36)\n return `${prefix}_${rand}`\n}\n\n// --- CMS, Assets ----------------------------------------------------------\n\n/**\n * Deterministic, config-owned schema timestamps (EC-183). CMS collections live\n * in `elytra.config.ts`, not the backend, so the synthesized `CmsSchemaRecord`\n * carries a stable placeholder rather than DB-row timestamps.\n */\nconst CONFIG_SCHEMA_TIMESTAMP = '2026-01-01T00:00:00.000Z'\n\ninterface DocumentDoc {\n projectId: string\n document: CmsDocument\n publishedVersion?: number\n createdAt: string\n updatedAt: string\n}\nfunction docRecordFromDoc(doc: DocumentDoc): CmsDocumentRecord {\n return {\n projectId: doc.projectId,\n document: doc.document,\n ...(doc.publishedVersion !== undefined ? { publishedVersion: doc.publishedVersion } : {}),\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n}\n\ninterface VersionDoc {\n collection: string\n docId: string\n version: number\n snapshot: CmsDocument\n label?: string\n createdAt: string\n}\n/** The backend row carries no `projectId` (single-tenant); stamp it from the call. */\nfunction versionRecordFromDoc(doc: VersionDoc, projectId: string): DocumentVersionRecord {\n return {\n projectId,\n collection: doc.collection,\n docId: doc.docId,\n version: doc.version,\n snapshot: doc.snapshot,\n createdAt: doc.createdAt,\n ...(doc.label ? { label: doc.label } : {}),\n }\n}\n\nclass ConvexCmsRepository implements CmsRepository {\n /**\n * @param collections the active project's config-owned CMS collections\n * (EC-183, AD-11), injected from `elytra.config.ts`. The Convex backend has\n * no `cmsSchemas` table — `findSchema`/`getSchema` serve these instead.\n */\n constructor(\n private readonly client: ConvexHttpClient,\n private readonly collections: readonly CollectionDef[] = [],\n private readonly clock: Clock = realClock,\n ) {}\n\n async saveSchema(\n _projectId: string,\n _collections: readonly CollectionDef[],\n ): Promise<CmsSchemaRecord> {\n // Read-only (EC-183, AD-11): the CMS collection schema is owned by\n // `elytra.config.ts`; the backend stores documents only. A write here is a\n // visible, structured error rather than a silent no-op (the studio's CMS\n // schema surfaces are read-only; legitimate writers were removed in EC-183).\n throw new PersistenceValidationError(\n 'CMS collection schema is owned by elytra.config.ts and cannot be written to the backend.',\n [\n {\n code: 'schema-config-owned',\n message:\n 'Edit elytra.config.ts to change collections; the backend stores documents only.',\n path: [],\n domain: 'cms',\n },\n ],\n )\n }\n\n /** Config-owned schema (EC-183): the active project's collections from config. */\n private configSchema(projectId: string): CmsSchemaRecord {\n return {\n projectId,\n collections: [...this.collections],\n createdAt: CONFIG_SCHEMA_TIMESTAMP,\n updatedAt: CONFIG_SCHEMA_TIMESTAMP,\n }\n }\n\n async getSchema(projectId: string): Promise<CmsSchemaRecord> {\n return this.configSchema(projectId)\n }\n\n async findSchema(projectId: string): Promise<CmsSchemaRecord | undefined> {\n return this.configSchema(projectId)\n }\n\n async upsertDocument(projectId: string, document: CmsDocument): Promise<CmsDocumentRecord> {\n // The backend is a pure document store (EC-183, AD-11): collection-membership\n // validation lives in `@elytracms/core/cms-core` `validateDocument`, which the studio\n // runs pre-dispatch (cell edits, imports). We still parse the canonical\n // document shape so malformed blobs never reach storage.\n const parsedDoc = documentSchema.parse(document)\n const now = this.clock()\n const doc = (await this.client.mutation(mutationRef('cms:upsertDocument'), {\n collection: parsedDoc.collection,\n docId: parsedDoc.id,\n document: parsedDoc,\n createdAt: now,\n updatedAt: now,\n })) as DocumentDoc\n return docRecordFromDoc(doc)\n }\n\n async getDocument(projectId: string, ref: DocumentRef): Promise<CmsDocumentRecord> {\n const found = await this.findDocument(projectId, ref)\n if (!found)\n throw new RecordNotFoundError('cms-document', `${projectId}/${ref.collection}:${ref.id}`)\n return found\n }\n\n async findDocument(projectId: string, ref: DocumentRef): Promise<CmsDocumentRecord | undefined> {\n const doc = (await this.client.query(queryRef('cms:getDocument'), {\n collection: ref.collection,\n docId: ref.id,\n })) as DocumentDoc | null\n return doc ? docRecordFromDoc(doc) : undefined\n }\n\n async listDocuments(projectId: string, collection?: string): Promise<CmsDocumentRecord[]> {\n const docs = (await this.client.query(queryRef('cms:listDocuments'), {\n ...(collection ? { collection } : {}),\n })) as DocumentDoc[]\n // EC-153 parity: deterministic document-key ordering (Convex index order\n // within a project is insertion order, so we sort client-side).\n return docs\n .map(docRecordFromDoc)\n .sort((a, b) => (documentKey(a.document) < documentKey(b.document) ? -1 : 1))\n }\n\n async deleteDocument(projectId: string, ref: DocumentRef): Promise<void> {\n // EC-153 parity: deleting a missing document is not-found, never a no-op.\n await this.getDocument(projectId, ref)\n await this.client.mutation(mutationRef('cms:deleteDocument'), {\n collection: ref.collection,\n docId: ref.id,\n })\n }\n\n async saveDocumentVersion(\n projectId: string,\n snapshot: CmsDocument,\n options: SaveDocumentVersionOptions = {},\n ): Promise<DocumentVersionRecord> {\n const parsed = documentSchema.parse(snapshot)\n const doc = (await this.client.mutation(mutationRef('cms:saveDocumentVersion'), {\n collection: parsed.collection,\n docId: parsed.id,\n snapshot: parsed,\n createdAt: this.clock(),\n ...(options.label ? { label: options.label } : {}),\n })) as VersionDoc\n return versionRecordFromDoc(doc, projectId)\n }\n\n async listDocumentVersions(\n projectId: string,\n ref: DocumentRef,\n ): Promise<DocumentVersionRecord[]> {\n const docs = (await this.client.query(queryRef('cms:listDocumentVersions'), {\n collection: ref.collection,\n docId: ref.id,\n })) as VersionDoc[]\n return docs.map((doc) => versionRecordFromDoc(doc, projectId))\n }\n\n async listAllDocumentVersions(projectId: string): Promise<DocumentVersionRecord[]> {\n const docs = (await this.client.query(\n queryRef('cms:listAllDocumentVersions'),\n {},\n )) as VersionDoc[]\n return docs.map((doc) => versionRecordFromDoc(doc, projectId))\n }\n\n async getDocumentVersion(\n projectId: string,\n ref: DocumentRef,\n version: number,\n ): Promise<DocumentVersionRecord> {\n const doc = (await this.client.query(queryRef('cms:getDocumentVersion'), {\n collection: ref.collection,\n docId: ref.id,\n version,\n })) as VersionDoc | null\n if (!doc) {\n throw new RecordNotFoundError(\n 'cms-document-version',\n `${projectId}/${ref.collection}:${ref.id}#${version}`,\n )\n }\n return versionRecordFromDoc(doc, projectId)\n }\n\n async publishDocumentVersion(\n projectId: string,\n ref: DocumentRef,\n version: number,\n ): Promise<CmsDocumentRecord> {\n // Taxonomy enforced adapter-side (the handler is lenient): the document and\n // the pinned version must both exist (each throws RecordNotFoundError).\n await this.getDocument(projectId, ref)\n await this.getDocumentVersion(projectId, ref, version)\n const doc = (await this.client.mutation(mutationRef('cms:publishDocumentVersion'), {\n collection: ref.collection,\n docId: ref.id,\n version,\n updatedAt: this.clock(),\n })) as DocumentDoc\n return docRecordFromDoc(doc)\n }\n\n async unpublishDocument(projectId: string, ref: DocumentRef): Promise<CmsDocumentRecord> {\n const existing = await this.getDocument(projectId, ref)\n if (existing.publishedVersion === undefined) {\n throw new PersistenceValidationError('Document is not currently published.', [\n {\n code: 'invalid-transition',\n message: 'Cannot unpublish: the document has no published version.',\n domain: 'cms',\n },\n ])\n }\n const doc = (await this.client.mutation(mutationRef('cms:unpublishDocument'), {\n collection: ref.collection,\n docId: ref.id,\n updatedAt: this.clock(),\n })) as DocumentDoc\n return docRecordFromDoc(doc)\n }\n}\n\ninterface AssetDoc {\n projectId: string\n assetId: string\n filename: string\n contentType: string\n byteSize: number\n width?: number\n height?: number\n alt?: string\n /** Editable display title (EC-152). */\n title?: string\n storageKey: string\n url?: string\n /** Normalized image focal point `{ x, y }` in 0–1 (EC-230). */\n focalPoint?: { x: number; y: number }\n /** Schema-driven asset metadata bag (EC-301). */\n meta?: Record<string, unknown>\n createdAt: string\n updatedAt: string\n}\n\n/** Map a Convex asset doc onto the contract record (assetId → id, drop _id/_creationTime). */\nfunction assetRecordFromDoc(doc: AssetDoc): AssetRecord {\n return {\n id: doc.assetId,\n projectId: doc.projectId,\n filename: doc.filename,\n contentType: doc.contentType,\n byteSize: doc.byteSize,\n ...(doc.width !== undefined ? { width: doc.width } : {}),\n ...(doc.height !== undefined ? { height: doc.height } : {}),\n ...(doc.alt !== undefined ? { alt: doc.alt } : {}),\n ...(doc.title !== undefined ? { title: doc.title } : {}),\n ...(doc.url !== undefined ? { url: doc.url } : {}),\n ...(doc.focalPoint !== undefined ? { focalPoint: doc.focalPoint } : {}),\n ...(doc.meta !== undefined ? { meta: doc.meta } : {}),\n storageKey: doc.storageKey,\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n}\n\nclass ConvexAssetRepository implements AssetRepository {\n constructor(\n private readonly client: ConvexHttpClient,\n private readonly clock: Clock = realClock,\n ) {}\n\n async upsertAsset(projectId: string, input: NewAssetInput): Promise<AssetRecord> {\n const now = this.clock()\n const id = input.id ?? newId('asset')\n const doc = (await this.client.mutation(mutationRef('assets:upsert'), {\n assetId: id,\n filename: input.filename,\n contentType: input.contentType,\n byteSize: input.byteSize,\n ...(input.width !== undefined ? { width: input.width } : {}),\n ...(input.height !== undefined ? { height: input.height } : {}),\n ...(input.alt !== undefined ? { alt: input.alt } : {}),\n // EC-153 parity: `title` (EC-152 metadata) must persist, not silently drop.\n ...(input.title !== undefined ? { title: input.title } : {}),\n ...(input.url !== undefined ? { url: input.url } : {}),\n ...(input.focalPoint !== undefined ? { focalPoint: input.focalPoint } : {}),\n ...(input.meta !== undefined ? { meta: input.meta } : {}),\n storageKey: input.storageKey ?? `${projectId}/${id}`,\n createdAt: now,\n updatedAt: now,\n })) as AssetDoc\n return assetRecordFromDoc(doc)\n }\n\n async getAsset(projectId: string, id: string): Promise<AssetRecord> {\n const found = await this.findAsset(projectId, id)\n if (!found) throw new RecordNotFoundError('asset', `${projectId}/${id}`)\n return found\n }\n\n async findAsset(projectId: string, id: string): Promise<AssetRecord | undefined> {\n const doc = (await this.client.query(queryRef('assets:get'), {\n assetId: id,\n })) as AssetDoc | null\n return doc ? assetRecordFromDoc(doc) : undefined\n }\n\n async listAssets(projectId: string): Promise<AssetRecord[]> {\n const docs = (await this.client.query(queryRef('assets:list'), {})) as AssetDoc[]\n return docs.map(assetRecordFromDoc)\n }\n\n async removeAsset(projectId: string, id: string): Promise<void> {\n // EC-153 parity: removing an unknown asset is not-found, never a no-op.\n await this.getAsset(projectId, id)\n await this.client.mutation(mutationRef('assets:remove'), { assetId: id })\n }\n\n async resolveMany(projectId: string, ids: readonly string[]): Promise<Map<string, AssetRecord>> {\n const all = await this.listAssets(projectId)\n const out = new Map<string, AssetRecord>()\n for (const asset of all) if (ids.includes(asset.id)) out.set(asset.id, asset)\n return out\n }\n}\n\n// --- Reference index (EC-155) ------------------------------------------------\n\n/** A Convex reference-entry doc (flattened source/target for index-backed lookups). */\ninterface ReferenceEntryDoc {\n projectId: string\n variant: ReferenceVariant\n sourceType: ReferenceSourceType\n sourceId: string\n path: string\n targetType: ReferenceTarget['type']\n targetId: string\n kind: ReferenceEntryRecord['kind']\n}\n\nfunction referenceRecordFromDoc(doc: ReferenceEntryDoc): ReferenceEntryRecord {\n return {\n projectId: doc.projectId,\n variant: doc.variant,\n source: { type: doc.sourceType, id: doc.sourceId },\n path: doc.path,\n target: { type: doc.targetType, id: doc.targetId },\n kind: doc.kind,\n }\n}\n\n/** Deterministic ordering is a repository contract; Convex docs sort client-side. */\nfunction sortedReferenceRecords(docs: ReferenceEntryDoc[]): ReferenceEntryRecord[] {\n return docs.map(referenceRecordFromDoc).sort(compareReferenceEntries)\n}\n\nclass ConvexReferenceIndexRepository implements ReferenceIndexRepository {\n constructor(private readonly client: ConvexHttpClient) {}\n\n async replaceForSource(\n projectId: string,\n variant: ReferenceVariant,\n source: ReferenceSource,\n references: readonly OutboundReference[],\n ): Promise<ReferenceEntryRecord[]> {\n await this.client.mutation(mutationRef('references:replaceForSource'), {\n variant,\n sourceType: source.type,\n sourceId: source.id,\n references: references.map((r) => ({\n path: r.path,\n targetType: r.target.type,\n targetId: r.target.id,\n kind: r.kind,\n })),\n })\n return this.outbound(projectId, source, { variant })\n }\n\n async replaceForSourceTypes(\n projectId: string,\n variant: ReferenceVariant,\n sourceTypes: readonly ReferenceSourceType[],\n entries: readonly ReferenceEntry[],\n ): Promise<ReferenceEntryRecord[]> {\n await this.client.mutation(mutationRef('references:replaceForSourceTypes'), {\n variant,\n sourceTypes: [...sourceTypes],\n entries: entries.map((e) => ({\n sourceType: e.source.type,\n sourceId: e.source.id,\n path: e.path,\n targetType: e.target.type,\n targetId: e.target.id,\n kind: e.kind,\n })),\n })\n const all = await this.listEntries(projectId, variant)\n const types = new Set(sourceTypes)\n return all.filter((record) => types.has(record.source.type))\n }\n\n async removeForSource(\n projectId: string,\n source: ReferenceSource,\n variant?: ReferenceVariant,\n ): Promise<void> {\n await this.client.mutation(mutationRef('references:removeForSource'), {\n sourceType: source.type,\n sourceId: source.id,\n ...(variant ? { variant } : {}),\n })\n }\n\n async outbound(\n projectId: string,\n source: ReferenceSource,\n options: ReferenceLookupOptions = {},\n ): Promise<ReferenceEntryRecord[]> {\n const docs = (await this.client.query(queryRef('references:outbound'), {\n sourceType: source.type,\n sourceId: source.id,\n ...(options.variant ? { variant: options.variant } : {}),\n })) as ReferenceEntryDoc[]\n return sortedReferenceRecords(docs)\n }\n\n async inbound(\n projectId: string,\n target: ReferenceTarget,\n options: ReferenceLookupOptions = {},\n ): Promise<ReferenceEntryRecord[]> {\n const docs = (await this.client.query(queryRef('references:inbound'), {\n targetType: target.type,\n targetId: target.id,\n ...(options.variant ? { variant: options.variant } : {}),\n })) as ReferenceEntryDoc[]\n return sortedReferenceRecords(docs)\n }\n\n async listEntries(\n projectId: string,\n variant?: ReferenceVariant,\n ): Promise<ReferenceEntryRecord[]> {\n const docs = (await this.client.query(queryRef('references:list'), {\n ...(variant ? { variant } : {}),\n })) as ReferenceEntryDoc[]\n return sortedReferenceRecords(docs)\n }\n\n async getBuildMarker(projectId: string): Promise<ReferenceIndexBuildMarker | null> {\n return (await this.client.query(queryRef('references:buildMarker'), {})) as\n | ReferenceIndexBuildMarker\n | null\n }\n\n async setBuildMarker(projectId: string, marker: ReferenceIndexBuildMarker): Promise<void> {\n await this.client.mutation(mutationRef('references:setBuildMarker'), {\n entryCount: marker.entryCount,\n })\n }\n\n async clearProject(projectId: string): Promise<void> {\n await this.client.mutation(mutationRef('references:clearProject'), {})\n }\n}\n\n// --- Members + CLI tokens (EC-150) -------------------------------------------\n\ninterface MemberDoc {\n userId: string\n role: ProjectRole\n createdAt: string\n updatedAt: string\n}\n\n/**\n * Single-tenant (EC-179): membership is deployment-scoped, so the backend rows\n * carry no `projectId`. The contract record still does — this adapter is bound\n * to its deployment's project, so it stamps that slug onto every record.\n */\nfunction memberRecordFromDoc(doc: MemberDoc, projectId: string): ProjectMemberRecord {\n return {\n projectId,\n userId: doc.userId,\n role: doc.role,\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n}\n\nclass ConvexMembersRepository implements MembersRepository {\n constructor(\n private readonly client: ConvexHttpClient,\n /** The slug of this deployment's one project — stamped onto records. */\n private readonly boundProjectId: string,\n private readonly clock: Clock = realClock,\n ) {}\n\n async setMember(\n projectId: string,\n userId: string,\n role: ProjectRole,\n ): Promise<ProjectMemberRecord> {\n const now = this.clock()\n const doc = (await this.client.mutation(mutationRef('members:set'), {\n userId,\n role,\n createdAt: now,\n updatedAt: now,\n })) as MemberDoc\n return memberRecordFromDoc(doc, projectId)\n }\n\n async findMember(projectId: string, userId: string): Promise<ProjectMemberRecord | undefined> {\n const doc = (await this.client.query(queryRef('members:get'), {\n userId,\n })) as MemberDoc | null\n return doc ? memberRecordFromDoc(doc, projectId) : undefined\n }\n\n async listMembers(projectId: string): Promise<ProjectMemberRecord[]> {\n const docs = (await this.client.query(queryRef('members:list'), {})) as MemberDoc[]\n return docs.map((d) => memberRecordFromDoc(d, projectId))\n }\n\n async listMembershipsForUser(userId: string): Promise<ProjectMemberRecord[]> {\n // `members:mine` is caller-scoped server-side and returns the caller's single\n // deployment membership (or null). The studio only ever asks about the\n // session user; records are stamped with this deployment's bound project.\n const doc = (await this.client.query(queryRef('members:mine'), {})) as MemberDoc | null\n return doc && doc.userId === userId ? [memberRecordFromDoc(doc, this.boundProjectId)] : []\n }\n\n async removeMember(projectId: string, userId: string): Promise<void> {\n try {\n await this.client.mutation(mutationRef('members:remove'), { userId })\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n if (/not-found/i.test(message)) {\n throw new RecordNotFoundError('project-member', `${projectId}/${userId}`)\n }\n throw error\n }\n }\n}\n\ninterface CliTokenDoc {\n /** Retired (EC-182): optional only because live rows may still carry it until the migration clears it. */\n projectId?: string\n tokenId: string\n label: string\n tokenHash: string\n createdAt: string\n revokedAt?: string\n}\n\nfunction cliTokenRecordFromDoc(doc: CliTokenDoc): CliTokenRecord {\n return {\n id: doc.tokenId,\n label: doc.label,\n tokenHash: doc.tokenHash,\n createdAt: doc.createdAt,\n ...(doc.revokedAt ? { revokedAt: doc.revokedAt } : {}),\n }\n}\n\nclass ConvexCliTokenRepository implements CliTokenRepository {\n constructor(\n private readonly client: ConvexHttpClient,\n private readonly clock: Clock = realClock,\n ) {}\n\n async createToken(input: NewCliTokenInput): Promise<CliTokenRecord> {\n const doc = (await this.client.mutation(mutationRef('cliTokens:create'), {\n tokenId: newId('tok'),\n label: input.label,\n tokenHash: input.tokenHash,\n createdAt: this.clock(),\n })) as CliTokenDoc\n return cliTokenRecordFromDoc(doc)\n }\n\n async listTokens(): Promise<CliTokenRecord[]> {\n const docs = (await this.client.query(queryRef('cliTokens:list'), {})) as CliTokenDoc[]\n return docs.map(cliTokenRecordFromDoc)\n }\n\n async revokeToken(tokenId: string): Promise<CliTokenRecord> {\n try {\n const doc = (await this.client.mutation(mutationRef('cliTokens:revoke'), {\n tokenId,\n revokedAt: this.clock(),\n })) as CliTokenDoc\n return cliTokenRecordFromDoc(doc)\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n if (/not-found/i.test(message)) {\n throw new RecordNotFoundError('cli-token', tokenId)\n }\n throw error\n }\n }\n\n async findByHash(tokenHash: string): Promise<CliTokenRecord | undefined> {\n const doc = (await this.client.query(queryRef('cliTokens:byHash'), {\n tokenHash,\n })) as CliTokenDoc | null\n return doc ? cliTokenRecordFromDoc(doc) : undefined\n }\n}\n\n/**\n * Convex-backed {@link PersistenceAdapter} (brief §10, EC-039). Every repository\n * is implemented against the Convex functions in `apps/builder/convex/*`, mapping\n * results and failures onto the provider-neutral contracts + error taxonomies.\n */\nexport class ConvexPersistenceAdapter implements PersistenceAdapter {\n readonly cms: CmsRepository\n readonly assets: AssetRepository\n /** Reference index — outbound/inbound entries per variant (EC-155, AD-6). */\n readonly references: ReferenceIndexRepository\n /** Per-project membership roles (EC-150). */\n readonly members: MembersRepository\n /** Revocable CLI sync tokens, stored hashed (EC-150). */\n readonly cliTokens: CliTokenRepository\n /** Convex file storage behind the EC-133 blob boundary (EC-151). */\n readonly blobs: BlobStorageAdapter\n /**\n * EC-277: the Convex mutations maintain the reference index in-transaction\n * (`convex/referenceMaintenance.ts`), so every writer — studio, CLI, webhook,\n * raw `convex run` — is caught at the source. The studio bootstrap therefore does\n * NOT attach the client-side `attachReferenceIndex` subscriber for this provider.\n */\n readonly maintainsReferenceIndex = true\n\n /**\n * @param client the Convex client bound to this deployment (one project).\n * @param projectId the slug of this deployment's one project (EC-179). Used to\n * stamp deployment-scoped member records onto the still-project-keyed contract.\n * @param collections the active project's config-owned CMS collections (EC-183,\n * AD-11), from `elytra.config.ts`. The backend has no `cmsSchemas` table, so\n * the CMS repository serves the schema from these.\n */\n constructor(\n private readonly client: ConvexHttpClient,\n projectId: string,\n collections: readonly CollectionDef[] = [],\n ) {\n this.cms = new ConvexCmsRepository(client, collections)\n this.assets = new ConvexAssetRepository(client)\n this.references = new ConvexReferenceIndexRepository(client)\n this.members = new ConvexMembersRepository(client, projectId)\n this.cliTokens = new ConvexCliTokenRepository(client)\n this.blobs = new ConvexBlobStorage(client)\n }\n\n async status(): Promise<BackendStatus> {\n try {\n // Lightweight connectivity probe (EC-182: no `projects` table). `members:mine`\n // takes no args and is soft-guarded (EC-279): it answers `null` for an\n // unauthenticated caller rather than throwing, so the pre-sign-in boot probe\n // resolves cleanly — backend answered ⇒ `available: true` — with no scary\n // `Uncaught Error` in the Convex log.\n await this.client.query(queryRef('members:mine'), {})\n return { backend: 'convex', available: true }\n } catch (error) {\n const detail = error instanceof Error ? error.message : String(error)\n // EC-153: an `unauthorized` rejection *is* a healthy backend — the\n // deployment answered and enforced auth. Now that `members:mine` is\n // soft-guarded this branch is a defensive fallback (a protected probe could\n // still throw); only transport/server failures count as unavailable, so the\n // BackendGate surfaces those visibly instead of falling back to in-memory.\n if (/unauthorized/i.test(detail)) return { backend: 'convex', available: true }\n return { backend: 'convex', available: false, detail }\n }\n }\n\n validate(input: BackendValidationInput): BackendValidationResult {\n return validateForPersistence(input)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"convex-adapter.js","sourceRoot":"","sources":["../../../src/lib/persistence/convex-adapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAEtE,OAAO,EACL,mBAAmB,EACnB,0BAA0B,EAC1B,uBAAuB,EACvB,sBAAsB,GACvB,MA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CAAC,CAAA;YACrE,mEAAmE;YACnE,oEAAoE;YACpE,4EAA4E;YAC5E,4EAA4E;YAC5E,2EAA2E;YAC3E,IAAI,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC;gBAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,CAAA;YAC/E,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA;QACxD,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,KAA6B;QACpC,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAA;IACtC,CAAC;CACF","sourcesContent":["import type { ConvexHttpClient } from 'convex/browser'\nimport { documentKey, documentSchema } from '@elytracms/core/cms-core'\nimport type { CmsDocument, CollectionDef, DocumentRef } from '@elytracms/core/cms-core'\nimport {\n RecordNotFoundError,\n PersistenceValidationError,\n compareReferenceEntries,\n validateForPersistence,\n} from '@elytracms/core/persistence'\nimport type {\n AssetRecord,\n AssetRepository,\n BackendStatus,\n BackendValidationInput,\n BackendValidationResult,\n BlobStorageAdapter,\n CliTokenRecord,\n CliTokenRepository,\n CmsRepository,\n CmsSchemaRecord,\n CmsDocumentRecord,\n DocumentVersionRecord,\n SaveDocumentVersionOptions,\n MembersRepository,\n NewAssetInput,\n NewCliTokenInput,\n PersistenceAdapter,\n OutboundReference,\n ProjectMemberRecord,\n ProjectRole,\n ReferenceEntry,\n ReferenceEntryRecord,\n ReferenceIndexBuildMarker,\n ReferenceIndexRepository,\n ReferenceLookupOptions,\n ReferenceSource,\n ReferenceSourceType,\n ReferenceTarget,\n ReferenceVariant,\n} from '@elytracms/core/persistence'\nimport { queryRef, mutationRef } from './convex-client'\nimport { ConvexBlobStorage } from './convex-blob-storage'\n\n/** Wall-clock for runtime writes (deterministic seeds use a fixed clock instead). */\ntype Clock = () => string\nconst realClock: Clock = () => new Date().toISOString()\n\nfunction newId(prefix: string): string {\n const rand =\n typeof globalThis.crypto?.randomUUID === 'function'\n ? globalThis.crypto.randomUUID()\n : Math.abs(Date.parse(new Date().toISOString())).toString(36)\n return `${prefix}_${rand}`\n}\n\n// --- CMS, Assets ----------------------------------------------------------\n\n/**\n * Deterministic, config-owned schema timestamps (EC-183). CMS collections live\n * in `elytra.config.ts`, not the backend, so the synthesized `CmsSchemaRecord`\n * carries a stable placeholder rather than DB-row timestamps.\n */\nconst CONFIG_SCHEMA_TIMESTAMP = '2026-01-01T00:00:00.000Z'\n\ninterface DocumentDoc {\n projectId: string\n document: CmsDocument\n publishedVersion?: number\n createdAt: string\n updatedAt: string\n}\nfunction docRecordFromDoc(doc: DocumentDoc): CmsDocumentRecord {\n return {\n projectId: doc.projectId,\n document: doc.document,\n ...(doc.publishedVersion !== undefined ? { publishedVersion: doc.publishedVersion } : {}),\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n}\n\ninterface VersionDoc {\n collection: string\n docId: string\n version: number\n snapshot: CmsDocument\n label?: string\n createdAt: string\n}\n/** The backend row carries no `projectId` (single-tenant); stamp it from the call. */\nfunction versionRecordFromDoc(doc: VersionDoc, projectId: string): DocumentVersionRecord {\n return {\n projectId,\n collection: doc.collection,\n docId: doc.docId,\n version: doc.version,\n snapshot: doc.snapshot,\n createdAt: doc.createdAt,\n ...(doc.label ? { label: doc.label } : {}),\n }\n}\n\nclass ConvexCmsRepository implements CmsRepository {\n /**\n * @param collections the active project's config-owned CMS collections\n * (EC-183, AD-11), injected from `elytra.config.ts`. The Convex backend has\n * no `cmsSchemas` table — `findSchema`/`getSchema` serve these instead.\n */\n constructor(\n private readonly client: ConvexHttpClient,\n private readonly collections: readonly CollectionDef[] = [],\n private readonly clock: Clock = realClock,\n ) {}\n\n async saveSchema(\n _projectId: string,\n _collections: readonly CollectionDef[],\n ): Promise<CmsSchemaRecord> {\n // Read-only (EC-183, AD-11): the CMS collection schema is owned by\n // `elytra.config.ts`; the backend stores documents only. A write here is a\n // visible, structured error rather than a silent no-op (the studio's CMS\n // schema surfaces are read-only; legitimate writers were removed in EC-183).\n throw new PersistenceValidationError(\n 'CMS collection schema is owned by elytra.config.ts and cannot be written to the backend.',\n [\n {\n code: 'schema-config-owned',\n message:\n 'Edit elytra.config.ts to change collections; the backend stores documents only.',\n path: [],\n domain: 'cms',\n },\n ],\n )\n }\n\n /** Config-owned schema (EC-183): the active project's collections from config. */\n private configSchema(projectId: string): CmsSchemaRecord {\n return {\n projectId,\n collections: [...this.collections],\n createdAt: CONFIG_SCHEMA_TIMESTAMP,\n updatedAt: CONFIG_SCHEMA_TIMESTAMP,\n }\n }\n\n async getSchema(projectId: string): Promise<CmsSchemaRecord> {\n return this.configSchema(projectId)\n }\n\n async findSchema(projectId: string): Promise<CmsSchemaRecord | undefined> {\n return this.configSchema(projectId)\n }\n\n async upsertDocument(projectId: string, document: CmsDocument): Promise<CmsDocumentRecord> {\n // The backend is a pure document store (EC-183, AD-11): collection-membership\n // validation lives in `@elytracms/core/cms-core` `validateDocument`, which the studio\n // runs pre-dispatch (cell edits, imports). We still parse the canonical\n // document shape so malformed blobs never reach storage.\n const parsedDoc = documentSchema.parse(document)\n const now = this.clock()\n const doc = (await this.client.mutation(mutationRef('cms:upsertDocument'), {\n collection: parsedDoc.collection,\n docId: parsedDoc.id,\n document: parsedDoc,\n createdAt: now,\n updatedAt: now,\n })) as DocumentDoc\n return docRecordFromDoc(doc)\n }\n\n async getDocument(projectId: string, ref: DocumentRef): Promise<CmsDocumentRecord> {\n const found = await this.findDocument(projectId, ref)\n if (!found)\n throw new RecordNotFoundError('cms-document', `${projectId}/${ref.collection}:${ref.id}`)\n return found\n }\n\n async findDocument(projectId: string, ref: DocumentRef): Promise<CmsDocumentRecord | undefined> {\n const doc = (await this.client.query(queryRef('cms:getDocument'), {\n collection: ref.collection,\n docId: ref.id,\n })) as DocumentDoc | null\n return doc ? docRecordFromDoc(doc) : undefined\n }\n\n async listDocuments(projectId: string, collection?: string): Promise<CmsDocumentRecord[]> {\n const docs = (await this.client.query(queryRef('cms:listDocuments'), {\n ...(collection ? { collection } : {}),\n })) as DocumentDoc[]\n // EC-153 parity: deterministic document-key ordering (Convex index order\n // within a project is insertion order, so we sort client-side).\n return docs\n .map(docRecordFromDoc)\n .sort((a, b) => (documentKey(a.document) < documentKey(b.document) ? -1 : 1))\n }\n\n async listPublishedDocuments(projectId: string, collection?: string): Promise<CmsDocument[]> {\n // EC-307: one bulk read for the published pool (collapses the per-document\n // `listVersions` fan-out). The handler resolves each pin to its snapshot.\n const snapshots = (await this.client.query(queryRef('cms:listPublishedDocuments'), {\n ...(collection ? { collection } : {}),\n })) as CmsDocument[]\n // Deterministic document-key order (parity with the in-memory adapter).\n return snapshots\n .map((doc) => documentSchema.parse(doc))\n .sort((a, b) => (documentKey(a) < documentKey(b) ? -1 : 1))\n }\n\n async deleteDocument(projectId: string, ref: DocumentRef): Promise<void> {\n // EC-153 parity: deleting a missing document is not-found, never a no-op.\n await this.getDocument(projectId, ref)\n await this.client.mutation(mutationRef('cms:deleteDocument'), {\n collection: ref.collection,\n docId: ref.id,\n })\n }\n\n async saveDocumentVersion(\n projectId: string,\n snapshot: CmsDocument,\n options: SaveDocumentVersionOptions = {},\n ): Promise<DocumentVersionRecord> {\n const parsed = documentSchema.parse(snapshot)\n const doc = (await this.client.mutation(mutationRef('cms:saveDocumentVersion'), {\n collection: parsed.collection,\n docId: parsed.id,\n snapshot: parsed,\n createdAt: this.clock(),\n ...(options.label ? { label: options.label } : {}),\n })) as VersionDoc\n return versionRecordFromDoc(doc, projectId)\n }\n\n async listDocumentVersions(\n projectId: string,\n ref: DocumentRef,\n ): Promise<DocumentVersionRecord[]> {\n const docs = (await this.client.query(queryRef('cms:listDocumentVersions'), {\n collection: ref.collection,\n docId: ref.id,\n })) as VersionDoc[]\n return docs.map((doc) => versionRecordFromDoc(doc, projectId))\n }\n\n async listAllDocumentVersions(projectId: string): Promise<DocumentVersionRecord[]> {\n const docs = (await this.client.query(\n queryRef('cms:listAllDocumentVersions'),\n {},\n )) as VersionDoc[]\n return docs.map((doc) => versionRecordFromDoc(doc, projectId))\n }\n\n async getDocumentVersion(\n projectId: string,\n ref: DocumentRef,\n version: number,\n ): Promise<DocumentVersionRecord> {\n const doc = (await this.client.query(queryRef('cms:getDocumentVersion'), {\n collection: ref.collection,\n docId: ref.id,\n version,\n })) as VersionDoc | null\n if (!doc) {\n throw new RecordNotFoundError(\n 'cms-document-version',\n `${projectId}/${ref.collection}:${ref.id}#${version}`,\n )\n }\n return versionRecordFromDoc(doc, projectId)\n }\n\n async publishDocumentVersion(\n projectId: string,\n ref: DocumentRef,\n version: number,\n ): Promise<CmsDocumentRecord> {\n // Taxonomy enforced adapter-side (the handler is lenient): the document and\n // the pinned version must both exist (each throws RecordNotFoundError).\n await this.getDocument(projectId, ref)\n await this.getDocumentVersion(projectId, ref, version)\n const doc = (await this.client.mutation(mutationRef('cms:publishDocumentVersion'), {\n collection: ref.collection,\n docId: ref.id,\n version,\n updatedAt: this.clock(),\n })) as DocumentDoc\n return docRecordFromDoc(doc)\n }\n\n async unpublishDocument(projectId: string, ref: DocumentRef): Promise<CmsDocumentRecord> {\n const existing = await this.getDocument(projectId, ref)\n if (existing.publishedVersion === undefined) {\n throw new PersistenceValidationError('Document is not currently published.', [\n {\n code: 'invalid-transition',\n message: 'Cannot unpublish: the document has no published version.',\n domain: 'cms',\n },\n ])\n }\n const doc = (await this.client.mutation(mutationRef('cms:unpublishDocument'), {\n collection: ref.collection,\n docId: ref.id,\n updatedAt: this.clock(),\n })) as DocumentDoc\n return docRecordFromDoc(doc)\n }\n}\n\ninterface AssetDoc {\n projectId: string\n assetId: string\n filename: string\n contentType: string\n byteSize: number\n width?: number\n height?: number\n alt?: string\n /** Editable display title (EC-152). */\n title?: string\n storageKey: string\n url?: string\n /** Normalized image focal point `{ x, y }` in 0–1 (EC-230). */\n focalPoint?: { x: number; y: number }\n /** Schema-driven asset metadata bag (EC-301). */\n meta?: Record<string, unknown>\n createdAt: string\n updatedAt: string\n}\n\n/** Map a Convex asset doc onto the contract record (assetId → id, drop _id/_creationTime). */\nfunction assetRecordFromDoc(doc: AssetDoc): AssetRecord {\n return {\n id: doc.assetId,\n projectId: doc.projectId,\n filename: doc.filename,\n contentType: doc.contentType,\n byteSize: doc.byteSize,\n ...(doc.width !== undefined ? { width: doc.width } : {}),\n ...(doc.height !== undefined ? { height: doc.height } : {}),\n ...(doc.alt !== undefined ? { alt: doc.alt } : {}),\n ...(doc.title !== undefined ? { title: doc.title } : {}),\n ...(doc.url !== undefined ? { url: doc.url } : {}),\n ...(doc.focalPoint !== undefined ? { focalPoint: doc.focalPoint } : {}),\n ...(doc.meta !== undefined ? { meta: doc.meta } : {}),\n storageKey: doc.storageKey,\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n}\n\nclass ConvexAssetRepository implements AssetRepository {\n constructor(\n private readonly client: ConvexHttpClient,\n private readonly clock: Clock = realClock,\n ) {}\n\n async upsertAsset(projectId: string, input: NewAssetInput): Promise<AssetRecord> {\n const now = this.clock()\n const id = input.id ?? newId('asset')\n const doc = (await this.client.mutation(mutationRef('assets:upsert'), {\n assetId: id,\n filename: input.filename,\n contentType: input.contentType,\n byteSize: input.byteSize,\n ...(input.width !== undefined ? { width: input.width } : {}),\n ...(input.height !== undefined ? { height: input.height } : {}),\n ...(input.alt !== undefined ? { alt: input.alt } : {}),\n // EC-153 parity: `title` (EC-152 metadata) must persist, not silently drop.\n ...(input.title !== undefined ? { title: input.title } : {}),\n ...(input.url !== undefined ? { url: input.url } : {}),\n ...(input.focalPoint !== undefined ? { focalPoint: input.focalPoint } : {}),\n ...(input.meta !== undefined ? { meta: input.meta } : {}),\n storageKey: input.storageKey ?? `${projectId}/${id}`,\n createdAt: now,\n updatedAt: now,\n })) as AssetDoc\n return assetRecordFromDoc(doc)\n }\n\n async getAsset(projectId: string, id: string): Promise<AssetRecord> {\n const found = await this.findAsset(projectId, id)\n if (!found) throw new RecordNotFoundError('asset', `${projectId}/${id}`)\n return found\n }\n\n async findAsset(projectId: string, id: string): Promise<AssetRecord | undefined> {\n const doc = (await this.client.query(queryRef('assets:get'), {\n assetId: id,\n })) as AssetDoc | null\n return doc ? assetRecordFromDoc(doc) : undefined\n }\n\n async listAssets(projectId: string): Promise<AssetRecord[]> {\n const docs = (await this.client.query(queryRef('assets:list'), {})) as AssetDoc[]\n return docs.map(assetRecordFromDoc)\n }\n\n async removeAsset(projectId: string, id: string): Promise<void> {\n // EC-153 parity: removing an unknown asset is not-found, never a no-op.\n await this.getAsset(projectId, id)\n await this.client.mutation(mutationRef('assets:remove'), { assetId: id })\n }\n\n async resolveMany(projectId: string, ids: readonly string[]): Promise<Map<string, AssetRecord>> {\n const all = await this.listAssets(projectId)\n const out = new Map<string, AssetRecord>()\n for (const asset of all) if (ids.includes(asset.id)) out.set(asset.id, asset)\n return out\n }\n}\n\n// --- Reference index (EC-155) ------------------------------------------------\n\n/** A Convex reference-entry doc (flattened source/target for index-backed lookups). */\ninterface ReferenceEntryDoc {\n projectId: string\n variant: ReferenceVariant\n sourceType: ReferenceSourceType\n sourceId: string\n path: string\n targetType: ReferenceTarget['type']\n targetId: string\n kind: ReferenceEntryRecord['kind']\n}\n\nfunction referenceRecordFromDoc(doc: ReferenceEntryDoc): ReferenceEntryRecord {\n return {\n projectId: doc.projectId,\n variant: doc.variant,\n source: { type: doc.sourceType, id: doc.sourceId },\n path: doc.path,\n target: { type: doc.targetType, id: doc.targetId },\n kind: doc.kind,\n }\n}\n\n/** Deterministic ordering is a repository contract; Convex docs sort client-side. */\nfunction sortedReferenceRecords(docs: ReferenceEntryDoc[]): ReferenceEntryRecord[] {\n return docs.map(referenceRecordFromDoc).sort(compareReferenceEntries)\n}\n\nclass ConvexReferenceIndexRepository implements ReferenceIndexRepository {\n constructor(private readonly client: ConvexHttpClient) {}\n\n async replaceForSource(\n projectId: string,\n variant: ReferenceVariant,\n source: ReferenceSource,\n references: readonly OutboundReference[],\n ): Promise<ReferenceEntryRecord[]> {\n await this.client.mutation(mutationRef('references:replaceForSource'), {\n variant,\n sourceType: source.type,\n sourceId: source.id,\n references: references.map((r) => ({\n path: r.path,\n targetType: r.target.type,\n targetId: r.target.id,\n kind: r.kind,\n })),\n })\n return this.outbound(projectId, source, { variant })\n }\n\n async replaceForSourceTypes(\n projectId: string,\n variant: ReferenceVariant,\n sourceTypes: readonly ReferenceSourceType[],\n entries: readonly ReferenceEntry[],\n ): Promise<ReferenceEntryRecord[]> {\n await this.client.mutation(mutationRef('references:replaceForSourceTypes'), {\n variant,\n sourceTypes: [...sourceTypes],\n entries: entries.map((e) => ({\n sourceType: e.source.type,\n sourceId: e.source.id,\n path: e.path,\n targetType: e.target.type,\n targetId: e.target.id,\n kind: e.kind,\n })),\n })\n const all = await this.listEntries(projectId, variant)\n const types = new Set(sourceTypes)\n return all.filter((record) => types.has(record.source.type))\n }\n\n async removeForSource(\n projectId: string,\n source: ReferenceSource,\n variant?: ReferenceVariant,\n ): Promise<void> {\n await this.client.mutation(mutationRef('references:removeForSource'), {\n sourceType: source.type,\n sourceId: source.id,\n ...(variant ? { variant } : {}),\n })\n }\n\n async outbound(\n projectId: string,\n source: ReferenceSource,\n options: ReferenceLookupOptions = {},\n ): Promise<ReferenceEntryRecord[]> {\n const docs = (await this.client.query(queryRef('references:outbound'), {\n sourceType: source.type,\n sourceId: source.id,\n ...(options.variant ? { variant: options.variant } : {}),\n })) as ReferenceEntryDoc[]\n return sortedReferenceRecords(docs)\n }\n\n async inbound(\n projectId: string,\n target: ReferenceTarget,\n options: ReferenceLookupOptions = {},\n ): Promise<ReferenceEntryRecord[]> {\n const docs = (await this.client.query(queryRef('references:inbound'), {\n targetType: target.type,\n targetId: target.id,\n ...(options.variant ? { variant: options.variant } : {}),\n })) as ReferenceEntryDoc[]\n return sortedReferenceRecords(docs)\n }\n\n async inboundMany(\n projectId: string,\n targets: readonly ReferenceTarget[],\n options: ReferenceLookupOptions = {},\n ): Promise<ReferenceEntryRecord[][]> {\n // EC-308: one round-trip for all targets (the handler loops the by_target\n // index server-side), replacing the client's per-target inbound fan-out.\n if (targets.length === 0) return []\n const groups = (await this.client.query(queryRef('references:inboundMany'), {\n targets: targets.map((target) => ({ targetType: target.type, targetId: target.id })),\n ...(options.variant ? { variant: options.variant } : {}),\n })) as ReferenceEntryDoc[][]\n return groups.map((docs) => sortedReferenceRecords(docs))\n }\n\n async listEntries(\n projectId: string,\n variant?: ReferenceVariant,\n ): Promise<ReferenceEntryRecord[]> {\n const docs = (await this.client.query(queryRef('references:list'), {\n ...(variant ? { variant } : {}),\n })) as ReferenceEntryDoc[]\n return sortedReferenceRecords(docs)\n }\n\n async getBuildMarker(projectId: string): Promise<ReferenceIndexBuildMarker | null> {\n return (await this.client.query(queryRef('references:buildMarker'), {})) as\n | ReferenceIndexBuildMarker\n | null\n }\n\n async setBuildMarker(projectId: string, marker: ReferenceIndexBuildMarker): Promise<void> {\n await this.client.mutation(mutationRef('references:setBuildMarker'), {\n entryCount: marker.entryCount,\n })\n }\n\n async clearProject(projectId: string): Promise<void> {\n await this.client.mutation(mutationRef('references:clearProject'), {})\n }\n}\n\n// --- Members + CLI tokens (EC-150) -------------------------------------------\n\ninterface MemberDoc {\n userId: string\n role: ProjectRole\n createdAt: string\n updatedAt: string\n}\n\n/**\n * Single-tenant (EC-179): membership is deployment-scoped, so the backend rows\n * carry no `projectId`. The contract record still does — this adapter is bound\n * to its deployment's project, so it stamps that slug onto every record.\n */\nfunction memberRecordFromDoc(doc: MemberDoc, projectId: string): ProjectMemberRecord {\n return {\n projectId,\n userId: doc.userId,\n role: doc.role,\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n}\n\nclass ConvexMembersRepository implements MembersRepository {\n constructor(\n private readonly client: ConvexHttpClient,\n /** The slug of this deployment's one project — stamped onto records. */\n private readonly boundProjectId: string,\n private readonly clock: Clock = realClock,\n ) {}\n\n async setMember(\n projectId: string,\n userId: string,\n role: ProjectRole,\n ): Promise<ProjectMemberRecord> {\n const now = this.clock()\n const doc = (await this.client.mutation(mutationRef('members:set'), {\n userId,\n role,\n createdAt: now,\n updatedAt: now,\n })) as MemberDoc\n return memberRecordFromDoc(doc, projectId)\n }\n\n async findMember(projectId: string, userId: string): Promise<ProjectMemberRecord | undefined> {\n const doc = (await this.client.query(queryRef('members:get'), {\n userId,\n })) as MemberDoc | null\n return doc ? memberRecordFromDoc(doc, projectId) : undefined\n }\n\n async listMembers(projectId: string): Promise<ProjectMemberRecord[]> {\n const docs = (await this.client.query(queryRef('members:list'), {})) as MemberDoc[]\n return docs.map((d) => memberRecordFromDoc(d, projectId))\n }\n\n async listMembershipsForUser(userId: string): Promise<ProjectMemberRecord[]> {\n // `members:mine` is caller-scoped server-side and returns the caller's single\n // deployment membership (or null). The studio only ever asks about the\n // session user; records are stamped with this deployment's bound project.\n const doc = (await this.client.query(queryRef('members:mine'), {})) as MemberDoc | null\n return doc && doc.userId === userId ? [memberRecordFromDoc(doc, this.boundProjectId)] : []\n }\n\n async removeMember(projectId: string, userId: string): Promise<void> {\n try {\n await this.client.mutation(mutationRef('members:remove'), { userId })\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n if (/not-found/i.test(message)) {\n throw new RecordNotFoundError('project-member', `${projectId}/${userId}`)\n }\n throw error\n }\n }\n}\n\ninterface CliTokenDoc {\n /** Retired (EC-182): optional only because live rows may still carry it until the migration clears it. */\n projectId?: string\n tokenId: string\n label: string\n tokenHash: string\n createdAt: string\n revokedAt?: string\n}\n\nfunction cliTokenRecordFromDoc(doc: CliTokenDoc): CliTokenRecord {\n return {\n id: doc.tokenId,\n label: doc.label,\n tokenHash: doc.tokenHash,\n createdAt: doc.createdAt,\n ...(doc.revokedAt ? { revokedAt: doc.revokedAt } : {}),\n }\n}\n\nclass ConvexCliTokenRepository implements CliTokenRepository {\n constructor(\n private readonly client: ConvexHttpClient,\n private readonly clock: Clock = realClock,\n ) {}\n\n async createToken(input: NewCliTokenInput): Promise<CliTokenRecord> {\n const doc = (await this.client.mutation(mutationRef('cliTokens:create'), {\n tokenId: newId('tok'),\n label: input.label,\n tokenHash: input.tokenHash,\n createdAt: this.clock(),\n })) as CliTokenDoc\n return cliTokenRecordFromDoc(doc)\n }\n\n async listTokens(): Promise<CliTokenRecord[]> {\n const docs = (await this.client.query(queryRef('cliTokens:list'), {})) as CliTokenDoc[]\n return docs.map(cliTokenRecordFromDoc)\n }\n\n async revokeToken(tokenId: string): Promise<CliTokenRecord> {\n try {\n const doc = (await this.client.mutation(mutationRef('cliTokens:revoke'), {\n tokenId,\n revokedAt: this.clock(),\n })) as CliTokenDoc\n return cliTokenRecordFromDoc(doc)\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n if (/not-found/i.test(message)) {\n throw new RecordNotFoundError('cli-token', tokenId)\n }\n throw error\n }\n }\n\n async findByHash(tokenHash: string): Promise<CliTokenRecord | undefined> {\n const doc = (await this.client.query(queryRef('cliTokens:byHash'), {\n tokenHash,\n })) as CliTokenDoc | null\n return doc ? cliTokenRecordFromDoc(doc) : undefined\n }\n}\n\n/**\n * Convex-backed {@link PersistenceAdapter} (brief §10, EC-039). Every repository\n * is implemented against the Convex functions in `apps/builder/convex/*`, mapping\n * results and failures onto the provider-neutral contracts + error taxonomies.\n */\nexport class ConvexPersistenceAdapter implements PersistenceAdapter {\n readonly cms: CmsRepository\n readonly assets: AssetRepository\n /** Reference index — outbound/inbound entries per variant (EC-155, AD-6). */\n readonly references: ReferenceIndexRepository\n /** Per-project membership roles (EC-150). */\n readonly members: MembersRepository\n /** Revocable CLI sync tokens, stored hashed (EC-150). */\n readonly cliTokens: CliTokenRepository\n /** Convex file storage behind the EC-133 blob boundary (EC-151). */\n readonly blobs: BlobStorageAdapter\n /**\n * EC-277: the Convex mutations maintain the reference index in-transaction\n * (`convex/referenceMaintenance.ts`), so every writer — studio, CLI, webhook,\n * raw `convex run` — is caught at the source. The studio bootstrap therefore does\n * NOT attach the client-side `attachReferenceIndex` subscriber for this provider.\n */\n readonly maintainsReferenceIndex = true\n\n /**\n * @param client the Convex client bound to this deployment (one project).\n * @param projectId the slug of this deployment's one project (EC-179). Used to\n * stamp deployment-scoped member records onto the still-project-keyed contract.\n * @param collections the active project's config-owned CMS collections (EC-183,\n * AD-11), from `elytra.config.ts`. The backend has no `cmsSchemas` table, so\n * the CMS repository serves the schema from these.\n */\n constructor(\n private readonly client: ConvexHttpClient,\n projectId: string,\n collections: readonly CollectionDef[] = [],\n ) {\n this.cms = new ConvexCmsRepository(client, collections)\n this.assets = new ConvexAssetRepository(client)\n this.references = new ConvexReferenceIndexRepository(client)\n this.members = new ConvexMembersRepository(client, projectId)\n this.cliTokens = new ConvexCliTokenRepository(client)\n this.blobs = new ConvexBlobStorage(client)\n }\n\n async status(): Promise<BackendStatus> {\n try {\n // Lightweight connectivity probe (EC-182: no `projects` table). `members:mine`\n // takes no args and is soft-guarded (EC-279): it answers `null` for an\n // unauthenticated caller rather than throwing, so the pre-sign-in boot probe\n // resolves cleanly — backend answered ⇒ `available: true` — with no scary\n // `Uncaught Error` in the Convex log.\n await this.client.query(queryRef('members:mine'), {})\n return { backend: 'convex', available: true }\n } catch (error) {\n const detail = error instanceof Error ? error.message : String(error)\n // EC-153: an `unauthorized` rejection *is* a healthy backend — the\n // deployment answered and enforced auth. Now that `members:mine` is\n // soft-guarded this branch is a defensive fallback (a protected probe could\n // still throw); only transport/server failures count as unavailable, so the\n // BackendGate surfaces those visibly instead of falling back to in-memory.\n if (/unauthorized/i.test(detail)) return { backend: 'convex', available: true }\n return { backend: 'convex', available: false, detail }\n }\n }\n\n validate(input: BackendValidationInput): BackendValidationResult {\n return validateForPersistence(input)\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createSeededPersistenceAdapter } from '@elytracms/core/persistence';
|
|
1
|
+
import { SEED_PROJECT_ID, createSeededPersistenceAdapter } from '@elytracms/core/persistence';
|
|
2
2
|
import { resolveDeploymentCollections, resolveDeploymentProjectId, resolveDeploymentUrl, } from '../workspace';
|
|
3
3
|
import { getConvexClient } from './convex-client';
|
|
4
4
|
import { ConvexPersistenceAdapter } from './convex-adapter';
|
|
@@ -26,7 +26,11 @@ export async function selectPersistenceAdapter() {
|
|
|
26
26
|
if (config.kind === 'playground') {
|
|
27
27
|
// EC-207: routes/redirects are config-sourced, never seeded to the backend —
|
|
28
28
|
// the playground adapter no longer seeds route documents.
|
|
29
|
-
|
|
29
|
+
// EC-310: key the seed under the ACTIVE project id (the config slug, e.g.
|
|
30
|
+
// `aurora`) — not the engine's default `prj_aurora` — so content + memberships
|
|
31
|
+
// sit under the same id the studio operates on. Otherwise authorization denies
|
|
32
|
+
// every read ("not a member of project 'aurora'") and content resolves empty.
|
|
33
|
+
return createSeededPersistenceAdapter(resolveDeploymentProjectId(SEED_PROJECT_ID));
|
|
30
34
|
}
|
|
31
35
|
throw new Error(config.detail);
|
|
32
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/persistence/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/persistence/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAA;AAE7F,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAGrD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB;IAC5C,MAAM,MAAM,GAAG,oBAAoB,EAAE,CAAA;IACrC,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,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EACpB,mBAAmB,GACpB,MAAM,gBAAgB,CAAA","sourcesContent":["import { SEED_PROJECT_ID, createSeededPersistenceAdapter } from '@elytracms/core/persistence'\nimport type { PersistenceAdapter } from '@elytracms/core/persistence'\nimport {\n resolveDeploymentCollections,\n resolveDeploymentProjectId,\n resolveDeploymentUrl,\n} from '../workspace'\nimport { getConvexClient } from './convex-client'\nimport { ConvexPersistenceAdapter } from './convex-adapter'\nimport { resolveBackendConfig } from './backend-mode'\nimport type { StudioBackendMode } from './backend-mode'\n\n/**\n * Select the persistence backend (EC-153, vision AD-1). **Convex is the\n * default**: a configured `VITE_CONVEX_URL` is required unless the explicit\n * playground flag (`VITE_ELYTRA_MODE=playground`) opts into the deterministic,\n * seeded in-memory adapter. There is **no automatic in-memory fallback** —\n * missing configuration is a hard, descriptive error (the `BackendGate`\n * renders it as a boot-error screen before any adapter is requested).\n *\n * EC-150: the Convex path uses the *shared* client so the auth adapter's\n * session JWT (set via `client.setAuth`) authenticates every persistence call.\n */\nexport async function selectPersistenceAdapter(): Promise<PersistenceAdapter> {\n const config = resolveBackendConfig()\n if (config.kind === 'convex') {\n return new ConvexPersistenceAdapter(\n getConvexClient(resolveDeploymentUrl(config.url)),\n resolveDeploymentProjectId('aurora-marketing'),\n // CMS collections are config-owned (EC-183, AD-11): inject the active\n // project's collections so the adapter serves the schema from config (the\n // backend has no `cmsSchemas` table).\n resolveDeploymentCollections(),\n )\n }\n if (config.kind === 'playground') {\n // EC-207: routes/redirects are config-sourced, never seeded to the backend —\n // the playground adapter no longer seeds route documents.\n // EC-310: key the seed under the ACTIVE project id (the config slug, e.g.\n // `aurora`) — not the engine's default `prj_aurora` — so content + memberships\n // sit under the same id the studio operates on. Otherwise authorization denies\n // every read (\"not a member of project 'aurora'\") and content resolves empty.\n return createSeededPersistenceAdapter(resolveDeploymentProjectId(SEED_PROJECT_ID))\n }\n throw new Error(config.detail)\n}\n\n/**\n * A stable key identifying the active backend (EC-179): the resolved deployment\n * URL for the active project under Convex, or `playground`. The operations\n * bootstrap caches one bundle per key, so switching to a project on a different\n * deployment transparently selects (or builds) that backend's operations client.\n */\nexport function activeDeploymentKey(): string {\n const config = resolveBackendConfig()\n if (config.kind === 'convex') return resolveDeploymentUrl(config.url)\n if (config.kind === 'playground') return 'playground'\n throw new Error(config.detail)\n}\n\n/**\n * The active backend mode. Throws the same descriptive error as\n * {@link selectPersistenceAdapter} when the studio is misconfigured — UI that\n * only needs \"is this the playground?\" should use `isPlaygroundMode()`.\n */\nexport function persistenceMode(): StudioBackendMode {\n const config = resolveBackendConfig()\n if (config.kind === 'misconfigured') throw new Error(config.detail)\n return config.kind\n}\n\nexport { ConvexPersistenceAdapter } from './convex-adapter'\nexport {\n CONVEX_URL_ENV_VAR,\n DEV_LOGIN_ENV_VAR,\n MODE_ENV_VAR,\n PLAYGROUND_MODE,\n isDevAutoLoginActive,\n isPlaygroundMode,\n resolveBackendConfig,\n resolveDevAutoLogin,\n} from './backend-mode'\nexport type {\n DevAutoLoginCredentials,\n EnvRecord,\n StudioBackendConfig,\n StudioBackendMode,\n} from './backend-mode'\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The studio client read seam (EC-308 / AD-17): one operations-backed query cache.
|
|
3
|
+
* See `./operations-query`.
|
|
4
|
+
*/
|
|
5
|
+
export { StudioQueryProvider, useOperationQuery, useOperationCache, useStableQueryKey, OPERATION_INVALIDATE_DEBOUNCE_MS, } from './operations-query';
|
|
6
|
+
export type { OperationCache, UseOperationQueryOptions } from './operations-query';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The studio client read seam (EC-308 / AD-17): one operations-backed query cache.
|
|
3
|
+
* See `./operations-query`.
|
|
4
|
+
*/
|
|
5
|
+
export { StudioQueryProvider, useOperationQuery, useOperationCache, useStableQueryKey, OPERATION_INVALIDATE_DEBOUNCE_MS, } from './operations-query';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/query/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,gCAAgC,GACjC,MAAM,oBAAoB,CAAA","sourcesContent":["/**\n * The studio client read seam (EC-308 / AD-17): one operations-backed query cache.\n * See `./operations-query`.\n */\nexport {\n StudioQueryProvider,\n useOperationQuery,\n useOperationCache,\n useStableQueryKey,\n OPERATION_INVALIDATE_DEBOUNCE_MS,\n} from './operations-query'\nexport type { OperationCache, UseOperationQueryOptions } from './operations-query'\n"]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { QueryKey, UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import type { OperationsClient } from '@elytracms/studio/lib/operations';
|
|
4
|
+
/**
|
|
5
|
+
* EC-308 / AD-17 — the ONE studio client read seam.
|
|
6
|
+
*
|
|
7
|
+
* Every studio **server read** goes through {@link useOperationQuery} over the
|
|
8
|
+
* shared operations client, cached by TanStack Query; invalidation rides the
|
|
9
|
+
* operations event bus into the same cache. This replaces the bespoke per-store
|
|
10
|
+
* `useState` + epoch-guard + debounce + reload machinery that each store used to
|
|
11
|
+
* hand-roll (the patchwork AD-17 calls out). See
|
|
12
|
+
* [`docs/client-data-flow.md`](../../../../../docs/client-data-flow.md) and
|
|
13
|
+
* [`docs/principles.md`](../../../../../docs/principles.md) §12.
|
|
14
|
+
*
|
|
15
|
+
* It is also the **Phase-2 prep** (EC-309): reactivity/multiplayer is added by
|
|
16
|
+
* swapping pull → push *behind this hook* (an adapter `subscribe` capability
|
|
17
|
+
* driving `queryClient.setQueryData`), never at the call sites — so call sites
|
|
18
|
+
* never change when push lands.
|
|
19
|
+
*
|
|
20
|
+
* Deliberately NOT here: the optimistic editing session (the draft being typed,
|
|
21
|
+
* live validation, the table working view-state in `cms-store`). That is client
|
|
22
|
+
* state, not server state, and stays local (principle 12).
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Trailing-debounce window (ms) for event-driven invalidation: a burst of
|
|
26
|
+
* commands — e.g. one `documents.upsert` per keystroke from autosave, or one
|
|
27
|
+
* event per row in a bulk action — coalesces into a single refetch once the
|
|
28
|
+
* writes settle. (The shared replacement for the per-store `*_RELOAD_DEBOUNCE_MS`.)
|
|
29
|
+
*/
|
|
30
|
+
export declare const OPERATION_INVALIDATE_DEBOUNCE_MS = 300;
|
|
31
|
+
/**
|
|
32
|
+
* Mounts the single studio `QueryClient` (one per studio lifetime, surviving
|
|
33
|
+
* project switches). Mounted package-owned in `StudioProvider`, above every
|
|
34
|
+
* per-project provider, so every studio hook can reach the cache.
|
|
35
|
+
*/
|
|
36
|
+
export declare function StudioQueryProvider({ children }: {
|
|
37
|
+
children: ReactNode;
|
|
38
|
+
}): ReactNode;
|
|
39
|
+
export interface UseOperationQueryOptions<T> {
|
|
40
|
+
/** Stable query key; the first element is the domain tag used for grouping. */
|
|
41
|
+
queryKey: QueryKey;
|
|
42
|
+
/** Loads the data from the shared operations client. */
|
|
43
|
+
loader: (operations: OperationsClient) => Promise<T>;
|
|
44
|
+
/**
|
|
45
|
+
* Which succeeded commands invalidate this query — a list of operation names
|
|
46
|
+
* (`'documents.publish'`) and/or domains (`'documents'`). A succeeded command
|
|
47
|
+
* matches when its `operation` OR `domain` is in the list. Keep it a stable
|
|
48
|
+
* (module-level) array. Omit for a query that only loads once / refetches
|
|
49
|
+
* manually.
|
|
50
|
+
*/
|
|
51
|
+
invalidateOn?: readonly string[];
|
|
52
|
+
/** Skip the query (e.g. fixture/playground sessions with no backend). */
|
|
53
|
+
enabled?: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* One operations-backed, cached, self-invalidating query. Thin wrapper over
|
|
57
|
+
* `useQuery` whose `queryFn` resolves the shared operations client and runs the
|
|
58
|
+
* loader, plus one shared invalidation subscriber (the only place that touches
|
|
59
|
+
* the operations event bus for reads).
|
|
60
|
+
*/
|
|
61
|
+
export declare function useOperationQuery<T>(options: UseOperationQueryOptions<T>): UseQueryResult<T>;
|
|
62
|
+
/**
|
|
63
|
+
* The write-side companion to {@link useOperationQuery}: an imperative handle on
|
|
64
|
+
* the studio cache for a store that OWNS its writes. Lets a store apply an
|
|
65
|
+
* EC-301-style optimistic patch (drop/replace one record) instead of re-listing
|
|
66
|
+
* the whole collection on every edit — keeping `@tanstack/react-query` out of the
|
|
67
|
+
* call sites so the seam stays the only place that knows the cache exists.
|
|
68
|
+
*/
|
|
69
|
+
export interface OperationCache {
|
|
70
|
+
/**
|
|
71
|
+
* Patch a cached query in place — no refetch. The EC-301 pattern: a focal-point
|
|
72
|
+
* or alt edit patches the one changed record; it does NOT trigger a full
|
|
73
|
+
* `*.list` round-trip. No-op if nothing is cached under `queryKey` yet.
|
|
74
|
+
*/
|
|
75
|
+
patch<T>(queryKey: QueryKey, updater: (prev: T | undefined) => T): void;
|
|
76
|
+
/**
|
|
77
|
+
* Invalidate a cached query, refetching it if it is currently active. Returns a
|
|
78
|
+
* promise that settles when the refetch does, so a caller that must sequence a
|
|
79
|
+
* read after a local write (e.g. flush-then-reload) can await it.
|
|
80
|
+
*/
|
|
81
|
+
invalidate(queryKey: QueryKey): Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
export declare function useOperationCache(): OperationCache;
|
|
84
|
+
/** Re-export the trigger-set type helper for hooks that build keyed queries. */
|
|
85
|
+
export declare function useStableQueryKey(parts: readonly (string | undefined)[]): QueryKey;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { QueryClient, QueryClientProvider, useQuery, useQueryClient, } from '@tanstack/react-query';
|
|
4
|
+
import { getStudioOperations } from '@elytracms/studio/lib/operations';
|
|
5
|
+
/**
|
|
6
|
+
* EC-308 / AD-17 — the ONE studio client read seam.
|
|
7
|
+
*
|
|
8
|
+
* Every studio **server read** goes through {@link useOperationQuery} over the
|
|
9
|
+
* shared operations client, cached by TanStack Query; invalidation rides the
|
|
10
|
+
* operations event bus into the same cache. This replaces the bespoke per-store
|
|
11
|
+
* `useState` + epoch-guard + debounce + reload machinery that each store used to
|
|
12
|
+
* hand-roll (the patchwork AD-17 calls out). See
|
|
13
|
+
* [`docs/client-data-flow.md`](../../../../../docs/client-data-flow.md) and
|
|
14
|
+
* [`docs/principles.md`](../../../../../docs/principles.md) §12.
|
|
15
|
+
*
|
|
16
|
+
* It is also the **Phase-2 prep** (EC-309): reactivity/multiplayer is added by
|
|
17
|
+
* swapping pull → push *behind this hook* (an adapter `subscribe` capability
|
|
18
|
+
* driving `queryClient.setQueryData`), never at the call sites — so call sites
|
|
19
|
+
* never change when push lands.
|
|
20
|
+
*
|
|
21
|
+
* Deliberately NOT here: the optimistic editing session (the draft being typed,
|
|
22
|
+
* live validation, the table working view-state in `cms-store`). That is client
|
|
23
|
+
* state, not server state, and stays local (principle 12).
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Trailing-debounce window (ms) for event-driven invalidation: a burst of
|
|
27
|
+
* commands — e.g. one `documents.upsert` per keystroke from autosave, or one
|
|
28
|
+
* event per row in a bulk action — coalesces into a single refetch once the
|
|
29
|
+
* writes settle. (The shared replacement for the per-store `*_RELOAD_DEBOUNCE_MS`.)
|
|
30
|
+
*/
|
|
31
|
+
export const OPERATION_INVALIDATE_DEBOUNCE_MS = 300;
|
|
32
|
+
/** Studio-tuned cache defaults: invalidation (not polling/focus) drives freshness. */
|
|
33
|
+
function createStudioQueryClient() {
|
|
34
|
+
return new QueryClient({
|
|
35
|
+
defaultOptions: {
|
|
36
|
+
queries: {
|
|
37
|
+
staleTime: 5_000,
|
|
38
|
+
refetchOnWindowFocus: false,
|
|
39
|
+
retry: false,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Mounts the single studio `QueryClient` (one per studio lifetime, surviving
|
|
46
|
+
* project switches). Mounted package-owned in `StudioProvider`, above every
|
|
47
|
+
* per-project provider, so every studio hook can reach the cache.
|
|
48
|
+
*/
|
|
49
|
+
export function StudioQueryProvider({ children }) {
|
|
50
|
+
const [client] = useState(createStudioQueryClient);
|
|
51
|
+
return _jsx(QueryClientProvider, { client: client, children: children });
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* One operations-backed, cached, self-invalidating query. Thin wrapper over
|
|
55
|
+
* `useQuery` whose `queryFn` resolves the shared operations client and runs the
|
|
56
|
+
* loader, plus one shared invalidation subscriber (the only place that touches
|
|
57
|
+
* the operations event bus for reads).
|
|
58
|
+
*/
|
|
59
|
+
export function useOperationQuery(options) {
|
|
60
|
+
const { queryKey, loader, invalidateOn, enabled = true } = options;
|
|
61
|
+
const queryClient = useQueryClient();
|
|
62
|
+
const result = useQuery({
|
|
63
|
+
queryKey,
|
|
64
|
+
queryFn: async () => {
|
|
65
|
+
const { operations } = await getStudioOperations();
|
|
66
|
+
return loader(operations);
|
|
67
|
+
},
|
|
68
|
+
enabled,
|
|
69
|
+
});
|
|
70
|
+
// Stable serializations so an inline `queryKey`/`invalidateOn` doesn't churn the
|
|
71
|
+
// subscription every render (re-subscribe only when their CONTENTS change).
|
|
72
|
+
const keyJson = JSON.stringify(queryKey);
|
|
73
|
+
const invalidateJson = JSON.stringify(invalidateOn ?? []);
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
const triggers = new Set(JSON.parse(invalidateJson));
|
|
76
|
+
if (triggers.size === 0)
|
|
77
|
+
return;
|
|
78
|
+
const key = JSON.parse(keyJson);
|
|
79
|
+
let timer;
|
|
80
|
+
let unsubscribe;
|
|
81
|
+
let disposed = false;
|
|
82
|
+
const matches = (event) => event.kind === 'command' &&
|
|
83
|
+
event.status === 'succeeded' &&
|
|
84
|
+
(triggers.has(event.operation) || triggers.has(event.domain));
|
|
85
|
+
void getStudioOperations().then((studio) => {
|
|
86
|
+
if (disposed)
|
|
87
|
+
return;
|
|
88
|
+
unsubscribe = studio.operations.events.subscribe((event) => {
|
|
89
|
+
if (!matches(event))
|
|
90
|
+
return;
|
|
91
|
+
// Trailing-debounce: a burst (per-keystroke autosave, bulk actions)
|
|
92
|
+
// collapses into one invalidation; the active query then refetches once.
|
|
93
|
+
if (timer)
|
|
94
|
+
clearTimeout(timer);
|
|
95
|
+
timer = setTimeout(() => {
|
|
96
|
+
void queryClient.invalidateQueries({ queryKey: key });
|
|
97
|
+
}, OPERATION_INVALIDATE_DEBOUNCE_MS);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
return () => {
|
|
101
|
+
disposed = true;
|
|
102
|
+
if (timer)
|
|
103
|
+
clearTimeout(timer);
|
|
104
|
+
unsubscribe?.();
|
|
105
|
+
};
|
|
106
|
+
}, [keyJson, invalidateJson, queryClient]);
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
export function useOperationCache() {
|
|
110
|
+
const queryClient = useQueryClient();
|
|
111
|
+
const patch = useCallback((queryKey, updater) => {
|
|
112
|
+
queryClient.setQueryData(queryKey, updater);
|
|
113
|
+
}, [queryClient]);
|
|
114
|
+
const invalidate = useCallback((queryKey) => queryClient.invalidateQueries({ queryKey }), [queryClient]);
|
|
115
|
+
return useMemo(() => ({ patch, invalidate }), [patch, invalidate]);
|
|
116
|
+
}
|
|
117
|
+
/** Re-export the trigger-set type helper for hooks that build keyed queries. */
|
|
118
|
+
export function useStableQueryKey(parts) {
|
|
119
|
+
// Memoize on the serialized parts so a hook can pass derived strings without a
|
|
120
|
+
// new key identity each render.
|
|
121
|
+
const json = JSON.stringify(parts);
|
|
122
|
+
return useMemo(() => JSON.parse(json), [json]);
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=operations-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oper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o, useState } from 'react'\nimport type { ReactNode } from 'react'\nimport {\n QueryClient,\n QueryClientProvider,\n useQuery,\n useQueryClient,\n} from '@tanstack/react-query'\nimport type { QueryKey, UseQueryResult } from '@tanstack/react-query'\nimport { getStudioOperations } from '@elytracms/studio/lib/operations'\nimport type { OperationEvent, OperationsClient } from '@elytracms/studio/lib/operations'\n\n/**\n * EC-308 / AD-17 — the ONE studio client read seam.\n *\n * Every studio **server read** goes through {@link useOperationQuery} over the\n * shared operations client, cached by TanStack Query; invalidation rides the\n * operations event bus into the same cache. This replaces the bespoke per-store\n * `useState` + epoch-guard + debounce + reload machinery that each store used to\n * hand-roll (the patchwork AD-17 calls out). See\n * [`docs/client-data-flow.md`](../../../../../docs/client-data-flow.md) and\n * [`docs/principles.md`](../../../../../docs/principles.md) §12.\n *\n * It is also the **Phase-2 prep** (EC-309): reactivity/multiplayer is added by\n * swapping pull → push *behind this hook* (an adapter `subscribe` capability\n * driving `queryClient.setQueryData`), never at the call sites — so call sites\n * never change when push lands.\n *\n * Deliberately NOT here: the optimistic editing session (the draft being typed,\n * live validation, the table working view-state in `cms-store`). That is client\n * state, not server state, and stays local (principle 12).\n */\n\n/**\n * Trailing-debounce window (ms) for event-driven invalidation: a burst of\n * commands — e.g. one `documents.upsert` per keystroke from autosave, or one\n * event per row in a bulk action — coalesces into a single refetch once the\n * writes settle. (The shared replacement for the per-store `*_RELOAD_DEBOUNCE_MS`.)\n */\nexport const OPERATION_INVALIDATE_DEBOUNCE_MS = 300\n\n/** Studio-tuned cache defaults: invalidation (not polling/focus) drives freshness. */\nfunction createStudioQueryClient(): QueryClient {\n return new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 5_000,\n refetchOnWindowFocus: false,\n retry: false,\n },\n },\n })\n}\n\n/**\n * Mounts the single studio `QueryClient` (one per studio lifetime, surviving\n * project switches). Mounted package-owned in `StudioProvider`, above every\n * per-project provider, so every studio hook can reach the cache.\n */\nexport function StudioQueryProvider({ children }: { children: ReactNode }): ReactNode {\n const [client] = useState(createStudioQueryClient)\n return <QueryClientProvider client={client}>{children}</QueryClientProvider>\n}\n\nexport interface UseOperationQueryOptions<T> {\n /** Stable query key; the first element is the domain tag used for grouping. */\n queryKey: QueryKey\n /** Loads the data from the shared operations client. */\n loader: (operations: OperationsClient) => Promise<T>\n /**\n * Which succeeded commands invalidate this query — a list of operation names\n * (`'documents.publish'`) and/or domains (`'documents'`). A succeeded command\n * matches when its `operation` OR `domain` is in the list. Keep it a stable\n * (module-level) array. Omit for a query that only loads once / refetches\n * manually.\n */\n invalidateOn?: readonly string[]\n /** Skip the query (e.g. fixture/playground sessions with no backend). */\n enabled?: boolean\n}\n\n/**\n * One operations-backed, cached, self-invalidating query. Thin wrapper over\n * `useQuery` whose `queryFn` resolves the shared operations client and runs the\n * loader, plus one shared invalidation subscriber (the only place that touches\n * the operations event bus for reads).\n */\nexport function useOperationQuery<T>(options: UseOperationQueryOptions<T>): UseQueryResult<T> {\n const { queryKey, loader, invalidateOn, enabled = true } = options\n const queryClient = useQueryClient()\n\n const result = useQuery<T>({\n queryKey,\n queryFn: async () => {\n const { operations } = await getStudioOperations()\n return loader(operations)\n },\n enabled,\n })\n\n // Stable serializations so an inline `queryKey`/`invalidateOn` doesn't churn the\n // subscription every render (re-subscribe only when their CONTENTS change).\n const keyJson = JSON.stringify(queryKey)\n const invalidateJson = JSON.stringify(invalidateOn ?? [])\n\n useEffect(() => {\n const triggers = new Set<string>(JSON.parse(invalidateJson) as string[])\n if (triggers.size === 0) return\n const key = JSON.parse(keyJson) as QueryKey\n let timer: ReturnType<typeof setTimeout> | undefined\n let unsubscribe: (() => void) | undefined\n let disposed = false\n const matches = (event: OperationEvent): boolean =>\n event.kind === 'command' &&\n event.status === 'succeeded' &&\n (triggers.has(event.operation) || triggers.has(event.domain))\n void getStudioOperations().then((studio) => {\n if (disposed) return\n unsubscribe = studio.operations.events.subscribe((event) => {\n if (!matches(event)) return\n // Trailing-debounce: a burst (per-keystroke autosave, bulk actions)\n // collapses into one invalidation; the active query then refetches once.\n if (timer) clearTimeout(timer)\n timer = setTimeout(() => {\n void queryClient.invalidateQueries({ queryKey: key })\n }, OPERATION_INVALIDATE_DEBOUNCE_MS)\n })\n })\n return () => {\n disposed = true\n if (timer) clearTimeout(timer)\n unsubscribe?.()\n }\n }, [keyJson, invalidateJson, queryClient])\n\n return result\n}\n\n/**\n * The write-side companion to {@link useOperationQuery}: an imperative handle on\n * the studio cache for a store that OWNS its writes. Lets a store apply an\n * EC-301-style optimistic patch (drop/replace one record) instead of re-listing\n * the whole collection on every edit — keeping `@tanstack/react-query` out of the\n * call sites so the seam stays the only place that knows the cache exists.\n */\nexport interface OperationCache {\n /**\n * Patch a cached query in place — no refetch. The EC-301 pattern: a focal-point\n * or alt edit patches the one changed record; it does NOT trigger a full\n * `*.list` round-trip. No-op if nothing is cached under `queryKey` yet.\n */\n patch<T>(queryKey: QueryKey, updater: (prev: T | undefined) => T): void\n /**\n * Invalidate a cached query, refetching it if it is currently active. Returns a\n * promise that settles when the refetch does, so a caller that must sequence a\n * read after a local write (e.g. flush-then-reload) can await it.\n */\n invalidate(queryKey: QueryKey): Promise<void>\n}\n\nexport function useOperationCache(): OperationCache {\n const queryClient = useQueryClient()\n const patch = useCallback(\n <T,>(queryKey: QueryKey, updater: (prev: T | undefined) => T): void => {\n queryClient.setQueryData<T>(queryKey, updater)\n },\n [queryClient],\n )\n const invalidate = useCallback(\n (queryKey: QueryKey): Promise<void> => queryClient.invalidateQueries({ queryKey }),\n [queryClient],\n )\n return useMemo(() => ({ patch, invalidate }), [patch, invalidate])\n}\n\n/** Re-export the trigger-set type helper for hooks that build keyed queries. */\nexport function useStableQueryKey(parts: readonly (string | undefined)[]): QueryKey {\n // Memoize on the serialized parts so a hook can pass derived strings without a\n // new key identity each render.\n const json = JSON.stringify(parts)\n return useMemo(() => JSON.parse(json) as QueryKey, [json])\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveDocumentTitle } from '@elytracms/core/cms-core';
|
|
1
2
|
/**
|
|
2
3
|
* Pure presentation model for the EC-172 references panels.
|
|
3
4
|
*
|
|
@@ -81,7 +82,12 @@ function collectionLabelOf(collection, collectionId) {
|
|
|
81
82
|
export function documentTitleOf(collection, document, fallback) {
|
|
82
83
|
if (!collection || !document)
|
|
83
84
|
return fallback;
|
|
84
|
-
|
|
85
|
+
// EC-242: a function `titleField` (title pattern) has no single source field —
|
|
86
|
+
// resolve it from the base values via the shared identity resolver.
|
|
87
|
+
if (typeof collection.titleField === 'function') {
|
|
88
|
+
return resolveDocumentTitle(collection, document.values, fallback);
|
|
89
|
+
}
|
|
90
|
+
const field = typeof collection.titleField === 'string' ? collection.titleField : 'title';
|
|
85
91
|
const direct = document.values[field];
|
|
86
92
|
if (typeof direct === 'string' && direct.length > 0)
|
|
87
93
|
return direct;
|