catalyst-core 0.0.1-beta.2
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/.prettierignore +2 -0
- package/.prettierrc.json +7 -0
- package/LICENSE +9 -0
- package/README.md +132 -0
- package/babel.config.json +24 -0
- package/bin/catalyst.js +41 -0
- package/caching.js +16 -0
- package/checkVersion.js +3 -0
- package/config/config.js +24 -0
- package/config.json +8 -0
- package/index.js +16 -0
- package/logger/index.js +96 -0
- package/package.json +87 -0
- package/packages/create-framework-app/node_modules/.package-lock.json +249 -0
- package/packages/create-framework-app/templates/redux-js/node_modules/@babel/core/lib/config/caching.js +261 -0
- package/packages/create-framework-app/templates/redux-js/node_modules/@remix-run/router/dist/router.js +4327 -0
- package/packages/create-framework-app/templates/redux-js/node_modules/catalyst/router.js +15 -0
- package/packages/create-framework-app/templates/redux-js/node_modules/http-proxy-middleware/dist/router.js +46 -0
- package/reducer/index.js +88 -0
- package/reducer/loadableConfigReducer.js +19 -0
- package/router/ClientRouter.js +15 -0
- package/router/ServerRouter.js +28 -0
- package/router/index.js +32 -0
- package/router.js +16 -0
- package/scripts/build.js +27 -0
- package/scripts/loadEnvironmentVariables.js +37 -0
- package/scripts/loadScriptsBeforeServerStarts.js +55 -0
- package/scripts/prepare.js +19 -0
- package/scripts/registerAliases.js +30 -0
- package/scripts/serve.js +27 -0
- package/scripts/start.js +28 -0
- package/scripts/validator.js +99 -0
- package/server/mainIndex.js +65 -0
- package/server/mainServer.js +70 -0
- package/server/renderer/document/Body.js +37 -0
- package/server/renderer/document/Head.js +44 -0
- package/server/renderer/document/index.js +25 -0
- package/server/renderer/extract.js +86 -0
- package/server/renderer/handler.js +228 -0
- package/server/renderer/index.js +13 -0
- package/server/renderer/render.js +71 -0
- package/server/renderer/userAgentUtil.js +55 -0
- package/server/utils/validator.js +98 -0
- package/store/index.dev.js +73 -0
- package/store/index.js +25 -0
- package/store/index.prod.js +66 -0
- package/tsconfig.json +110 -0
- package/types/caching.d.ts +1 -0
- package/types/config/config.d.ts +19 -0
- package/types/index.d.ts +1 -0
- package/types/logger/index.d.ts +14 -0
- package/types/reducer/index.d.ts +22 -0
- package/types/reducer/loadableConfigReducer.d.ts +9 -0
- package/types/router/ClientRouter.d.ts +5 -0
- package/types/router/ServerRouter.d.ts +7 -0
- package/types/router/index.d.ts +8 -0
- package/types/router.d.ts +1 -0
- package/types/scripts/build.d.ts +1 -0
- package/types/scripts/loadEnvironmentVariables.d.ts +5 -0
- package/types/scripts/loadScriptsBeforeServerStarts.d.ts +1 -0
- package/types/scripts/prepare.d.ts +1 -0
- package/types/scripts/registerAliases.d.ts +1 -0
- package/types/scripts/serve.d.ts +1 -0
- package/types/scripts/start.d.ts +1 -0
- package/types/scripts/validator.d.ts +9 -0
- package/types/scripts/verifyConfig.d.ts +1 -0
- package/types/server/mainIndex.d.ts +1 -0
- package/types/server/mainServer.d.ts +2 -0
- package/types/server/renderer/document/Body.d.ts +11 -0
- package/types/server/renderer/document/Head.d.ts +11 -0
- package/types/server/renderer/document/index.d.ts +2 -0
- package/types/server/renderer/extract.d.ts +18 -0
- package/types/server/renderer/handler.d.ts +6 -0
- package/types/server/renderer/index.d.ts +2 -0
- package/types/server/renderer/render.d.ts +38 -0
- package/types/server/renderer/userAgentUtil.d.ts +1 -0
- package/types/store/index.d.ts +11 -0
- package/types/store/index.dev.d.ts +8 -0
- package/types/store/index.prod.d.ts +8 -0
- package/types/webpack/babel-plugins/remove-client.plugin.d.ts +10 -0
- package/types/webpack/babel-plugins/remove-ssr.plugin.d.ts +10 -0
- package/types/webpack/babel.config.client.d.ts +21 -0
- package/types/webpack/babel.config.d.ts +16 -0
- package/types/webpack/babel.config.ssr.d.ts +21 -0
- package/types/webpack/base.babel.d.ts +184 -0
- package/types/webpack/development.client.babel.d.ts +1 -0
- package/types/webpack/plugins/mime-types.d.ts +78 -0
- package/types/webpack/plugins/route-manifest-plugin.d.ts +1 -0
- package/types/webpack/plugins/upload-assets-plugin.d.ts +1 -0
- package/types/webpack/production.client.babel.d.ts +174 -0
- package/types/webpack/production.ssr.babel.d.ts +2 -0
- package/types/webpack/scssParams.d.ts +2 -0
- package/webpack/babel-plugins/remove-client.plugin.js +31 -0
- package/webpack/babel-plugins/remove-ssr.plugin.js +21 -0
- package/webpack/babel.config.client.js +24 -0
- package/webpack/babel.config.js +20 -0
- package/webpack/babel.config.ssr.js +24 -0
- package/webpack/base.babel.js +174 -0
- package/webpack/development.client.babel.js +82 -0
- package/webpack/plugins/mime-types.js +82 -0
- package/webpack/plugins/route-manifest-copy.js +122 -0
- package/webpack/plugins/route-manifest-plugin.js +122 -0
- package/webpack/plugins/upload-assets-plugin.js +181 -0
- package/webpack/production.client.babel.js +79 -0
- package/webpack/production.ssr.babel.js +61 -0
- package/webpack/scssParams.js +31 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lockfileVersion": 3,
|
|
3
|
+
"requires": true,
|
|
4
|
+
"packages": {
|
|
5
|
+
"../..": {
|
|
6
|
+
"version": "0.0.1",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@babel/cli": "^7.23.0",
|
|
10
|
+
"@babel/core": "^7.23.2",
|
|
11
|
+
"@babel/node": "^7.22.19",
|
|
12
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
13
|
+
"@babel/plugin-transform-react-jsx": "^7.22.15",
|
|
14
|
+
"@babel/preset-env": "^7.23.2",
|
|
15
|
+
"@babel/preset-react": "^7.22.15",
|
|
16
|
+
"@babel/register": "^7.22.15",
|
|
17
|
+
"@loadable/babel-plugin": "^5.16.1",
|
|
18
|
+
"@loadable/component": "^5.15.3",
|
|
19
|
+
"@loadable/server": "^5.16.1",
|
|
20
|
+
"@loadable/webpack-plugin": "^5.15.2",
|
|
21
|
+
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
|
|
22
|
+
"@svgr/webpack": "^8.1.0",
|
|
23
|
+
"@tata1mg/router": "^0.0.1-alpha.13",
|
|
24
|
+
"acorn-loose": "^8.4.0",
|
|
25
|
+
"aws-sdk": "^2.1490.0",
|
|
26
|
+
"axios": "^0.19.2",
|
|
27
|
+
"babel-loader": "^9.1.3",
|
|
28
|
+
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
29
|
+
"babel-plugin-syntax-dynamic-import": "^6.18.0",
|
|
30
|
+
"babel-plugin-transform-class-properties": "^6.24.1",
|
|
31
|
+
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
|
|
32
|
+
"babel-plugin-transform-export-extensions": "^6.22.0",
|
|
33
|
+
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
|
|
34
|
+
"body-parser": "^1.20.2",
|
|
35
|
+
"compression": "^1.7.4",
|
|
36
|
+
"cookie-parser": "^1.4.6",
|
|
37
|
+
"css-hot-loader": "^1.4.4",
|
|
38
|
+
"css-loader": "^6.8.1",
|
|
39
|
+
"css-modules-require-hook": "^4.2.3",
|
|
40
|
+
"dotenv-webpack": "^8.0.1",
|
|
41
|
+
"esm-module-alias": "^2.0.3",
|
|
42
|
+
"express": "^4.18.2",
|
|
43
|
+
"express-static-gzip": "^2.1.7",
|
|
44
|
+
"file-loader": "^6.2.0",
|
|
45
|
+
"helmet": "^7.0.0",
|
|
46
|
+
"html-loader": "^4.2.0",
|
|
47
|
+
"img-loader": "^4.0.0",
|
|
48
|
+
"isomorphic-dompurify": "^1.13.0",
|
|
49
|
+
"lodash.template": "^4.5.0",
|
|
50
|
+
"mini-css-extract-plugin": "^2.7.6",
|
|
51
|
+
"module-alias": "^2.2.3",
|
|
52
|
+
"node-dev": "^7.4.3",
|
|
53
|
+
"postcss-loader": "^7.3.3",
|
|
54
|
+
"react": "^18.2.0",
|
|
55
|
+
"react-dom": "^18.2.0",
|
|
56
|
+
"react-redux": "^8.1.3",
|
|
57
|
+
"react-refresh": "^0.14.0",
|
|
58
|
+
"react-router-dom": "^6.16.0",
|
|
59
|
+
"redux": "^4.2.1",
|
|
60
|
+
"redux-logger": "^3.0.6",
|
|
61
|
+
"redux-thunk": "^2.4.2",
|
|
62
|
+
"sass": "^1.69.5",
|
|
63
|
+
"sass-loader": "^13.3.2",
|
|
64
|
+
"sass-resources-loader": "^2.2.5",
|
|
65
|
+
"ua-parser-js": "^1.0.37",
|
|
66
|
+
"url-loader": "^4.1.1",
|
|
67
|
+
"webpack": "^5.88.2",
|
|
68
|
+
"webpack-bundle-analyzer": "^4.9.1",
|
|
69
|
+
"webpack-cli": "^5.1.4",
|
|
70
|
+
"webpack-dev-server": "^4.15.1",
|
|
71
|
+
"webpack-merge": "^5.9.0",
|
|
72
|
+
"webpack-node-externals": "^3.0.0",
|
|
73
|
+
"winston": "^3.11.0",
|
|
74
|
+
"winston-daily-rotate-file": "^5.0.0"
|
|
75
|
+
},
|
|
76
|
+
"bin": {
|
|
77
|
+
"catalyst": "bin/catalyst.js",
|
|
78
|
+
"framework": "bin/framework.js"
|
|
79
|
+
},
|
|
80
|
+
"devDependencies": {
|
|
81
|
+
"@babel/cli": "^7.23.0",
|
|
82
|
+
"@babel/core": "^7.23.2",
|
|
83
|
+
"@babel/node": "^7.22.19",
|
|
84
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
85
|
+
"@babel/plugin-transform-react-jsx": "^7.22.15",
|
|
86
|
+
"@babel/preset-env": "^7.23.2",
|
|
87
|
+
"@babel/preset-react": "^7.22.15",
|
|
88
|
+
"@babel/register": "^7.22.15",
|
|
89
|
+
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
|
|
90
|
+
"babel-loader": "^9.1.3",
|
|
91
|
+
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
92
|
+
"babel-plugin-syntax-dynamic-import": "^6.18.0",
|
|
93
|
+
"babel-plugin-transform-class-properties": "^6.24.1",
|
|
94
|
+
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
|
|
95
|
+
"babel-plugin-transform-export-extensions": "^6.22.0",
|
|
96
|
+
"body-parser": "^1.20.2",
|
|
97
|
+
"compression": "^1.7.4",
|
|
98
|
+
"cookie-parser": "^1.4.6",
|
|
99
|
+
"css-loader": "^6.8.1",
|
|
100
|
+
"css-modules-require-hook": "^4.2.3",
|
|
101
|
+
"dotenv-webpack": "^8.0.1",
|
|
102
|
+
"express": "^4.18.2",
|
|
103
|
+
"express-static-gzip": "^2.1.7",
|
|
104
|
+
"helmet": "^7.0.0",
|
|
105
|
+
"mini-css-extract-plugin": "^2.7.6",
|
|
106
|
+
"node-dev": "^7.4.3",
|
|
107
|
+
"react-refresh": "^0.14.0",
|
|
108
|
+
"redux-logger": "^3.0.6",
|
|
109
|
+
"webpack": "^5.88.2",
|
|
110
|
+
"webpack-bundle-analyzer": "^4.9.1",
|
|
111
|
+
"webpack-cli": "^5.1.4",
|
|
112
|
+
"webpack-dev-server": "^4.15.1",
|
|
113
|
+
"webpack-merge": "^5.9.0"
|
|
114
|
+
},
|
|
115
|
+
"peerDependencies": {
|
|
116
|
+
"isomorphic-dompurify": "^1.9.0",
|
|
117
|
+
"react": "^18.2.0",
|
|
118
|
+
"react-dom": "^18.2.0",
|
|
119
|
+
"react-helmet-async": "^1.3.0",
|
|
120
|
+
"react-redux": "^8.0.4",
|
|
121
|
+
"react-router-dom": "^6.22.0"
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
"node_modules/ansi-regex": {
|
|
125
|
+
"extraneous": true
|
|
126
|
+
},
|
|
127
|
+
"node_modules/catalyst": {
|
|
128
|
+
"resolved": "../..",
|
|
129
|
+
"link": true
|
|
130
|
+
},
|
|
131
|
+
"node_modules/chalk": {
|
|
132
|
+
"extraneous": true
|
|
133
|
+
},
|
|
134
|
+
"node_modules/chownr": {
|
|
135
|
+
"extraneous": true
|
|
136
|
+
},
|
|
137
|
+
"node_modules/cli-cursor": {
|
|
138
|
+
"extraneous": true
|
|
139
|
+
},
|
|
140
|
+
"node_modules/cli-spinners": {
|
|
141
|
+
"extraneous": true
|
|
142
|
+
},
|
|
143
|
+
"node_modules/commander": {
|
|
144
|
+
"extraneous": true
|
|
145
|
+
},
|
|
146
|
+
"node_modules/data-uri-to-buffer": {
|
|
147
|
+
"extraneous": true
|
|
148
|
+
},
|
|
149
|
+
"node_modules/emoji-regex": {
|
|
150
|
+
"extraneous": true
|
|
151
|
+
},
|
|
152
|
+
"node_modules/fetch-blob": {
|
|
153
|
+
"extraneous": true
|
|
154
|
+
},
|
|
155
|
+
"node_modules/formdata-polyfill": {
|
|
156
|
+
"extraneous": true
|
|
157
|
+
},
|
|
158
|
+
"node_modules/fs": {
|
|
159
|
+
"extraneous": true
|
|
160
|
+
},
|
|
161
|
+
"node_modules/fs-minipass": {
|
|
162
|
+
"extraneous": true
|
|
163
|
+
},
|
|
164
|
+
"node_modules/fs-minipass/node_modules/minipass": {
|
|
165
|
+
"extraneous": true
|
|
166
|
+
},
|
|
167
|
+
"node_modules/get-east-asian-width": {
|
|
168
|
+
"extraneous": true
|
|
169
|
+
},
|
|
170
|
+
"node_modules/https": {
|
|
171
|
+
"extraneous": true
|
|
172
|
+
},
|
|
173
|
+
"node_modules/is-interactive": {
|
|
174
|
+
"extraneous": true
|
|
175
|
+
},
|
|
176
|
+
"node_modules/is-unicode-supported": {
|
|
177
|
+
"extraneous": true
|
|
178
|
+
},
|
|
179
|
+
"node_modules/kleur": {
|
|
180
|
+
"extraneous": true
|
|
181
|
+
},
|
|
182
|
+
"node_modules/log-symbols": {
|
|
183
|
+
"extraneous": true
|
|
184
|
+
},
|
|
185
|
+
"node_modules/log-symbols/node_modules/is-unicode-supported": {
|
|
186
|
+
"extraneous": true
|
|
187
|
+
},
|
|
188
|
+
"node_modules/mimic-fn": {
|
|
189
|
+
"extraneous": true
|
|
190
|
+
},
|
|
191
|
+
"node_modules/minipass": {
|
|
192
|
+
"extraneous": true
|
|
193
|
+
},
|
|
194
|
+
"node_modules/minizlib": {
|
|
195
|
+
"extraneous": true
|
|
196
|
+
},
|
|
197
|
+
"node_modules/minizlib/node_modules/minipass": {
|
|
198
|
+
"extraneous": true
|
|
199
|
+
},
|
|
200
|
+
"node_modules/mkdirp": {
|
|
201
|
+
"extraneous": true
|
|
202
|
+
},
|
|
203
|
+
"node_modules/node-domexception": {
|
|
204
|
+
"extraneous": true
|
|
205
|
+
},
|
|
206
|
+
"node_modules/node-fetch": {
|
|
207
|
+
"extraneous": true
|
|
208
|
+
},
|
|
209
|
+
"node_modules/onetime": {
|
|
210
|
+
"extraneous": true
|
|
211
|
+
},
|
|
212
|
+
"node_modules/ora": {
|
|
213
|
+
"extraneous": true
|
|
214
|
+
},
|
|
215
|
+
"node_modules/picocolors": {
|
|
216
|
+
"extraneous": true
|
|
217
|
+
},
|
|
218
|
+
"node_modules/prompts": {
|
|
219
|
+
"extraneous": true
|
|
220
|
+
},
|
|
221
|
+
"node_modules/restore-cursor": {
|
|
222
|
+
"extraneous": true
|
|
223
|
+
},
|
|
224
|
+
"node_modules/signal-exit": {
|
|
225
|
+
"extraneous": true
|
|
226
|
+
},
|
|
227
|
+
"node_modules/sisteransi": {
|
|
228
|
+
"extraneous": true
|
|
229
|
+
},
|
|
230
|
+
"node_modules/stdin-discarder": {
|
|
231
|
+
"extraneous": true
|
|
232
|
+
},
|
|
233
|
+
"node_modules/string-width": {
|
|
234
|
+
"extraneous": true
|
|
235
|
+
},
|
|
236
|
+
"node_modules/strip-ansi": {
|
|
237
|
+
"extraneous": true
|
|
238
|
+
},
|
|
239
|
+
"node_modules/tar": {
|
|
240
|
+
"extraneous": true
|
|
241
|
+
},
|
|
242
|
+
"node_modules/web-streams-polyfill": {
|
|
243
|
+
"extraneous": true
|
|
244
|
+
},
|
|
245
|
+
"node_modules/yallist": {
|
|
246
|
+
"extraneous": true
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.assertSimpleType = assertSimpleType;
|
|
7
|
+
exports.makeStrongCache = makeStrongCache;
|
|
8
|
+
exports.makeStrongCacheSync = makeStrongCacheSync;
|
|
9
|
+
exports.makeWeakCache = makeWeakCache;
|
|
10
|
+
exports.makeWeakCacheSync = makeWeakCacheSync;
|
|
11
|
+
function _gensync() {
|
|
12
|
+
const data = require("gensync");
|
|
13
|
+
_gensync = function () {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
var _async = require("../gensync-utils/async.js");
|
|
19
|
+
var _util = require("./util.js");
|
|
20
|
+
const synchronize = gen => {
|
|
21
|
+
return _gensync()(gen).sync;
|
|
22
|
+
};
|
|
23
|
+
function* genTrue() {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
function makeWeakCache(handler) {
|
|
27
|
+
return makeCachedFunction(WeakMap, handler);
|
|
28
|
+
}
|
|
29
|
+
function makeWeakCacheSync(handler) {
|
|
30
|
+
return synchronize(makeWeakCache(handler));
|
|
31
|
+
}
|
|
32
|
+
function makeStrongCache(handler) {
|
|
33
|
+
return makeCachedFunction(Map, handler);
|
|
34
|
+
}
|
|
35
|
+
function makeStrongCacheSync(handler) {
|
|
36
|
+
return synchronize(makeStrongCache(handler));
|
|
37
|
+
}
|
|
38
|
+
function makeCachedFunction(CallCache, handler) {
|
|
39
|
+
const callCacheSync = new CallCache();
|
|
40
|
+
const callCacheAsync = new CallCache();
|
|
41
|
+
const futureCache = new CallCache();
|
|
42
|
+
return function* cachedFunction(arg, data) {
|
|
43
|
+
const asyncContext = yield* (0, _async.isAsync)();
|
|
44
|
+
const callCache = asyncContext ? callCacheAsync : callCacheSync;
|
|
45
|
+
const cached = yield* getCachedValueOrWait(asyncContext, callCache, futureCache, arg, data);
|
|
46
|
+
if (cached.valid) return cached.value;
|
|
47
|
+
const cache = new CacheConfigurator(data);
|
|
48
|
+
const handlerResult = handler(arg, cache);
|
|
49
|
+
let finishLock;
|
|
50
|
+
let value;
|
|
51
|
+
if ((0, _util.isIterableIterator)(handlerResult)) {
|
|
52
|
+
value = yield* (0, _async.onFirstPause)(handlerResult, () => {
|
|
53
|
+
finishLock = setupAsyncLocks(cache, futureCache, arg);
|
|
54
|
+
});
|
|
55
|
+
} else {
|
|
56
|
+
value = handlerResult;
|
|
57
|
+
}
|
|
58
|
+
updateFunctionCache(callCache, cache, arg, value);
|
|
59
|
+
if (finishLock) {
|
|
60
|
+
futureCache.delete(arg);
|
|
61
|
+
finishLock.release(value);
|
|
62
|
+
}
|
|
63
|
+
return value;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function* getCachedValue(cache, arg, data) {
|
|
67
|
+
const cachedValue = cache.get(arg);
|
|
68
|
+
if (cachedValue) {
|
|
69
|
+
for (const {
|
|
70
|
+
value,
|
|
71
|
+
valid
|
|
72
|
+
} of cachedValue) {
|
|
73
|
+
if (yield* valid(data)) return {
|
|
74
|
+
valid: true,
|
|
75
|
+
value
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
valid: false,
|
|
81
|
+
value: null
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function* getCachedValueOrWait(asyncContext, callCache, futureCache, arg, data) {
|
|
85
|
+
const cached = yield* getCachedValue(callCache, arg, data);
|
|
86
|
+
if (cached.valid) {
|
|
87
|
+
return cached;
|
|
88
|
+
}
|
|
89
|
+
if (asyncContext) {
|
|
90
|
+
const cached = yield* getCachedValue(futureCache, arg, data);
|
|
91
|
+
if (cached.valid) {
|
|
92
|
+
const value = yield* (0, _async.waitFor)(cached.value.promise);
|
|
93
|
+
return {
|
|
94
|
+
valid: true,
|
|
95
|
+
value
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
valid: false,
|
|
101
|
+
value: null
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function setupAsyncLocks(config, futureCache, arg) {
|
|
105
|
+
const finishLock = new Lock();
|
|
106
|
+
updateFunctionCache(futureCache, config, arg, finishLock);
|
|
107
|
+
return finishLock;
|
|
108
|
+
}
|
|
109
|
+
function updateFunctionCache(cache, config, arg, value) {
|
|
110
|
+
if (!config.configured()) config.forever();
|
|
111
|
+
let cachedValue = cache.get(arg);
|
|
112
|
+
config.deactivate();
|
|
113
|
+
switch (config.mode()) {
|
|
114
|
+
case "forever":
|
|
115
|
+
cachedValue = [{
|
|
116
|
+
value,
|
|
117
|
+
valid: genTrue
|
|
118
|
+
}];
|
|
119
|
+
cache.set(arg, cachedValue);
|
|
120
|
+
break;
|
|
121
|
+
case "invalidate":
|
|
122
|
+
cachedValue = [{
|
|
123
|
+
value,
|
|
124
|
+
valid: config.validator()
|
|
125
|
+
}];
|
|
126
|
+
cache.set(arg, cachedValue);
|
|
127
|
+
break;
|
|
128
|
+
case "valid":
|
|
129
|
+
if (cachedValue) {
|
|
130
|
+
cachedValue.push({
|
|
131
|
+
value,
|
|
132
|
+
valid: config.validator()
|
|
133
|
+
});
|
|
134
|
+
} else {
|
|
135
|
+
cachedValue = [{
|
|
136
|
+
value,
|
|
137
|
+
valid: config.validator()
|
|
138
|
+
}];
|
|
139
|
+
cache.set(arg, cachedValue);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
class CacheConfigurator {
|
|
144
|
+
constructor(data) {
|
|
145
|
+
this._active = true;
|
|
146
|
+
this._never = false;
|
|
147
|
+
this._forever = false;
|
|
148
|
+
this._invalidate = false;
|
|
149
|
+
this._configured = false;
|
|
150
|
+
this._pairs = [];
|
|
151
|
+
this._data = void 0;
|
|
152
|
+
this._data = data;
|
|
153
|
+
}
|
|
154
|
+
simple() {
|
|
155
|
+
return makeSimpleConfigurator(this);
|
|
156
|
+
}
|
|
157
|
+
mode() {
|
|
158
|
+
if (this._never) return "never";
|
|
159
|
+
if (this._forever) return "forever";
|
|
160
|
+
if (this._invalidate) return "invalidate";
|
|
161
|
+
return "valid";
|
|
162
|
+
}
|
|
163
|
+
forever() {
|
|
164
|
+
if (!this._active) {
|
|
165
|
+
throw new Error("Cannot change caching after evaluation has completed.");
|
|
166
|
+
}
|
|
167
|
+
if (this._never) {
|
|
168
|
+
throw new Error("Caching has already been configured with .never()");
|
|
169
|
+
}
|
|
170
|
+
this._forever = true;
|
|
171
|
+
this._configured = true;
|
|
172
|
+
}
|
|
173
|
+
never() {
|
|
174
|
+
if (!this._active) {
|
|
175
|
+
throw new Error("Cannot change caching after evaluation has completed.");
|
|
176
|
+
}
|
|
177
|
+
if (this._forever) {
|
|
178
|
+
throw new Error("Caching has already been configured with .forever()");
|
|
179
|
+
}
|
|
180
|
+
this._never = true;
|
|
181
|
+
this._configured = true;
|
|
182
|
+
}
|
|
183
|
+
using(handler) {
|
|
184
|
+
if (!this._active) {
|
|
185
|
+
throw new Error("Cannot change caching after evaluation has completed.");
|
|
186
|
+
}
|
|
187
|
+
if (this._never || this._forever) {
|
|
188
|
+
throw new Error("Caching has already been configured with .never or .forever()");
|
|
189
|
+
}
|
|
190
|
+
this._configured = true;
|
|
191
|
+
const key = handler(this._data);
|
|
192
|
+
const fn = (0, _async.maybeAsync)(handler, `You appear to be using an async cache handler, but Babel has been called synchronously`);
|
|
193
|
+
if ((0, _async.isThenable)(key)) {
|
|
194
|
+
return key.then(key => {
|
|
195
|
+
this._pairs.push([key, fn]);
|
|
196
|
+
return key;
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
this._pairs.push([key, fn]);
|
|
200
|
+
return key;
|
|
201
|
+
}
|
|
202
|
+
invalidate(handler) {
|
|
203
|
+
this._invalidate = true;
|
|
204
|
+
return this.using(handler);
|
|
205
|
+
}
|
|
206
|
+
validator() {
|
|
207
|
+
const pairs = this._pairs;
|
|
208
|
+
return function* (data) {
|
|
209
|
+
for (const [key, fn] of pairs) {
|
|
210
|
+
if (key !== (yield* fn(data))) return false;
|
|
211
|
+
}
|
|
212
|
+
return true;
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
deactivate() {
|
|
216
|
+
this._active = false;
|
|
217
|
+
}
|
|
218
|
+
configured() {
|
|
219
|
+
return this._configured;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function makeSimpleConfigurator(cache) {
|
|
223
|
+
function cacheFn(val) {
|
|
224
|
+
if (typeof val === "boolean") {
|
|
225
|
+
if (val) cache.forever();else cache.never();
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
return cache.using(() => assertSimpleType(val()));
|
|
229
|
+
}
|
|
230
|
+
cacheFn.forever = () => cache.forever();
|
|
231
|
+
cacheFn.never = () => cache.never();
|
|
232
|
+
cacheFn.using = cb => cache.using(() => assertSimpleType(cb()));
|
|
233
|
+
cacheFn.invalidate = cb => cache.invalidate(() => assertSimpleType(cb()));
|
|
234
|
+
return cacheFn;
|
|
235
|
+
}
|
|
236
|
+
function assertSimpleType(value) {
|
|
237
|
+
if ((0, _async.isThenable)(value)) {
|
|
238
|
+
throw new Error(`You appear to be using an async cache handler, ` + `which your current version of Babel does not support. ` + `We may add support for this in the future, ` + `but if you're on the most recent version of @babel/core and still ` + `seeing this error, then you'll need to synchronously handle your caching logic.`);
|
|
239
|
+
}
|
|
240
|
+
if (value != null && typeof value !== "string" && typeof value !== "boolean" && typeof value !== "number") {
|
|
241
|
+
throw new Error("Cache keys must be either string, boolean, number, null, or undefined.");
|
|
242
|
+
}
|
|
243
|
+
return value;
|
|
244
|
+
}
|
|
245
|
+
class Lock {
|
|
246
|
+
constructor() {
|
|
247
|
+
this.released = false;
|
|
248
|
+
this.promise = void 0;
|
|
249
|
+
this._resolve = void 0;
|
|
250
|
+
this.promise = new Promise(resolve => {
|
|
251
|
+
this._resolve = resolve;
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
release(value) {
|
|
255
|
+
this.released = true;
|
|
256
|
+
this._resolve(value);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
0 && 0;
|
|
260
|
+
|
|
261
|
+
//# sourceMappingURL=caching.js.map
|