[BREAKING-CHANGE] Centralize system View viewField side effect (#23081)
# Introduction Closes https://github.com/twentyhq/core-team-issues/issues/2669 Part of the `isSystemSideEffect` engine-ownership effort. Until now, a custom object's default **INDEX** table view (`All {objectLabelPlural}`) and its view fields were built imperatively in `ObjectMetadataService` with random `v4()` identifiers, while `twenty-standard` authored its own copies with hardcoded literals. The two never converged, an object rename could drift the view, and nothing marked these rows as engine-owned. This PR makes the metadata side-effect engine the **single owner** of the INDEX view and its view fields, on name-free deterministic identifiers, for custom and standard objects alike. ## Core design - **Name-free deterministic identity.** The INDEX view identifier derives from `object identifier + ViewKey.INDEX` (`getSystemViewUniversalIdentifier`); each view-field identifier derives from `view identifier + field identifier` (`getViewFieldUniversalIdentifier`). An object rename (with a pinned object identifier) keeps the same view, losslessly. - **`isSystemSideEffect: true` is provenance.** Every INDEX view / view field the engine emits is flagged system-owned, so manifest deletion inference never drops it. The flag follows the view: a view field inherits its parent view's flag. - **The engine is the sole owner of the INDEX view.** It always emits it; a caller providing one with the same derived identifier is a genuine conflict surfaced by the engine's reserved-identifier collision, not silently deferred. ## Changes ### Shared (`twenty-shared`) - `getIndexViewUniversalIdentifier` → `getSystemViewUniversalIdentifier`, now taking a `viewKey` (generalizes to any singleton engine-owned view). - Standard field identifiers extracted into a new `STANDARD_OBJECT_FIELDS` constant, so both an object's `fields` and its INDEX view read the same field identifiers. - `buildStandardObjectIndexView` derives the standard INDEX view + view-field identifiers from `STANDARD_OBJECT_FIELDS`, replacing the hardcoded literals in `standard-object.constant.ts`. ### Metadata side-effect engine (custom objects) - **`objectSystemFieldsAndIndexViewOnCreate`** (replaces `objectSystemFieldsOnCreate`): on object creation, provisions the 7 reserved system fields **and** the INDEX view with one view field per displayable system field, all `isSystemSideEffect: true`. - **`fieldIndexViewFieldOnCreate`** (new): on field creation, provisions the field's INDEX view field. Object created in the same batch → visible, positioned before the system view fields; pre-existing object → hidden, appended (preserving the historical `createOneField` behavior). Both branches resolve the INDEX view by its derived identifier (single map access, never a scan). - **`fieldSystemViewFieldsOnDelete`** (new): on field deletion, cascade-deletes every engine-owned view field displaying it. - **`objectSystemSideEffectsOnDelete`** (extended): now also cascade-deletes the object's engine-owned views and their view fields (in addition to system fields, indexes, searchFieldMetadata). Every lookup walks a foreign-key aggregator down from the deleted object, so the work is proportional to what the object owns, never to workspace size. - Object-create and field-create positions are derived from the same caller-input field list, so the INDEX view layout is contiguous with no handler-ordering dependency. - `view` / `viewField` added to the side-effect companion metadata names for `fieldMetadata` and `objectMetadata`. ### Reserved-identifier invariant A caller can never define an entity whose identifier collides with one a system side effect produces: caller inputs are forced `isSystemSideEffect: false` at every entry point (API and app-manifest transpilers), and the engine raises `RESERVED_SYSTEM_UNIVERSAL_IDENTIFIER`, aborting the operation, when a system emission lands on a caller-claimed identifier. Covered by a new engine-level test. ### Caller-side provisioning removed The imperative INDEX view + view-field provisioning is removed from `ObjectMetadataService.createOneObject`. The record-page `FIELDS_WIDGET` view is intentionally left caller-side and deferred to the follow-up (see below). ### `twenty-standard` convergence Standard INDEX views and their view fields converge on the same derived-identifier + `isSystemSideEffect: true` scheme as the engine. `twenty-standard` syncs through the from/to migration path (which never runs the side-effect engine), so it authors this INDEX surface itself, matching what the engine produces for custom objects. ## Rollout Two `2.26.0` workspace commands, running after the `2.25` messageCampaign commands: - `upgrade:2-26:reconcile-index-view-universal-identifier` re-owns the INDEX views of the **twenty-standard and workspace-custom applications** and all their view fields to the derived identifiers with `isSystemSideEffect: true`, in a single per-workspace transaction. Each view field identifier is keyed on the application of the **displayed field** (an app or user column on a standard INDEX view converges too). Soft-deleted views and view fields are skipped: one can coexist with an active successor on the same derivation inputs and both would derive the same identifier. Children reference the view by primary key, so the re-own is lossless. - `upgrade:2-26:demote-and-backfill-application-index-view` handles **manifest-installed applications**, which never had their INDEX view auto-provisioned: every caller-authored INDEX view of another application is demoted to `key: null` (a plain additional view under its manifest identifier), then every application object gets the engine-owned INDEX view and its full view-field layout backfilled through the migration pipeline's legacy path (no side-effect expansion), views committed before view fields across applications since a view field belongs to the application owning its field. Idempotent and retry-safe: engine-owned INDEX views are neither demoted nor re-backfilled, and view creation and view-field creation are gated independently, so a retry after a partial failure still backfills the missing view fields of an already-committed view. Both support `--dry-run` and invalidate the full flat-maps closure (parents aggregate the re-owned identifiers, children resolve them as universal foreign keys, and page-layout widget universal configurations resolve view PKs at cache-build time). The `2.25` `upgrade:2-25:add-message-campaign-name-field` command is adapted to resolve the campaign INDEX view by its INDEX key on the object instead of by universal identifier: it now runs before the reconcile, on workspaces still holding legacy identifiers. ## ⚠️ Breaking change This PR **mutates 187 previously hardcoded universal identifiers** — the standard objects' INDEX views and their view fields (the literals removed from `standard-object.constant.ts`), now derived. - **Handled by the `2.26` commands above** for all existing workspaces. - **The INDEX key is now engine-reserved.** The flat view validator rejects caller-created INDEX views (API and manifest inputs are forced `isSystemSideEffect: false`) and enforces a single non-deleted INDEX view per object; `view.key` is no longer a comparable/updatable property, so no writer can promote or demote a view after creation. `ViewManifest.key` is deprecated and ignored (manifest views are always additional views, so old apps keep syncing and demoted views are not promoted back); the REST/GraphQL create path now rejects `key: INDEX`. In-repo example apps (`hello-world`, `document-generator`) no longer declare it. - **12 declared-but-never-seeded standard INDEX view field identifiers deleted** (the former `preservedViewFields` on `timelineActivity`, `workflowRun` and `workspaceMember`): after the reconcile, no workspace row references them. - **`computeFlatViewFieldsToCreate` now derives view field identifiers** instead of drawing `v4()` ones, which also changes what the committed `1-23` record-page backfill produces going forward (deliberate, documented in-code). - **Record-page views and view fields are not affected** (identifiers unchanged). - **In-repo apps: `twenty-last-contact` updated.** It was the only app declaring explicit INDEX view fields (10 columns across `allPeople` / `allCompanies` / `allOpportunities`) through manifest `viewFields`. Those target identifiers are now engine-owned and derived, so the manifest inputs no longer resolve and install failed with `View not found`. The app now declares only its fields; the engine's `fieldIndexViewFieldOnCreate` provisions the matching INDEX view field automatically. No other app under `packages/twenty-apps` references any of the 187 mutated identifiers, and apps that target standard views point at record-page views (e.g. `real-estate` → `opportunityRecordPageFields`) or their own objects (`twenty-partners`), all unchanged. ### Loss of granularity for app maintainers The engine now owns the INDEX view field of every field a caller adds to an object, so app maintainers lose direct control over those columns. Previously an app could target the engine-owned INDEX view with an explicit manifest `viewField` and set its `position` and `isVisible`. Now `fieldIndexViewFieldOnCreate` appends a **hidden** view field in caller-input order on field creation, so: - Columns an app previously showed at a **dedicated position** and **visible** (e.g. `twenty-last-contact`'s last-contact columns) become **hidden** and **appended in input order** after install. - There is currently **no manifest way to override** the engine-provisioned INDEX view field's position, visibility, or size. This is a deliberate regression accepted for the sake of single-ownership, and app maintainers should expect their INDEX columns to move/hide after upgrading. A follow-up override API will let maintainers reclaim per-field control over the engine-provisioned INDEX view field. ## Testing - Unit specs for each handler: object create (system fields + INDEX view/view fields, override, position offset), field create (same-batch vs existing-object, non-displayable noop, no-INDEX-view noop), field delete, object delete (fields/indexes/searchFieldMetadata/views/view fields cascade, reverse-relation view field on another object). - Engine-level test for the reserved-identifier collision. - `twenty-standard` guard test that its INDEX views/view fields stay on the derived scheme and stay system-owned. - Integration test: full engine provisioning of the INDEX view/view fields on object creation, same view id preserved across an object rename, and cascade delete on object deletion. ## Follow-up The full record-page stack (record-page view, its view fields, view field groups, page layout / tab / widget) is still built imperatively and moves into the engine in https://github.com/twentyhq/core-team-issues/issues/2721.
This commit is contained in:
+356
-392
@@ -2493,54 +2493,48 @@ exports[`getStandardObjectMetadataRelatedEntityIds should return standard object
|
||||
"id": "00000000-0000-0000-0000-000000000730",
|
||||
},
|
||||
},
|
||||
"id": "00000000-0000-0000-0000-000000000760",
|
||||
"id": "00000000-0000-0000-0000-000000000758",
|
||||
"views": {
|
||||
"allTimelineActivities": {
|
||||
"id": "00000000-0000-0000-0000-000000000759",
|
||||
"id": "00000000-0000-0000-0000-000000000757",
|
||||
"viewFieldGroups": {},
|
||||
"viewFields": {
|
||||
"happensAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000746",
|
||||
},
|
||||
"linkedRecordCachedName": {
|
||||
"id": "00000000-0000-0000-0000-000000000749",
|
||||
},
|
||||
"name": {
|
||||
"id": "00000000-0000-0000-0000-000000000745",
|
||||
},
|
||||
"properties": {
|
||||
"id": "00000000-0000-0000-0000-000000000747",
|
||||
},
|
||||
"targetCompany": {
|
||||
"id": "00000000-0000-0000-0000-000000000751",
|
||||
"id": "00000000-0000-0000-0000-000000000749",
|
||||
},
|
||||
"targetDashboard": {
|
||||
"id": "00000000-0000-0000-0000-000000000758",
|
||||
},
|
||||
"targetNote": {
|
||||
"id": "00000000-0000-0000-0000-000000000754",
|
||||
},
|
||||
"targetOpportunity": {
|
||||
"id": "00000000-0000-0000-0000-000000000752",
|
||||
},
|
||||
"targetPerson": {
|
||||
"id": "00000000-0000-0000-0000-000000000750",
|
||||
},
|
||||
"targetTask": {
|
||||
"id": "00000000-0000-0000-0000-000000000753",
|
||||
},
|
||||
"targetWorkflow": {
|
||||
"id": "00000000-0000-0000-0000-000000000755",
|
||||
},
|
||||
"targetWorkflowRun": {
|
||||
"id": "00000000-0000-0000-0000-000000000757",
|
||||
},
|
||||
"targetWorkflowVersion": {
|
||||
"id": "00000000-0000-0000-0000-000000000756",
|
||||
},
|
||||
"workspaceMember": {
|
||||
"targetNote": {
|
||||
"id": "00000000-0000-0000-0000-000000000752",
|
||||
},
|
||||
"targetOpportunity": {
|
||||
"id": "00000000-0000-0000-0000-000000000750",
|
||||
},
|
||||
"targetPerson": {
|
||||
"id": "00000000-0000-0000-0000-000000000748",
|
||||
},
|
||||
"targetTask": {
|
||||
"id": "00000000-0000-0000-0000-000000000751",
|
||||
},
|
||||
"targetWorkflow": {
|
||||
"id": "00000000-0000-0000-0000-000000000753",
|
||||
},
|
||||
"targetWorkflowRun": {
|
||||
"id": "00000000-0000-0000-0000-000000000755",
|
||||
},
|
||||
"targetWorkflowVersion": {
|
||||
"id": "00000000-0000-0000-0000-000000000754",
|
||||
},
|
||||
"workspaceMember": {
|
||||
"id": "00000000-0000-0000-0000-000000000747",
|
||||
},
|
||||
},
|
||||
"viewGroups": {},
|
||||
},
|
||||
@@ -2549,80 +2543,80 @@ exports[`getStandardObjectMetadataRelatedEntityIds should return standard object
|
||||
"workflow": {
|
||||
"fields": {
|
||||
"attachments": {
|
||||
"id": "00000000-0000-0000-0000-000000000777",
|
||||
},
|
||||
"automatedTriggers": {
|
||||
"id": "00000000-0000-0000-0000-000000000775",
|
||||
},
|
||||
"coreWorkflowId": {
|
||||
"id": "00000000-0000-0000-0000-000000000771",
|
||||
},
|
||||
"createdAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000762",
|
||||
},
|
||||
"createdBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000765",
|
||||
},
|
||||
"deletedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000764",
|
||||
},
|
||||
"id": {
|
||||
"id": "00000000-0000-0000-0000-000000000761",
|
||||
},
|
||||
"lastPublishedVersionId": {
|
||||
"id": "00000000-0000-0000-0000-000000000770",
|
||||
},
|
||||
"name": {
|
||||
"id": "00000000-0000-0000-0000-000000000769",
|
||||
},
|
||||
"position": {
|
||||
"id": "00000000-0000-0000-0000-000000000767",
|
||||
},
|
||||
"runs": {
|
||||
"id": "00000000-0000-0000-0000-000000000774",
|
||||
},
|
||||
"searchVector": {
|
||||
"id": "00000000-0000-0000-0000-000000000768",
|
||||
},
|
||||
"statuses": {
|
||||
"id": "00000000-0000-0000-0000-000000000772",
|
||||
},
|
||||
"timelineActivities": {
|
||||
"id": "00000000-0000-0000-0000-000000000776",
|
||||
},
|
||||
"updatedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000763",
|
||||
},
|
||||
"updatedBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000766",
|
||||
},
|
||||
"versions": {
|
||||
"automatedTriggers": {
|
||||
"id": "00000000-0000-0000-0000-000000000773",
|
||||
},
|
||||
"coreWorkflowId": {
|
||||
"id": "00000000-0000-0000-0000-000000000769",
|
||||
},
|
||||
"createdAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000760",
|
||||
},
|
||||
"createdBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000763",
|
||||
},
|
||||
"deletedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000762",
|
||||
},
|
||||
"id": {
|
||||
"id": "00000000-0000-0000-0000-000000000759",
|
||||
},
|
||||
"lastPublishedVersionId": {
|
||||
"id": "00000000-0000-0000-0000-000000000768",
|
||||
},
|
||||
"name": {
|
||||
"id": "00000000-0000-0000-0000-000000000767",
|
||||
},
|
||||
"position": {
|
||||
"id": "00000000-0000-0000-0000-000000000765",
|
||||
},
|
||||
"runs": {
|
||||
"id": "00000000-0000-0000-0000-000000000772",
|
||||
},
|
||||
"searchVector": {
|
||||
"id": "00000000-0000-0000-0000-000000000766",
|
||||
},
|
||||
"statuses": {
|
||||
"id": "00000000-0000-0000-0000-000000000770",
|
||||
},
|
||||
"timelineActivities": {
|
||||
"id": "00000000-0000-0000-0000-000000000774",
|
||||
},
|
||||
"updatedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000761",
|
||||
},
|
||||
"updatedBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000764",
|
||||
},
|
||||
"versions": {
|
||||
"id": "00000000-0000-0000-0000-000000000771",
|
||||
},
|
||||
},
|
||||
"id": "00000000-0000-0000-0000-000000000785",
|
||||
"id": "00000000-0000-0000-0000-000000000783",
|
||||
"views": {
|
||||
"allWorkflows": {
|
||||
"id": "00000000-0000-0000-0000-000000000784",
|
||||
"id": "00000000-0000-0000-0000-000000000782",
|
||||
"viewFieldGroups": {},
|
||||
"viewFields": {
|
||||
"createdBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000781",
|
||||
},
|
||||
"name": {
|
||||
"id": "00000000-0000-0000-0000-000000000778",
|
||||
},
|
||||
"runs": {
|
||||
"id": "00000000-0000-0000-0000-000000000783",
|
||||
},
|
||||
"statuses": {
|
||||
"id": "00000000-0000-0000-0000-000000000779",
|
||||
},
|
||||
"name": {
|
||||
"id": "00000000-0000-0000-0000-000000000776",
|
||||
},
|
||||
"runs": {
|
||||
"id": "00000000-0000-0000-0000-000000000781",
|
||||
},
|
||||
"statuses": {
|
||||
"id": "00000000-0000-0000-0000-000000000777",
|
||||
},
|
||||
"updatedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000780",
|
||||
"id": "00000000-0000-0000-0000-000000000778",
|
||||
},
|
||||
"versions": {
|
||||
"id": "00000000-0000-0000-0000-000000000782",
|
||||
"id": "00000000-0000-0000-0000-000000000780",
|
||||
},
|
||||
},
|
||||
"viewGroups": {},
|
||||
@@ -2632,80 +2626,80 @@ exports[`getStandardObjectMetadataRelatedEntityIds should return standard object
|
||||
"workflowAutomatedTrigger": {
|
||||
"fields": {
|
||||
"createdAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000787",
|
||||
"id": "00000000-0000-0000-0000-000000000785",
|
||||
},
|
||||
"createdBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000790",
|
||||
},
|
||||
"deletedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000789",
|
||||
},
|
||||
"id": {
|
||||
"id": "00000000-0000-0000-0000-000000000786",
|
||||
},
|
||||
"position": {
|
||||
"id": "00000000-0000-0000-0000-000000000792",
|
||||
},
|
||||
"searchVector": {
|
||||
"id": "00000000-0000-0000-0000-000000000793",
|
||||
},
|
||||
"settings": {
|
||||
"id": "00000000-0000-0000-0000-000000000795",
|
||||
},
|
||||
"type": {
|
||||
"id": "00000000-0000-0000-0000-000000000794",
|
||||
},
|
||||
"updatedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000788",
|
||||
},
|
||||
"updatedBy": {
|
||||
"deletedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000787",
|
||||
},
|
||||
"id": {
|
||||
"id": "00000000-0000-0000-0000-000000000784",
|
||||
},
|
||||
"position": {
|
||||
"id": "00000000-0000-0000-0000-000000000790",
|
||||
},
|
||||
"searchVector": {
|
||||
"id": "00000000-0000-0000-0000-000000000791",
|
||||
},
|
||||
"settings": {
|
||||
"id": "00000000-0000-0000-0000-000000000793",
|
||||
},
|
||||
"type": {
|
||||
"id": "00000000-0000-0000-0000-000000000792",
|
||||
},
|
||||
"updatedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000786",
|
||||
},
|
||||
"updatedBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000789",
|
||||
},
|
||||
"workflow": {
|
||||
"id": "00000000-0000-0000-0000-000000000796",
|
||||
"id": "00000000-0000-0000-0000-000000000794",
|
||||
},
|
||||
},
|
||||
"id": "00000000-0000-0000-0000-000000000808",
|
||||
"id": "00000000-0000-0000-0000-000000000806",
|
||||
"views": {
|
||||
"allWorkflowAutomatedTriggers": {
|
||||
"id": "00000000-0000-0000-0000-000000000800",
|
||||
"id": "00000000-0000-0000-0000-000000000798",
|
||||
"viewFieldGroups": {},
|
||||
"viewFields": {
|
||||
"createdAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000799",
|
||||
},
|
||||
"type": {
|
||||
"id": "00000000-0000-0000-0000-000000000797",
|
||||
},
|
||||
"type": {
|
||||
"id": "00000000-0000-0000-0000-000000000795",
|
||||
},
|
||||
"workflow": {
|
||||
"id": "00000000-0000-0000-0000-000000000798",
|
||||
"id": "00000000-0000-0000-0000-000000000796",
|
||||
},
|
||||
},
|
||||
"viewGroups": {},
|
||||
},
|
||||
"workflowAutomatedTriggerRecordPageFields": {
|
||||
"id": "00000000-0000-0000-0000-000000000807",
|
||||
"id": "00000000-0000-0000-0000-000000000805",
|
||||
"viewFieldGroups": {
|
||||
"general": {
|
||||
"id": "00000000-0000-0000-0000-000000000805",
|
||||
"id": "00000000-0000-0000-0000-000000000803",
|
||||
},
|
||||
"system": {
|
||||
"id": "00000000-0000-0000-0000-000000000806",
|
||||
"id": "00000000-0000-0000-0000-000000000804",
|
||||
},
|
||||
},
|
||||
"viewFields": {
|
||||
"createdAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000803",
|
||||
},
|
||||
"createdBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000804",
|
||||
},
|
||||
"type": {
|
||||
"id": "00000000-0000-0000-0000-000000000801",
|
||||
},
|
||||
"workflow": {
|
||||
"createdBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000802",
|
||||
},
|
||||
"type": {
|
||||
"id": "00000000-0000-0000-0000-000000000799",
|
||||
},
|
||||
"workflow": {
|
||||
"id": "00000000-0000-0000-0000-000000000800",
|
||||
},
|
||||
},
|
||||
"viewGroups": {},
|
||||
},
|
||||
@@ -2714,134 +2708,125 @@ exports[`getStandardObjectMetadataRelatedEntityIds should return standard object
|
||||
"workflowRun": {
|
||||
"fields": {
|
||||
"createdAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000810",
|
||||
"id": "00000000-0000-0000-0000-000000000808",
|
||||
},
|
||||
"createdBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000813",
|
||||
},
|
||||
"deletedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000812",
|
||||
},
|
||||
"endedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000822",
|
||||
},
|
||||
"enqueuedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000820",
|
||||
},
|
||||
"id": {
|
||||
"id": "00000000-0000-0000-0000-000000000809",
|
||||
},
|
||||
"name": {
|
||||
"id": "00000000-0000-0000-0000-000000000817",
|
||||
},
|
||||
"position": {
|
||||
"id": "00000000-0000-0000-0000-000000000815",
|
||||
},
|
||||
"searchVector": {
|
||||
"id": "00000000-0000-0000-0000-000000000816",
|
||||
},
|
||||
"startedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000821",
|
||||
},
|
||||
"state": {
|
||||
"id": "00000000-0000-0000-0000-000000000824",
|
||||
},
|
||||
"status": {
|
||||
"id": "00000000-0000-0000-0000-000000000823",
|
||||
},
|
||||
"stepLogs": {
|
||||
"id": "00000000-0000-0000-0000-000000000825",
|
||||
},
|
||||
"timelineActivities": {
|
||||
"id": "00000000-0000-0000-0000-000000000826",
|
||||
},
|
||||
"updatedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000811",
|
||||
},
|
||||
"updatedBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000814",
|
||||
"deletedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000810",
|
||||
},
|
||||
"workflow": {
|
||||
"id": "00000000-0000-0000-0000-000000000819",
|
||||
"endedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000820",
|
||||
},
|
||||
"workflowVersion": {
|
||||
"enqueuedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000818",
|
||||
},
|
||||
"id": {
|
||||
"id": "00000000-0000-0000-0000-000000000807",
|
||||
},
|
||||
"name": {
|
||||
"id": "00000000-0000-0000-0000-000000000815",
|
||||
},
|
||||
"position": {
|
||||
"id": "00000000-0000-0000-0000-000000000813",
|
||||
},
|
||||
"searchVector": {
|
||||
"id": "00000000-0000-0000-0000-000000000814",
|
||||
},
|
||||
"startedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000819",
|
||||
},
|
||||
"state": {
|
||||
"id": "00000000-0000-0000-0000-000000000822",
|
||||
},
|
||||
"status": {
|
||||
"id": "00000000-0000-0000-0000-000000000821",
|
||||
},
|
||||
"stepLogs": {
|
||||
"id": "00000000-0000-0000-0000-000000000823",
|
||||
},
|
||||
"timelineActivities": {
|
||||
"id": "00000000-0000-0000-0000-000000000824",
|
||||
},
|
||||
"updatedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000809",
|
||||
},
|
||||
"updatedBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000812",
|
||||
},
|
||||
"workflow": {
|
||||
"id": "00000000-0000-0000-0000-000000000817",
|
||||
},
|
||||
"workflowVersion": {
|
||||
"id": "00000000-0000-0000-0000-000000000816",
|
||||
},
|
||||
},
|
||||
"id": "00000000-0000-0000-0000-000000000849",
|
||||
"id": "00000000-0000-0000-0000-000000000844",
|
||||
"views": {
|
||||
"allWorkflowRuns": {
|
||||
"id": "00000000-0000-0000-0000-000000000833",
|
||||
"id": "00000000-0000-0000-0000-000000000828",
|
||||
"viewFieldGroups": {},
|
||||
"viewFields": {
|
||||
"createdBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000831",
|
||||
},
|
||||
"name": {
|
||||
"id": "00000000-0000-0000-0000-000000000827",
|
||||
},
|
||||
"startedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000830",
|
||||
"id": "00000000-0000-0000-0000-000000000825",
|
||||
},
|
||||
"status": {
|
||||
"id": "00000000-0000-0000-0000-000000000829",
|
||||
"id": "00000000-0000-0000-0000-000000000827",
|
||||
},
|
||||
"workflow": {
|
||||
"id": "00000000-0000-0000-0000-000000000828",
|
||||
},
|
||||
"workflowVersion": {
|
||||
"id": "00000000-0000-0000-0000-000000000832",
|
||||
"id": "00000000-0000-0000-0000-000000000826",
|
||||
},
|
||||
},
|
||||
"viewGroups": {},
|
||||
},
|
||||
"workflowRunRecordPageFields": {
|
||||
"id": "00000000-0000-0000-0000-000000000848",
|
||||
"id": "00000000-0000-0000-0000-000000000843",
|
||||
"viewFieldGroups": {
|
||||
"general": {
|
||||
"id": "00000000-0000-0000-0000-000000000846",
|
||||
"id": "00000000-0000-0000-0000-000000000841",
|
||||
},
|
||||
"system": {
|
||||
"id": "00000000-0000-0000-0000-000000000847",
|
||||
"id": "00000000-0000-0000-0000-000000000842",
|
||||
},
|
||||
},
|
||||
"viewFields": {
|
||||
"createdAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000839",
|
||||
},
|
||||
"createdBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000840",
|
||||
},
|
||||
"endedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000838",
|
||||
},
|
||||
"enqueuedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000841",
|
||||
},
|
||||
"startedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000837",
|
||||
},
|
||||
"state": {
|
||||
"id": "00000000-0000-0000-0000-000000000842",
|
||||
},
|
||||
"status": {
|
||||
"id": "00000000-0000-0000-0000-000000000834",
|
||||
},
|
||||
"timelineActivities": {
|
||||
"id": "00000000-0000-0000-0000-000000000845",
|
||||
},
|
||||
"updatedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000843",
|
||||
},
|
||||
"updatedBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000844",
|
||||
},
|
||||
"workflow": {
|
||||
"createdBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000835",
|
||||
},
|
||||
"workflowVersion": {
|
||||
"endedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000833",
|
||||
},
|
||||
"enqueuedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000836",
|
||||
},
|
||||
"startedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000832",
|
||||
},
|
||||
"state": {
|
||||
"id": "00000000-0000-0000-0000-000000000837",
|
||||
},
|
||||
"status": {
|
||||
"id": "00000000-0000-0000-0000-000000000829",
|
||||
},
|
||||
"timelineActivities": {
|
||||
"id": "00000000-0000-0000-0000-000000000840",
|
||||
},
|
||||
"updatedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000838",
|
||||
},
|
||||
"updatedBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000839",
|
||||
},
|
||||
"workflow": {
|
||||
"id": "00000000-0000-0000-0000-000000000830",
|
||||
},
|
||||
"workflowVersion": {
|
||||
"id": "00000000-0000-0000-0000-000000000831",
|
||||
},
|
||||
},
|
||||
"viewGroups": {},
|
||||
},
|
||||
@@ -2850,118 +2835,118 @@ exports[`getStandardObjectMetadataRelatedEntityIds should return standard object
|
||||
"workflowVersion": {
|
||||
"fields": {
|
||||
"coreWorkflowVersionId": {
|
||||
"id": "00000000-0000-0000-0000-000000000864",
|
||||
},
|
||||
"createdAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000851",
|
||||
},
|
||||
"createdBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000854",
|
||||
},
|
||||
"deletedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000853",
|
||||
},
|
||||
"id": {
|
||||
"id": "00000000-0000-0000-0000-000000000850",
|
||||
},
|
||||
"name": {
|
||||
"id": "00000000-0000-0000-0000-000000000858",
|
||||
},
|
||||
"position": {
|
||||
"id": "00000000-0000-0000-0000-000000000856",
|
||||
},
|
||||
"runs": {
|
||||
"id": "00000000-0000-0000-0000-000000000862",
|
||||
},
|
||||
"searchVector": {
|
||||
"id": "00000000-0000-0000-0000-000000000857",
|
||||
},
|
||||
"status": {
|
||||
"id": "00000000-0000-0000-0000-000000000861",
|
||||
},
|
||||
"steps": {
|
||||
"id": "00000000-0000-0000-0000-000000000863",
|
||||
},
|
||||
"timelineActivities": {
|
||||
"id": "00000000-0000-0000-0000-000000000865",
|
||||
},
|
||||
"trigger": {
|
||||
"id": "00000000-0000-0000-0000-000000000860",
|
||||
},
|
||||
"updatedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000852",
|
||||
},
|
||||
"updatedBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000855",
|
||||
},
|
||||
"workflow": {
|
||||
"id": "00000000-0000-0000-0000-000000000859",
|
||||
},
|
||||
"createdAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000846",
|
||||
},
|
||||
"createdBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000849",
|
||||
},
|
||||
"deletedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000848",
|
||||
},
|
||||
"id": {
|
||||
"id": "00000000-0000-0000-0000-000000000845",
|
||||
},
|
||||
"name": {
|
||||
"id": "00000000-0000-0000-0000-000000000853",
|
||||
},
|
||||
"position": {
|
||||
"id": "00000000-0000-0000-0000-000000000851",
|
||||
},
|
||||
"runs": {
|
||||
"id": "00000000-0000-0000-0000-000000000857",
|
||||
},
|
||||
"searchVector": {
|
||||
"id": "00000000-0000-0000-0000-000000000852",
|
||||
},
|
||||
"status": {
|
||||
"id": "00000000-0000-0000-0000-000000000856",
|
||||
},
|
||||
"steps": {
|
||||
"id": "00000000-0000-0000-0000-000000000858",
|
||||
},
|
||||
"timelineActivities": {
|
||||
"id": "00000000-0000-0000-0000-000000000860",
|
||||
},
|
||||
"trigger": {
|
||||
"id": "00000000-0000-0000-0000-000000000855",
|
||||
},
|
||||
"updatedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000847",
|
||||
},
|
||||
"updatedBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000850",
|
||||
},
|
||||
"workflow": {
|
||||
"id": "00000000-0000-0000-0000-000000000854",
|
||||
},
|
||||
},
|
||||
"id": "00000000-0000-0000-0000-000000000885",
|
||||
"id": "00000000-0000-0000-0000-000000000880",
|
||||
"views": {
|
||||
"allWorkflowVersions": {
|
||||
"id": "00000000-0000-0000-0000-000000000871",
|
||||
"id": "00000000-0000-0000-0000-000000000866",
|
||||
"viewFieldGroups": {},
|
||||
"viewFields": {
|
||||
"name": {
|
||||
"id": "00000000-0000-0000-0000-000000000866",
|
||||
"id": "00000000-0000-0000-0000-000000000861",
|
||||
},
|
||||
"runs": {
|
||||
"id": "00000000-0000-0000-0000-000000000870",
|
||||
"id": "00000000-0000-0000-0000-000000000865",
|
||||
},
|
||||
"status": {
|
||||
"id": "00000000-0000-0000-0000-000000000868",
|
||||
"id": "00000000-0000-0000-0000-000000000863",
|
||||
},
|
||||
"updatedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000869",
|
||||
"id": "00000000-0000-0000-0000-000000000864",
|
||||
},
|
||||
"workflow": {
|
||||
"id": "00000000-0000-0000-0000-000000000867",
|
||||
"id": "00000000-0000-0000-0000-000000000862",
|
||||
},
|
||||
},
|
||||
"viewGroups": {},
|
||||
},
|
||||
"workflowVersionRecordPageFields": {
|
||||
"id": "00000000-0000-0000-0000-000000000884",
|
||||
"id": "00000000-0000-0000-0000-000000000879",
|
||||
"viewFieldGroups": {
|
||||
"general": {
|
||||
"id": "00000000-0000-0000-0000-000000000882",
|
||||
"id": "00000000-0000-0000-0000-000000000877",
|
||||
},
|
||||
"system": {
|
||||
"id": "00000000-0000-0000-0000-000000000883",
|
||||
"id": "00000000-0000-0000-0000-000000000878",
|
||||
},
|
||||
},
|
||||
"viewFields": {
|
||||
"createdAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000875",
|
||||
"id": "00000000-0000-0000-0000-000000000870",
|
||||
},
|
||||
"createdBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000877",
|
||||
},
|
||||
"runs": {
|
||||
"id": "00000000-0000-0000-0000-000000000880",
|
||||
},
|
||||
"status": {
|
||||
"id": "00000000-0000-0000-0000-000000000872",
|
||||
},
|
||||
"runs": {
|
||||
"id": "00000000-0000-0000-0000-000000000875",
|
||||
},
|
||||
"status": {
|
||||
"id": "00000000-0000-0000-0000-000000000867",
|
||||
},
|
||||
"steps": {
|
||||
"id": "00000000-0000-0000-0000-000000000876",
|
||||
"id": "00000000-0000-0000-0000-000000000871",
|
||||
},
|
||||
"timelineActivities": {
|
||||
"id": "00000000-0000-0000-0000-000000000881",
|
||||
"id": "00000000-0000-0000-0000-000000000876",
|
||||
},
|
||||
"trigger": {
|
||||
"id": "00000000-0000-0000-0000-000000000874",
|
||||
"id": "00000000-0000-0000-0000-000000000869",
|
||||
},
|
||||
"updatedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000878",
|
||||
"id": "00000000-0000-0000-0000-000000000873",
|
||||
},
|
||||
"updatedBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000879",
|
||||
"id": "00000000-0000-0000-0000-000000000874",
|
||||
},
|
||||
"workflow": {
|
||||
"id": "00000000-0000-0000-0000-000000000873",
|
||||
"id": "00000000-0000-0000-0000-000000000868",
|
||||
},
|
||||
},
|
||||
"viewGroups": {},
|
||||
@@ -2971,125 +2956,104 @@ exports[`getStandardObjectMetadataRelatedEntityIds should return standard object
|
||||
"workspaceMember": {
|
||||
"fields": {
|
||||
"accountOwnerForCompanies": {
|
||||
"id": "00000000-0000-0000-0000-000000000903",
|
||||
},
|
||||
"assignedTasks": {
|
||||
"id": "00000000-0000-0000-0000-000000000901",
|
||||
},
|
||||
"avatarUrl": {
|
||||
"id": "00000000-0000-0000-0000-000000000897",
|
||||
},
|
||||
"blocklist": {
|
||||
"id": "00000000-0000-0000-0000-000000000905",
|
||||
},
|
||||
"calendarEventParticipants": {
|
||||
"id": "00000000-0000-0000-0000-000000000906",
|
||||
},
|
||||
"calendarStartDay": {
|
||||
"id": "00000000-0000-0000-0000-000000000911",
|
||||
},
|
||||
"colorScheme": {
|
||||
"id": "00000000-0000-0000-0000-000000000895",
|
||||
},
|
||||
"createdAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000887",
|
||||
},
|
||||
"createdBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000890",
|
||||
},
|
||||
"dateFormat": {
|
||||
"id": "00000000-0000-0000-0000-000000000909",
|
||||
},
|
||||
"deletedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000889",
|
||||
},
|
||||
"id": {
|
||||
"id": "00000000-0000-0000-0000-000000000886",
|
||||
},
|
||||
"jobTitle": {
|
||||
"id": "00000000-0000-0000-0000-000000000899",
|
||||
},
|
||||
"locale": {
|
||||
"id": "00000000-0000-0000-0000-000000000896",
|
||||
},
|
||||
"messageParticipants": {
|
||||
"id": "00000000-0000-0000-0000-000000000904",
|
||||
},
|
||||
"name": {
|
||||
"id": "00000000-0000-0000-0000-000000000894",
|
||||
},
|
||||
"numberFormat": {
|
||||
"id": "00000000-0000-0000-0000-000000000912",
|
||||
},
|
||||
"ownedOpportunities": {
|
||||
"id": "00000000-0000-0000-0000-000000000902",
|
||||
},
|
||||
"position": {
|
||||
"id": "00000000-0000-0000-0000-000000000892",
|
||||
},
|
||||
"searchVector": {
|
||||
"id": "00000000-0000-0000-0000-000000000893",
|
||||
},
|
||||
"timeFormat": {
|
||||
"id": "00000000-0000-0000-0000-000000000910",
|
||||
},
|
||||
"timeZone": {
|
||||
"id": "00000000-0000-0000-0000-000000000908",
|
||||
},
|
||||
"timelineActivities": {
|
||||
"id": "00000000-0000-0000-0000-000000000907",
|
||||
},
|
||||
"updatedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000888",
|
||||
},
|
||||
"updatedBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000891",
|
||||
},
|
||||
"userEmail": {
|
||||
"id": "00000000-0000-0000-0000-000000000898",
|
||||
},
|
||||
"userId": {
|
||||
"assignedTasks": {
|
||||
"id": "00000000-0000-0000-0000-000000000896",
|
||||
},
|
||||
"avatarUrl": {
|
||||
"id": "00000000-0000-0000-0000-000000000892",
|
||||
},
|
||||
"blocklist": {
|
||||
"id": "00000000-0000-0000-0000-000000000900",
|
||||
},
|
||||
"calendarEventParticipants": {
|
||||
"id": "00000000-0000-0000-0000-000000000901",
|
||||
},
|
||||
"calendarStartDay": {
|
||||
"id": "00000000-0000-0000-0000-000000000906",
|
||||
},
|
||||
"colorScheme": {
|
||||
"id": "00000000-0000-0000-0000-000000000890",
|
||||
},
|
||||
"createdAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000882",
|
||||
},
|
||||
"createdBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000885",
|
||||
},
|
||||
"dateFormat": {
|
||||
"id": "00000000-0000-0000-0000-000000000904",
|
||||
},
|
||||
"deletedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000884",
|
||||
},
|
||||
"id": {
|
||||
"id": "00000000-0000-0000-0000-000000000881",
|
||||
},
|
||||
"jobTitle": {
|
||||
"id": "00000000-0000-0000-0000-000000000894",
|
||||
},
|
||||
"locale": {
|
||||
"id": "00000000-0000-0000-0000-000000000891",
|
||||
},
|
||||
"messageParticipants": {
|
||||
"id": "00000000-0000-0000-0000-000000000899",
|
||||
},
|
||||
"name": {
|
||||
"id": "00000000-0000-0000-0000-000000000889",
|
||||
},
|
||||
"numberFormat": {
|
||||
"id": "00000000-0000-0000-0000-000000000907",
|
||||
},
|
||||
"ownedOpportunities": {
|
||||
"id": "00000000-0000-0000-0000-000000000897",
|
||||
},
|
||||
"position": {
|
||||
"id": "00000000-0000-0000-0000-000000000887",
|
||||
},
|
||||
"searchVector": {
|
||||
"id": "00000000-0000-0000-0000-000000000888",
|
||||
},
|
||||
"timeFormat": {
|
||||
"id": "00000000-0000-0000-0000-000000000905",
|
||||
},
|
||||
"timeZone": {
|
||||
"id": "00000000-0000-0000-0000-000000000903",
|
||||
},
|
||||
"timelineActivities": {
|
||||
"id": "00000000-0000-0000-0000-000000000902",
|
||||
},
|
||||
"updatedAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000883",
|
||||
},
|
||||
"updatedBy": {
|
||||
"id": "00000000-0000-0000-0000-000000000886",
|
||||
},
|
||||
"userEmail": {
|
||||
"id": "00000000-0000-0000-0000-000000000893",
|
||||
},
|
||||
"userId": {
|
||||
"id": "00000000-0000-0000-0000-000000000895",
|
||||
},
|
||||
},
|
||||
"id": "00000000-0000-0000-0000-000000000925",
|
||||
"id": "00000000-0000-0000-0000-000000000913",
|
||||
"views": {
|
||||
"allWorkspaceMembers": {
|
||||
"id": "00000000-0000-0000-0000-000000000924",
|
||||
"id": "00000000-0000-0000-0000-000000000912",
|
||||
"viewFieldGroups": {},
|
||||
"viewFields": {
|
||||
"assignedTasks": {
|
||||
"id": "00000000-0000-0000-0000-000000000923",
|
||||
},
|
||||
"avatarUrl": {
|
||||
"id": "00000000-0000-0000-0000-000000000915",
|
||||
},
|
||||
"colorScheme": {
|
||||
"id": "00000000-0000-0000-0000-000000000916",
|
||||
"id": "00000000-0000-0000-0000-000000000911",
|
||||
},
|
||||
"createdAt": {
|
||||
"id": "00000000-0000-0000-0000-000000000921",
|
||||
},
|
||||
"dateFormat": {
|
||||
"id": "00000000-0000-0000-0000-000000000919",
|
||||
},
|
||||
"locale": {
|
||||
"id": "00000000-0000-0000-0000-000000000917",
|
||||
"id": "00000000-0000-0000-0000-000000000909",
|
||||
},
|
||||
"name": {
|
||||
"id": "00000000-0000-0000-0000-000000000913",
|
||||
"id": "00000000-0000-0000-0000-000000000908",
|
||||
},
|
||||
"ownedOpportunities": {
|
||||
"id": "00000000-0000-0000-0000-000000000922",
|
||||
},
|
||||
"timeFormat": {
|
||||
"id": "00000000-0000-0000-0000-000000000920",
|
||||
},
|
||||
"timeZone": {
|
||||
"id": "00000000-0000-0000-0000-000000000918",
|
||||
},
|
||||
"userEmail": {
|
||||
"id": "00000000-0000-0000-0000-000000000914",
|
||||
"id": "00000000-0000-0000-0000-000000000910",
|
||||
},
|
||||
},
|
||||
"viewGroups": {},
|
||||
|
||||
+9
-5
@@ -1,17 +1,21 @@
|
||||
import { getStandardObjectMetadataRelatedEntityIds } from 'src/engine/workspace-manager/twenty-standard-application/utils/get-standard-object-metadata-related-entity-ids.util';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
let uuidCounter = 0;
|
||||
import { getStandardObjectMetadataRelatedEntityIds } from 'src/engine/workspace-manager/twenty-standard-application/utils/get-standard-object-metadata-related-entity-ids.util';
|
||||
|
||||
jest.mock('uuid', () => ({
|
||||
...jest.requireActual('uuid'),
|
||||
v4: jest.fn(
|
||||
() => `00000000-0000-0000-0000-${String(++uuidCounter).padStart(12, '0')}`,
|
||||
),
|
||||
v4: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('getStandardObjectMetadataRelatedEntityIds', () => {
|
||||
let uuidCounter = 0;
|
||||
|
||||
beforeEach(() => {
|
||||
uuidCounter = 0;
|
||||
(v4 as jest.Mock).mockImplementation(
|
||||
() =>
|
||||
`00000000-0000-0000-0000-${String(++uuidCounter).padStart(12, '0')}`,
|
||||
);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
|
||||
+1
-11
@@ -79,8 +79,6 @@ export type BuildStandardFlatViewFieldMetadataMapsArgs = Omit<
|
||||
export const buildStandardFlatViewFieldMetadataMaps = (
|
||||
args: BuildStandardFlatViewFieldMetadataMapsArgs,
|
||||
): FlatEntityMaps<FlatViewField> => {
|
||||
const { flatViewMaps } = args.dependencyFlatEntityMaps;
|
||||
|
||||
const allViewFieldMetadatas: FlatViewField[] = (
|
||||
Object.keys(
|
||||
STANDARD_FLAT_VIEW_FIELD_METADATA_BUILDERS_BY_OBJECT_NAME,
|
||||
@@ -100,16 +98,8 @@ export const buildStandardFlatViewFieldMetadataMaps = (
|
||||
let flatViewFieldMaps = createEmptyFlatEntityMaps();
|
||||
|
||||
for (const viewFieldMetadata of allViewFieldMetadatas) {
|
||||
const parentView =
|
||||
flatViewMaps.byUniversalIdentifier[
|
||||
viewFieldMetadata.viewUniversalIdentifier
|
||||
];
|
||||
|
||||
flatViewFieldMaps = addFlatEntityToFlatEntityMapsOrThrow({
|
||||
flatEntity: {
|
||||
...viewFieldMetadata,
|
||||
isSystemSideEffect: parentView?.isSystemSideEffect ?? false,
|
||||
},
|
||||
flatEntity: viewFieldMetadata,
|
||||
flatEntityMaps: flatViewFieldMaps,
|
||||
});
|
||||
}
|
||||
|
||||
+14
-2
@@ -1,7 +1,7 @@
|
||||
import { STANDARD_OBJECTS } from 'twenty-shared/metadata';
|
||||
import { type AggregateOperations } from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { v4 } from 'uuid';
|
||||
import { type AggregateOperations } from 'twenty-shared/types';
|
||||
|
||||
import { type FlatViewField } from 'src/engine/metadata-modules/flat-view-field/types/flat-view-field.type';
|
||||
import { TWENTY_STANDARD_APPLICATION } from 'src/engine/workspace-manager/twenty-standard-application/constants/twenty-standard-applications';
|
||||
@@ -51,6 +51,7 @@ export const createStandardViewFieldFlatMetadata = <
|
||||
viewFieldGroupName = null,
|
||||
},
|
||||
standardObjectMetadataRelatedEntityIds,
|
||||
dependencyFlatEntityMaps,
|
||||
twentyStandardApplicationId,
|
||||
now,
|
||||
}: CreateStandardViewFieldArgs<O, V>): FlatViewField => {
|
||||
@@ -79,6 +80,17 @@ export const createStandardViewFieldFlatMetadata = <
|
||||
);
|
||||
}
|
||||
|
||||
const parentView =
|
||||
dependencyFlatEntityMaps.flatViewMaps.byUniversalIdentifier[
|
||||
viewDefinition.universalIdentifier
|
||||
];
|
||||
|
||||
if (!isDefined(parentView)) {
|
||||
throw new Error(
|
||||
`Missing parent view ${objectName} ${viewName.toString()} for view field ${viewFieldName}`,
|
||||
);
|
||||
}
|
||||
|
||||
let viewFieldGroupId: string | null = null;
|
||||
let viewFieldGroupUniversalIdentifier: string | null = null;
|
||||
|
||||
@@ -121,7 +133,7 @@ export const createStandardViewFieldFlatMetadata = <
|
||||
size,
|
||||
aggregateOperation,
|
||||
isActive: true,
|
||||
isSystemSideEffect: false,
|
||||
isSystemSideEffect: parentView.isSystemSideEffect,
|
||||
overrides: null,
|
||||
universalOverrides: null,
|
||||
createdAt: now,
|
||||
|
||||
-1
@@ -54,7 +54,6 @@ type Assertions = [
|
||||
| 'deletedAt'
|
||||
| 'type'
|
||||
| 'position'
|
||||
| 'key'
|
||||
| 'isCompact'
|
||||
| 'openRecordIn'
|
||||
| 'kanbanAggregateOperation'
|
||||
|
||||
+186
@@ -0,0 +1,186 @@
|
||||
import { ViewKey, ViewType } from 'twenty-shared/types';
|
||||
|
||||
import { FlatViewValidatorService } from 'src/engine/workspace-manager/workspace-migration/workspace-migration-builder/validators/services/flat-view-validator.service';
|
||||
|
||||
const OBJECT_UNIVERSAL_IDENTIFIER = '00000000-0000-4000-8000-0000000000b1';
|
||||
const VIEW_UNIVERSAL_IDENTIFIER = '00000000-0000-4000-8000-0000000000c1';
|
||||
const OTHER_VIEW_UNIVERSAL_IDENTIFIER = '00000000-0000-4000-8000-0000000000c2';
|
||||
|
||||
type TestFlatView = {
|
||||
universalIdentifier: string;
|
||||
objectMetadataUniversalIdentifier: string;
|
||||
key: ViewKey | null;
|
||||
type: ViewType;
|
||||
isSystemSideEffect: boolean;
|
||||
deletedAt: string | null;
|
||||
};
|
||||
|
||||
const buildFlatView = (
|
||||
overrides: Partial<TestFlatView> = {},
|
||||
): TestFlatView => ({
|
||||
universalIdentifier: VIEW_UNIVERSAL_IDENTIFIER,
|
||||
objectMetadataUniversalIdentifier: OBJECT_UNIVERSAL_IDENTIFIER,
|
||||
key: null,
|
||||
type: ViewType.TABLE,
|
||||
isSystemSideEffect: false,
|
||||
deletedAt: null,
|
||||
...overrides,
|
||||
});
|
||||
|
||||
const mapsFrom = (
|
||||
entities: { universalIdentifier: string; [key: string]: unknown }[],
|
||||
) => ({
|
||||
byUniversalIdentifier: Object.fromEntries(
|
||||
entities.map((entity) => [entity.universalIdentifier, entity]),
|
||||
),
|
||||
});
|
||||
|
||||
const buildCreationArgs = ({
|
||||
flatViewToValidate,
|
||||
existingFlatViews = [],
|
||||
}: {
|
||||
flatViewToValidate: TestFlatView;
|
||||
existingFlatViews?: TestFlatView[];
|
||||
}) =>
|
||||
({
|
||||
flatEntityToValidate: flatViewToValidate,
|
||||
optimisticFlatEntityMapsAndRelatedFlatEntityMaps: {
|
||||
flatViewMaps: mapsFrom(existingFlatViews),
|
||||
flatFieldMetadataMaps: mapsFrom([]),
|
||||
flatObjectMetadataMaps: mapsFrom([
|
||||
{
|
||||
universalIdentifier: OBJECT_UNIVERSAL_IDENTIFIER,
|
||||
viewUniversalIdentifiers: existingFlatViews.map(
|
||||
(existingFlatView) => existingFlatView.universalIdentifier,
|
||||
),
|
||||
},
|
||||
]),
|
||||
},
|
||||
additionalCacheDataMaps: { featureFlagsMap: {} },
|
||||
}) as unknown as Parameters<
|
||||
FlatViewValidatorService['validateFlatViewCreation']
|
||||
>[0];
|
||||
|
||||
const buildUpdateArgs = ({
|
||||
flatEntityUpdate,
|
||||
existingFlatView,
|
||||
}: {
|
||||
flatEntityUpdate: Record<string, unknown>;
|
||||
existingFlatView: TestFlatView;
|
||||
}) =>
|
||||
({
|
||||
universalIdentifier: existingFlatView.universalIdentifier,
|
||||
flatEntityUpdate,
|
||||
optimisticFlatEntityMapsAndRelatedFlatEntityMaps: {
|
||||
flatViewMaps: mapsFrom([existingFlatView]),
|
||||
flatFieldMetadataMaps: mapsFrom([]),
|
||||
},
|
||||
additionalCacheDataMaps: { featureFlagsMap: {} },
|
||||
}) as unknown as Parameters<
|
||||
FlatViewValidatorService['validateFlatViewUpdate']
|
||||
>[0];
|
||||
|
||||
describe('FlatViewValidatorService INDEX key reservation', () => {
|
||||
let service: FlatViewValidatorService;
|
||||
|
||||
beforeEach(() => {
|
||||
service = new FlatViewValidatorService();
|
||||
});
|
||||
|
||||
describe('creation', () => {
|
||||
it('rejects a caller-provided INDEX view', () => {
|
||||
const result = service.validateFlatViewCreation(
|
||||
buildCreationArgs({
|
||||
flatViewToValidate: buildFlatView({
|
||||
key: ViewKey.INDEX,
|
||||
isSystemSideEffect: false,
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
expect(result.errors).toHaveLength(1);
|
||||
expect(result.errors[0].message).toContain('reserved');
|
||||
});
|
||||
|
||||
it('accepts an engine-emitted INDEX view', () => {
|
||||
const result = service.validateFlatViewCreation(
|
||||
buildCreationArgs({
|
||||
flatViewToValidate: buildFlatView({
|
||||
key: ViewKey.INDEX,
|
||||
isSystemSideEffect: true,
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
expect(result.errors).toEqual([]);
|
||||
});
|
||||
|
||||
it('rejects a second INDEX view on the same object', () => {
|
||||
const result = service.validateFlatViewCreation(
|
||||
buildCreationArgs({
|
||||
flatViewToValidate: buildFlatView({
|
||||
key: ViewKey.INDEX,
|
||||
isSystemSideEffect: true,
|
||||
}),
|
||||
existingFlatViews: [
|
||||
buildFlatView({
|
||||
universalIdentifier: OTHER_VIEW_UNIVERSAL_IDENTIFIER,
|
||||
key: ViewKey.INDEX,
|
||||
isSystemSideEffect: true,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
expect(result.errors).toHaveLength(1);
|
||||
expect(result.errors[0].message).toContain('already has an INDEX view');
|
||||
});
|
||||
|
||||
it('ignores a soft-deleted INDEX view when checking the singleton', () => {
|
||||
const result = service.validateFlatViewCreation(
|
||||
buildCreationArgs({
|
||||
flatViewToValidate: buildFlatView({
|
||||
key: ViewKey.INDEX,
|
||||
isSystemSideEffect: true,
|
||||
}),
|
||||
existingFlatViews: [
|
||||
buildFlatView({
|
||||
universalIdentifier: OTHER_VIEW_UNIVERSAL_IDENTIFIER,
|
||||
key: ViewKey.INDEX,
|
||||
isSystemSideEffect: true,
|
||||
deletedAt: '2024-01-01T00:00:00.000Z',
|
||||
}),
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
expect(result.errors).toEqual([]);
|
||||
});
|
||||
|
||||
it('accepts a caller-provided view without a key', () => {
|
||||
const result = service.validateFlatViewCreation(
|
||||
buildCreationArgs({
|
||||
flatViewToValidate: buildFlatView({ key: null }),
|
||||
}),
|
||||
);
|
||||
|
||||
expect(result.errors).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('update', () => {
|
||||
it('accepts an update on an INDEX view', () => {
|
||||
const result = service.validateFlatViewUpdate(
|
||||
buildUpdateArgs({
|
||||
flatEntityUpdate: { name: 'Renamed default view' },
|
||||
existingFlatView: buildFlatView({
|
||||
key: ViewKey.INDEX,
|
||||
isSystemSideEffect: true,
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
expect(result.errors).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
+36
@@ -5,6 +5,7 @@ import {
|
||||
FieldMetadataType,
|
||||
RelationType,
|
||||
ViewCalendarLayout,
|
||||
ViewKey,
|
||||
ViewType,
|
||||
} from 'twenty-shared/types';
|
||||
import { getViewLayoutFromViewType, isDefined } from 'twenty-shared/utils';
|
||||
@@ -459,6 +460,41 @@ export class FlatViewValidatorService {
|
||||
});
|
||||
}
|
||||
|
||||
if (flatViewToValidate.key === ViewKey.INDEX) {
|
||||
if (flatViewToValidate.isSystemSideEffect !== true) {
|
||||
validationResult.errors.push({
|
||||
code: ViewExceptionCode.INVALID_VIEW_DATA,
|
||||
message: t`The INDEX view key is reserved for the engine-owned default view; remove the key from the view definition`,
|
||||
userFriendlyMessage: msg`The INDEX view key is reserved for the default view`,
|
||||
});
|
||||
}
|
||||
|
||||
const objectAlreadyHasIndexFlatView =
|
||||
isDefined(optimisticFlatObjectMetadata) &&
|
||||
optimisticFlatObjectMetadata.viewUniversalIdentifiers.some(
|
||||
(viewUniversalIdentifier) => {
|
||||
const flatView = findFlatEntityByUniversalIdentifier({
|
||||
universalIdentifier: viewUniversalIdentifier,
|
||||
flatEntityMaps: optimisticFlatViewMaps,
|
||||
});
|
||||
|
||||
return (
|
||||
isDefined(flatView) &&
|
||||
flatView.key === ViewKey.INDEX &&
|
||||
!isDefined(flatView.deletedAt)
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (objectAlreadyHasIndexFlatView) {
|
||||
validationResult.errors.push({
|
||||
code: ViewExceptionCode.INVALID_VIEW_DATA,
|
||||
message: t`Object already has an INDEX view`,
|
||||
userFriendlyMessage: msg`This object already has a default view`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
isDefined(
|
||||
flatViewToValidate.kanbanAggregateOperationFieldMetadataUniversalIdentifier,
|
||||
|
||||
Reference in New Issue
Block a user