@enonic/nextjs-adapter 2.0.0 → 3.0.0-B2

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.
Files changed (245) hide show
  1. package/baseMappings.js +3 -2
  2. package/baseMappings.js.map +1 -0
  3. package/client.d.ts +1 -0
  4. package/client.js +3 -0
  5. package/client.js.map +1 -0
  6. package/common/ComponentRegistry.d.ts +34 -0
  7. package/{ComponentRegistry.js → common/ComponentRegistry.js} +26 -26
  8. package/common/ComponentRegistry.js.map +1 -0
  9. package/{UrlProcessor.d.ts → common/UrlProcessor.d.ts} +5 -4
  10. package/{UrlProcessor.js → common/UrlProcessor.js} +40 -17
  11. package/common/UrlProcessor.js.map +1 -0
  12. package/common/constants.d.ts +50 -0
  13. package/common/constants.js +79 -0
  14. package/common/constants.js.map +1 -0
  15. package/common/env.d.ts +11 -0
  16. package/common/env.js +28 -0
  17. package/common/env.js.map +1 -0
  18. package/guillotine/applyProcessors.d.ts +2 -0
  19. package/guillotine/applyProcessors.js +33 -0
  20. package/guillotine/applyProcessors.js.map +1 -0
  21. package/guillotine/buildComponentTree.d.ts +2 -0
  22. package/guillotine/buildComponentTree.js +45 -0
  23. package/guillotine/buildComponentTree.js.map +1 -0
  24. package/guillotine/buildErrorResponse.d.ts +3 -0
  25. package/guillotine/buildErrorResponse.js +26 -0
  26. package/guillotine/buildErrorResponse.js.map +1 -0
  27. package/guillotine/buildPage.d.ts +2 -0
  28. package/guillotine/buildPage.js +10 -0
  29. package/guillotine/buildPage.js.map +1 -0
  30. package/guillotine/collectComponentDescriptors.d.ts +6 -0
  31. package/guillotine/collectComponentDescriptors.js +43 -0
  32. package/guillotine/collectComponentDescriptors.js.map +1 -0
  33. package/guillotine/combineMultipleQueries.d.ts +2 -0
  34. package/guillotine/combineMultipleQueries.js +58 -0
  35. package/guillotine/combineMultipleQueries.js.map +1 -0
  36. package/guillotine/createMetaData.d.ts +17 -0
  37. package/guillotine/createMetaData.js +44 -0
  38. package/guillotine/createMetaData.js.map +1 -0
  39. package/guillotine/fetchContent.d.ts +1 -41
  40. package/guillotine/fetchContent.js +193 -800
  41. package/guillotine/fetchContent.js.map +1 -0
  42. package/guillotine/fetchContentData.d.ts +2 -0
  43. package/guillotine/fetchContentData.js +27 -0
  44. package/guillotine/fetchContentData.js.map +1 -0
  45. package/guillotine/fetchContentPathsForAllLocales.d.ts +2 -0
  46. package/guillotine/fetchContentPathsForAllLocales.js +21 -0
  47. package/guillotine/fetchContentPathsForAllLocales.js.map +1 -0
  48. package/guillotine/fetchContentPathsForLocale.d.ts +2 -0
  49. package/guillotine/fetchContentPathsForLocale.js +40 -0
  50. package/guillotine/fetchContentPathsForLocale.js.map +1 -0
  51. package/guillotine/fetchFromApi.d.ts +3 -0
  52. package/guillotine/fetchFromApi.js +65 -0
  53. package/guillotine/fetchFromApi.js.map +1 -0
  54. package/guillotine/fetchGuillotine.d.ts +3 -0
  55. package/guillotine/fetchGuillotine.js +55 -0
  56. package/guillotine/fetchGuillotine.js.map +1 -0
  57. package/guillotine/fetchMetaData.d.ts +2 -0
  58. package/guillotine/fetchMetaData.js +30 -0
  59. package/guillotine/fetchMetaData.js.map +1 -0
  60. package/guillotine/getCleanContentPathArrayOrThrow400.d.ts +2 -0
  61. package/guillotine/getCleanContentPathArrayOrThrow400.js +20 -0
  62. package/guillotine/getCleanContentPathArrayOrThrow400.js.map +1 -0
  63. package/guillotine/getComponentConfig.d.ts +2 -0
  64. package/guillotine/getComponentConfig.js +5 -0
  65. package/guillotine/getComponentConfig.js.map +1 -0
  66. package/guillotine/getContentAndComponentPaths.d.ts +1 -0
  67. package/guillotine/getContentAndComponentPaths.js +12 -0
  68. package/guillotine/getContentAndComponentPaths.js.map +1 -0
  69. package/guillotine/getMetaData.d.ts +0 -92
  70. package/guillotine/getMetaData.js +47 -109
  71. package/guillotine/getMetaData.js.map +1 -0
  72. package/guillotine/getParentRegion.d.ts +2 -0
  73. package/guillotine/getParentRegion.js +40 -0
  74. package/guillotine/getParentRegion.js.map +1 -0
  75. package/guillotine/getQueryAndVariables.d.ts +2 -0
  76. package/guillotine/getQueryAndVariables.js +32 -0
  77. package/guillotine/getQueryAndVariables.js.map +1 -0
  78. package/guillotine/metadata/configQuery.d.ts +2 -0
  79. package/guillotine/metadata/configQuery.js +36 -0
  80. package/guillotine/metadata/configQuery.js.map +1 -0
  81. package/guillotine/metadata/richTextQuery.d.ts +1 -0
  82. package/guillotine/metadata/richTextQuery.js +32 -0
  83. package/guillotine/metadata/richTextQuery.js.map +1 -0
  84. package/guillotine/parseComponentPath.d.ts +2 -0
  85. package/guillotine/parseComponentPath.js +22 -0
  86. package/guillotine/parseComponentPath.js.map +1 -0
  87. package/guillotine/prefixLayoutPath.d.ts +1 -0
  88. package/guillotine/prefixLayoutPath.js +13 -0
  89. package/guillotine/prefixLayoutPath.js.map +1 -0
  90. package/guillotine/processComponentConfig.d.ts +2 -0
  91. package/guillotine/processComponentConfig.js +30 -0
  92. package/guillotine/processComponentConfig.js.map +1 -0
  93. package/guillotine/restrictComponentsToPath.d.ts +2 -0
  94. package/guillotine/restrictComponentsToPath.js +35 -0
  95. package/guillotine/restrictComponentsToPath.js.map +1 -0
  96. package/guillotine/validateData.d.ts +2 -0
  97. package/guillotine/validateData.js +7 -0
  98. package/guillotine/validateData.js.map +1 -0
  99. package/guillotine/validateNotFound.d.ts +2 -0
  100. package/guillotine/validateNotFound.js +16 -0
  101. package/guillotine/validateNotFound.js.map +1 -0
  102. package/guillotine/validateShortcut.d.ts +2 -0
  103. package/guillotine/validateShortcut.js +29 -0
  104. package/guillotine/validateShortcut.js.map +1 -0
  105. package/i18n/LocaleContext.d.ts +7 -0
  106. package/i18n/LocaleContext.jsx +46 -0
  107. package/i18n/LocaleContext.jsx.map +1 -0
  108. package/i18n/i18n.d.ts +11 -0
  109. package/i18n/i18n.js +57 -0
  110. package/i18n/i18n.js.map +1 -0
  111. package/index.d.ts +18 -5
  112. package/index.js +18 -5
  113. package/index.js.map +1 -0
  114. package/package.json +67 -16
  115. package/query/Shortcut.js +1 -0
  116. package/query/Shortcut.js.map +1 -0
  117. package/types/component.d.ts +114 -0
  118. package/types/component.js +2 -0
  119. package/types/component.js.map +1 -0
  120. package/types/componentProps.d.ts +104 -0
  121. package/types/componentProps.js +2 -0
  122. package/types/componentProps.js.map +1 -0
  123. package/types/guillotine.d.ts +342 -0
  124. package/types/guillotine.js +2 -0
  125. package/types/guillotine.js.map +1 -0
  126. package/types/i18n.d.ts +7 -0
  127. package/types/i18n.js +2 -0
  128. package/types/i18n.js.map +1 -0
  129. package/types/index.d.ts +45 -0
  130. package/types/index.js +3 -0
  131. package/types/index.js.map +1 -0
  132. package/types/next.d.ts +6 -0
  133. package/types/next.js +2 -0
  134. package/types/next.js.map +1 -0
  135. package/types/util.d.ts +3 -0
  136. package/types/util.js +3 -0
  137. package/types/util.js.map +1 -0
  138. package/utils/addLineNumbers.d.ts +1 -0
  139. package/utils/addLineNumbers.js +4 -0
  140. package/utils/addLineNumbers.js.map +1 -0
  141. package/utils/buildGuillotineRequestHeaders.d.ts +7 -0
  142. package/utils/buildGuillotineRequestHeaders.js +16 -0
  143. package/utils/buildGuillotineRequestHeaders.js.map +1 -0
  144. package/utils/commonChars.d.ts +1 -0
  145. package/utils/commonChars.js +17 -0
  146. package/utils/commonChars.js.map +1 -0
  147. package/utils/fixDoubleSlashes.d.ts +1 -0
  148. package/utils/fixDoubleSlashes.js +4 -0
  149. package/utils/fixDoubleSlashes.js.map +1 -0
  150. package/utils/getContentApiUrl.d.ts +2 -0
  151. package/utils/getContentApiUrl.js +15 -0
  152. package/utils/getContentApiUrl.js.map +1 -0
  153. package/utils/getProjectLocaleConfig.d.ts +2 -0
  154. package/utils/getProjectLocaleConfig.js +19 -0
  155. package/utils/getProjectLocaleConfig.js.map +1 -0
  156. package/utils/getProjectLocaleConfigById.d.ts +2 -0
  157. package/utils/getProjectLocaleConfigById.js +16 -0
  158. package/utils/getProjectLocaleConfigById.js.map +1 -0
  159. package/utils/getProjectLocaleConfigByLocale.d.ts +2 -0
  160. package/utils/getProjectLocaleConfigByLocale.js +13 -0
  161. package/utils/getProjectLocaleConfigByLocale.js.map +1 -0
  162. package/utils/getProjectLocaleConfigs.d.ts +2 -0
  163. package/utils/getProjectLocaleConfigs.js +30 -0
  164. package/utils/getProjectLocaleConfigs.js.map +1 -0
  165. package/utils/getProjectLocales.d.ts +1 -0
  166. package/utils/getProjectLocales.js +5 -0
  167. package/utils/getProjectLocales.js.map +1 -0
  168. package/utils/getRenderMode.d.ts +3 -0
  169. package/utils/getRenderMode.js +8 -0
  170. package/utils/getRenderMode.js.map +1 -0
  171. package/utils/getRequestLocaleInfo.d.ts +6 -0
  172. package/utils/getRequestLocaleInfo.js +26 -0
  173. package/utils/getRequestLocaleInfo.js.map +1 -0
  174. package/utils/getXpBaseUrl.d.ts +2 -0
  175. package/utils/getXpBaseUrl.js +8 -0
  176. package/utils/getXpBaseUrl.js.map +1 -0
  177. package/utils/indent.d.ts +1 -0
  178. package/utils/indent.js +5 -0
  179. package/utils/indent.js.map +1 -0
  180. package/utils/sanitizeGraphqlName.d.ts +1 -0
  181. package/utils/sanitizeGraphqlName.js +12 -0
  182. package/utils/sanitizeGraphqlName.js.map +1 -0
  183. package/views/BaseComponent.d.ts +5 -10
  184. package/views/BaseComponent.jsx +17 -6
  185. package/views/BaseComponent.jsx.map +1 -0
  186. package/views/BaseContent.d.ts +3 -3
  187. package/views/BaseContent.jsx +2 -5
  188. package/views/BaseContent.jsx.map +1 -0
  189. package/views/BaseLayout.d.ts +3 -16
  190. package/views/BaseLayout.jsx +3 -3
  191. package/views/BaseLayout.jsx.map +1 -0
  192. package/views/BaseMacro.d.ts +3 -13
  193. package/views/BaseMacro.jsx +4 -3
  194. package/views/BaseMacro.jsx.map +1 -0
  195. package/views/BasePage.d.ts +3 -18
  196. package/views/BasePage.jsx +3 -3
  197. package/views/BasePage.jsx.map +1 -0
  198. package/views/BasePart.d.ts +3 -18
  199. package/views/BasePart.jsx +3 -3
  200. package/views/BasePart.jsx.map +1 -0
  201. package/views/Empty.d.ts +2 -2
  202. package/views/Empty.jsx +2 -1
  203. package/views/Empty.jsx.map +1 -0
  204. package/views/Fragment.d.ts +3 -9
  205. package/views/Fragment.jsx +2 -2
  206. package/views/Fragment.jsx.map +1 -0
  207. package/views/MainView.d.ts +3 -3
  208. package/views/MainView.jsx +2 -2
  209. package/views/MainView.jsx.map +1 -0
  210. package/views/PropsView.d.ts +3 -0
  211. package/views/PropsView.jsx +21 -0
  212. package/views/PropsView.jsx.map +1 -0
  213. package/views/Region.d.ts +4 -17
  214. package/views/Region.jsx +2 -2
  215. package/views/Region.jsx.map +1 -0
  216. package/views/RichTextView.d.ts +3 -13
  217. package/views/RichTextView.jsx +6 -3
  218. package/views/RichTextView.jsx.map +1 -0
  219. package/views/SingleComponent.d.ts +3 -3
  220. package/views/SingleComponent.jsx +1 -2
  221. package/views/SingleComponent.jsx.map +1 -0
  222. package/views/StaticContent.d.ts +2 -6
  223. package/views/StaticContent.jsx +1 -0
  224. package/views/StaticContent.jsx.map +1 -0
  225. package/views/Text.d.ts +5 -5
  226. package/views/Text.jsx +1 -1
  227. package/views/Text.jsx.map +1 -0
  228. package/views/getClientHydratedHtml.d.ts +2 -0
  229. package/views/getClientHydratedHtml.jsx +9 -0
  230. package/views/getClientHydratedHtml.jsx.map +1 -0
  231. package/views/macros/DefaultMacro.d.ts +1 -1
  232. package/views/macros/DefaultMacro.jsx +1 -0
  233. package/views/macros/DefaultMacro.jsx.map +1 -0
  234. package/views/macros/DisableMacro.d.ts +1 -1
  235. package/views/macros/DisableMacro.jsx +1 -0
  236. package/views/macros/DisableMacro.jsx.map +1 -0
  237. package/ComponentRegistry.d.ts +0 -64
  238. package/server/ClearableFileCache.d.ts +0 -31
  239. package/server/ClearableFileCache.js +0 -472
  240. package/server/cache.d.ts +0 -2
  241. package/server/cache.js +0 -129
  242. package/server/index.d.ts +0 -5
  243. package/server/index.js +0 -132
  244. package/utils.d.ts +0 -114
  245. package/utils.js +0 -241
@@ -1,472 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- var path_1 = __importDefault(require("path"));
43
- var lru_cache_1 = require("lru-cache");
44
- var utils_1 = require("next/dist/server/lib/incremental-cache/utils");
45
- var memoryCache;
46
- var tagsManifest;
47
- var FileSystemCache = /** @class */ (function () {
48
- function FileSystemCache(ctx) {
49
- this.fs = ctx.fs;
50
- this.flushToDisk = ctx.flushToDisk;
51
- this.serverDistDir = ctx.serverDistDir;
52
- this.appDir = !!ctx._appDir;
53
- this.revalidatedTags = ctx.revalidatedTags;
54
- if (ctx.maxMemoryCacheSize && !memoryCache) {
55
- memoryCache = new lru_cache_1.LRUCache({
56
- max: ctx.maxMemoryCacheSize,
57
- maxSize: 10 * ctx.maxMemoryCacheSize,
58
- sizeCalculation: function (_a) {
59
- var _b;
60
- var value = _a.value;
61
- if (!value) {
62
- return 25;
63
- }
64
- else if (value.kind === 'REDIRECT') {
65
- return JSON.stringify(value.props).length;
66
- }
67
- else if (value.kind === 'IMAGE') {
68
- throw new Error('invariant image should not be incremental-cache');
69
- }
70
- else if (value.kind === 'FETCH') {
71
- return JSON.stringify(value.data || '').length;
72
- }
73
- else if (value.kind === 'ROUTE') {
74
- return value.body.length;
75
- }
76
- // rough estimate of size of cache value
77
- return (value.html.length + (((_b = JSON.stringify(value.pageData)) === null || _b === void 0 ? void 0 : _b.length) || 0));
78
- },
79
- });
80
- }
81
- if (this.serverDistDir && this.fs) {
82
- this.tagsManifestPath = path_1.default.join(this.serverDistDir, '..', 'cache', 'fetch-cache', 'tags-manifest.json');
83
- this.loadTagsManifest();
84
- }
85
- }
86
- FileSystemCache.prototype.clear = function () {
87
- memoryCache === null || memoryCache === void 0 ? void 0 : memoryCache.clear();
88
- };
89
- FileSystemCache.prototype.delete = function (path) {
90
- return memoryCache === null || memoryCache === void 0 ? void 0 : memoryCache.delete(path);
91
- };
92
- FileSystemCache.prototype.loadTagsManifest = function () {
93
- if (!this.tagsManifestPath || !this.fs || tagsManifest)
94
- return;
95
- try {
96
- tagsManifest = JSON.parse(this.fs.readFileSync(this.tagsManifestPath).toString('utf8'));
97
- }
98
- catch (err) {
99
- tagsManifest = { version: 1, items: {} };
100
- }
101
- };
102
- FileSystemCache.prototype.setTags = function (key, tags) {
103
- return __awaiter(this, void 0, void 0, function () {
104
- var _i, tags_1, tag, data, err_1;
105
- return __generator(this, function (_a) {
106
- switch (_a.label) {
107
- case 0:
108
- this.loadTagsManifest();
109
- if (!tagsManifest || !this.tagsManifestPath) {
110
- return [2 /*return*/];
111
- }
112
- for (_i = 0, tags_1 = tags; _i < tags_1.length; _i++) {
113
- tag = tags_1[_i];
114
- data = tagsManifest.items[tag] || { keys: [] };
115
- if (!data.keys.includes(key)) {
116
- data.keys.push(key);
117
- }
118
- tagsManifest.items[tag] = data;
119
- }
120
- _a.label = 1;
121
- case 1:
122
- _a.trys.push([1, 4, , 5]);
123
- return [4 /*yield*/, this.fs.mkdir(path_1.default.dirname(this.tagsManifestPath))];
124
- case 2:
125
- _a.sent();
126
- return [4 /*yield*/, this.fs.writeFile(this.tagsManifestPath, JSON.stringify(tagsManifest || {}))];
127
- case 3:
128
- _a.sent();
129
- return [3 /*break*/, 5];
130
- case 4:
131
- err_1 = _a.sent();
132
- console.warn('Failed to update tags manifest.', err_1);
133
- return [3 /*break*/, 5];
134
- case 5: return [2 /*return*/];
135
- }
136
- });
137
- });
138
- };
139
- FileSystemCache.prototype.revalidateTag = function (tag) {
140
- return __awaiter(this, void 0, void 0, function () {
141
- var data, err_2;
142
- return __generator(this, function (_a) {
143
- switch (_a.label) {
144
- case 0:
145
- // we need to ensure the tagsManifest is refreshed
146
- // since separate workers can be updating it at the same
147
- // time and we can't flush out of sync data
148
- this.loadTagsManifest();
149
- if (!tagsManifest || !this.tagsManifestPath) {
150
- return [2 /*return*/];
151
- }
152
- data = tagsManifest.items[tag] || { keys: [] };
153
- data.revalidatedAt = Date.now();
154
- tagsManifest.items[tag] = data;
155
- _a.label = 1;
156
- case 1:
157
- _a.trys.push([1, 4, , 5]);
158
- return [4 /*yield*/, this.fs.mkdir(path_1.default.dirname(this.tagsManifestPath))];
159
- case 2:
160
- _a.sent();
161
- return [4 /*yield*/, this.fs.writeFile(this.tagsManifestPath, JSON.stringify(tagsManifest || {}))];
162
- case 3:
163
- _a.sent();
164
- return [3 /*break*/, 5];
165
- case 4:
166
- err_2 = _a.sent();
167
- console.warn('Failed to update tags manifest.', err_2);
168
- return [3 /*break*/, 5];
169
- case 5: return [2 /*return*/];
170
- }
171
- });
172
- });
173
- };
174
- FileSystemCache.prototype.get = function (key, fetchCache) {
175
- var _a, _b, _c, _d;
176
- return __awaiter(this, void 0, void 0, function () {
177
- var data, filePath, fileData, mtime, meta, _e, _f, cacheEntry, _1, _g, filePath, isAppPath, fileData, mtime, lastModified, parsedData, pageData, _h, _j, _k, _l, _m, _o, _p, meta, _q, _r, _2, _3, cacheTags, tagsHeader, derivedTags, isStale, innerData, derivedTags, wasRevalidated;
178
- var _this = this;
179
- return __generator(this, function (_s) {
180
- switch (_s.label) {
181
- case 0:
182
- data = memoryCache === null || memoryCache === void 0 ? void 0 : memoryCache.get(key);
183
- if (!(!data && process.env.NEXT_RUNTIME !== 'edge')) return [3 /*break*/, 24];
184
- _s.label = 1;
185
- case 1:
186
- _s.trys.push([1, 6, , 7]);
187
- return [4 /*yield*/, this.getFsPath({
188
- pathname: "".concat(key, ".body"),
189
- appDir: true,
190
- })];
191
- case 2:
192
- filePath = (_s.sent()).filePath;
193
- return [4 /*yield*/, this.fs.readFile(filePath)];
194
- case 3:
195
- fileData = _s.sent();
196
- return [4 /*yield*/, this.fs.stat(filePath)];
197
- case 4:
198
- mtime = (_s.sent()).mtime;
199
- _f = (_e = JSON).parse;
200
- return [4 /*yield*/, this.fs.readFile(filePath.replace(/\.body$/, '.meta'))];
201
- case 5:
202
- meta = _f.apply(_e, [(_s.sent()).toString('utf8')]);
203
- cacheEntry = {
204
- lastModified: mtime.getTime(),
205
- value: {
206
- kind: 'ROUTE',
207
- body: fileData,
208
- headers: meta.headers,
209
- status: meta.status,
210
- },
211
- };
212
- return [2 /*return*/, cacheEntry];
213
- case 6:
214
- _1 = _s.sent();
215
- return [3 /*break*/, 7];
216
- case 7:
217
- _s.trys.push([7, 23, , 24]);
218
- return [4 /*yield*/, this.getFsPath({
219
- pathname: fetchCache ? key : "".concat(key, ".html"),
220
- fetchCache: fetchCache,
221
- })];
222
- case 8:
223
- _g = _s.sent(), filePath = _g.filePath, isAppPath = _g.isAppPath;
224
- return [4 /*yield*/, this.fs.readFile(filePath)];
225
- case 9:
226
- fileData = (_s.sent()).toString('utf-8');
227
- return [4 /*yield*/, this.fs.stat(filePath)];
228
- case 10:
229
- mtime = (_s.sent()).mtime;
230
- if (!fetchCache) return [3 /*break*/, 11];
231
- lastModified = mtime.getTime();
232
- parsedData = JSON.parse(fileData);
233
- data = {
234
- lastModified: lastModified,
235
- value: parsedData,
236
- };
237
- return [3 /*break*/, 22];
238
- case 11:
239
- if (!isAppPath) return [3 /*break*/, 14];
240
- _k = (_j = this.fs).readFile;
241
- return [4 /*yield*/, this.getFsPath({
242
- pathname: "".concat(key, ".rsc"),
243
- appDir: true,
244
- })];
245
- case 12: return [4 /*yield*/, _k.apply(_j, [(_s.sent()).filePath])];
246
- case 13:
247
- _h = (_s.sent()).toString('utf8');
248
- return [3 /*break*/, 17];
249
- case 14:
250
- _m = (_l = JSON).parse;
251
- _p = (_o = this.fs).readFile;
252
- return [4 /*yield*/, this.getFsPath({
253
- pathname: "".concat(key, ".json"),
254
- appDir: false,
255
- })];
256
- case 15: return [4 /*yield*/, _p.apply(_o, [(_s.sent()).filePath])];
257
- case 16:
258
- _h = _m.apply(_l, [(_s.sent()).toString('utf8')]);
259
- _s.label = 17;
260
- case 17:
261
- pageData = _h;
262
- meta = {};
263
- if (!isAppPath) return [3 /*break*/, 21];
264
- _s.label = 18;
265
- case 18:
266
- _s.trys.push([18, 20, , 21]);
267
- _r = (_q = JSON).parse;
268
- return [4 /*yield*/, this.fs.readFile(filePath.replace(/\.html$/, '.meta'))];
269
- case 19:
270
- meta = _r.apply(_q, [(_s.sent()).toString('utf-8')]);
271
- return [3 /*break*/, 21];
272
- case 20:
273
- _2 = _s.sent();
274
- return [3 /*break*/, 21];
275
- case 21:
276
- data = {
277
- lastModified: mtime.getTime(),
278
- value: {
279
- kind: 'PAGE',
280
- html: fileData,
281
- pageData: pageData,
282
- headers: meta.headers,
283
- status: meta.status,
284
- },
285
- };
286
- _s.label = 22;
287
- case 22:
288
- if (data) {
289
- memoryCache === null || memoryCache === void 0 ? void 0 : memoryCache.set(key, data);
290
- }
291
- return [3 /*break*/, 24];
292
- case 23:
293
- _3 = _s.sent();
294
- return [3 /*break*/, 24];
295
- case 24:
296
- if (((_a = data === null || data === void 0 ? void 0 : data.value) === null || _a === void 0 ? void 0 : _a.kind) === 'PAGE') {
297
- tagsHeader = (_b = data.value.headers) === null || _b === void 0 ? void 0 : _b['x-next-cache-tags'];
298
- if (typeof tagsHeader === 'string') {
299
- cacheTags = tagsHeader.split(',');
300
- }
301
- }
302
- if (((_c = data === null || data === void 0 ? void 0 : data.value) === null || _c === void 0 ? void 0 : _c.kind) === 'PAGE' && (cacheTags === null || cacheTags === void 0 ? void 0 : cacheTags.length)) {
303
- this.loadTagsManifest();
304
- derivedTags = (0, utils_1.getDerivedTags)(cacheTags || []);
305
- isStale = derivedTags.some(function (tag) {
306
- var _a;
307
- return (((_a = tagsManifest === null || tagsManifest === void 0 ? void 0 : tagsManifest.items[tag]) === null || _a === void 0 ? void 0 : _a.revalidatedAt) &&
308
- (tagsManifest === null || tagsManifest === void 0 ? void 0 : tagsManifest.items[tag].revalidatedAt) >=
309
- ((data === null || data === void 0 ? void 0 : data.lastModified) || Date.now()));
310
- });
311
- // we trigger a blocking validation if an ISR page
312
- // had a tag revalidated, if we want to be a background
313
- // revalidation instead we return data.lastModified = -1
314
- if (isStale) {
315
- data = undefined;
316
- }
317
- }
318
- if (data && ((_d = data === null || data === void 0 ? void 0 : data.value) === null || _d === void 0 ? void 0 : _d.kind) === 'FETCH') {
319
- this.loadTagsManifest();
320
- innerData = data.value.data;
321
- derivedTags = (0, utils_1.getDerivedTags)(innerData.tags || []);
322
- wasRevalidated = derivedTags.some(function (tag) {
323
- var _a;
324
- if (_this.revalidatedTags.includes(tag)) {
325
- return true;
326
- }
327
- return (((_a = tagsManifest === null || tagsManifest === void 0 ? void 0 : tagsManifest.items[tag]) === null || _a === void 0 ? void 0 : _a.revalidatedAt) &&
328
- (tagsManifest === null || tagsManifest === void 0 ? void 0 : tagsManifest.items[tag].revalidatedAt) >=
329
- ((data === null || data === void 0 ? void 0 : data.lastModified) || Date.now()));
330
- });
331
- // When revalidate tag is called we don't return
332
- // stale data so it's updated right away
333
- if (wasRevalidated) {
334
- data = undefined;
335
- }
336
- }
337
- return [2 /*return*/, data || null];
338
- }
339
- });
340
- });
341
- };
342
- FileSystemCache.prototype.set = function (key, data) {
343
- return __awaiter(this, void 0, void 0, function () {
344
- var filePath, isAppPath, htmlPath, _a, _b, filePath;
345
- return __generator(this, function (_c) {
346
- switch (_c.label) {
347
- case 0:
348
- memoryCache === null || memoryCache === void 0 ? void 0 : memoryCache.set(key, {
349
- value: data,
350
- lastModified: Date.now(),
351
- });
352
- if (!this.flushToDisk)
353
- return [2 /*return*/];
354
- if (!((data === null || data === void 0 ? void 0 : data.kind) === 'ROUTE')) return [3 /*break*/, 5];
355
- return [4 /*yield*/, this.getFsPath({
356
- pathname: "".concat(key, ".body"),
357
- appDir: true,
358
- })];
359
- case 1:
360
- filePath = (_c.sent()).filePath;
361
- return [4 /*yield*/, this.fs.mkdir(path_1.default.dirname(filePath))];
362
- case 2:
363
- _c.sent();
364
- return [4 /*yield*/, this.fs.writeFile(filePath, data.body)];
365
- case 3:
366
- _c.sent();
367
- return [4 /*yield*/, this.fs.writeFile(filePath.replace(/\.body$/, '.meta'), JSON.stringify({ headers: data.headers, status: data.status }))];
368
- case 4:
369
- _c.sent();
370
- return [2 /*return*/];
371
- case 5:
372
- if (!((data === null || data === void 0 ? void 0 : data.kind) === 'PAGE')) return [3 /*break*/, 13];
373
- isAppPath = typeof data.pageData === 'string';
374
- return [4 /*yield*/, this.getFsPath({
375
- pathname: "".concat(key, ".html"),
376
- appDir: isAppPath,
377
- })];
378
- case 6:
379
- htmlPath = (_c.sent()).filePath;
380
- return [4 /*yield*/, this.fs.mkdir(path_1.default.dirname(htmlPath))];
381
- case 7:
382
- _c.sent();
383
- return [4 /*yield*/, this.fs.writeFile(htmlPath, data.html)];
384
- case 8:
385
- _c.sent();
386
- _b = (_a = this.fs).writeFile;
387
- return [4 /*yield*/, this.getFsPath({
388
- pathname: "".concat(key, ".").concat(isAppPath ? 'rsc' : 'json'),
389
- appDir: isAppPath,
390
- })];
391
- case 9: return [4 /*yield*/, _b.apply(_a, [(_c.sent()).filePath,
392
- isAppPath ? data.pageData : JSON.stringify(data.pageData)])];
393
- case 10:
394
- _c.sent();
395
- if (!(data.headers || data.status)) return [3 /*break*/, 12];
396
- return [4 /*yield*/, this.fs.writeFile(htmlPath.replace(/\.html$/, '.meta'), JSON.stringify({
397
- headers: data.headers,
398
- status: data.status,
399
- }))];
400
- case 11:
401
- _c.sent();
402
- _c.label = 12;
403
- case 12: return [3 /*break*/, 18];
404
- case 13:
405
- if (!((data === null || data === void 0 ? void 0 : data.kind) === 'FETCH')) return [3 /*break*/, 18];
406
- return [4 /*yield*/, this.getFsPath({
407
- pathname: key,
408
- fetchCache: true,
409
- })];
410
- case 14:
411
- filePath = (_c.sent()).filePath;
412
- return [4 /*yield*/, this.fs.mkdir(path_1.default.dirname(filePath))];
413
- case 15:
414
- _c.sent();
415
- return [4 /*yield*/, this.fs.writeFile(filePath, JSON.stringify(data))];
416
- case 16:
417
- _c.sent();
418
- return [4 /*yield*/, this.setTags(key, data.data.tags || [])];
419
- case 17:
420
- _c.sent();
421
- _c.label = 18;
422
- case 18: return [2 /*return*/];
423
- }
424
- });
425
- });
426
- };
427
- FileSystemCache.prototype.getFsPath = function (_a) {
428
- var pathname = _a.pathname, appDir = _a.appDir, fetchCache = _a.fetchCache;
429
- return __awaiter(this, void 0, void 0, function () {
430
- var isAppPath, filePath, err_3;
431
- return __generator(this, function (_b) {
432
- switch (_b.label) {
433
- case 0:
434
- if (fetchCache) {
435
- // we store in .next/cache/fetch-cache so it can be persisted
436
- // across deploys
437
- return [2 /*return*/, {
438
- filePath: path_1.default.join(this.serverDistDir, '..', 'cache', 'fetch-cache', pathname),
439
- isAppPath: false,
440
- }];
441
- }
442
- isAppPath = false;
443
- filePath = path_1.default.join(this.serverDistDir, 'pages', pathname);
444
- if (!this.appDir || appDir === false)
445
- return [2 /*return*/, {
446
- filePath: filePath,
447
- isAppPath: isAppPath,
448
- }];
449
- _b.label = 1;
450
- case 1:
451
- _b.trys.push([1, 3, , 4]);
452
- return [4 /*yield*/, this.fs.readFile(filePath)];
453
- case 2:
454
- _b.sent();
455
- return [2 /*return*/, {
456
- filePath: filePath,
457
- isAppPath: isAppPath,
458
- }];
459
- case 3:
460
- err_3 = _b.sent();
461
- return [2 /*return*/, {
462
- filePath: path_1.default.join(this.serverDistDir, 'app', pathname),
463
- isAppPath: true,
464
- }];
465
- case 4: return [2 /*return*/];
466
- }
467
- });
468
- });
469
- };
470
- return FileSystemCache;
471
- }());
472
- exports.default = FileSystemCache;
package/server/cache.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { IncrementalCache } from 'next/dist/server/lib/incremental-cache';
2
- export declare const purgeCache: (cache: IncrementalCache, pathname?: string) => Promise<void>;
package/server/cache.js DELETED
@@ -1,129 +0,0 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __generator = (this && this.__generator) || function (thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- };
61
- Object.defineProperty(exports, "__esModule", { value: true });
62
- exports.purgeCache = void 0;
63
- var fs = __importStar(require("fs"));
64
- var getCacheHandler = function (cache) {
65
- return cache.cacheHandler;
66
- };
67
- var purgeCache = function (cache, pathname) { return __awaiter(void 0, void 0, void 0, function () {
68
- return __generator(this, function (_a) {
69
- if (pathname) {
70
- return [2 /*return*/, purgePath(cache, pathname)];
71
- }
72
- else {
73
- return [2 /*return*/, purgeAll(cache)];
74
- }
75
- return [2 /*return*/];
76
- });
77
- }); };
78
- exports.purgeCache = purgeCache;
79
- var purgePath = function (cache, pathname) { return __awaiter(void 0, void 0, void 0, function () {
80
- var handler, fsPathObj;
81
- return __generator(this, function (_a) {
82
- switch (_a.label) {
83
- case 0:
84
- handler = getCacheHandler(cache);
85
- return [4 /*yield*/, handler.getFsPath({ pathname: pathname })];
86
- case 1:
87
- fsPathObj = _a.sent();
88
- try {
89
- /* Delete entry in cache */
90
- handler.delete(pathname);
91
- /* Delete files from disc */
92
- fs.unlinkSync("".concat(fsPathObj.filePath, ".html"));
93
- fs.unlinkSync("".concat(fsPathObj.filePath, ".json"));
94
- console.info("\nCache deleted for '".concat(fsPathObj.filePath, "'\n"));
95
- }
96
- catch (err) {
97
- console.error("Could not delete cache of '".concat(fsPathObj.filePath, "':"), err);
98
- }
99
- return [2 /*return*/];
100
- }
101
- });
102
- }); };
103
- var purgeAll = function (cache) { return __awaiter(void 0, void 0, void 0, function () {
104
- var handler, pagesRoot, err_1;
105
- return __generator(this, function (_a) {
106
- switch (_a.label) {
107
- case 0:
108
- handler = getCacheHandler(cache);
109
- _a.label = 1;
110
- case 1:
111
- _a.trys.push([1, 3, , 4]);
112
- /* Purge cache */
113
- handler.clear();
114
- return [4 /*yield*/, handler.getFsPath({ pathname: '' })];
115
- case 2:
116
- pagesRoot = (_a.sent()).filePath;
117
- if (fs.existsSync(pagesRoot)) {
118
- fs.rmSync(pagesRoot, { recursive: true });
119
- }
120
- console.info('\nCache was successfully purged\n');
121
- return [3 /*break*/, 4];
122
- case 3:
123
- err_1 = _a.sent();
124
- console.error('Could not purge cache:', err_1);
125
- return [3 /*break*/, 4];
126
- case 4: return [2 /*return*/];
127
- }
128
- });
129
- }); };
package/server/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import { NextServer } from 'next/dist/server/next';
2
- export declare const PURGE_CACHE_URL = "/_/enonic/cache/purge";
3
- export declare const withEnonicCache: (config: any) => any;
4
- declare const _default: (next: (options: any) => any) => Promise<NextServer>;
5
- export default _default;