@teleporthq/teleport-plugin-common 0.43.75 → 0.44.0

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.
@@ -1,4 +1,4 @@
1
- import { UIDLWorkflows } from '@teleporthq/teleport-types'
1
+ import { UIDLStateDefinition, UIDLWorkflows } from '@teleporthq/teleport-types'
2
2
  import { RoutePaths, TableAccess } from '@teleporthq/teleport-shared'
3
3
 
4
4
  /**
@@ -132,3 +132,37 @@ export const pageReadsProtectedTable = (uidl: {
132
132
  collectResourceTables(uidl.node, tables, new Set())
133
133
  return TableAccess.PROTECTED_TABLES.some((table) => tables.has(table))
134
134
  }
135
+
136
+ /**
137
+ * Any `{{…}}` template placeholder (`{{Current User.id}}`, `{{urlDifferentiator}}`).
138
+ * A state query carrying one can only be resolved in the browser, so the page's
139
+ * server data function never runs it — sending the literal placeholder to the
140
+ * database fails (`invalid input syntax for type uuid: "{{Current User.id}}"`).
141
+ */
142
+ const TEMPLATE_PLACEHOLDER = /\{\{[^}]+\}\}/
143
+
144
+ export const stateQueryHasTemplatePlaceholder = (definition: UIDLStateDefinition): boolean =>
145
+ typeof definition.query === 'string' && TEMPLATE_PLACEHOLDER.test(definition.query)
146
+
147
+ /**
148
+ * True when the page's own data function seeds a state from one of the
149
+ * project's data sources — a state bound to a table or a raw query that has no
150
+ * `{{…}}` placeholder. Such a page renders per request: those values have to be
151
+ * computed every time a visitor arrives, and a statically generated page hands a
152
+ * client-side navigation the copy Next.js cached in the browser (prefetched
153
+ * links included) or the one ISR rendered before the last write.
154
+ *
155
+ * Shared by the static-paths plugin and the page pipeline's getServerSideProps
156
+ * finalizer, which must reach the same verdict. The state data-source plugin
157
+ * splits states with the same `stateQueryHasTemplatePlaceholder` test.
158
+ */
159
+ export const pageSeedsStateFromDataSource = (
160
+ uidl: { stateDefinitions?: Record<string, UIDLStateDefinition> },
161
+ dataSources?: Record<string, unknown>
162
+ ): boolean =>
163
+ Object.values(uidl.stateDefinitions || {}).some(
164
+ (definition) =>
165
+ !!definition.dataSourceBinding &&
166
+ !!dataSources?.[definition.dataSourceBinding.dataSourceId] &&
167
+ !stateQueryHasTemplatePlaceholder(definition)
168
+ )