solidstep 0.2.0 → 0.3.1

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/utils/cache.js CHANGED
@@ -39,7 +39,7 @@ export const getCache = (key) => {
39
39
  const entry = cacheMap.get(key);
40
40
  if (!entry || !entry.expiresAt)
41
41
  return null;
42
- if (entry.expiresAt && entry.expiresAt < Date.now()) {
42
+ if (entry.expiresAt && entry.expiresAt < performance.now()) {
43
43
  cacheMap.delete(key);
44
44
  if (entry.prev)
45
45
  entry.prev.next = entry.next;
@@ -58,14 +58,14 @@ export const setCache = (key, value, ttlMs) => {
58
58
  if (cacheMap.has(key)) {
59
59
  const node = cacheMap.get(key);
60
60
  node.value = value;
61
- node.expiresAt = ttlMs ? Date.now() + ttlMs : null;
61
+ node.expiresAt = ttlMs ? performance.now() + ttlMs : null;
62
62
  moveToFront(node);
63
63
  return;
64
64
  }
65
65
  const newNode = {
66
66
  key,
67
67
  value,
68
- expiresAt: ttlMs ? Date.now() + ttlMs : null
68
+ expiresAt: ttlMs ? performance.now() + ttlMs : null
69
69
  };
70
70
  newNode.next = head;
71
71
  if (head)
@@ -0,0 +1,70 @@
1
+ export type Import = {
2
+ src: string;
3
+ import: any;
4
+ };
5
+ export type RoutePageHandler = {
6
+ type: 'page';
7
+ mainPage: {
8
+ manifestPath: string;
9
+ page: Import;
10
+ loader?: Import;
11
+ generateMeta?: Import;
12
+ options?: Import;
13
+ };
14
+ loadingPage?: {
15
+ manifestPath: string;
16
+ page: Import;
17
+ generateMeta?: Import;
18
+ };
19
+ errorPage?: {
20
+ manifestPath: string;
21
+ page: Import;
22
+ generateMeta?: Import;
23
+ };
24
+ notFoundPage?: {
25
+ manifestPath: string;
26
+ page: Import;
27
+ generateMeta?: Import;
28
+ };
29
+ layouts: {
30
+ manifestPath: string;
31
+ layout: Import;
32
+ loader?: Import;
33
+ generateMeta?: Import;
34
+ }[];
35
+ groups?: {
36
+ [key: string]: {
37
+ manifestPath: string;
38
+ page: Import;
39
+ loader?: Import;
40
+ };
41
+ };
42
+ };
43
+ export type RouteHandler = {
44
+ type: 'route';
45
+ handler: Import;
46
+ manifestPath: string;
47
+ } | RoutePageHandler;
48
+ type Params = Record<string, string | string[]>;
49
+ export type RouteNode = {
50
+ staticChildren: Map<string, RouteNode>;
51
+ paramChild?: {
52
+ name: string;
53
+ node: RouteNode;
54
+ };
55
+ catchAllChild?: {
56
+ name: string;
57
+ optional: boolean;
58
+ node: RouteNode;
59
+ };
60
+ handler?: RouteHandler;
61
+ };
62
+ export declare const createNode: () => RouteNode;
63
+ export declare const insertRoute: (root: RouteNode, path: string, handler: RouteHandler) => void;
64
+ type MatchResult = {
65
+ handler: RouteHandler;
66
+ params: Params;
67
+ } | null;
68
+ export declare const matchRoute: (root: RouteNode, path: string) => MatchResult;
69
+ export {};
70
+ //# sourceMappingURL=path-router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-router.d.ts","sourceRoot":"","sources":["../../utils/path-router.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,MAAM,GAAG;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,GAAG,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE;QACN,YAAY,EAAE,MAAM,CAAC;QACrB,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,OAAO,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,WAAW,CAAC,EAAE;QACV,YAAY,EAAE,MAAM,CAAC;QACrB,IAAI,EAAE,MAAM,CAAC;QACb,YAAY,CAAC,EAAE,MAAM,CAAC;KACzB,CAAC;IACF,SAAS,CAAC,EAAE;QACR,YAAY,EAAE,MAAM,CAAC;QACrB,IAAI,EAAE,MAAM,CAAC;QACb,YAAY,CAA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AAC;AAEF,KAAK,WAAW,GAAG;IACf,OAAO,EAAE,YAAY,CAAA;IACrB,MAAM,EAAE,MAAM,CAAA;CACjB,GAAG,IAAI,CAAA;AAER,eAAO,MAAM,UAAU,GACnB,MAAM,SAAS,EACf,MAAM,MAAM,KACb,WAmDF,CAAA"}
@@ -0,0 +1,97 @@
1
+ export const createNode = () => ({
2
+ staticChildren: new Map()
3
+ });
4
+ const parseSegment = (segment) => {
5
+ // [[...slug]]
6
+ if (segment.startsWith('[[...') && segment.endsWith(']]')) {
7
+ return { type: 'catchAll', name: segment.slice(5, -2), optional: true };
8
+ }
9
+ // [...slug]
10
+ if (segment.startsWith('[...') && segment.endsWith(']')) {
11
+ return { type: 'catchAll', name: segment.slice(4, -1), optional: false };
12
+ }
13
+ // [id]
14
+ if (segment.startsWith('[') && segment.endsWith(']')) {
15
+ return { type: 'param', name: segment.slice(1, -1) };
16
+ }
17
+ return { type: 'static', value: segment };
18
+ };
19
+ export const insertRoute = (root, path, handler) => {
20
+ const segments = path.split('/').filter(Boolean);
21
+ let node = root;
22
+ for (const segment of segments) {
23
+ const parsed = parseSegment(segment);
24
+ if (parsed.type === 'static' && parsed.value) {
25
+ if (!node.staticChildren.has(parsed.value)) {
26
+ node.staticChildren.set(parsed.value, createNode());
27
+ }
28
+ node = node.staticChildren.get(parsed.value);
29
+ continue;
30
+ }
31
+ if (parsed.type === 'param') {
32
+ if (!node.paramChild) {
33
+ node.paramChild = {
34
+ name: parsed.name,
35
+ node: createNode()
36
+ };
37
+ }
38
+ node = node.paramChild.node;
39
+ continue;
40
+ }
41
+ if (parsed.type === 'catchAll') {
42
+ if (!node.catchAllChild) {
43
+ node.catchAllChild = {
44
+ name: parsed.name,
45
+ optional: parsed.optional,
46
+ node: createNode()
47
+ };
48
+ }
49
+ node = node.catchAllChild.node;
50
+ break; // catch-all always consumes the rest
51
+ }
52
+ }
53
+ node.handler = handler;
54
+ };
55
+ export const matchRoute = (root, path) => {
56
+ const segments = path.split('/').filter(Boolean);
57
+ const params = {};
58
+ const walk = (node, index) => {
59
+ // End of path
60
+ if (index === segments.length) {
61
+ if (node.handler)
62
+ return node.handler;
63
+ // Optional catch-all can match empty
64
+ if (node.catchAllChild?.optional) {
65
+ params[node.catchAllChild.name] = [];
66
+ return node.catchAllChild.node.handler ?? null;
67
+ }
68
+ return null;
69
+ }
70
+ const segment = segments[index];
71
+ // 1. Static
72
+ const staticChild = node.staticChildren.get(segment);
73
+ if (staticChild) {
74
+ const res = walk(staticChild, index + 1);
75
+ if (res)
76
+ return res;
77
+ }
78
+ // 2. Param
79
+ if (node.paramChild) {
80
+ params[node.paramChild.name] = segment;
81
+ const res = walk(node.paramChild.node, index + 1);
82
+ if (res)
83
+ return res;
84
+ delete params[node.paramChild.name];
85
+ }
86
+ // 3. Catch-all
87
+ if (node.catchAllChild) {
88
+ params[node.catchAllChild.name] = segments.slice(index);
89
+ return node.catchAllChild.node.handler ?? null;
90
+ }
91
+ return null;
92
+ };
93
+ const handler = walk(root, 0);
94
+ if (!handler)
95
+ return null;
96
+ return { handler, params };
97
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"server-action.server.d.ts","sourceRoot":"","sources":["../../utils/server-action.server.ts"],"names":[],"mappings":"AAgBA,OAAO,EAIN,KAAK,SAAS,EAWd,MAAM,YAAY,CAAC;AAuHpB,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,SAAS,oBA0M1D;;AAED,wBAAkD"}
1
+ {"version":3,"file":"server-action.server.d.ts","sourceRoot":"","sources":["../../utils/server-action.server.ts"],"names":[],"mappings":"AAgBA,OAAO,EAIN,KAAK,SAAS,EAWd,MAAM,YAAY,CAAC;AAuHpB,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,SAAS,oBA2M1D;;AAED,wBAAkD"}
@@ -244,9 +244,10 @@ export async function handleServerFunction(event) {
244
244
  // Step 4: diff the cache with new html from server
245
245
  const reqUrl = new URL(request.url);
246
246
  const serverUrl = reqUrl.origin;
247
- await fetch(serverUrl + revalidatePath, {
247
+ const response = await fetch(serverUrl + revalidatePath, {
248
248
  method: 'GET'
249
249
  }, false);
250
+ await response.text(); // ensure the fetch is completed and cache is populated
250
251
  const newCacheValue = getCache(revalidatePath);
251
252
  const newHtml = newCacheValue?.rendered;
252
253
  const dd = createDiffDOM({