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.
Files changed (114) 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 +6 -3
  51. package/dist/routing/History.d.ts.map +1 -1
  52. package/dist/routing/History.js +7 -1
  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 +47 -35
  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 +71 -6
  65. package/dist/routing/Router.d.ts +59 -52
  66. package/dist/routing/Router.d.ts.map +1 -1
  67. package/dist/routing/Router.js +95 -116
  68. package/dist/routing/Site.d.ts +1 -1
  69. package/dist/routing/Site.js +1 -1
  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/ssr/SsrCache.d.ts +17 -0
  74. package/dist/ssr/SsrCache.d.ts.map +1 -1
  75. package/dist/ssr/SsrCache.js +17 -4
  76. package/dist/ssr/SsrComponents.d.ts +1 -0
  77. package/dist/ssr/SsrComponents.d.ts.map +1 -1
  78. package/dist/ssr/SsrComponents.js +1 -0
  79. package/package.json +6 -6
  80. package/src/Crelte.ts +124 -52
  81. package/src/CrelteRequest.ts +124 -0
  82. package/src/blocks/Blocks.svelte +35 -18
  83. package/src/blocks/Blocks.ts +38 -6
  84. package/src/blocks/index.ts +19 -10
  85. package/src/cookies/ServerCookies.ts +1 -1
  86. package/src/cookies/index.ts +7 -1
  87. package/src/graphql/GraphQl.ts +79 -27
  88. package/src/graphql/index.ts +7 -1
  89. package/src/index.ts +65 -29
  90. package/src/init/client.ts +55 -10
  91. package/src/init/server.ts +70 -10
  92. package/src/init/shared.ts +8 -7
  93. package/src/loadData/Globals.ts +43 -7
  94. package/src/loadData/index.ts +76 -13
  95. package/src/plugins/Events.ts +16 -5
  96. package/src/plugins/Plugins.ts +28 -2
  97. package/src/routing/History.ts +13 -4
  98. package/src/routing/InnerRouter.ts +55 -39
  99. package/src/routing/PageLoader.ts +10 -10
  100. package/src/routing/Request.ts +175 -0
  101. package/src/routing/Route.ts +73 -8
  102. package/src/routing/Router.ts +108 -162
  103. package/src/routing/Site.ts +1 -1
  104. package/src/routing/index.ts +12 -3
  105. package/src/ssr/SsrCache.ts +17 -4
  106. package/src/ssr/SsrComponents.ts +1 -0
  107. package/dist/CrelteBase.d.ts +0 -16
  108. package/dist/CrelteBase.d.ts.map +0 -1
  109. package/dist/CrelteBase.js +0 -1
  110. package/dist/CrelteRouted.d.ts +0 -50
  111. package/dist/CrelteRouted.d.ts.map +0 -1
  112. package/dist/CrelteRouted.js +0 -88
  113. package/src/CrelteBase.ts +0 -24
  114. package/src/CrelteRouted.ts +0 -128
@@ -12,9 +12,16 @@ export interface Cookies {
12
12
  get(name: string): string | null;
13
13
  /**
14
14
  * sets the value of the cookie
15
+ *
16
+ * ## Note
17
+ * in most cases you probably wan't to set the path to '/'
15
18
  */
16
19
  set(name: string, value: string, opts?: SetOptions): void;
20
+ /**
21
+ * removes the cookie
22
+ */
17
23
  remove(name: string): void;
24
+ /** @hidden */
18
25
  _init(cookies: string): void;
19
26
  }
20
27
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cookies/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,WAAW,OAAO;IACvB;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAEjC;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAE1D,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAG3B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cookies/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,WAAW,OAAO;IACvB;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAEjC;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAE1D;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAE3B,cAAc;IACd,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B"}
@@ -1,22 +1,56 @@
1
+ import Route from '../routing/Route.js';
1
2
  import SsrCache from '../ssr/SsrCache.js';
2
3
  export type GraphQlErrorResponse = {
3
4
  status?: number;
4
5
  body?: string;
5
6
  };
7
+ /**
8
+ * A GraphQL query
9
+ *
10
+ * You should almost never create this object directly
11
+ * but instead import a graphql file or use the gql template.
12
+ */
13
+ export interface GraphQlQuery {
14
+ path?: string;
15
+ query: string;
16
+ }
17
+ /**
18
+ * A GraphQL error
19
+ */
6
20
  export declare class GraphQlError extends Error {
7
21
  resp: GraphQlErrorResponse;
8
22
  ctx: any;
9
23
  constructor(resp: GraphQlErrorResponse, ctx?: any);
24
+ /**
25
+ * The status code of the response
26
+ */
10
27
  status(): number;
11
28
  __isGraphQlError__(): void;
29
+ /**
30
+ * The error message in string form
31
+ */
12
32
  get message(): string;
13
33
  }
34
+ /**
35
+ * Options for the GraphQl class
36
+ */
14
37
  export type GraphQlOptions = {
15
38
  debug?: boolean;
16
39
  debugTiming?: boolean;
17
40
  };
41
+ /**
42
+ * Options to configure the request
43
+ *
44
+ * If you use `Crelte*.query` the following options
45
+ * will be set automatically:
46
+ * - path
47
+ * - route
48
+ * - previewToken
49
+ * - siteToken
50
+ */
18
51
  export type GraphQlRequestOptions = {
19
52
  path?: string;
53
+ route?: Route;
20
54
  ignoreStatusCode?: boolean;
21
55
  previewToken?: string;
22
56
  siteToken?: string;
@@ -24,6 +58,9 @@ export type GraphQlRequestOptions = {
24
58
  headers?: Record<string, string>;
25
59
  status?: number;
26
60
  };
61
+ /**
62
+ * A GraphQL client
63
+ */
27
64
  export default class GraphQl {
28
65
  private endpoint;
29
66
  private ssrCache;
@@ -31,30 +68,32 @@ export default class GraphQl {
31
68
  private loggingRequests;
32
69
  private loggingTiming;
33
70
  /**
34
- * Create a new GraphQL
35
- *
36
- * @param {Object} [opts={}] opts `{ debug: false, debugTiming: false }`
71
+ * Create a new GraphQL client
37
72
  */
38
73
  constructor(endpoint: string, ssrCache: SsrCache, opts?: GraphQlOptions);
39
- request(query: string, variables?: Record<string, unknown>, options?: GraphQlRequestOptions): Promise<unknown>;
74
+ /**
75
+ * Run a GraphQl Query
76
+ *
77
+ * @param query the default export from a graphql file or the gql`query {}`
78
+ * function
79
+ * @param variables variables that should be passed to the
80
+ * graphql query
81
+ */
82
+ query(query: GraphQlQuery, variables?: Record<string, unknown>, opts?: GraphQlRequestOptions): Promise<unknown>;
83
+ private request;
40
84
  private rawRequest;
41
85
  }
42
- export declare class GraphQlQuery {
43
- query: string;
44
- path: string;
45
- constructor(query: string, path: string);
46
- __GraphQlQuery__(): boolean;
47
- }
48
86
  /** Returns true if the passed object is a GraphQlQuery */
49
87
  export declare function isGraphQlQuery(obj: any): obj is GraphQlQuery;
50
88
  /**
51
- * @description Create a GraphQL query string with variables.
89
+ * Create a GraphQL query string with variables.
52
90
  * @param strings
53
91
  * @param keys
54
92
  *
55
- * @example
56
- *
57
- * const query = gql`query ($id: ID!) { page(id: $id) { id } }`
93
+ * ## Example
94
+ * ```
95
+ * const query = gql`query ($id: ID!) { page(id: $id) { id } }`;
96
+ * ```
58
97
  */
59
98
  export declare function gql(strings: TemplateStringsArray | string[] | string, ...keys: unknown[]): GraphQlQuery;
60
99
  //# sourceMappingURL=GraphQl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GraphQl.d.ts","sourceRoot":"","sources":["../../../../src/graphql/GraphQl.ts"],"names":[],"mappings":"AAAA,OAAO,QAAwC,MAAM,oBAAoB,CAAC;AAE1E,MAAM,MAAM,oBAAoB,GAAG;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAGF,qBAAa,YAAa,SAAQ,KAAK;IACtC,IAAI,EAAE,oBAAoB,CAAC;IAC3B,GAAG,EAAE,GAAG,CAAC;gBAG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O,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,OAAO;IAC3B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,SAAS,CAGf;IAEF,OAAO,CAAC,eAAe,CAAU;IACjC,OAAO,CAAC,aAAa,CAAU;IAE/B;;OAEG;gBAEF,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,QAAQ,EAClB,IAAI,GAAE,cAAmB;IAU1B;;;;;;;OAOG;IACG,KAAK,CACV,KAAK,EAAE,YAAY,EACnB,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACvC,IAAI,GAAE,qBAA0B,GAC9B,OAAO,CAAC,OAAO,CAAC;YAsBL,OAAO;YA0DP,UAAU;CAmFxB;AAED,0DAA0D;AAC1D,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,YAAY,CAI5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,GAAG,CAClB,OAAO,EAAE,oBAAoB,GAAG,MAAM,EAAE,GAAG,MAAM,EACjD,GAAG,IAAI,EAAE,OAAO,EAAE,GAChB,YAAY,CAuBd"}
@@ -1,5 +1,8 @@
1
1
  import { calcKey as ssrCacheCalcKey } from '../ssr/SsrCache.js';
2
2
  // todo improve this
3
+ /**
4
+ * A GraphQL error
5
+ */
3
6
  export class GraphQlError extends Error {
4
7
  resp;
5
8
  ctx;
@@ -9,14 +12,23 @@ export class GraphQlError extends Error {
9
12
  this.resp = resp;
10
13
  this.ctx = ctx;
11
14
  }
15
+ /**
16
+ * The status code of the response
17
+ */
12
18
  status() {
13
19
  return this.resp?.status ?? 500;
14
20
  }
15
21
  __isGraphQlError__() { }
22
+ /**
23
+ * The error message in string form
24
+ */
16
25
  get message() {
17
26
  return 'GraphqlError: ' + JSON.stringify(this.resp);
18
27
  }
19
28
  }
29
+ /**
30
+ * A GraphQL client
31
+ */
20
32
  export default class GraphQl {
21
33
  endpoint;
22
34
  ssrCache;
@@ -24,9 +36,7 @@ export default class GraphQl {
24
36
  loggingRequests;
25
37
  loggingTiming;
26
38
  /**
27
- * Create a new GraphQL
28
- *
29
- * @param {Object} [opts={}] opts `{ debug: false, debugTiming: false }`
39
+ * Create a new GraphQL client
30
40
  */
31
41
  constructor(endpoint, ssrCache, opts = {}) {
32
42
  this.endpoint = endpoint;
@@ -35,6 +45,30 @@ export default class GraphQl {
35
45
  this.loggingRequests = opts?.debug ?? false;
36
46
  this.loggingTiming = opts?.debugTiming ?? false;
37
47
  }
48
+ /**
49
+ * Run a GraphQl Query
50
+ *
51
+ * @param query the default export from a graphql file or the gql`query {}`
52
+ * function
53
+ * @param variables variables that should be passed to the
54
+ * graphql query
55
+ */
56
+ async query(query, variables = {}, opts = {}) {
57
+ if (opts.route) {
58
+ const search = opts.route.search;
59
+ // todo should variables contain siteId
60
+ // or maybe gql should detect loadData and add it there
61
+ // it might make export const loadData = query; easier
62
+ if (search.has('token') && search.get('x-craft-live-preview')) {
63
+ opts.previewToken = search.get('token');
64
+ }
65
+ else if (search.has('siteToken')) {
66
+ opts.siteToken = search.get('siteToken');
67
+ }
68
+ }
69
+ opts.path = query.path;
70
+ return await this.request(query.query, variables, opts);
71
+ }
38
72
  // returns {} or throws
39
73
  // options: {ignoreStatusCode, previewToken, caching, headers}
40
74
  async request(query, variables = {}, options = {}) {
@@ -145,32 +179,19 @@ export default class GraphQl {
145
179
  return jsonResp.data ?? null;
146
180
  }
147
181
  }
148
- export class GraphQlQuery {
149
- query;
150
- path;
151
- constructor(query, path) {
152
- this.query = query;
153
- this.path = path;
154
- }
155
- /// doc hidden
156
- __GraphQlQuery__() {
157
- return true;
158
- }
159
- }
160
182
  /** Returns true if the passed object is a GraphQlQuery */
161
183
  export function isGraphQlQuery(obj) {
162
- return (typeof obj === 'object' &&
163
- obj !== null &&
164
- typeof obj.__GraphQlQuery__ === 'function');
184
+ return (typeof obj === 'object' && obj !== null && typeof obj.query === 'string');
165
185
  }
166
186
  /**
167
- * @description Create a GraphQL query string with variables.
187
+ * Create a GraphQL query string with variables.
168
188
  * @param strings
169
189
  * @param keys
170
190
  *
171
- * @example
172
- *
173
- * const query = gql`query ($id: ID!) { page(id: $id) { id } }`
191
+ * ## Example
192
+ * ```
193
+ * const query = gql`query ($id: ID!) { page(id: $id) { id } }`;
194
+ * ```
174
195
  */
175
196
  export function gql(strings, ...keys) {
176
197
  if (typeof strings === 'string')
@@ -193,5 +214,5 @@ export function gql(strings, ...keys) {
193
214
  }
194
215
  }
195
216
  });
196
- return new GraphQlQuery(query, import.meta.url);
217
+ return { query, path: import.meta.url };
197
218
  }
@@ -1,3 +1,3 @@
1
1
  import GraphQl, { gql, GraphQlQuery, GraphQlError, GraphQlRequestOptions } from './GraphQl.js';
2
- export { GraphQl, gql, GraphQlQuery, GraphQlError, type GraphQlRequestOptions };
2
+ export { GraphQl, gql, type GraphQlQuery, GraphQlError, type GraphQlRequestOptions, };
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/graphql/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EACf,GAAG,EACH,YAAY,EACZ,YAAY,EACZ,qBAAqB,EACrB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,YAAY,EAAE,KAAK,qBAAqB,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/graphql/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EACf,GAAG,EACH,YAAY,EACZ,YAAY,EACZ,qBAAqB,EACrB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACN,OAAO,EACP,GAAG,EACH,KAAK,YAAY,EACjB,YAAY,EACZ,KAAK,qBAAqB,GAC1B,CAAC"}
@@ -1,2 +1,2 @@
1
- import GraphQl, { gql, GraphQlQuery, GraphQlError, } from './GraphQl.js';
2
- export { GraphQl, gql, GraphQlQuery, GraphQlError };
1
+ import GraphQl, { gql, GraphQlError, } from './GraphQl.js';
2
+ export { GraphQl, gql, GraphQlError, };
package/dist/index.d.ts CHANGED
@@ -3,65 +3,98 @@ import type Router from './routing/Router.js';
3
3
  import type SsrCache from './ssr/SsrCache.js';
4
4
  import type Site from './routing/Site.js';
5
5
  import type GraphQl from './graphql/GraphQl.js';
6
- import Crelte from './Crelte.js';
7
- import CrelteRouted from './CrelteRouted.js';
8
- import CrelteBase from './CrelteBase.js';
9
- import { Global, GlobalData } from './loadData/Globals.js';
10
- import { Cookies } from './cookies/index.js';
11
- import { Readable } from 'crelte-std/stores';
12
- export { Crelte, CrelteRouted };
13
- export type { CrelteBase };
6
+ import Crelte, { type QueryOptions } from './Crelte.js';
7
+ import CrelteRequest from './CrelteRequest.js';
8
+ import type { Global, GlobalData } from './loadData/Globals.js';
9
+ import type { Cookies } from './cookies/index.js';
10
+ import type { Readable } from 'crelte-std/stores';
11
+ export { Crelte, CrelteRequest, type QueryOptions };
14
12
  /**
15
- * Get the Crelte from the current context
13
+ * Get Crelte from the current context
14
+ *
15
+ * ## Note
16
+ * This only works during component initialisation.
16
17
  */
17
18
  export declare function getCrelte(): Crelte;
18
19
  /**
19
20
  * Get the router from the current context
21
+ *
22
+ * ## Note
23
+ * This only works during component initialisation.
20
24
  */
21
25
  export declare function getRouter(): Router;
22
26
  /**
23
27
  * Get the SSR cache from the current context
28
+ *
29
+ * ## Note
30
+ * This only works during component initialisation.
24
31
  */
25
32
  export declare function getSsrCache(): SsrCache;
26
33
  /**
27
34
  * Get the GraphQl from the current context
35
+ *
36
+ * ## Note
37
+ * This only works during component initialisation.
28
38
  */
29
39
  export declare function getGraphQl(): GraphQl;
30
40
  /**
31
- * Get the current route
41
+ * Get a store with the current route
42
+ *
43
+ * ## Note
44
+ * This only works during component initialisation.
32
45
  */
33
46
  export declare function getRoute(): Readable<Route>;
34
47
  /**
35
- * Get the current site
48
+ * Get a store with the current site
49
+ *
50
+ * ## Note
51
+ * This only works during component initialisation.
36
52
  */
37
53
  export declare function getSite(): Readable<Site>;
38
54
  /**
39
- * Get the next route
40
- */
41
- export declare function getNextRoute(): Readable<Route>;
42
- /**
43
- * Get the next site
44
- */
45
- export declare function getNextSite(): Readable<Site>;
46
- /**
47
- * returns an env Variables, always needs to be prefixed VITE_
48
- * Except ENDPOINT_URL and CRAFT_WEB_URL
55
+ * returns an env variable from the craft/.env file.
56
+ * All env variables need to start with VITE_
57
+ * except ENDPOINT_URL and CRAFT_WEB_URL
58
+ *
59
+ * ## Note
60
+ * This only works during component initialisation.
49
61
  */
62
+ export declare function getEnv(name: 'ENDPOINT_URL'): string;
63
+ export declare function getEnv(name: 'CRAFT_WEB_URL'): string;
50
64
  export declare function getEnv(name: string): string | null;
51
65
  /**
52
66
  * returns a store which indicates if the a page is loading
67
+ *
68
+ * ## Note
69
+ * This only works during component initialisation.
53
70
  */
54
71
  export declare function getLoading(): Readable<boolean>;
55
72
  /**
56
- * returns a store which indicates the loading progress
73
+ * returns a store which indicates the loading progress between 0 and 1
74
+ *
75
+ * ## Note
76
+ * This only works during component initialisation.
57
77
  */
58
78
  export declare function getLoadingProgress(): Readable<number>;
59
79
  /**
60
80
  * returns a store which contains a globalSet
81
+ *
82
+ * ## Note
83
+ * This only works during component initialisation.
61
84
  */
62
85
  export declare function getGlobal<T extends GlobalData>(name: string): Global<T> | null;
63
86
  /**
64
87
  * returns the cookies instance
88
+ *
89
+ * ## Note
90
+ * This only works during component initialisation.
65
91
  */
66
92
  export declare function getCookies(): Cookies;
93
+ /**
94
+ * Listen for requests
95
+ *
96
+ * ## Note
97
+ * This only works during component initialisation.
98
+ */
99
+ export declare function onRequest(fn: (cr: CrelteRequest) => void): void;
67
100
  //# source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G;AACH,wBAAgB,QAAQ,IAAI,QAAQ,CAAC,KAAK,CAAC,CAE1C;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,CAExC;AAED;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAAC;AACrD,wBAAgB,MAAM,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAAC;AACtD,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAKpD;;;;;GAKG;AACH,wBAAgB,UAAU,IAAI,QAAQ,CAAC,OAAO,CAAC,CAE9C;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,QAAQ,CAAC,MAAM,CAAC,CAErD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,UAAU,EAC7C,IAAI,EAAE,MAAM,GACV,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAElB;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,IAAI,OAAO,CAEpC;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,aAAa,KAAK,IAAI,QAOxD"}
package/dist/index.js CHANGED
@@ -1,83 +1,110 @@
1
- import { getContext } from 'svelte';
1
+ import { getContext, onDestroy } from 'svelte';
2
2
  import Crelte from './Crelte.js';
3
- import CrelteRouted from './CrelteRouted.js';
4
- export { Crelte, CrelteRouted };
3
+ import CrelteRequest from './CrelteRequest.js';
4
+ export { Crelte, CrelteRequest };
5
5
  /**
6
- * Get the Crelte from the current context
6
+ * Get Crelte from the current context
7
+ *
8
+ * ## Note
9
+ * This only works during component initialisation.
7
10
  */
8
11
  export function getCrelte() {
9
12
  return getContext('crelte');
10
13
  }
11
14
  /**
12
15
  * Get the router from the current context
16
+ *
17
+ * ## Note
18
+ * This only works during component initialisation.
13
19
  */
14
20
  export function getRouter() {
15
21
  return getCrelte().router;
16
22
  }
17
23
  /**
18
24
  * Get the SSR cache from the current context
25
+ *
26
+ * ## Note
27
+ * This only works during component initialisation.
19
28
  */
20
29
  export function getSsrCache() {
21
30
  return getCrelte().ssrCache;
22
31
  }
23
32
  /**
24
33
  * Get the GraphQl from the current context
34
+ *
35
+ * ## Note
36
+ * This only works during component initialisation.
25
37
  */
26
38
  export function getGraphQl() {
27
39
  return getCrelte().graphQl;
28
40
  }
29
41
  /**
30
- * Get the current route
42
+ * Get a store with the current route
43
+ *
44
+ * ## Note
45
+ * This only works during component initialisation.
31
46
  */
32
47
  export function getRoute() {
33
48
  return getRouter().route;
34
49
  }
35
50
  /**
36
- * Get the current site
51
+ * Get a store with the current site
52
+ *
53
+ * ## Note
54
+ * This only works during component initialisation.
37
55
  */
38
56
  export function getSite() {
39
57
  return getRouter().site;
40
58
  }
41
- /**
42
- * Get the next route
43
- */
44
- export function getNextRoute() {
45
- return getRouter().nextRoute;
46
- }
47
- /**
48
- * Get the next site
49
- */
50
- export function getNextSite() {
51
- return getRouter().nextSite;
52
- }
53
- /**
54
- * returns an env Variables, always needs to be prefixed VITE_
55
- * Except ENDPOINT_URL and CRAFT_WEB_URL
56
- */
57
59
  export function getEnv(name) {
58
60
  return getCrelte().getEnv(name);
59
61
  }
60
62
  /**
61
63
  * returns a store which indicates if the a page is loading
64
+ *
65
+ * ## Note
66
+ * This only works during component initialisation.
62
67
  */
63
68
  export function getLoading() {
64
69
  return getRouter().loading;
65
70
  }
66
71
  /**
67
- * returns a store which indicates the loading progress
72
+ * returns a store which indicates the loading progress between 0 and 1
73
+ *
74
+ * ## Note
75
+ * This only works during component initialisation.
68
76
  */
69
77
  export function getLoadingProgress() {
70
78
  return getRouter().loadingProgress;
71
79
  }
72
80
  /**
73
81
  * returns a store which contains a globalSet
82
+ *
83
+ * ## Note
84
+ * This only works during component initialisation.
74
85
  */
75
86
  export function getGlobal(name) {
76
87
  return getCrelte().globals.get(name) ?? null;
77
88
  }
78
89
  /**
79
90
  * returns the cookies instance
91
+ *
92
+ * ## Note
93
+ * This only works during component initialisation.
80
94
  */
81
95
  export function getCookies() {
82
96
  return getCrelte().cookies;
83
97
  }
98
+ /**
99
+ * Listen for requests
100
+ *
101
+ * ## Note
102
+ * This only works during component initialisation.
103
+ */
104
+ export function onRequest(fn) {
105
+ const crelte = getCrelte();
106
+ const rmListener = crelte.router.onRequest((req, site) => {
107
+ fn(new CrelteRequest(crelte, req, site));
108
+ });
109
+ onDestroy(rmListener);
110
+ }
@@ -1,13 +1,54 @@
1
+ import { GraphQlQuery } from '../graphql/GraphQl.js';
2
+ /**
3
+ * The main function to start the client side rendering
4
+ */
1
5
  export type MainData = {
6
+ /** The App.svelte module */
2
7
  app: any;
8
+ /** The Error.svelte module */
3
9
  errorPage: any;
4
- entryQuery: any;
5
- globalQuery?: any;
10
+ /** The entry query from queries/entry.graphql */
11
+ entryQuery: GraphQlQuery;
12
+ /** The global query from queries/global.graphql */
13
+ globalQuery?: GraphQlQuery;
14
+ /**
15
+ * Preload pages on mouse over
16
+ * @default false
17
+ */
6
18
  preloadOnMouseOver?: boolean;
19
+ /**
20
+ * Use view transitions
21
+ * @default false
22
+ */
7
23
  viewTransition?: boolean;
24
+ /**
25
+ * Play the intro animation
26
+ * @default false
27
+ */
8
28
  playIntro?: boolean;
29
+ /** Enable graphql query debugging */
9
30
  graphQlDebug?: boolean;
31
+ /** Enable request and render timing measurement */
10
32
  debugTiming?: boolean;
11
33
  };
34
+ /**
35
+ * The main function to start the client side rendering
36
+ *
37
+ * ## Example
38
+ * ```
39
+ * import * as app from './App.svelte';
40
+ * import * as errorPage from './Error.svelte';
41
+ * import entryQuery from './queries/entry.graphql';
42
+ * import globalQuery from './queries/global.graphql';
43
+ * import { main } from 'crelte/client';
44
+ *
45
+ * main({
46
+ * app,
47
+ * errorPage,
48
+ * entryQuery,
49
+ * globalQuery,
50
+ * });
51
+ * ```
52
+ */
12
53
  export declare function main(data: MainData): void;
13
54
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/init/client.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,QAAQ,GAAG;IAEtB,GAAG,EAAE,GAAG,CAAC;IAET,SAAS,EAAE,GAAG,CAAC;IACf,UAAU,EAAE,GAAG,CAAC;IAChB,WAAW,CAAC,EAAE,GAAG,CAAC;IAGlB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,SAAS,CAAC,EAAE,OAAO,CAAC;IAGpB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAYF,wBAAgB,IAAI,CAAC,IAAI,EAAE,QAAQ,QAsIlC"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/init/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAKrD;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACtB,4BAA4B;IAC5B,GAAG,EAAE,GAAG,CAAC;IACT,8BAA8B;IAC9B,SAAS,EAAE,GAAG,CAAC;IACf,iDAAiD;IACjD,UAAU,EAAE,YAAY,CAAC;IACzB,mDAAmD;IACnD,WAAW,CAAC,EAAE,YAAY,CAAC;IAI3B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAIpB,qCAAqC;IACrC,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB,mDAAmD;IACnD,WAAW,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAYF;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,QAAQ,QAsIlC"}