crelte 0.1.0 → 0.1.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/dist/Crelte.d.ts +89 -25
- package/dist/Crelte.d.ts.map +1 -1
- package/dist/Crelte.js +79 -38
- package/dist/CrelteRequest.d.ts +63 -0
- package/dist/CrelteRequest.d.ts.map +1 -0
- package/dist/CrelteRequest.js +94 -0
- package/dist/blocks/Blocks.d.ts +27 -3
- package/dist/blocks/Blocks.d.ts.map +1 -1
- package/dist/blocks/Blocks.js +8 -0
- package/dist/blocks/Blocks.svelte +1 -1
- package/dist/blocks/Blocks.svelte.d.ts +36 -4
- package/dist/blocks/Blocks.svelte.d.ts.map +1 -1
- package/dist/blocks/index.d.ts +6 -3
- package/dist/blocks/index.d.ts.map +1 -1
- package/dist/blocks/index.js +3 -2
- package/dist/cookies/ServerCookies.d.ts +1 -1
- package/dist/cookies/ServerCookies.d.ts.map +1 -1
- package/dist/cookies/index.d.ts +7 -0
- package/dist/cookies/index.d.ts.map +1 -1
- package/dist/graphql/GraphQl.d.ts +53 -14
- package/dist/graphql/GraphQl.d.ts.map +1 -1
- package/dist/graphql/GraphQl.js +44 -23
- package/dist/graphql/index.d.ts +1 -1
- package/dist/graphql/index.d.ts.map +1 -1
- package/dist/graphql/index.js +2 -2
- package/dist/index.d.ts +55 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +50 -23
- package/dist/init/client.d.ts +43 -2
- package/dist/init/client.d.ts.map +1 -1
- package/dist/init/client.js +26 -6
- package/dist/init/server.d.ts +49 -2
- package/dist/init/server.d.ts.map +1 -1
- package/dist/init/server.js +56 -6
- package/dist/init/shared.d.ts +5 -4
- package/dist/init/shared.d.ts.map +1 -1
- package/dist/init/shared.js +3 -3
- package/dist/loadData/Globals.d.ts +41 -2
- package/dist/loadData/Globals.d.ts.map +1 -1
- package/dist/loadData/Globals.js +33 -5
- package/dist/loadData/index.d.ts +74 -11
- package/dist/loadData/index.d.ts.map +1 -1
- package/dist/loadData/index.js +5 -8
- package/dist/plugins/Events.d.ts +18 -5
- package/dist/plugins/Events.d.ts.map +1 -1
- package/dist/plugins/Events.js +3 -0
- package/dist/plugins/Plugins.d.ts +28 -2
- package/dist/plugins/Plugins.d.ts.map +1 -1
- package/dist/plugins/Plugins.js +8 -0
- package/dist/routing/History.d.ts +6 -3
- package/dist/routing/History.d.ts.map +1 -1
- package/dist/routing/History.js +7 -1
- package/dist/routing/InnerRouter.d.ts +10 -9
- package/dist/routing/InnerRouter.d.ts.map +1 -1
- package/dist/routing/InnerRouter.js +47 -35
- package/dist/routing/PageLoader.d.ts +5 -5
- package/dist/routing/PageLoader.d.ts.map +1 -1
- package/dist/routing/PageLoader.js +7 -7
- package/dist/routing/Request.d.ts +102 -0
- package/dist/routing/Request.d.ts.map +1 -0
- package/dist/routing/Request.js +128 -0
- package/dist/routing/Route.d.ts +73 -5
- package/dist/routing/Route.d.ts.map +1 -1
- package/dist/routing/Route.js +71 -6
- package/dist/routing/Router.d.ts +59 -52
- package/dist/routing/Router.d.ts.map +1 -1
- package/dist/routing/Router.js +95 -116
- package/dist/routing/Site.d.ts +1 -1
- package/dist/routing/Site.js +1 -1
- package/dist/routing/index.d.ts +4 -3
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/index.js +2 -1
- package/dist/ssr/SsrCache.d.ts +17 -0
- package/dist/ssr/SsrCache.d.ts.map +1 -1
- package/dist/ssr/SsrCache.js +17 -4
- package/dist/ssr/SsrComponents.d.ts +1 -0
- package/dist/ssr/SsrComponents.d.ts.map +1 -1
- package/dist/ssr/SsrComponents.js +1 -0
- package/package.json +6 -6
- package/src/Crelte.ts +124 -52
- package/src/CrelteRequest.ts +124 -0
- package/src/blocks/Blocks.svelte +35 -18
- package/src/blocks/Blocks.ts +38 -6
- package/src/blocks/index.ts +19 -10
- package/src/cookies/ServerCookies.ts +1 -1
- package/src/cookies/index.ts +7 -1
- package/src/graphql/GraphQl.ts +79 -27
- package/src/graphql/index.ts +7 -1
- package/src/index.ts +65 -29
- package/src/init/client.ts +55 -10
- package/src/init/server.ts +70 -10
- package/src/init/shared.ts +8 -7
- package/src/loadData/Globals.ts +43 -7
- package/src/loadData/index.ts +76 -13
- package/src/plugins/Events.ts +16 -5
- package/src/plugins/Plugins.ts +28 -2
- package/src/routing/History.ts +13 -4
- package/src/routing/InnerRouter.ts +55 -39
- package/src/routing/PageLoader.ts +10 -10
- package/src/routing/Request.ts +175 -0
- package/src/routing/Route.ts +73 -8
- package/src/routing/Router.ts +108 -162
- package/src/routing/Site.ts +1 -1
- package/src/routing/index.ts +12 -3
- package/src/ssr/SsrCache.ts +17 -4
- package/src/ssr/SsrComponents.ts +1 -0
- package/dist/CrelteBase.d.ts +0 -16
- package/dist/CrelteBase.d.ts.map +0 -1
- package/dist/CrelteBase.js +0 -1
- package/dist/CrelteRouted.d.ts +0 -50
- package/dist/CrelteRouted.d.ts.map +0 -1
- package/dist/CrelteRouted.js +0 -88
- package/src/CrelteBase.ts +0 -24
- package/src/CrelteRouted.ts +0 -128
package/dist/routing/Router.js
CHANGED
|
@@ -2,7 +2,8 @@ import Route from './Route.js';
|
|
|
2
2
|
import InnerRouter from './InnerRouter.js';
|
|
3
3
|
import PageLoader from './PageLoader.js';
|
|
4
4
|
import { Writable } from 'crelte-std/stores';
|
|
5
|
-
import {
|
|
5
|
+
import { Listeners } from 'crelte-std/sync';
|
|
6
|
+
import Request from './Request.js';
|
|
6
7
|
const defaultRouterOpts = {
|
|
7
8
|
preloadOnMouseOver: false,
|
|
8
9
|
deubgTiming: false,
|
|
@@ -20,14 +21,8 @@ export default class Router {
|
|
|
20
21
|
* The current site
|
|
21
22
|
*/
|
|
22
23
|
_site;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*/
|
|
26
|
-
_nextRoute;
|
|
27
|
-
/**
|
|
28
|
-
* The next site which is currently being loaded
|
|
29
|
-
*/
|
|
30
|
-
_nextSite;
|
|
24
|
+
// the next request, just here to destroy it
|
|
25
|
+
_request;
|
|
31
26
|
/**
|
|
32
27
|
* The loading flag, specifies if a page is currently
|
|
33
28
|
* getting loaded
|
|
@@ -38,9 +33,8 @@ export default class Router {
|
|
|
38
33
|
*/
|
|
39
34
|
_loadingProgress;
|
|
40
35
|
_onRouteEv;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// doc hidden
|
|
36
|
+
_onRequest;
|
|
37
|
+
/** @hidden */
|
|
44
38
|
_internal;
|
|
45
39
|
inner;
|
|
46
40
|
pageLoader;
|
|
@@ -55,52 +49,36 @@ export default class Router {
|
|
|
55
49
|
// in the first onRoute call we will update this value
|
|
56
50
|
this._route = new Writable(null);
|
|
57
51
|
this._site = new Writable(null);
|
|
58
|
-
this.
|
|
59
|
-
this._nextSite = new Writable(null);
|
|
52
|
+
this._request = null;
|
|
60
53
|
this._loading = new Writable(false);
|
|
61
54
|
this._loadingProgress = new Writable(0);
|
|
62
55
|
this._onRouteEv = new Listeners();
|
|
63
|
-
this.
|
|
64
|
-
this._renderBarrier = null;
|
|
56
|
+
this._onRequest = new Listeners();
|
|
65
57
|
this._internal = {
|
|
66
58
|
onLoaded: () => { },
|
|
67
59
|
onLoad: () => { },
|
|
68
|
-
domReady:
|
|
60
|
+
domReady: req => this.inner.domReady(req),
|
|
69
61
|
initClient: () => this._initClient(),
|
|
70
62
|
initServer: (url, acceptLang) => this._initServer(url, acceptLang),
|
|
71
63
|
};
|
|
72
64
|
this.inner.onRoute = (route, site, changeHistory) => this._onRoute(route, site, changeHistory);
|
|
73
65
|
this.inner.onPreload = (route, site) => this._onPreload(route, site);
|
|
74
|
-
this.pageLoader.onLoaded = (resp,
|
|
75
|
-
this.pageLoader.loadFn = (
|
|
66
|
+
this.pageLoader.onLoaded = (resp, req, site, more) => this._onLoaded(resp, req, site, more);
|
|
67
|
+
this.pageLoader.loadFn = (req, site, opts) => this._internal.onLoad(req, site, opts);
|
|
76
68
|
this.pageLoader.onProgress = (loading, progress) => this._onProgress(loading, progress);
|
|
77
69
|
}
|
|
78
70
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* this is a svelte store
|
|
71
|
+
* returns a store with the current route
|
|
82
72
|
*/
|
|
83
73
|
get route() {
|
|
84
74
|
return this._route.readclone();
|
|
85
75
|
}
|
|
86
76
|
/**
|
|
87
|
-
*
|
|
77
|
+
* returns a store with the current site
|
|
88
78
|
*/
|
|
89
79
|
get site() {
|
|
90
80
|
return this._site.readonly();
|
|
91
81
|
}
|
|
92
|
-
/**
|
|
93
|
-
* The next route which is currently being loaded
|
|
94
|
-
*/
|
|
95
|
-
get nextRoute() {
|
|
96
|
-
return this._nextRoute.readclone();
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* The next site which is currently being loaded
|
|
100
|
-
*/
|
|
101
|
-
get nextSite() {
|
|
102
|
-
return this._nextSite.readonly();
|
|
103
|
-
}
|
|
104
82
|
/**
|
|
105
83
|
* The sites which are available
|
|
106
84
|
*/
|
|
@@ -108,14 +86,13 @@ export default class Router {
|
|
|
108
86
|
return this.inner.sites;
|
|
109
87
|
}
|
|
110
88
|
/**
|
|
111
|
-
*
|
|
112
|
-
* getting loaded
|
|
89
|
+
* returns a store which indicates if the a page is loading
|
|
113
90
|
*/
|
|
114
91
|
get loading() {
|
|
115
92
|
return this._loading.readonly();
|
|
116
93
|
}
|
|
117
94
|
/**
|
|
118
|
-
*
|
|
95
|
+
* returns a store which indicates the loading progress between 0 and 1
|
|
119
96
|
*/
|
|
120
97
|
get loadingProgress() {
|
|
121
98
|
return this._loadingProgress.readonly();
|
|
@@ -126,6 +103,17 @@ export default class Router {
|
|
|
126
103
|
* @param target the target to open can be an url or a route
|
|
127
104
|
* the url needs to start with http or with a / which will be considered as
|
|
128
105
|
* the site baseUrl
|
|
106
|
+
*
|
|
107
|
+
* ## Example
|
|
108
|
+
* ```
|
|
109
|
+
* import { getRouter } from 'crelte';
|
|
110
|
+
*
|
|
111
|
+
* const router = getRouter();
|
|
112
|
+
* console.log(router.site.get().url.href); // 'https://example.com/de';
|
|
113
|
+
*
|
|
114
|
+
* router.open('/foo/bar');
|
|
115
|
+
* // the following page will be opened https://example.com/de/foo/bar
|
|
116
|
+
* ```
|
|
129
117
|
*/
|
|
130
118
|
open(target) {
|
|
131
119
|
this.inner.open(target);
|
|
@@ -136,7 +124,17 @@ export default class Router {
|
|
|
136
124
|
* You can use this when using pagination for example change the route object
|
|
137
125
|
* (search argument) and then call pushState
|
|
138
126
|
*
|
|
139
|
-
*
|
|
127
|
+
* ## Example
|
|
128
|
+
* ```
|
|
129
|
+
* import { getRouter } from 'crelte';
|
|
130
|
+
*
|
|
131
|
+
* const router = getRouter();
|
|
132
|
+
*
|
|
133
|
+
* const page = 1;
|
|
134
|
+
* const route = router.route.get();
|
|
135
|
+
* route.setSearchParam('page', page > 0 ? page : null);
|
|
136
|
+
* router.pushState(route);
|
|
137
|
+
* ```
|
|
140
138
|
*/
|
|
141
139
|
pushState(route) {
|
|
142
140
|
this.pageLoader.discard();
|
|
@@ -146,7 +144,19 @@ export default class Router {
|
|
|
146
144
|
/**
|
|
147
145
|
* This replaces the state of the route without triggering an event
|
|
148
146
|
*
|
|
149
|
-
*
|
|
147
|
+
* You can use this when using some filters for example a search filter
|
|
148
|
+
*
|
|
149
|
+
* ## Example
|
|
150
|
+
* ```
|
|
151
|
+
* import { getRouter } from 'crelte';
|
|
152
|
+
*
|
|
153
|
+
* const router = getRouter();
|
|
154
|
+
*
|
|
155
|
+
* const search = 'foo';
|
|
156
|
+
* const route = router.route.get();
|
|
157
|
+
* route.setSearchParam('search', search ? search : null);
|
|
158
|
+
* router.replaceState(route);
|
|
159
|
+
* ```
|
|
150
160
|
*/
|
|
151
161
|
replaceState(route) {
|
|
152
162
|
this.pageLoader.discard();
|
|
@@ -163,7 +173,7 @@ export default class Router {
|
|
|
163
173
|
* Go back in the history
|
|
164
174
|
*/
|
|
165
175
|
back() {
|
|
166
|
-
|
|
176
|
+
this.inner.history.back();
|
|
167
177
|
}
|
|
168
178
|
/**
|
|
169
179
|
* Preload a url
|
|
@@ -176,26 +186,30 @@ export default class Router {
|
|
|
176
186
|
*
|
|
177
187
|
* This differs from router.route.subscribe in the way that
|
|
178
188
|
* it will only trigger if a new render / load will occur
|
|
189
|
+
*
|
|
190
|
+
* @returns a function to remove the listener
|
|
179
191
|
*/
|
|
180
192
|
onRoute(fn) {
|
|
181
193
|
return this._onRouteEv.add(fn);
|
|
182
194
|
}
|
|
183
|
-
|
|
184
|
-
|
|
195
|
+
/**
|
|
196
|
+
* Add a listener for the onRequest event
|
|
197
|
+
*
|
|
198
|
+
* This will trigger every time a new route is requested
|
|
199
|
+
*
|
|
200
|
+
* @returns a function to remove the listener
|
|
201
|
+
*/
|
|
202
|
+
onRequest(fn) {
|
|
203
|
+
return this._onRequest.add(fn);
|
|
185
204
|
}
|
|
186
205
|
setNewRoute(route) {
|
|
206
|
+
this.destroyRequest();
|
|
187
207
|
this._route.setSilent(route);
|
|
188
|
-
|
|
189
|
-
if (route.site) {
|
|
208
|
+
if (route.site)
|
|
190
209
|
this._site.setSilent(route.site);
|
|
191
|
-
this._nextSite.setSilent(route.site);
|
|
192
|
-
}
|
|
193
|
-
this._nextRoute.notify();
|
|
194
210
|
this._route.notify();
|
|
195
|
-
if (route.site)
|
|
196
|
-
this._nextSite.notify();
|
|
211
|
+
if (route.site)
|
|
197
212
|
this._site.notify();
|
|
198
|
-
}
|
|
199
213
|
}
|
|
200
214
|
async _initClient() {
|
|
201
215
|
this.inner.initClient();
|
|
@@ -203,19 +217,19 @@ export default class Router {
|
|
|
203
217
|
async _initServer(url, acceptLang) {
|
|
204
218
|
this.inner.initServer();
|
|
205
219
|
const prom = new Promise(resolve => {
|
|
206
|
-
this._internal.onLoaded = (success,
|
|
220
|
+
this._internal.onLoaded = (success, req, site, ready) => {
|
|
207
221
|
const props = ready();
|
|
208
222
|
this._internal.onLoaded = () => { };
|
|
209
223
|
resolve({
|
|
210
224
|
success,
|
|
211
225
|
redirect: false,
|
|
212
|
-
|
|
226
|
+
req,
|
|
213
227
|
site,
|
|
214
228
|
props,
|
|
215
229
|
});
|
|
216
230
|
};
|
|
217
231
|
});
|
|
218
|
-
const route = this.inner.
|
|
232
|
+
const route = this.inner.targetToRequest(url);
|
|
219
233
|
route.origin = 'init';
|
|
220
234
|
// let's see if the url matches any route and site
|
|
221
235
|
// if not let's redirect to the site which matches the acceptLang
|
|
@@ -224,11 +238,13 @@ export default class Router {
|
|
|
224
238
|
return {
|
|
225
239
|
success: true,
|
|
226
240
|
redirect: true,
|
|
227
|
-
|
|
241
|
+
req: new Request(site.url, site),
|
|
228
242
|
site,
|
|
229
243
|
props: {},
|
|
230
244
|
};
|
|
231
245
|
}
|
|
246
|
+
this.inner.setRoute(route);
|
|
247
|
+
const resp = await prom;
|
|
232
248
|
const hist = this.inner.history;
|
|
233
249
|
if (hist.url) {
|
|
234
250
|
const nRoute = new Route(hist.url, null);
|
|
@@ -236,52 +252,43 @@ export default class Router {
|
|
|
236
252
|
return {
|
|
237
253
|
success: true,
|
|
238
254
|
redirect: true,
|
|
239
|
-
|
|
255
|
+
req: Request.fromRoute(nRoute),
|
|
240
256
|
site: route.site,
|
|
241
257
|
props: {},
|
|
242
258
|
};
|
|
243
259
|
}
|
|
244
260
|
}
|
|
245
|
-
|
|
246
|
-
return await prom;
|
|
261
|
+
return resp;
|
|
247
262
|
}
|
|
248
|
-
_onRoute(
|
|
249
|
-
this.
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
this._nextSite.notify();
|
|
255
|
-
if (this._renderBarrier) {
|
|
256
|
-
const barr = this._renderBarrier;
|
|
257
|
-
this._renderBarrier = null;
|
|
258
|
-
// make sure nobody waits forevery
|
|
259
|
-
barr.cancel();
|
|
263
|
+
_onRoute(req, site, changeHistory) {
|
|
264
|
+
this.destroyRequest();
|
|
265
|
+
this._request = req;
|
|
266
|
+
const barrier = req._renderBarrier;
|
|
267
|
+
if (barrier.isOpen()) {
|
|
268
|
+
throw new Error('render barrier is already open');
|
|
260
269
|
}
|
|
261
|
-
|
|
262
|
-
this._renderBarrier = barrier;
|
|
263
|
-
this._onNextRoute.trigger(route.clone(), site, {
|
|
264
|
-
delayRender: () => barrier.add(),
|
|
265
|
-
});
|
|
270
|
+
this._onRequest.trigger(req, site);
|
|
266
271
|
// route prepared
|
|
267
|
-
this.pageLoader.load(
|
|
272
|
+
this.pageLoader.load(req, site, { changeHistory });
|
|
268
273
|
}
|
|
269
|
-
|
|
270
|
-
this.
|
|
274
|
+
destroyRequest() {
|
|
275
|
+
if (!this._request)
|
|
276
|
+
return;
|
|
277
|
+
this._request._renderBarrier.cancel();
|
|
278
|
+
this._request = null;
|
|
271
279
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
this._renderBarrier = null;
|
|
280
|
-
}
|
|
280
|
+
_onPreload(req, site) {
|
|
281
|
+
this.pageLoader.preload(req, site);
|
|
282
|
+
}
|
|
283
|
+
async _onLoaded(resp, req, site, more) {
|
|
284
|
+
// check if the render was cancelled
|
|
285
|
+
if (await req._renderBarrier.ready())
|
|
286
|
+
return;
|
|
281
287
|
// when the data is loaded let's update the route of the inner
|
|
282
288
|
// this is will only happen if no other route has been requested
|
|
283
289
|
// in the meantime
|
|
284
290
|
more.changeHistory();
|
|
291
|
+
const route = req.toRoute();
|
|
285
292
|
const updateRoute = () => {
|
|
286
293
|
this._route.setSilent(route);
|
|
287
294
|
const siteChanged = this.site.get()?.id !== site.id;
|
|
@@ -291,7 +298,7 @@ export default class Router {
|
|
|
291
298
|
this._site.notify();
|
|
292
299
|
this._onRouteEv.trigger(route.clone(), site);
|
|
293
300
|
};
|
|
294
|
-
this._internal.onLoaded(resp.success,
|
|
301
|
+
this._internal.onLoaded(resp.success, req, site, () => {
|
|
295
302
|
updateRoute();
|
|
296
303
|
return resp.data;
|
|
297
304
|
});
|
|
@@ -303,31 +310,3 @@ export default class Router {
|
|
|
303
310
|
this._loadingProgress.set(progress);
|
|
304
311
|
}
|
|
305
312
|
}
|
|
306
|
-
class RenderBarrier {
|
|
307
|
-
inner;
|
|
308
|
-
cancelled;
|
|
309
|
-
root;
|
|
310
|
-
constructor() {
|
|
311
|
-
this.inner = new Barrier();
|
|
312
|
-
this.cancelled = false;
|
|
313
|
-
this.root = this.add();
|
|
314
|
-
}
|
|
315
|
-
add() {
|
|
316
|
-
const action = this.inner.add();
|
|
317
|
-
return {
|
|
318
|
-
ready: async () => {
|
|
319
|
-
await action.ready(null);
|
|
320
|
-
return this.cancelled;
|
|
321
|
-
},
|
|
322
|
-
remove: () => action.remove(),
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
cancel() {
|
|
326
|
-
this.cancelled = true;
|
|
327
|
-
this.root.remove();
|
|
328
|
-
}
|
|
329
|
-
// returns if the render was cancelled
|
|
330
|
-
ready() {
|
|
331
|
-
return this.root.ready();
|
|
332
|
-
}
|
|
333
|
-
}
|
package/dist/routing/Site.d.ts
CHANGED
package/dist/routing/Site.js
CHANGED
package/dist/routing/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import Router
|
|
2
|
-
import Route from './Route.js';
|
|
1
|
+
import Router from './Router.js';
|
|
2
|
+
import Route, { type RouteOptions } from './Route.js';
|
|
3
|
+
import Request, { type RequestOptions, type DelayRender } from './Request.js';
|
|
3
4
|
import Site from './Site.js';
|
|
4
|
-
export { Router, Route, Site,
|
|
5
|
+
export { Router, Route, RouteOptions, Site, Request, DelayRender, RequestOptions, };
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/routing/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/routing/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,KAAK,EAAE,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,OAAO,EAAE,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACN,MAAM,EACN,KAAK,EACL,YAAY,EACZ,IAAI,EACJ,OAAO,EACP,WAAW,EACX,cAAc,GACd,CAAC"}
|
package/dist/routing/index.js
CHANGED
package/dist/ssr/SsrCache.d.ts
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
export declare function calcKey(data: any): Promise<string>;
|
|
2
|
+
/**
|
|
3
|
+
* A simple cache for server side rendering
|
|
4
|
+
*
|
|
5
|
+
* You can use this to store data to pass to the client or to cache data
|
|
6
|
+
* generally. Storing data and retrieving it will also work on the client.
|
|
7
|
+
*/
|
|
2
8
|
export default class SsrCache {
|
|
3
9
|
private store;
|
|
4
10
|
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* check if the value is in the cache else calls the fn
|
|
13
|
+
*/
|
|
5
14
|
load<T>(key: string, fn: () => Promise<T>): Promise<any>;
|
|
15
|
+
/**
|
|
16
|
+
* Get a value from the cache
|
|
17
|
+
*/
|
|
6
18
|
get<T>(key: string): T | null;
|
|
19
|
+
/**
|
|
20
|
+
* Set a value in the cache
|
|
21
|
+
*/
|
|
7
22
|
set<T>(key: string, val: T): T;
|
|
23
|
+
/** @hidden */
|
|
8
24
|
clear(): void;
|
|
9
25
|
private exportAsJson;
|
|
26
|
+
/** @hidden */
|
|
10
27
|
_exportToHead(): string;
|
|
11
28
|
}
|
|
12
29
|
//# sourceMappingURL=SsrCache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SsrCache.d.ts","sourceRoot":"","sources":["../../../../src/ssr/SsrCache.ts"],"names":[],"mappings":"AAAA,wBAAsB,OAAO,CAAC,IAAI,EAAE,GAAG,mBAetC;AAED,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC5B,OAAO,CAAC,KAAK,CAAsB;;
|
|
1
|
+
{"version":3,"file":"SsrCache.d.ts","sourceRoot":"","sources":["../../../../src/ssr/SsrCache.ts"],"names":[],"mappings":"AAAA,wBAAsB,OAAO,CAAC,IAAI,EAAE,GAAG,mBAetC;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC5B,OAAO,CAAC,KAAK,CAAsB;;IAYnC;;OAEG;IACG,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC;IAO/C;;OAEG;IACH,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI;IAI7B;;OAEG;IACH,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC;IAI9B,cAAc;IACd,KAAK;IAIL,OAAO,CAAC,YAAY;IAIpB,cAAc;IACd,aAAa,IAAI,MAAM;CAGvB"}
|
package/dist/ssr/SsrCache.js
CHANGED
|
@@ -11,6 +11,12 @@ export async function calcKey(data) {
|
|
|
11
11
|
.join(''); // Convert to hex string
|
|
12
12
|
return hashHex;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* A simple cache for server side rendering
|
|
16
|
+
*
|
|
17
|
+
* You can use this to store data to pass to the client or to cache data
|
|
18
|
+
* generally. Storing data and retrieving it will also work on the client.
|
|
19
|
+
*/
|
|
14
20
|
export default class SsrCache {
|
|
15
21
|
store;
|
|
16
22
|
constructor() {
|
|
@@ -21,7 +27,9 @@ export default class SsrCache {
|
|
|
21
27
|
this.store = window.SSR_STORE;
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
|
-
|
|
30
|
+
/**
|
|
31
|
+
* check if the value is in the cache else calls the fn
|
|
32
|
+
*/
|
|
25
33
|
async load(key, fn) {
|
|
26
34
|
if (key in this.store)
|
|
27
35
|
return this.store[key];
|
|
@@ -29,21 +37,26 @@ export default class SsrCache {
|
|
|
29
37
|
this.set(key, v);
|
|
30
38
|
return v;
|
|
31
39
|
}
|
|
32
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Get a value from the cache
|
|
42
|
+
*/
|
|
33
43
|
get(key) {
|
|
34
44
|
return this.store[key] ?? null;
|
|
35
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Set a value in the cache
|
|
48
|
+
*/
|
|
36
49
|
set(key, val) {
|
|
37
50
|
return (this.store[key] = val);
|
|
38
51
|
}
|
|
52
|
+
/** @hidden */
|
|
39
53
|
clear() {
|
|
40
54
|
this.store = {};
|
|
41
55
|
}
|
|
42
|
-
// internal
|
|
43
56
|
exportAsJson() {
|
|
44
57
|
return JSON.stringify(this.store).replace(/</g, '\\u003c');
|
|
45
58
|
}
|
|
46
|
-
|
|
59
|
+
/** @hidden */
|
|
47
60
|
_exportToHead() {
|
|
48
61
|
return `\n\t\t<script>window.SSR_STORE = ${this.exportAsJson()};</script>`;
|
|
49
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SsrComponents.d.ts","sourceRoot":"","sources":["../../../../src/ssr/SsrComponents.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,aAAa;IACjC,OAAO,CAAC,OAAO,CAAc;;IAO7B,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC;IAOlC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;CAkB5C"}
|
|
1
|
+
{"version":3,"file":"SsrComponents.d.ts","sourceRoot":"","sources":["../../../../src/ssr/SsrComponents.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,MAAM,CAAC,OAAO,OAAO,aAAa;IACjC,OAAO,CAAC,OAAO,CAAc;;IAO7B,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC;IAOlC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;CAkB5C"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crelte",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"author": "Crelte <support@crelte.com>",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"check": "
|
|
7
|
+
"check": "svelte-check",
|
|
8
|
+
"check-fmt": "prettier -c .",
|
|
9
|
+
"fmt": "prettier -w .",
|
|
8
10
|
"lint": "eslint ./src",
|
|
9
11
|
"test": "vitest",
|
|
10
12
|
"build": "svelte-package -i ./src",
|
|
@@ -70,10 +72,8 @@
|
|
|
70
72
|
"devDependencies": {
|
|
71
73
|
"@sveltejs/package": "^2.3.1",
|
|
72
74
|
"@sveltejs/vite-plugin-svelte": "^3.0.0",
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"typescript": "^5.2.2",
|
|
76
|
-
"typescript-eslint": "^7.11.0",
|
|
75
|
+
"svelte-check": "^4.1.4",
|
|
76
|
+
"typescript-svelte-plugin": "^0.3.45",
|
|
77
77
|
"vitest": "^2.0.0"
|
|
78
78
|
}
|
|
79
79
|
}
|