crelte 0.1.0

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 (130) hide show
  1. package/LICENSE.md +41 -0
  2. package/dist/Crelte.d.ts +55 -0
  3. package/dist/Crelte.d.ts.map +1 -0
  4. package/dist/Crelte.js +106 -0
  5. package/dist/CrelteBase.d.ts +16 -0
  6. package/dist/CrelteBase.d.ts.map +1 -0
  7. package/dist/CrelteBase.js +1 -0
  8. package/dist/CrelteRouted.d.ts +50 -0
  9. package/dist/CrelteRouted.d.ts.map +1 -0
  10. package/dist/CrelteRouted.js +88 -0
  11. package/dist/blocks/Blocks.d.ts +35 -0
  12. package/dist/blocks/Blocks.d.ts.map +1 -0
  13. package/dist/blocks/Blocks.js +100 -0
  14. package/dist/blocks/Blocks.svelte +21 -0
  15. package/dist/blocks/Blocks.svelte.d.ts +24 -0
  16. package/dist/blocks/Blocks.svelte.d.ts.map +1 -0
  17. package/dist/blocks/index.d.ts +5 -0
  18. package/dist/blocks/index.d.ts.map +1 -0
  19. package/dist/blocks/index.js +3 -0
  20. package/dist/cookies/ClientCookies.d.ts +9 -0
  21. package/dist/cookies/ClientCookies.d.ts.map +1 -0
  22. package/dist/cookies/ClientCookies.js +22 -0
  23. package/dist/cookies/ServerCookies.d.ts +13 -0
  24. package/dist/cookies/ServerCookies.d.ts.map +1 -0
  25. package/dist/cookies/ServerCookies.js +31 -0
  26. package/dist/cookies/index.d.ts +20 -0
  27. package/dist/cookies/index.d.ts.map +1 -0
  28. package/dist/cookies/index.js +1 -0
  29. package/dist/cookies/utils.d.ts +12 -0
  30. package/dist/cookies/utils.d.ts.map +1 -0
  31. package/dist/cookies/utils.js +32 -0
  32. package/dist/graphql/GraphQl.d.ts +60 -0
  33. package/dist/graphql/GraphQl.d.ts.map +1 -0
  34. package/dist/graphql/GraphQl.js +197 -0
  35. package/dist/graphql/gql.test.d.ts +2 -0
  36. package/dist/graphql/gql.test.d.ts.map +1 -0
  37. package/dist/graphql/gql.test.js +80 -0
  38. package/dist/graphql/index.d.ts +3 -0
  39. package/dist/graphql/index.d.ts.map +1 -0
  40. package/dist/graphql/index.js +2 -0
  41. package/dist/index.d.ts +67 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +83 -0
  44. package/dist/init/client.d.ts +13 -0
  45. package/dist/init/client.d.ts.map +1 -0
  46. package/dist/init/client.js +129 -0
  47. package/dist/init/server.d.ts +38 -0
  48. package/dist/init/server.d.ts.map +1 -0
  49. package/dist/init/server.js +95 -0
  50. package/dist/init/shared.d.ts +29 -0
  51. package/dist/init/shared.d.ts.map +1 -0
  52. package/dist/init/shared.js +154 -0
  53. package/dist/loadData/Globals.d.ts +33 -0
  54. package/dist/loadData/Globals.d.ts.map +1 -0
  55. package/dist/loadData/Globals.js +119 -0
  56. package/dist/loadData/index.d.ts +25 -0
  57. package/dist/loadData/index.d.ts.map +1 -0
  58. package/dist/loadData/index.js +39 -0
  59. package/dist/plugins/Events.d.ts +11 -0
  60. package/dist/plugins/Events.d.ts.map +1 -0
  61. package/dist/plugins/Events.js +29 -0
  62. package/dist/plugins/Plugins.d.ts +12 -0
  63. package/dist/plugins/Plugins.d.ts.map +1 -0
  64. package/dist/plugins/Plugins.js +12 -0
  65. package/dist/plugins/index.d.ts +5 -0
  66. package/dist/plugins/index.d.ts.map +1 -0
  67. package/dist/plugins/index.js +2 -0
  68. package/dist/routing/History.d.ts +22 -0
  69. package/dist/routing/History.d.ts.map +1 -0
  70. package/dist/routing/History.js +36 -0
  71. package/dist/routing/InnerRouter.d.ts +111 -0
  72. package/dist/routing/InnerRouter.d.ts.map +1 -0
  73. package/dist/routing/InnerRouter.js +397 -0
  74. package/dist/routing/PageLoader.d.ts +37 -0
  75. package/dist/routing/PageLoader.d.ts.map +1 -0
  76. package/dist/routing/PageLoader.js +72 -0
  77. package/dist/routing/Route.d.ts +82 -0
  78. package/dist/routing/Route.d.ts.map +1 -0
  79. package/dist/routing/Route.js +134 -0
  80. package/dist/routing/Router.d.ts +162 -0
  81. package/dist/routing/Router.d.ts.map +1 -0
  82. package/dist/routing/Router.js +333 -0
  83. package/dist/routing/Site.d.ts +47 -0
  84. package/dist/routing/Site.d.ts.map +1 -0
  85. package/dist/routing/Site.js +48 -0
  86. package/dist/routing/index.d.ts +5 -0
  87. package/dist/routing/index.d.ts.map +1 -0
  88. package/dist/routing/index.js +4 -0
  89. package/dist/ssr/SsrCache.d.ts +12 -0
  90. package/dist/ssr/SsrCache.d.ts.map +1 -0
  91. package/dist/ssr/SsrCache.js +50 -0
  92. package/dist/ssr/SsrComponents.d.ts +7 -0
  93. package/dist/ssr/SsrComponents.d.ts.map +1 -0
  94. package/dist/ssr/SsrComponents.js +30 -0
  95. package/dist/ssr/index.d.ts +4 -0
  96. package/dist/ssr/index.d.ts.map +1 -0
  97. package/dist/ssr/index.js +3 -0
  98. package/package.json +79 -0
  99. package/src/Crelte.ts +135 -0
  100. package/src/CrelteBase.ts +24 -0
  101. package/src/CrelteRouted.ts +128 -0
  102. package/src/blocks/Blocks.svelte +68 -0
  103. package/src/blocks/Blocks.ts +155 -0
  104. package/src/blocks/index.ts +14 -0
  105. package/src/cookies/ClientCookies.ts +30 -0
  106. package/src/cookies/ServerCookies.ts +42 -0
  107. package/src/cookies/index.ts +24 -0
  108. package/src/cookies/utils.ts +53 -0
  109. package/src/graphql/GraphQl.ts +281 -0
  110. package/src/graphql/gql.test.ts +123 -0
  111. package/src/graphql/index.ts +8 -0
  112. package/src/index.ts +109 -0
  113. package/src/init/client.ts +190 -0
  114. package/src/init/server.ts +177 -0
  115. package/src/init/shared.ts +221 -0
  116. package/src/loadData/Globals.ts +150 -0
  117. package/src/loadData/index.ts +67 -0
  118. package/src/plugins/Events.ts +50 -0
  119. package/src/plugins/Plugins.ts +23 -0
  120. package/src/plugins/index.ts +5 -0
  121. package/src/routing/History.ts +52 -0
  122. package/src/routing/InnerRouter.ts +469 -0
  123. package/src/routing/PageLoader.ts +112 -0
  124. package/src/routing/Route.ts +184 -0
  125. package/src/routing/Router.ts +476 -0
  126. package/src/routing/Site.ts +65 -0
  127. package/src/routing/index.ts +5 -0
  128. package/src/ssr/SsrCache.ts +61 -0
  129. package/src/ssr/SsrComponents.ts +34 -0
  130. package/src/ssr/index.ts +4 -0
package/LICENSE.md ADDED
@@ -0,0 +1,41 @@
1
+ Copyright © Dunkel
2
+
3
+
4
+ Permission is hereby granted to any person obtaining a copy of this software
5
+ (the “Software”) to use, copy, modify, merge, publish and/or distribute copies
6
+ of the Software, and to permit persons to whom the Software is furnished to do
7
+ so, subject to the following conditions:
8
+
9
+ 1. **Don’t plagiarize.** The above copyright notice and this license shall be
10
+ included in all copies or substantial portions of the Software.
11
+
12
+ 2. **Don’t use the same license on more than one project.** Each licensed copy
13
+ of the Software shall be actively installed in no more than one production
14
+ environment at a time.
15
+
16
+ 3. **Don’t mess with the licensing features.** Software features related to
17
+ licensing shall not be altered or circumvented in any way, including (but
18
+ not limited to) license validation, payment prompts, feature restrictions,
19
+ and update eligibility.
20
+
21
+ 4. **Pay up.** Payment shall be made immediately upon receipt of any notice,
22
+ prompt, reminder, or other message indicating that a payment is owed.
23
+
24
+ 5. **Follow the law.** All use of the Software shall not violate any applicable
25
+ law or regulation, nor infringe the rights of any other person or entity.
26
+
27
+ Failure to comply with the foregoing conditions will automatically and
28
+ immediately result in termination of the permission granted hereby. This
29
+ license does not include any right to receive updates to the Software or
30
+ technical support. Licensees bear all risk related to the quality and
31
+ performance of the Software and any modifications made or obtained to it,
32
+ including liability for actual and consequential harm, such as loss or
33
+ corruption of data, and any necessary service, repair, or correction.
34
+
35
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER
39
+ LIABILITY, INCLUDING SPECIAL, INCIDENTAL AND CONSEQUENTIAL DAMAGES, WHETHER IN
40
+ AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
41
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,55 @@
1
+ import { Cookies } from './cookies/index.js';
2
+ import CrelteBase from './CrelteBase.js';
3
+ import CrelteRouted, { GraphQlQuery } from './CrelteRouted.js';
4
+ import GraphQl, { GraphQlOptions, GraphQlRequestOptions } from './graphql/GraphQl.js';
5
+ import Globals from './loadData/Globals.js';
6
+ import Events from './plugins/Events.js';
7
+ import Plugins, { Plugin } from './plugins/Plugins.js';
8
+ import Route from './routing/Route.js';
9
+ import Router, { RouterOpts } from './routing/Router.js';
10
+ import Site, { SiteFromGraphQl } from './routing/Site.js';
11
+ import SsrCache from './ssr/SsrCache.js';
12
+ export declare class CrelteBuilder {
13
+ ssrCache: SsrCache;
14
+ plugins: Plugins;
15
+ events: Events;
16
+ graphQl?: GraphQl;
17
+ router?: Router;
18
+ globals: Globals;
19
+ cookies: Cookies;
20
+ constructor();
21
+ setupGraphQl(endpoint: string, opts?: GraphQlOptions): void;
22
+ setupRouter(sites: SiteFromGraphQl[], opts?: RouterOpts): void;
23
+ setupCookies(cookies: string): void;
24
+ build(): Crelte;
25
+ }
26
+ export default class Crelte implements CrelteBase {
27
+ ssrCache: SsrCache;
28
+ graphQl: GraphQl;
29
+ router: Router;
30
+ plugins: Plugins;
31
+ events: Events;
32
+ globals: Globals;
33
+ cookies: Cookies;
34
+ constructor(builder: CrelteBuilder);
35
+ getPlugin(name: string): Plugin | null;
36
+ /**
37
+ * returns an env Variables, always needs to be prefixed VITE_
38
+ * Except ENDPOINT_URL and CRAFT_WEB_URL
39
+ */
40
+ getEnv(name: string): string | null;
41
+ getGlobal(name: string): any | null;
42
+ toRouted(route?: Route, site?: Site): CrelteRouted;
43
+ /**
44
+ * Run a GraphQl Query
45
+ *
46
+ * @param query the default export from a graphql file
47
+ * @param variables variables that should be passed to the
48
+ * graphql query
49
+ * @param options opts `{ caching: true, previewToken: string,
50
+ * siteToken: string, ignoreStatusCode: false, headers: {} }`
51
+ */
52
+ query(query: GraphQlQuery, variables?: Record<string, unknown>, opts?: GraphQlRequestOptions): Promise<unknown>;
53
+ _getContext(): Map<string, any>;
54
+ }
55
+ //# sourceMappingURL=Crelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Crelte.d.ts","sourceRoot":"","sources":["../../../src/Crelte.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,UAAU,MAAM,iBAAiB,CAAC;AACzC,OAAO,YAAY,EAAE,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,OAAO,EAAE,EACf,cAAc,EACd,qBAAqB,EACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,OAAO,MAAM,uBAAuB,CAAC;AAC5C,OAAO,MAAM,MAAM,qBAAqB,CAAC;AACzC,OAAO,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,MAAM,oBAAoB,CAAC;AACvC,OAAO,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,IAAI,EAAE,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AAEzC,qBAAa,aAAa;IACzB,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;;IAajB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,GAAE,cAAmB;IAIxD,WAAW,CAAC,KAAK,EAAE,eAAe,EAAE,EAAE,IAAI,GAAE,UAAe;IAI3D,YAAY,CAAC,OAAO,EAAE,MAAM;IAI5B,KAAK,IAAI,MAAM;CAGf;AAED,MAAM,CAAC,OAAO,OAAO,MAAO,YAAW,UAAU;IAChD,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;gBAEL,OAAO,EAAE,aAAa;IAalC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAItC;;;OAGG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAMnC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI;IAKnC,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,YAAY;IAalD;;;;;;;;OAQG;IACG,KAAK,CACV,KAAK,EAAE,YAAY,EACnB,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACvC,IAAI,GAAE,qBAA0B,GAC9B,OAAO,CAAC,OAAO,CAAC;IAMnB,WAAW,IAAI,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC;CAO/B"}
package/dist/Crelte.js ADDED
@@ -0,0 +1,106 @@
1
+ import ClientCookies from './cookies/ClientCookies.js';
2
+ import ServerCookies from './cookies/ServerCookies.js';
3
+ import CrelteRouted from './CrelteRouted.js';
4
+ import GraphQl from './graphql/GraphQl.js';
5
+ import Globals from './loadData/Globals.js';
6
+ import Events from './plugins/Events.js';
7
+ import Plugins from './plugins/Plugins.js';
8
+ import Router from './routing/Router.js';
9
+ import SsrCache from './ssr/SsrCache.js';
10
+ export class CrelteBuilder {
11
+ ssrCache;
12
+ plugins;
13
+ events;
14
+ graphQl;
15
+ router;
16
+ globals;
17
+ cookies;
18
+ constructor() {
19
+ this.ssrCache = new SsrCache();
20
+ this.plugins = new Plugins();
21
+ this.events = new Events();
22
+ this.globals = new Globals();
23
+ // @ts-ignore
24
+ this.cookies = import.meta.env.SSR
25
+ ? new ServerCookies()
26
+ : new ClientCookies();
27
+ }
28
+ setupGraphQl(endpoint, opts = {}) {
29
+ this.graphQl = new GraphQl(endpoint, this.ssrCache, opts);
30
+ }
31
+ setupRouter(sites, opts = {}) {
32
+ this.router = new Router(sites, opts);
33
+ }
34
+ setupCookies(cookies) {
35
+ this.cookies._init(cookies);
36
+ }
37
+ build() {
38
+ return new Crelte(this);
39
+ }
40
+ }
41
+ export default class Crelte {
42
+ ssrCache;
43
+ graphQl;
44
+ router;
45
+ plugins;
46
+ events;
47
+ globals;
48
+ cookies;
49
+ constructor(builder) {
50
+ if (!builder.graphQl || !builder.router)
51
+ throw new Error('builder not ready');
52
+ this.ssrCache = builder.ssrCache;
53
+ this.graphQl = builder.graphQl;
54
+ this.router = builder.router;
55
+ this.plugins = builder.plugins;
56
+ this.events = builder.events;
57
+ this.globals = builder.globals;
58
+ this.cookies = builder.cookies;
59
+ }
60
+ getPlugin(name) {
61
+ return this.plugins.get(name);
62
+ }
63
+ /**
64
+ * returns an env Variables, always needs to be prefixed VITE_
65
+ * Except ENDPOINT_URL and CRAFT_WEB_URL
66
+ */
67
+ getEnv(name) {
68
+ return this.ssrCache.get(name);
69
+ }
70
+ /// calling this from loadGlobalData will always return null
71
+ /// this does return the resolved store
72
+ getGlobal(name) {
73
+ return this.globals.get(name) ?? null;
74
+ }
75
+ /// requires a site if the route does not contain a site
76
+ toRouted(route, site) {
77
+ if (!route) {
78
+ route = this.router.route.get();
79
+ }
80
+ if (!site) {
81
+ if (!route.site)
82
+ throw new Error('site is required');
83
+ site = route.site;
84
+ }
85
+ return new CrelteRouted(this, route, site);
86
+ }
87
+ /**
88
+ * Run a GraphQl Query
89
+ *
90
+ * @param query the default export from a graphql file
91
+ * @param variables variables that should be passed to the
92
+ * graphql query
93
+ * @param options opts `{ caching: true, previewToken: string,
94
+ * siteToken: string, ignoreStatusCode: false, headers: {} }`
95
+ */
96
+ async query(query, variables = {}, opts = {}) {
97
+ // this function is added as convenience
98
+ return this.toRouted().query(query, variables, opts);
99
+ }
100
+ // don't use
101
+ _getContext() {
102
+ const map = new Map();
103
+ map.set('crelte', this);
104
+ return map;
105
+ }
106
+ }
@@ -0,0 +1,16 @@
1
+ import { GraphQlQuery } from './CrelteRouted.js';
2
+ import { GraphQlRequestOptions } from './graphql/GraphQl.js';
3
+ export default interface CrelteBase {
4
+ getGlobal(name: string): any | null;
5
+ /**
6
+ * Run a GraphQl Query
7
+ *
8
+ * @param query the default export from a graphql file
9
+ * @param variables variables that should be passed to the
10
+ * graphql query
11
+ * @param options opts `{ caching: true, previewToken: string,
12
+ * siteToken: string, ignoreStatusCode: false, headers: {} }`
13
+ */
14
+ query(query: GraphQlQuery, variables?: Record<string, unknown>, opts?: GraphQlRequestOptions): Promise<unknown>;
15
+ }
16
+ //# sourceMappingURL=CrelteBase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CrelteBase.d.ts","sourceRoot":"","sources":["../../../src/CrelteBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAG7D,MAAM,CAAC,OAAO,WAAW,UAAU;IAGlC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC;IAEpC;;;;;;;;OAQG;IACH,KAAK,CACJ,KAAK,EAAE,YAAY,EACnB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,IAAI,CAAC,EAAE,qBAAqB,GAC1B,OAAO,CAAC,OAAO,CAAC,CAAC;CACpB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,50 @@
1
+ import { Cookies } from './cookies/index.js';
2
+ import Crelte from './Crelte.js';
3
+ import CrelteBase from './CrelteBase.js';
4
+ import GraphQl, { GraphQlRequestOptions } from './graphql/GraphQl.js';
5
+ import type Globals from './loadData/Globals.js';
6
+ import type Events from './plugins/Events.js';
7
+ import Plugins, { Plugin } from './plugins/Plugins.js';
8
+ import Route from './routing/Route.js';
9
+ import Router from './routing/Router.js';
10
+ import Site from './routing/Site.js';
11
+ import SsrCache from './ssr/SsrCache.js';
12
+ export type GraphQlQuery = {
13
+ path?: string;
14
+ query: string;
15
+ };
16
+ export default class CrelteRouted implements CrelteBase {
17
+ route: Route;
18
+ site: Site;
19
+ private inner;
20
+ private innerGlobals;
21
+ constructor(inner: Crelte, route: Route, site: Site);
22
+ get crelte(): Crelte;
23
+ get ssrCache(): SsrCache;
24
+ get plugins(): Plugins;
25
+ get events(): Events;
26
+ get graphQl(): GraphQl;
27
+ get router(): Router;
28
+ get globals(): Globals;
29
+ get cookies(): Cookies;
30
+ getPlugin(name: string): Plugin | null;
31
+ /**
32
+ * returns an env Variables, always needs to be prefixed VITE_
33
+ * Except ENDPOINT_URL and CRAFT_WEB_URL
34
+ */
35
+ getEnv(name: string): string | null;
36
+ getGlobal(name: string): any | null;
37
+ getGlobalAsync(name: string): Promise<any | null>;
38
+ /**
39
+ * Run a GraphQl Query
40
+ *
41
+ * @param query the default export from a graphql file
42
+ * @param variables variables that should be passed to the
43
+ * graphql query
44
+ * @param options opts `{ caching: true, previewToken: string,
45
+ * siteToken: string, ignoreStatusCode: false, headers: {} }`
46
+ */
47
+ query(query: GraphQlQuery, variables?: Record<string, unknown>, opts?: GraphQlRequestOptions): Promise<unknown>;
48
+ _globalDataLoaded(): void;
49
+ }
50
+ //# sourceMappingURL=CrelteRouted.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CrelteRouted.d.ts","sourceRoot":"","sources":["../../../src/CrelteRouted.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,UAAU,MAAM,iBAAiB,CAAC;AACzC,OAAO,OAAO,EAAE,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,MAAM,MAAM,qBAAqB,CAAC;AAC9C,OAAO,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,MAAM,oBAAoB,CAAC;AACvC,OAAO,MAAM,MAAM,qBAAqB,CAAC;AACzC,OAAO,IAAI,MAAM,mBAAmB,CAAC;AACrC,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AAEzC,MAAM,MAAM,YAAY,GAAG;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,YAAa,YAAW,UAAU;IACtD,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,EAAE,IAAI,CAAC;IAEX,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,YAAY,CAAmB;gBAE3B,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI;IAQnD,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,QAAQ,IAAI,QAAQ,CAEvB;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAGD,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAItC;;;OAGG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAMnC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI;IAO7B,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;IAUvD;;;;;;;;OAQG;IACG,KAAK,CACV,KAAK,EAAE,YAAY,EACnB,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACvC,IAAI,GAAE,qBAA0B,GAC9B,OAAO,CAAC,OAAO,CAAC;IAenB,iBAAiB;CAGjB"}
@@ -0,0 +1,88 @@
1
+ export default class CrelteRouted {
2
+ route;
3
+ site;
4
+ inner;
5
+ innerGlobals;
6
+ constructor(inner, route, site) {
7
+ this.route = route;
8
+ this.site = site;
9
+ this.inner = inner;
10
+ this.innerGlobals = new Map();
11
+ }
12
+ get crelte() {
13
+ return this.inner;
14
+ }
15
+ get ssrCache() {
16
+ return this.inner.ssrCache;
17
+ }
18
+ get plugins() {
19
+ return this.inner.plugins;
20
+ }
21
+ get events() {
22
+ return this.inner.events;
23
+ }
24
+ get graphQl() {
25
+ return this.inner.graphQl;
26
+ }
27
+ get router() {
28
+ return this.inner.router;
29
+ }
30
+ get globals() {
31
+ return this.inner.globals;
32
+ }
33
+ get cookies() {
34
+ return this.inner.cookies;
35
+ }
36
+ // overload this function to add your plugin type
37
+ getPlugin(name) {
38
+ return this.inner.plugins.get(name);
39
+ }
40
+ /**
41
+ * returns an env Variables, always needs to be prefixed VITE_
42
+ * Except ENDPOINT_URL and CRAFT_WEB_URL
43
+ */
44
+ getEnv(name) {
45
+ return this.inner.getEnv(name);
46
+ }
47
+ /// calling this from loadGlobalData will always return null
48
+ /// this does return the resolved store
49
+ getGlobal(name) {
50
+ return this.innerGlobals.get(name) ?? null;
51
+ }
52
+ /// get a global and wait for it if it is still loaded
53
+ /// this is useful when you need to load a global in the
54
+ /// loadGlobalData function
55
+ async getGlobalAsync(name) {
56
+ const global = this.innerGlobals.get(name);
57
+ if (global)
58
+ return global;
59
+ const r = await this.inner.globals.getAsync(name);
60
+ if (!r)
61
+ return null;
62
+ return r.bySiteId(this.site.id);
63
+ }
64
+ /**
65
+ * Run a GraphQl Query
66
+ *
67
+ * @param query the default export from a graphql file
68
+ * @param variables variables that should be passed to the
69
+ * graphql query
70
+ * @param options opts `{ caching: true, previewToken: string,
71
+ * siteToken: string, ignoreStatusCode: false, headers: {} }`
72
+ */
73
+ async query(query, variables = {}, opts = {}) {
74
+ const search = this.route.search;
75
+ if (search.has('token') && search.get('x-craft-live-preview')) {
76
+ opts.previewToken = search.get('token');
77
+ }
78
+ else if (search.has('siteToken')) {
79
+ opts.siteToken = search.get('siteToken');
80
+ }
81
+ opts.path = query.path;
82
+ return await this.graphQl.request(query.query, variables, opts);
83
+ }
84
+ // hidden
85
+ _globalDataLoaded() {
86
+ this.innerGlobals = this.inner.globals._globalsBySite(this.site.id);
87
+ }
88
+ }
@@ -0,0 +1,35 @@
1
+ import { CrelteRouted } from '../index.js';
2
+ export interface Module {
3
+ default: any;
4
+ handle?: string | string[];
5
+ keepTypeHandle?: boolean;
6
+ loadData?: (block: any) => Promise<any>;
7
+ }
8
+ export type AsyncModule = (() => Promise<Module>) | Module;
9
+ export type BlockModulesOptions = {
10
+ alias?: Record<string, string>;
11
+ };
12
+ export declare class BlockModules {
13
+ modules: Map<string, AsyncModule>;
14
+ alias: Map<string, string>;
15
+ constructor(modules: Record<string, AsyncModule>, opts?: BlockModulesOptions);
16
+ /**
17
+ * Loads the required modules
18
+ *
19
+ * @throws an error if a module is not found
20
+ */
21
+ load(requiredModules: Set<string>): Promise<Map<string, Module>>;
22
+ }
23
+ export declare function newBlocks(blocks: any[], modules: BlockModules): Promise<Blocks>;
24
+ export default class Blocks {
25
+ blocks: any[];
26
+ data: any[];
27
+ modules: Map<string, Module>;
28
+ constructor(blocks: any[], modules: Map<string, Module>);
29
+ loadData(cr: CrelteRouted): Promise<void>;
30
+ each(): {
31
+ mod: any;
32
+ props: any;
33
+ }[];
34
+ }
35
+ //# sourceMappingURL=Blocks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Blocks.d.ts","sourceRoot":"","sources":["../../../../src/blocks/Blocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,MAAM,WAAW,MAAM;IAEtB,OAAO,EAAE,GAAG,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CACxC;AAED,MAAM,MAAM,WAAW,GAAG,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC;AAE3D,MAAM,MAAM,mBAAmB,GAAG;IAEjC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B,CAAC;AAEF,qBAAa,YAAY;IACxB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAClC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAG1B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACpC,IAAI,GAAE,mBAAwB;IAgC/B;;;;OAIG;IACG,IAAI,CAAC,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAmBtE;AAED,wBAAsB,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,YAAY,mBAanE;AAED,MAAM,CAAC,OAAO,OAAO,MAAM;IAC1B,MAAM,EAAE,GAAG,EAAE,CAAC;IACd,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAEjB,MAAM,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAMjD,QAAQ,CAAC,EAAE,EAAE,YAAY;IAkB/B,IAAI,IAAI;QAAE,GAAG,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,GAAG,CAAA;KAAE,EAAE;CAclC"}
@@ -0,0 +1,100 @@
1
+ import { callLoadData } from '../loadData/index.js';
2
+ export class BlockModules {
3
+ modules;
4
+ alias;
5
+ constructor(modules, opts = {}) {
6
+ this.modules = new Map(Object.entries(modules)
7
+ .map(([path, mod]) => {
8
+ const [name, ext] = parseFilename(path);
9
+ return [ext === 'svelte' ? name : '', mod];
10
+ })
11
+ .filter(([name, _mod]) => !!name));
12
+ this.alias = new Map(Object.entries(opts.alias ?? {}));
13
+ // backwards compatibility allow to use the export const handle
14
+ this.modules.forEach((mod, name) => {
15
+ if (typeof mod === 'function')
16
+ return;
17
+ if (mod.handle) {
18
+ const handles = Array.isArray(mod.handle)
19
+ ? mod.handle
20
+ : [mod.handle];
21
+ handles.forEach(handle => {
22
+ this.alias.set(handle, name);
23
+ });
24
+ }
25
+ });
26
+ }
27
+ /**
28
+ * Loads the required modules
29
+ *
30
+ * @throws an error if a module is not found
31
+ */
32
+ async load(requiredModules) {
33
+ const loaded = await Promise.all([...requiredModules.keys()].map(mod => {
34
+ let module = this.modules.get(mod);
35
+ if (!module)
36
+ module = this.modules.get(this.alias.get(mod) ?? '');
37
+ if (!module)
38
+ throw new Error(`Module ${mod} not found`);
39
+ return typeof module === 'function' ? module() : module;
40
+ }));
41
+ // todo once loaded override it in module again
42
+ return new Map([...requiredModules.keys()].map((mod, i) => [mod, loaded[i]]));
43
+ }
44
+ }
45
+ export async function newBlocks(blocks, modules) {
46
+ // define all required modules
47
+ const requiredModules = new Set();
48
+ for (const block of blocks) {
49
+ if (!block.typeHandle)
50
+ throw new Error('Block must have a typeHandle');
51
+ requiredModules.add(block.typeHandle);
52
+ }
53
+ const loadedModules = await modules.load(requiredModules);
54
+ return new Blocks(blocks, loadedModules);
55
+ }
56
+ export default class Blocks {
57
+ blocks;
58
+ data;
59
+ modules;
60
+ constructor(blocks, modules) {
61
+ this.blocks = blocks;
62
+ this.modules = modules;
63
+ this.data = blocks.map(() => null);
64
+ }
65
+ async loadData(cr) {
66
+ this.data = await Promise.all(this.blocks.map((block, i) => {
67
+ const mod = this.modules.get(block.typeHandle);
68
+ if ('loadData' in mod) {
69
+ return callLoadData(mod.loadData, cr, block, {
70
+ getSibling: (offset) => {
71
+ return this.blocks[i + offset] ?? null;
72
+ },
73
+ });
74
+ }
75
+ return {};
76
+ }));
77
+ }
78
+ each() {
79
+ return this.blocks.map((block, i) => {
80
+ const mod = this.modules.get(block.typeHandle);
81
+ const props = { ...block };
82
+ if (!mod.keepTypeHandle)
83
+ delete props.typeHandle;
84
+ Object.assign(props, this.data[i]);
85
+ return {
86
+ mod: mod.default,
87
+ props,
88
+ };
89
+ });
90
+ }
91
+ }
92
+ function parseFilename(path) {
93
+ // get filename with extension
94
+ const slash = path.lastIndexOf('/');
95
+ const filename = path.substring(slash + 1);
96
+ const extPos = filename.lastIndexOf('.');
97
+ const name = filename.substring(0, extPos);
98
+ const ext = filename.substring(extPos + 1);
99
+ return [name, ext];
100
+ }
@@ -0,0 +1,21 @@
1
+ <script context="module">import { CrelteRouted } from "../index.js";
2
+ import Blocks, {
3
+ BlockModules,
4
+ newBlocks
5
+ } from "./Blocks.js";
6
+ export function blockModules(modules, opts = {}) {
7
+ return new BlockModules(modules, opts);
8
+ }
9
+ export async function loadBlocksData(cr, blocks, modules) {
10
+ const nBlocks = await newBlocks(blocks, modules);
11
+ await nBlocks.loadData(cr);
12
+ return nBlocks;
13
+ }
14
+ </script>
15
+
16
+ <script>export let blocks;
17
+ </script>
18
+
19
+ {#each blocks.each() as { mod, props }}
20
+ <svelte:component this={mod} {...props} {...$$restProps} />
21
+ {/each}
@@ -0,0 +1,24 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import { CrelteRouted } from '../index.js';
3
+ import Blocks, { type AsyncModule, type Module, type BlockModulesOptions, BlockModules } from './Blocks.js';
4
+ export type { BlockModules, BlockModulesOptions, AsyncModule, Module };
5
+ export declare function blockModules(modules: Record<string, AsyncModule>, opts?: BlockModulesOptions): BlockModules;
6
+ export declare function loadBlocksData(cr: CrelteRouted, blocks: any[], modules: BlockModules): Promise<Blocks>;
7
+ declare const __propDef: {
8
+ props: {
9
+ [x: string]: any;
10
+ blocks: Blocks;
11
+ };
12
+ events: {
13
+ [evt: string]: CustomEvent<any>;
14
+ };
15
+ slots: {};
16
+ exports?: undefined;
17
+ bindings?: undefined;
18
+ };
19
+ export type BlocksProps = typeof __propDef.props;
20
+ export type BlocksEvents = typeof __propDef.events;
21
+ export type BlocksSlots = typeof __propDef.slots;
22
+ export default class Blocks extends SvelteComponent<BlocksProps, BlocksEvents, BlocksSlots> {
23
+ }
24
+ //# sourceMappingURL=Blocks.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Blocks.svelte.d.ts","sourceRoot":"","sources":["../../../../src/blocks/Blocks.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAEvC;AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AA8B3C,OAAO,MAAM,EAAE,EACd,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,mBAAmB,EACxB,YAAY,EAEZ,MAAM,aAAa,CAAC;AAErB,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AAEvE,wBAAgB,YAAY,CAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACpC,IAAI,GAAE,mBAAwB,GAC5B,YAAY,CAEd;AAED,wBAAsB,cAAc,CACnC,EAAE,EAAE,YAAY,EAChB,MAAM,EAAE,GAAG,EAAE,EACb,OAAO,EAAE,YAAY,GACnB,OAAO,CAAC,MAAM,CAAC,CAMjB;AAcF,QAAA,MAAM,SAAS;;;gBAD8B,MAAM;;;;;;;;CAC2B,CAAC;AAC/E,MAAM,MAAM,WAAW,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AACjD,MAAM,MAAM,YAAY,GAAG,OAAO,SAAS,CAAC,MAAM,CAAC;AACnD,MAAM,MAAM,WAAW,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAEjD,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,eAAe,CAAC,WAAW,EAAE,YAAY,EAAE,WAAW,CAAC;CAC1F"}
@@ -0,0 +1,5 @@
1
+ import Blocks, { type BlockModules, type BlockModulesOptions, type AsyncModule, type Module, blockModules, loadBlocksData } from './Blocks.svelte';
2
+ export type { BlockModules, BlockModulesOptions, AsyncModule, Module };
3
+ export { Blocks, blockModules, loadBlocksData };
4
+ export default Blocks;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/blocks/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EACd,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,YAAY,EACZ,cAAc,EACd,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AAEvE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC;AAEhD,eAAe,MAAM,CAAC"}
@@ -0,0 +1,3 @@
1
+ import Blocks, { blockModules, loadBlocksData, } from './Blocks.svelte';
2
+ export { Blocks, blockModules, loadBlocksData };
3
+ export default Blocks;
@@ -0,0 +1,9 @@
1
+ import { Cookies, SetOptions } from './index.js';
2
+ export default class ClientCookies implements Cookies {
3
+ constructor();
4
+ _init(_cookies: string): void;
5
+ get(name: string): string | null;
6
+ set(name: string, value: string, opts?: SetOptions): void;
7
+ remove(name: string): void;
8
+ }
9
+ //# sourceMappingURL=ClientCookies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClientCookies.d.ts","sourceRoot":"","sources":["../../../../src/cookies/ClientCookies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAMjD,MAAM,CAAC,OAAO,OAAO,aAAc,YAAW,OAAO;;IAGpD,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAE7B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAKhC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI;IAMzD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAG1B"}
@@ -0,0 +1,22 @@
1
+ import { parseCookies, setCookieToString } from './utils.js';
2
+ // the philosophy here is that document.cookie is the source of truth
3
+ // so we don't cache cookies here
4
+ // if this changes, modify init/client.ts
5
+ export default class ClientCookies {
6
+ constructor() { }
7
+ _init(_cookies) { }
8
+ get(name) {
9
+ const cookies = getCookies();
10
+ return cookies.get(name) ?? null;
11
+ }
12
+ set(name, value, opts) {
13
+ const setCookie = { name, value, ...opts };
14
+ document.cookie = setCookieToString(setCookie);
15
+ }
16
+ remove(name) {
17
+ this.set(name, '', { maxAge: 0 });
18
+ }
19
+ }
20
+ function getCookies() {
21
+ return parseCookies(document.cookie);
22
+ }
@@ -0,0 +1,13 @@
1
+ import { Cookies, SetOptions } from './index.js';
2
+ import { SetCookie } from './utils.js';
3
+ export default class ServerCookies implements Cookies {
4
+ requestCookies: Map<string, string>;
5
+ setCookies: Map<string, SetCookie>;
6
+ constructor();
7
+ _init(cookies: string): void;
8
+ get(name: string): string | null;
9
+ set(name: string, value: string, opts?: SetOptions): void;
10
+ remove(name: string): void;
11
+ _getSetCookiesHeaders(): string[];
12
+ }
13
+ //# sourceMappingURL=ServerCookies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServerCookies.d.ts","sourceRoot":"","sources":["../../../../src/cookies/ServerCookies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAgB,SAAS,EAAqB,MAAM,YAAY,CAAC;AAExE,MAAM,CAAC,OAAO,OAAO,aAAc,YAAW,OAAO;IACpD,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;;IAOnC,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAM5B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAUhC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI;IAIzD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI1B,qBAAqB,IAAI,MAAM,EAAE;CAKjC"}