@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.
- package/__tests__/node-handlers/node-to-jsx/attribute-value-mapper.ts +77 -0
- package/__tests__/utils/ast-utils.ts +23 -2
- package/__tests__/utils/page-seeds-state-from-data-source.ts +70 -0
- package/dist/cjs/node-handlers/node-to-jsx/index.js +15 -0
- package/dist/cjs/node-handlers/node-to-jsx/index.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/cjs/utils/ast-utils.d.ts +10 -0
- package/dist/cjs/utils/ast-utils.d.ts.map +1 -1
- package/dist/cjs/utils/ast-utils.js +83 -2
- package/dist/cjs/utils/ast-utils.js.map +1 -1
- package/dist/cjs/utils/route-utils.d.ts +17 -1
- package/dist/cjs/utils/route-utils.d.ts.map +1 -1
- package/dist/cjs/utils/route-utils.js +32 -1
- package/dist/cjs/utils/route-utils.js.map +1 -1
- package/dist/esm/node-handlers/node-to-jsx/index.js +15 -0
- package/dist/esm/node-handlers/node-to-jsx/index.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/utils/ast-utils.d.ts +10 -0
- package/dist/esm/utils/ast-utils.d.ts.map +1 -1
- package/dist/esm/utils/ast-utils.js +81 -1
- package/dist/esm/utils/ast-utils.js.map +1 -1
- package/dist/esm/utils/route-utils.d.ts +17 -1
- package/dist/esm/utils/route-utils.d.ts.map +1 -1
- package/dist/esm/utils/route-utils.js +29 -0
- package/dist/esm/utils/route-utils.js.map +1 -1
- package/package.json +4 -4
- package/src/node-handlers/node-to-jsx/index.ts +27 -0
- package/src/utils/ast-utils.ts +87 -1
- package/src/utils/route-utils.ts +35 -1
package/src/utils/route-utils.ts
CHANGED
|
@@ -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
|
+
)
|