@teleporthq/teleport-plugin-next-data-source 0.43.55 → 0.43.57
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__/array-mapper-cache-wiring.test.ts +425 -0
- package/__tests__/data-source-cache-wrapping.test.ts +152 -0
- package/__tests__/ecommerce-product-storefront-tax.test.ts +118 -0
- package/dist/cjs/cache/ast.d.ts +71 -0
- package/dist/cjs/cache/ast.d.ts.map +1 -0
- package/dist/cjs/cache/ast.js +229 -0
- package/dist/cjs/cache/ast.js.map +1 -0
- package/dist/cjs/cache/config.d.ts +22 -0
- package/dist/cjs/cache/config.d.ts.map +1 -0
- package/dist/cjs/cache/config.js +67 -0
- package/dist/cjs/cache/config.js.map +1 -0
- package/dist/cjs/cache/types.d.ts +31 -0
- package/dist/cjs/cache/types.d.ts.map +1 -0
- package/dist/cjs/cache/types.js +3 -0
- package/dist/cjs/cache/types.js.map +1 -0
- package/dist/cjs/data-source-fetchers.d.ts +5 -3
- package/dist/cjs/data-source-fetchers.d.ts.map +1 -1
- package/dist/cjs/data-source-fetchers.js +51 -8
- package/dist/cjs/data-source-fetchers.js.map +1 -1
- package/dist/cjs/fetchers/teleport.d.ts +2 -2
- package/dist/cjs/fetchers/teleport.d.ts.map +1 -1
- package/dist/cjs/fetchers/teleport.js +3 -2
- package/dist/cjs/fetchers/teleport.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +14 -9
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/loading-state.d.ts.map +1 -1
- package/dist/cjs/loading-state.js +74 -2
- package/dist/cjs/loading-state.js.map +1 -1
- package/dist/cjs/pagination-plugin.d.ts.map +1 -1
- package/dist/cjs/pagination-plugin.js +204 -64
- package/dist/cjs/pagination-plugin.js.map +1 -1
- package/dist/cjs/transformations/ecommerce-product.d.ts +15 -1
- package/dist/cjs/transformations/ecommerce-product.d.ts.map +1 -1
- package/dist/cjs/transformations/ecommerce-product.js +7 -3
- package/dist/cjs/transformations/ecommerce-product.js.map +1 -1
- package/dist/cjs/transformations/index.d.ts +13 -2
- package/dist/cjs/transformations/index.d.ts.map +1 -1
- package/dist/cjs/transformations/index.js +21 -3
- package/dist/cjs/transformations/index.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/cjs/utils.d.ts +4 -3
- package/dist/cjs/utils.d.ts.map +1 -1
- package/dist/cjs/utils.js +6 -4
- package/dist/cjs/utils.js.map +1 -1
- package/dist/esm/cache/ast.d.ts +71 -0
- package/dist/esm/cache/ast.d.ts.map +1 -0
- package/dist/esm/cache/ast.js +196 -0
- package/dist/esm/cache/ast.js.map +1 -0
- package/dist/esm/cache/config.d.ts +22 -0
- package/dist/esm/cache/config.d.ts.map +1 -0
- package/dist/esm/cache/config.js +62 -0
- package/dist/esm/cache/config.js.map +1 -0
- package/dist/esm/cache/types.d.ts +31 -0
- package/dist/esm/cache/types.d.ts.map +1 -0
- package/dist/esm/cache/types.js +2 -0
- package/dist/esm/cache/types.js.map +1 -0
- package/dist/esm/data-source-fetchers.d.ts +5 -3
- package/dist/esm/data-source-fetchers.d.ts.map +1 -1
- package/dist/esm/data-source-fetchers.js +51 -8
- package/dist/esm/data-source-fetchers.js.map +1 -1
- package/dist/esm/fetchers/teleport.d.ts +2 -2
- package/dist/esm/fetchers/teleport.d.ts.map +1 -1
- package/dist/esm/fetchers/teleport.js +3 -2
- package/dist/esm/fetchers/teleport.js.map +1 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +12 -8
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/loading-state.d.ts.map +1 -1
- package/dist/esm/loading-state.js +74 -2
- package/dist/esm/loading-state.js.map +1 -1
- package/dist/esm/pagination-plugin.d.ts.map +1 -1
- package/dist/esm/pagination-plugin.js +205 -65
- package/dist/esm/pagination-plugin.js.map +1 -1
- package/dist/esm/transformations/ecommerce-product.d.ts +15 -1
- package/dist/esm/transformations/ecommerce-product.d.ts.map +1 -1
- package/dist/esm/transformations/ecommerce-product.js +7 -3
- package/dist/esm/transformations/ecommerce-product.js.map +1 -1
- package/dist/esm/transformations/index.d.ts +13 -2
- package/dist/esm/transformations/index.d.ts.map +1 -1
- package/dist/esm/transformations/index.js +20 -3
- package/dist/esm/transformations/index.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/utils.d.ts +4 -3
- package/dist/esm/utils.d.ts.map +1 -1
- package/dist/esm/utils.js +6 -4
- package/dist/esm/utils.js.map +1 -1
- package/package.json +5 -5
- package/src/cache/ast.ts +265 -0
- package/src/cache/config.ts +79 -0
- package/src/cache/types.ts +31 -0
- package/src/data-source-fetchers.ts +66 -12
- package/src/fetchers/teleport.ts +3 -3
- package/src/index.ts +10 -4
- package/src/loading-state.ts +65 -2
- package/src/pagination-plugin.ts +315 -116
- package/src/transformations/ecommerce-product.ts +53 -2
- package/src/transformations/index.ts +25 -4
- package/src/utils.ts +10 -5
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as types from '@babel/types';
|
|
2
|
+
import { UIDLDependency } from '@teleporthq/teleport-types';
|
|
3
|
+
import { ResolvedDataSourceCache } from './types';
|
|
4
|
+
/** Identifiers the emitted page imports from `utils/tq-cache/client`. */
|
|
5
|
+
export declare const CACHE_CLIENT_IMPORTS: string[];
|
|
6
|
+
export declare const cachedValueVarFor: (index: number) => string;
|
|
7
|
+
/**
|
|
8
|
+
* Registers the client runtime's named imports on the page.
|
|
9
|
+
*
|
|
10
|
+
* Each identifier is its own dependency entry because that is how the
|
|
11
|
+
* import-statements plugin keys them; they share one path, so they collapse
|
|
12
|
+
* into a single `import { … } from '…/utils/tq-cache/client'`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const registerCacheClientImports: (dependencies: Record<string, UIDLDependency>, folderPath: string[] | undefined) => void;
|
|
15
|
+
/**
|
|
16
|
+
* The terminal `.then` of a cached fetch: record the version the server
|
|
17
|
+
* answered with (which purges the scope if it moved) and store the rows.
|
|
18
|
+
*
|
|
19
|
+
* `tqCacheSet` returns the value it was given, so the promise still resolves to
|
|
20
|
+
* exactly what the uncached chain resolved to — `response?.data`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const buildCacheStoreThen: (cache: ResolvedDataSourceCache) => types.ArrowFunctionExpression;
|
|
23
|
+
/** Wraps a network chain in the peek preamble, producing the cached body. */
|
|
24
|
+
export declare const buildCachedFetchBody: (networkChain: types.Expression, cache: ResolvedDataSourceCache) => types.BlockStatement;
|
|
25
|
+
/**
|
|
26
|
+
* Finds the `return <fetch(...)…>` statement inside a cached `fetchData` body.
|
|
27
|
+
*
|
|
28
|
+
* Shared with `loading-state` so both modules agree on what "the network chain"
|
|
29
|
+
* means: the body also contains an early `return Promise.resolve(hit)`, and
|
|
30
|
+
* attaching in-flight bookkeeping to THAT would flip the loading flag on every
|
|
31
|
+
* cache hit — the exact flash this feature exists to remove.
|
|
32
|
+
*/
|
|
33
|
+
export declare const findCachedFetchNetworkChain: (body: types.BlockStatement) => {
|
|
34
|
+
statement: types.ReturnStatement;
|
|
35
|
+
index: number;
|
|
36
|
+
} | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Hoists a cached provider's `params` into a component const and adds the
|
|
39
|
+
* synchronous cache peek beside it.
|
|
40
|
+
*
|
|
41
|
+
* The peek is what removes the loading flash on a page or search change: those
|
|
42
|
+
* change the provider's `key`, so it REMOUNTS with `data: undefined` and paints
|
|
43
|
+
* `renderLoading()` before any promise — even an already-resolved one — can
|
|
44
|
+
* resume. Feeding a hit into `initialData` makes the provider skip its first
|
|
45
|
+
* fetch entirely and paint the cached rows on the very first frame.
|
|
46
|
+
*
|
|
47
|
+
* `sticky` is set because this value is handed to a mounted provider: once it
|
|
48
|
+
* has been, TTL expiry must not flip it back to `undefined`, or the list would
|
|
49
|
+
* blank out without refetching (its `params` never changed).
|
|
50
|
+
*
|
|
51
|
+
* Reference identity comes from the runtime's own map, not from this `useMemo`
|
|
52
|
+
* — the memo only keeps the peek from re-running on unrelated renders.
|
|
53
|
+
*/
|
|
54
|
+
export declare const buildCachedParamsDeclarations: (params: {
|
|
55
|
+
index: number;
|
|
56
|
+
paramsMemo: types.Expression;
|
|
57
|
+
cache: ResolvedDataSourceCache;
|
|
58
|
+
}) => {
|
|
59
|
+
declarations: types.Statement[];
|
|
60
|
+
paramsIdentifier: string;
|
|
61
|
+
cachedIdentifier: string;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* `useEffect(() => { tqMarkHydrated(); tqCacheRevalidate([...]) }, [])`
|
|
65
|
+
*
|
|
66
|
+
* One effect per page, covering every scope on it in a single request. Flipping
|
|
67
|
+
* the hydration latch here rather than at import time is what keeps the first
|
|
68
|
+
* client render byte-identical to the server render.
|
|
69
|
+
*/
|
|
70
|
+
export declare const buildCacheHydrationEffect: (scopes: string[]) => types.Statement;
|
|
71
|
+
//# sourceMappingURL=ast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../../src/cache/ast.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAEjD,yEAAyE;AACzE,eAAO,MAAM,oBAAoB,UAOhC,CAAA;AAMD,eAAO,MAAM,iBAAiB,UAAW,MAAM,KAAG,MAA8B,CAAA;AAEhF;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,iBACvB,OAAO,MAAM,EAAE,cAAc,CAAC,cAChC,MAAM,EAAE,GAAG,SAAS,KAC/B,IAaF,CAAA;AAyCD;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,UACvB,uBAAuB,KAC7B,MAAM,uBAkCR,CAAA;AAED,6EAA6E;AAC7E,eAAO,MAAM,oBAAoB,iBACjB,MAAM,UAAU,SACvB,uBAAuB,KAC7B,MAAM,cAIL,CAAA;AAEJ;;;;;;;GAOG;AACH,eAAO,MAAM,2BAA2B,SAChC,MAAM,cAAc,KACzB;IAAE,SAAS,EAAE,MAAM,eAAe,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,SAcxD,CAAA;AAkBD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,6BAA6B,WAAY;IACpD,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,UAAU,CAAA;IAC5B,KAAK,EAAE,uBAAuB,CAAA;CAC/B;kBACe,MAAM,SAAS,EAAE;sBACb,MAAM;sBACN,MAAM;CAkCzB,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,WAAY,MAAM,EAAE,KAAG,MAAM,SAgBhE,CAAA"}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
26
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
27
|
+
if (ar || !(i in from)) {
|
|
28
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
29
|
+
ar[i] = from[i];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.buildCacheHydrationEffect = exports.buildCachedParamsDeclarations = exports.findCachedFetchNetworkChain = exports.buildCachedFetchBody = exports.buildCacheStoreThen = exports.registerCacheClientImports = exports.cachedValueVarFor = exports.CACHE_CLIENT_IMPORTS = void 0;
|
|
36
|
+
var types = __importStar(require("@babel/types"));
|
|
37
|
+
/** Identifiers the emitted page imports from `utils/tq-cache/client`. */
|
|
38
|
+
exports.CACHE_CLIENT_IMPORTS = [
|
|
39
|
+
'tqCacheKey',
|
|
40
|
+
'tqCacheGet',
|
|
41
|
+
'tqCacheSet',
|
|
42
|
+
'tqCacheSetVersion',
|
|
43
|
+
'tqMarkHydrated',
|
|
44
|
+
'tqCacheRevalidate',
|
|
45
|
+
];
|
|
46
|
+
/** Local identifiers used inside the generated `fetchData` body. */
|
|
47
|
+
var KEY_VAR = '__tqKey';
|
|
48
|
+
var HIT_VAR = '__tqHit';
|
|
49
|
+
var cachedValueVarFor = function (index) { return "ds_".concat(index, "_cached"); };
|
|
50
|
+
exports.cachedValueVarFor = cachedValueVarFor;
|
|
51
|
+
/**
|
|
52
|
+
* Registers the client runtime's named imports on the page.
|
|
53
|
+
*
|
|
54
|
+
* Each identifier is its own dependency entry because that is how the
|
|
55
|
+
* import-statements plugin keys them; they share one path, so they collapse
|
|
56
|
+
* into a single `import { … } from '…/utils/tq-cache/client'`.
|
|
57
|
+
*/
|
|
58
|
+
var registerCacheClientImports = function (dependencies, folderPath) {
|
|
59
|
+
var depth = (folderPath ? folderPath.length : 0) + 1;
|
|
60
|
+
var path = "".concat('../'.repeat(depth), "utils/tq-cache/client");
|
|
61
|
+
exports.CACHE_CLIENT_IMPORTS.forEach(function (identifier) {
|
|
62
|
+
if (!dependencies[identifier]) {
|
|
63
|
+
dependencies[identifier] = {
|
|
64
|
+
type: 'local',
|
|
65
|
+
path: path,
|
|
66
|
+
meta: { namedImport: true },
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
exports.registerCacheClientImports = registerCacheClientImports;
|
|
72
|
+
/**
|
|
73
|
+
* `const __tqKey = tqCacheKey(params)` +
|
|
74
|
+
* `const __tqHit = tqCacheGet(SCOPE, __tqKey)` +
|
|
75
|
+
* `if (__tqHit !== undefined) return Promise.resolve(__tqHit)`
|
|
76
|
+
*
|
|
77
|
+
* The early return is what keeps a hit from ever touching the network — and,
|
|
78
|
+
* just as importantly, from raising the in-flight flag that would paint the
|
|
79
|
+
* loading slot. `loading-state` deliberately attaches its bookkeeping to the
|
|
80
|
+
* network chain BELOW this, never to the `Promise.resolve`.
|
|
81
|
+
*/
|
|
82
|
+
var buildCachePeekPreamble = function (scope) { return [
|
|
83
|
+
types.variableDeclaration('const', [
|
|
84
|
+
types.variableDeclarator(types.identifier(KEY_VAR), types.callExpression(types.identifier('tqCacheKey'), [types.identifier('params')])),
|
|
85
|
+
]),
|
|
86
|
+
types.variableDeclaration('const', [
|
|
87
|
+
types.variableDeclarator(types.identifier(HIT_VAR), types.callExpression(types.identifier('tqCacheGet'), [
|
|
88
|
+
types.stringLiteral(scope),
|
|
89
|
+
types.identifier(KEY_VAR),
|
|
90
|
+
])),
|
|
91
|
+
]),
|
|
92
|
+
types.ifStatement(types.binaryExpression('!==', types.identifier(HIT_VAR), types.identifier('undefined')), types.blockStatement([
|
|
93
|
+
types.returnStatement(types.callExpression(types.memberExpression(types.identifier('Promise'), types.identifier('resolve')), [types.identifier(HIT_VAR)])),
|
|
94
|
+
])),
|
|
95
|
+
]; };
|
|
96
|
+
/**
|
|
97
|
+
* The terminal `.then` of a cached fetch: record the version the server
|
|
98
|
+
* answered with (which purges the scope if it moved) and store the rows.
|
|
99
|
+
*
|
|
100
|
+
* `tqCacheSet` returns the value it was given, so the promise still resolves to
|
|
101
|
+
* exactly what the uncached chain resolved to — `response?.data`.
|
|
102
|
+
*/
|
|
103
|
+
var buildCacheStoreThen = function (cache) {
|
|
104
|
+
var responseData = types.optionalMemberExpression(types.identifier('response'), types.identifier('data'), false, true);
|
|
105
|
+
var responseVersion = types.optionalMemberExpression(types.identifier('response'), types.identifier('version'), false, true);
|
|
106
|
+
return types.arrowFunctionExpression([types.identifier('response')], types.blockStatement([
|
|
107
|
+
types.expressionStatement(types.callExpression(types.identifier('tqCacheSetVersion'), [
|
|
108
|
+
types.stringLiteral(cache.scope),
|
|
109
|
+
types.cloneNode(responseVersion, true),
|
|
110
|
+
])),
|
|
111
|
+
types.returnStatement(types.callExpression(types.identifier('tqCacheSet'), [
|
|
112
|
+
types.stringLiteral(cache.scope),
|
|
113
|
+
types.identifier(KEY_VAR),
|
|
114
|
+
responseData,
|
|
115
|
+
types.numericLiteral(cache.ttlSeconds),
|
|
116
|
+
types.cloneNode(responseVersion, true),
|
|
117
|
+
])),
|
|
118
|
+
]));
|
|
119
|
+
};
|
|
120
|
+
exports.buildCacheStoreThen = buildCacheStoreThen;
|
|
121
|
+
/** Wraps a network chain in the peek preamble, producing the cached body. */
|
|
122
|
+
var buildCachedFetchBody = function (networkChain, cache) {
|
|
123
|
+
return types.blockStatement(__spreadArray(__spreadArray([], buildCachePeekPreamble(cache.scope), true), [
|
|
124
|
+
types.returnStatement(networkChain),
|
|
125
|
+
], false));
|
|
126
|
+
};
|
|
127
|
+
exports.buildCachedFetchBody = buildCachedFetchBody;
|
|
128
|
+
/**
|
|
129
|
+
* Finds the `return <fetch(...)…>` statement inside a cached `fetchData` body.
|
|
130
|
+
*
|
|
131
|
+
* Shared with `loading-state` so both modules agree on what "the network chain"
|
|
132
|
+
* means: the body also contains an early `return Promise.resolve(hit)`, and
|
|
133
|
+
* attaching in-flight bookkeeping to THAT would flip the loading flag on every
|
|
134
|
+
* cache hit — the exact flash this feature exists to remove.
|
|
135
|
+
*/
|
|
136
|
+
var findCachedFetchNetworkChain = function (body) {
|
|
137
|
+
for (var index = body.body.length - 1; index >= 0; index--) {
|
|
138
|
+
var statement = body.body[index];
|
|
139
|
+
if (statement.type !== 'ReturnStatement' || !statement.argument) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (statement.argument.type === 'CallExpression' &&
|
|
143
|
+
callChainStartsWithFetch(statement.argument)) {
|
|
144
|
+
return { statement: statement, index: index };
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return undefined;
|
|
148
|
+
};
|
|
149
|
+
exports.findCachedFetchNetworkChain = findCachedFetchNetworkChain;
|
|
150
|
+
var callChainStartsWithFetch = function (expression) {
|
|
151
|
+
var current = expression;
|
|
152
|
+
while (current.type === 'CallExpression') {
|
|
153
|
+
var callee = current.callee;
|
|
154
|
+
if (callee.type === 'Identifier' && callee.name === 'fetch') {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
if (callee.type === 'MemberExpression') {
|
|
158
|
+
current = callee.object;
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Hoists a cached provider's `params` into a component const and adds the
|
|
167
|
+
* synchronous cache peek beside it.
|
|
168
|
+
*
|
|
169
|
+
* The peek is what removes the loading flash on a page or search change: those
|
|
170
|
+
* change the provider's `key`, so it REMOUNTS with `data: undefined` and paints
|
|
171
|
+
* `renderLoading()` before any promise — even an already-resolved one — can
|
|
172
|
+
* resume. Feeding a hit into `initialData` makes the provider skip its first
|
|
173
|
+
* fetch entirely and paint the cached rows on the very first frame.
|
|
174
|
+
*
|
|
175
|
+
* `sticky` is set because this value is handed to a mounted provider: once it
|
|
176
|
+
* has been, TTL expiry must not flip it back to `undefined`, or the list would
|
|
177
|
+
* blank out without refetching (its `params` never changed).
|
|
178
|
+
*
|
|
179
|
+
* Reference identity comes from the runtime's own map, not from this `useMemo`
|
|
180
|
+
* — the memo only keeps the peek from re-running on unrelated renders.
|
|
181
|
+
*/
|
|
182
|
+
var buildCachedParamsDeclarations = function (params) {
|
|
183
|
+
var paramsIdentifier = "ds_".concat(params.index, "_params");
|
|
184
|
+
var cachedIdentifier = (0, exports.cachedValueVarFor)(params.index);
|
|
185
|
+
return {
|
|
186
|
+
paramsIdentifier: paramsIdentifier,
|
|
187
|
+
cachedIdentifier: cachedIdentifier,
|
|
188
|
+
declarations: [
|
|
189
|
+
types.variableDeclaration('const', [
|
|
190
|
+
types.variableDeclarator(types.identifier(paramsIdentifier), params.paramsMemo),
|
|
191
|
+
]),
|
|
192
|
+
types.variableDeclaration('const', [
|
|
193
|
+
types.variableDeclarator(types.identifier(cachedIdentifier), types.callExpression(types.identifier('useMemo'), [
|
|
194
|
+
types.arrowFunctionExpression([], types.callExpression(types.identifier('tqCacheGet'), [
|
|
195
|
+
types.stringLiteral(params.cache.scope),
|
|
196
|
+
types.callExpression(types.identifier('tqCacheKey'), [
|
|
197
|
+
types.identifier(paramsIdentifier),
|
|
198
|
+
]),
|
|
199
|
+
types.objectExpression([
|
|
200
|
+
types.objectProperty(types.identifier('sticky'), types.booleanLiteral(true)),
|
|
201
|
+
]),
|
|
202
|
+
])),
|
|
203
|
+
types.arrayExpression([types.identifier(paramsIdentifier)]),
|
|
204
|
+
])),
|
|
205
|
+
]),
|
|
206
|
+
],
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
exports.buildCachedParamsDeclarations = buildCachedParamsDeclarations;
|
|
210
|
+
/**
|
|
211
|
+
* `useEffect(() => { tqMarkHydrated(); tqCacheRevalidate([...]) }, [])`
|
|
212
|
+
*
|
|
213
|
+
* One effect per page, covering every scope on it in a single request. Flipping
|
|
214
|
+
* the hydration latch here rather than at import time is what keeps the first
|
|
215
|
+
* client render byte-identical to the server render.
|
|
216
|
+
*/
|
|
217
|
+
var buildCacheHydrationEffect = function (scopes) {
|
|
218
|
+
return types.expressionStatement(types.callExpression(types.identifier('useEffect'), [
|
|
219
|
+
types.arrowFunctionExpression([], types.blockStatement([
|
|
220
|
+
types.expressionStatement(types.callExpression(types.identifier('tqMarkHydrated'), [])),
|
|
221
|
+
types.expressionStatement(types.callExpression(types.identifier('tqCacheRevalidate'), [
|
|
222
|
+
types.arrayExpression(scopes.map(function (scope) { return types.stringLiteral(scope); })),
|
|
223
|
+
])),
|
|
224
|
+
])),
|
|
225
|
+
types.arrayExpression([]),
|
|
226
|
+
]));
|
|
227
|
+
};
|
|
228
|
+
exports.buildCacheHydrationEffect = buildCacheHydrationEffect;
|
|
229
|
+
//# sourceMappingURL=ast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.js","sourceRoot":"","sources":["../../../src/cache/ast.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAqC;AAIrC,yEAAyE;AAC5D,QAAA,oBAAoB,GAAG;IAClC,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,mBAAmB;IACnB,gBAAgB;IAChB,mBAAmB;CACpB,CAAA;AAED,oEAAoE;AACpE,IAAM,OAAO,GAAG,SAAS,CAAA;AACzB,IAAM,OAAO,GAAG,SAAS,CAAA;AAElB,IAAM,iBAAiB,GAAG,UAAC,KAAa,IAAa,OAAA,aAAM,KAAK,YAAS,EAApB,CAAoB,CAAA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BnC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { UIDLDataCacheConfig } from '@teleporthq/teleport-types';
|
|
2
|
+
import { DataSourceServerCacheOptions, ResolvedDataSourceCache } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Reads the `cache` block off a `cms-list-repeater`.
|
|
5
|
+
*
|
|
6
|
+
* Returns `undefined` — meaning "emit exactly what this generator emitted
|
|
7
|
+
* before caching existed" — for anything that is off, incomplete, or caches
|
|
8
|
+
* into neither layer.
|
|
9
|
+
*/
|
|
10
|
+
export declare const resolveCacheFromRepeaterContent: (cache: UIDLDataCacheConfig | undefined, resourceDefinition: {
|
|
11
|
+
dataSourceId?: string;
|
|
12
|
+
tableName?: string;
|
|
13
|
+
} | undefined) => ResolvedDataSourceCache | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Folds several mappers' requests for the same generated file into one.
|
|
16
|
+
*
|
|
17
|
+
* Enabled if ANY mapper wants it, but with the SHORTEST requested TTL and the
|
|
18
|
+
* shortest shared-cache window — a mapper that asked for fresher data must
|
|
19
|
+
* never be made staler by a sibling that asked for less.
|
|
20
|
+
*/
|
|
21
|
+
export declare const mergeServerCacheOptions: (entries: DataSourceServerCacheOptions[]) => DataSourceServerCacheOptions | undefined;
|
|
22
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/cache/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAChE,OAAO,EAAE,4BAA4B,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAE/E;;;;;;GAMG;AACH,eAAO,MAAM,+BAA+B,UACnC,mBAAmB,GAAG,SAAS,sBAClB;IAAE,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,KAC5E,uBAAuB,GAAG,SAoC5B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,YACzB,4BAA4B,EAAE,KACtC,4BAA4B,GAAG,SAiBjC,CAAA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mergeServerCacheOptions = exports.resolveCacheFromRepeaterContent = void 0;
|
|
4
|
+
var teleport_shared_1 = require("@teleporthq/teleport-shared");
|
|
5
|
+
/**
|
|
6
|
+
* Reads the `cache` block off a `cms-list-repeater`.
|
|
7
|
+
*
|
|
8
|
+
* Returns `undefined` — meaning "emit exactly what this generator emitted
|
|
9
|
+
* before caching existed" — for anything that is off, incomplete, or caches
|
|
10
|
+
* into neither layer.
|
|
11
|
+
*/
|
|
12
|
+
var resolveCacheFromRepeaterContent = function (cache, resourceDefinition) {
|
|
13
|
+
if (!cache || cache.enabled !== true) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
var client = cache.client === true;
|
|
17
|
+
var server = cache.server === true;
|
|
18
|
+
if (!client && !server) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
var scope = cache.versionScope ||
|
|
22
|
+
((resourceDefinition === null || resourceDefinition === void 0 ? void 0 : resourceDefinition.dataSourceId) && (resourceDefinition === null || resourceDefinition === void 0 ? void 0 : resourceDefinition.tableName)
|
|
23
|
+
? teleport_shared_1.DataCache.cacheScopeFor(resourceDefinition.dataSourceId, resourceDefinition.tableName)
|
|
24
|
+
: '');
|
|
25
|
+
if (!scope) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
var ttlSeconds = typeof cache.ttlSeconds === 'number' && cache.ttlSeconds > 0
|
|
29
|
+
? Math.trunc(cache.ttlSeconds)
|
|
30
|
+
: teleport_shared_1.DataCache.DEFAULT_CACHE_TTL_SECONDS;
|
|
31
|
+
return {
|
|
32
|
+
scope: scope,
|
|
33
|
+
ttlSeconds: ttlSeconds,
|
|
34
|
+
client: client,
|
|
35
|
+
server: server,
|
|
36
|
+
sMaxAge: typeof cache.cdnSMaxAge === 'number' && cache.cdnSMaxAge > 0 ? cache.cdnSMaxAge : 0,
|
|
37
|
+
staleWhileRevalidate: typeof cache.cdnStaleWhileRevalidate === 'number' && cache.cdnStaleWhileRevalidate > 0
|
|
38
|
+
? cache.cdnStaleWhileRevalidate
|
|
39
|
+
: undefined,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
exports.resolveCacheFromRepeaterContent = resolveCacheFromRepeaterContent;
|
|
43
|
+
/**
|
|
44
|
+
* Folds several mappers' requests for the same generated file into one.
|
|
45
|
+
*
|
|
46
|
+
* Enabled if ANY mapper wants it, but with the SHORTEST requested TTL and the
|
|
47
|
+
* shortest shared-cache window — a mapper that asked for fresher data must
|
|
48
|
+
* never be made staler by a sibling that asked for less.
|
|
49
|
+
*/
|
|
50
|
+
var mergeServerCacheOptions = function (entries) {
|
|
51
|
+
var enabled = entries.filter(function (entry) { return entry.ttlSeconds > 0 || (entry.sMaxAge || 0) > 0; });
|
|
52
|
+
if (!enabled.length) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
var positive = function (values) { return values.filter(function (value) { return value > 0; }); };
|
|
56
|
+
var ttls = positive(enabled.map(function (entry) { return entry.ttlSeconds; }));
|
|
57
|
+
var sMaxAges = positive(enabled.map(function (entry) { return entry.sMaxAge || 0; }));
|
|
58
|
+
var swrs = positive(enabled.map(function (entry) { return entry.staleWhileRevalidate || 0; }));
|
|
59
|
+
return {
|
|
60
|
+
scope: enabled[0].scope,
|
|
61
|
+
ttlSeconds: ttls.length ? Math.min.apply(Math, ttls) : 0,
|
|
62
|
+
sMaxAge: sMaxAges.length ? Math.min.apply(Math, sMaxAges) : 0,
|
|
63
|
+
staleWhileRevalidate: swrs.length ? Math.min.apply(Math, swrs) : undefined,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
exports.mergeServerCacheOptions = mergeServerCacheOptions;
|
|
67
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/cache/config.ts"],"names":[],"mappings":";;;AAAA,+DAAuD;AAIvD;;;;;;GAMG;AACI,IAAM,+BAA+B,GAAG,UAC7C,KAAsC,EACtC,kBAA6E;IAE7E,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,KAAK,IAAI,EAAE;QACpC,OAAO,SAAS,CAAA;KACjB;IAED,IAAM,MAAM,GAAG,KAAK,CAAC,MAAM,KAAK,IAAI,CAAA;IACpC,IAAM,MAAM,GAAG,KAAK,CAAC,MAAM,KAAK,IAAI,CAAA;IACpC,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE;QACtB,OAAO,SAAS,CAAA;KACjB;IAED,IAAM,KAAK,GACT,KAAK,CAAC,YAAY;QAClB,CAAC,CAAA,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAE,YAAY,MAAI,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAE,SAAS,CAAA;YAChE,CAAC,CAAC,2BAAS,CAAC,aAAa,CAAC,kBAAkB,CAAC,YAAY,EAAE,kBAAkB,CAAC,SAAS,CAAC;YACxF,CAAC,CAAC,EAAE,CAAC,CAAA;IACT,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,SAAS,CAAA;KACjB;IAED,IAAM,UAAU,GACd,OAAO,KAAK,CAAC,UAAU,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,GAAG,CAAC;QAC1D,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC;QAC9B,CAAC,CAAC,2BAAS,CAAC,yBAAyB,CAAA;IAEzC,OAAO;QACL,KAAK,OAAA;QACL,UAAU,YAAA;QACV,MAAM,QAAA;QACN,MAAM,QAAA;QACN,OAAO,EAAE,OAAO,KAAK,CAAC,UAAU,KA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AC,CAAA;IAE9E,OAAO;QACL,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK;QACvB,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,OAAR,IAAI,EAAQ,IAAI,EAAE,CAAC,CAAC,CAAC;QAC/C,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,OAAR,IAAI,EAAQ,QAAQ,EAAE,CAAC,CAAC,CAAC;QACpD,oBAAoB,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,OAAR,IAAI,EAAQ,IAAI,EAAE,CAAC,CAAC,SAAS;KAClE,CAAA;AACH,CAAC,CAAA;AAnBY,QAAA,uBAAuB,2BAmBnC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A mapper's caching setup once the UIDL has been read and the defaults filled
|
|
3
|
+
* in. `client` and `server` are independent — both layers may run at once.
|
|
4
|
+
*/
|
|
5
|
+
export interface ResolvedDataSourceCache {
|
|
6
|
+
scope: string;
|
|
7
|
+
ttlSeconds: number;
|
|
8
|
+
client: boolean;
|
|
9
|
+
server: boolean;
|
|
10
|
+
/** `Cache-Control: s-maxage`. Zero unless a shared window was granted. */
|
|
11
|
+
sMaxAge: number;
|
|
12
|
+
staleWhileRevalidate?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Cache configuration as it reaches the emitters.
|
|
16
|
+
*
|
|
17
|
+
* Resolved per generated data-source FILE, not per array mapper: the
|
|
18
|
+
* `utils/data-sources/<file>.js` module is shared by every mapper reading the
|
|
19
|
+
* same `(type, table, dataSourceId)` triple, so two mappers on two pages must
|
|
20
|
+
* agree on one server-side setup. See `mergeServerCacheOptions`.
|
|
21
|
+
*/
|
|
22
|
+
export interface DataSourceServerCacheOptions {
|
|
23
|
+
/** `<dataSourceId>:<tableName>` — the unit of invalidation. */
|
|
24
|
+
scope: string;
|
|
25
|
+
/** In-process TTL, seconds. `0` disables the server cache. */
|
|
26
|
+
ttlSeconds: number;
|
|
27
|
+
/** `Cache-Control: s-maxage`, seconds. `0` keeps the response private. */
|
|
28
|
+
sMaxAge?: number;
|
|
29
|
+
staleWhileRevalidate?: number;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/cache/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,OAAO,CAAA;IACf,MAAM,EAAE,OAAO,CAAA;IACf,0EAA0E;IAC1E,OAAO,EAAE,MAAM,CAAA;IACf,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC9B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,4BAA4B;IAC3C,+DAA+D;IAC/D,KAAK,EAAE,MAAM,CAAA;IACb,8DAA8D;IAC9D,UAAU,EAAE,MAAM,CAAA;IAClB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/cache/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { DataSourceType, UIDLDataSource
|
|
1
|
+
import { DataSourceType, UIDLDataSource } from '@teleporthq/teleport-types';
|
|
2
2
|
import { generateRawQueryFetcher, parseQueryTemplateVariables } from './fetchers';
|
|
3
|
+
import type { EcommerceProductTransformOptions } from './transformations';
|
|
4
|
+
import type { DataSourceServerCacheOptions } from './cache/types';
|
|
3
5
|
export { generateRawQueryFetcher, parseQueryTemplateVariables };
|
|
4
6
|
interface DataSourceFetcherDependencies {
|
|
5
7
|
packages: string[];
|
|
@@ -7,10 +9,10 @@ interface DataSourceFetcherDependencies {
|
|
|
7
9
|
}
|
|
8
10
|
export declare const isSupabaseConnectionStringFallback: (config: Record<string, unknown>) => boolean;
|
|
9
11
|
export declare const getDataSourceDependencies: (type: DataSourceType, config?: Record<string, unknown>) => DataSourceFetcherDependencies;
|
|
10
|
-
export declare function generateDataSourceFetcher(dataSource: UIDLDataSource, tableName: string,
|
|
12
|
+
export declare function generateDataSourceFetcher(dataSource: UIDLDataSource, tableName: string, transformOptions?: EcommerceProductTransformOptions): string;
|
|
11
13
|
/**
|
|
12
14
|
* Generates a fetcher with both a core fetchData function (for server-side use in getStaticProps)
|
|
13
15
|
* and an API handler (for client-side use)
|
|
14
16
|
*/
|
|
15
|
-
export declare function generateDataSourceFetcherWithCore(dataSource: UIDLDataSource, tableName: string, isApiRoute?: boolean,
|
|
17
|
+
export declare function generateDataSourceFetcherWithCore(dataSource: UIDLDataSource, tableName: string, isApiRoute?: boolean, transformOptions?: EcommerceProductTransformOptions, cacheOptions?: DataSourceServerCacheOptions): string;
|
|
16
18
|
//# sourceMappingURL=data-source-fetchers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-source-fetchers.d.ts","sourceRoot":"","sources":["../../src/data-source-fetchers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"data-source-fetchers.d.ts","sourceRoot":"","sources":["../../src/data-source-fetchers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3E,OAAO,EA6BL,uBAAuB,EACvB,2BAA2B,EAC5B,MAAM,YAAY,CAAA;AAGnB,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,mBAAmB,CAAA;AAEzE,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAA;AAEjE,OAAO,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,CAAA;AAE/D,UAAU,6BAA6B;IACrC,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED,eAAO,MAAM,kCAAkC,WAAY,OAAO,MAAM,EAAE,OAAO,CAAC,KAAG,OAEpF,CAAA;AAED,eAAO,MAAM,yBAAyB,SAC9B,cAAc,WACX,OAAO,MAAM,EAAE,OAAO,CAAC,KAC/B,6BA4BF,CAAA;AAED,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,cAAc,EAC1B,SAAS,EAAE,MAAM,EACjB,gBAAgB,GAAE,gCAAqC,GACtD,MAAM,CAsKR;AAED;;;GAGG;AACH,wBAAgB,iCAAiC,CAC/C,UAAU,EAAE,cAAc,EAC1B,SAAS,EAAE,MAAM,EACjB,UAAU,GAAE,OAAe,EAC3B,gBAAgB,GAAE,gCAAqC,EACvD,YAAY,CAAC,EAAE,4BAA4B,GAC1C,MAAM,CAqJR"}
|
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "generateRawQueryFetcher", { enumerable: true, ge
|
|
|
15
15
|
Object.defineProperty(exports, "parseQueryTemplateVariables", { enumerable: true, get: function () { return fetchers_1.parseQueryTemplateVariables; } });
|
|
16
16
|
var validation_1 = require("./validation");
|
|
17
17
|
var count_fetchers_1 = require("./count-fetchers");
|
|
18
|
+
var teleport_shared_1 = require("@teleporthq/teleport-shared");
|
|
18
19
|
var isSupabaseConnectionStringFallback = function (config) {
|
|
19
20
|
return !!(config === null || config === void 0 ? void 0 : config.connectionString) && !(config === null || config === void 0 ? void 0 : config.supabaseUrl);
|
|
20
21
|
};
|
|
@@ -47,7 +48,8 @@ var getDataSourceDependencies = function (type, config) {
|
|
|
47
48
|
return dependencyMap[type];
|
|
48
49
|
};
|
|
49
50
|
exports.getDataSourceDependencies = getDataSourceDependencies;
|
|
50
|
-
function generateDataSourceFetcher(dataSource, tableName,
|
|
51
|
+
function generateDataSourceFetcher(dataSource, tableName, transformOptions) {
|
|
52
|
+
if (transformOptions === void 0) { transformOptions = {}; }
|
|
51
53
|
if (!dataSource || typeof dataSource !== 'object') {
|
|
52
54
|
throw new Error('Invalid data source: data source must be a valid object');
|
|
53
55
|
}
|
|
@@ -180,7 +182,7 @@ function generateDataSourceFetcher(dataSource, tableName, categories) {
|
|
|
180
182
|
if (!validation.isValid) {
|
|
181
183
|
throw new Error("Teleport config validation failed: ".concat(validation.error));
|
|
182
184
|
}
|
|
183
|
-
return (0, fetchers_1.generateTeleportFetcher)(config, tableName,
|
|
185
|
+
return (0, fetchers_1.generateTeleportFetcher)(config, tableName, transformOptions);
|
|
184
186
|
}
|
|
185
187
|
default:
|
|
186
188
|
throw new Error("Unsupported data source type: ".concat(type));
|
|
@@ -197,9 +199,10 @@ exports.generateDataSourceFetcher = generateDataSourceFetcher;
|
|
|
197
199
|
* Generates a fetcher with both a core fetchData function (for server-side use in getStaticProps)
|
|
198
200
|
* and an API handler (for client-side use)
|
|
199
201
|
*/
|
|
200
|
-
function generateDataSourceFetcherWithCore(dataSource, tableName, isApiRoute,
|
|
202
|
+
function generateDataSourceFetcherWithCore(dataSource, tableName, isApiRoute, transformOptions, cacheOptions) {
|
|
201
203
|
if (isApiRoute === void 0) { isApiRoute = false; }
|
|
202
|
-
|
|
204
|
+
if (transformOptions === void 0) { transformOptions = {}; }
|
|
205
|
+
var apiHandler = generateDataSourceFetcher(dataSource, tableName, transformOptions);
|
|
203
206
|
// Extract the handler function body from the API route
|
|
204
207
|
// The API route is structured as: export default async function handler(req, res) { ... }
|
|
205
208
|
// We need to create a fetchData function that can be called directly
|
|
@@ -215,12 +218,52 @@ function generateDataSourceFetcherWithCore(dataSource, tableName, isApiRoute, ca
|
|
|
215
218
|
var countFetcherWithoutImports = countFetcherCode.replace(importRegex, '').trim();
|
|
216
219
|
// Combine and deduplicate imports
|
|
217
220
|
var allImports = Array.from(new Set(__spreadArray(__spreadArray([], imports, true), countImports, true)));
|
|
221
|
+
// Caching is applied HERE rather than in the API route because four separate
|
|
222
|
+
// places emit an `api/<file>` route and a fifth path (`getStaticProps` →
|
|
223
|
+
// `fetchData` → `handler`) never goes through a route at all. Wrapping the
|
|
224
|
+
// module's exports is the one point that covers all five, and leaves every
|
|
225
|
+
// route emitter untouched.
|
|
226
|
+
//
|
|
227
|
+
// The import depth differs by destination: this module is written to
|
|
228
|
+
// `utils/data-sources/` normally, but the `isApiRoute` variant is inlined
|
|
229
|
+
// straight into `pages/api/`.
|
|
230
|
+
var cachePreamble = cacheOptions
|
|
231
|
+
? "import { tqWithCache } from '".concat(isApiRoute ? '../../' : '../', "tq-cache/server'")
|
|
232
|
+
: '';
|
|
233
|
+
var cacheWiring = cacheOptions
|
|
234
|
+
? "\nconst __tqDataCache = ".concat(JSON.stringify({
|
|
235
|
+
scope: cacheOptions.scope,
|
|
236
|
+
ttl: cacheOptions.ttlSeconds,
|
|
237
|
+
sMaxAge: cacheOptions.sMaxAge || 0,
|
|
238
|
+
swr: cacheOptions.staleWhileRevalidate || 0,
|
|
239
|
+
}), "\nconst __tqCountCache = ").concat(JSON.stringify({
|
|
240
|
+
scope: teleport_shared_1.DataCache.countScopeFor(cacheOptions.scope),
|
|
241
|
+
// Its OWN keyspace, but the DATA scope's version row. A write bumps one
|
|
242
|
+
// row; if the count kept a separate version nothing would ever bump it,
|
|
243
|
+
// and the total would stay stale after every create and delete — the
|
|
244
|
+
// grid showing one more row than the pager counts.
|
|
245
|
+
versionScope: cacheOptions.scope,
|
|
246
|
+
ttl: cacheOptions.ttlSeconds,
|
|
247
|
+
sMaxAge: cacheOptions.sMaxAge || 0,
|
|
248
|
+
swr: cacheOptions.staleWhileRevalidate || 0,
|
|
249
|
+
}), "\n\nconst cachedHandler = tqWithCache(handler, __tqDataCache)\nconst cachedGetCount = tqWithCache(getCount, __tqCountCache)\n")
|
|
250
|
+
: '';
|
|
251
|
+
var handlerExport = cacheOptions ? 'cachedHandler' : 'handler';
|
|
252
|
+
var countExport = cacheOptions ? 'cachedGetCount' : 'getCount';
|
|
218
253
|
// For API routes, export just the handler function
|
|
219
254
|
// For utils files, export the full object with all functions
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
255
|
+
//
|
|
256
|
+
// The uncached branch is spelled out verbatim rather than interpolated, so an
|
|
257
|
+
// uncached project keeps generating byte-identical output — `handler as
|
|
258
|
+
// handler` would be harmless at runtime and still a diff in every snapshot.
|
|
259
|
+
var exports = !cacheOptions
|
|
260
|
+
? isApiRoute
|
|
261
|
+
? 'export default handler'
|
|
262
|
+
: "export { fetchData, fetchCount, handler, getCount }\nexport default { fetchData, fetchCount, handler, getCount }"
|
|
263
|
+
: isApiRoute
|
|
264
|
+
? "export default ".concat(handlerExport)
|
|
265
|
+
: "export { fetchData, fetchCount, ".concat(handlerExport, " as handler, ").concat(countExport, " as getCount }\nexport default { fetchData, fetchCount, handler: ").concat(handlerExport, ", getCount: ").concat(countExport, " }");
|
|
266
|
+
return "".concat(__spreadArray(__spreadArray([], allImports, true), [cachePreamble], false).filter(Boolean).join('\n'), "\n\nasync function fetchData(params = {}) {\n const req = {\n query: params,\n method: 'GET',\n }\n \n let result = null\n let statusCode = 200\n \n const res = {\n status: (code) => {\n statusCode = code\n return res\n },\n json: (data) => {\n result = data\n return res\n },\n }\n \n await ").concat(handlerExport, "(req, res)\n \n if (statusCode !== 200 || !result || !result.success) {\n throw new Error(result?.error || 'Failed to fetch data')\n }\n \n return result.data\n}\n\nasync function fetchCount(params = {}) {\n const req = {\n query: params,\n method: 'GET',\n }\n \n let result = null\n let statusCode = 200\n \n const res = {\n status: (code) => {\n statusCode = code\n return res\n },\n json: (data) => {\n result = data\n return res\n },\n }\n \n await ").concat(countExport, "(req, res)\n \n if (statusCode !== 200 || !result || !result.success) {\n throw new Error(result?.error || 'Failed to get count')\n }\n \n return result.count\n}\n\n").concat(countFetcherWithoutImports, "\n\n").concat(handlerWithoutImports, "\n").concat(cacheWiring, "\n").concat(exports, "\n");
|
|
224
267
|
}
|
|
225
268
|
exports.generateDataSourceFetcherWithCore = generateDataSourceFetcherWithCore;
|
|
226
269
|
//# sourceMappingURL=data-source-fetchers.js.map
|