crelte 0.1.1 → 0.1.3

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