revojs 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -38,8 +38,6 @@ declare class Scope extends EventTarget {
38
38
  stop(): boolean;
39
39
  }
40
40
  declare function defineContext<T>(name: string): Descriptor<T>;
41
- declare function isClient(): boolean;
42
- declare function isServer(): boolean;
43
41
  declare function isFailure<T>(result: Output<T>): result is Failure;
44
42
  declare function parseSchema<T extends Schema>(scope: Scope, schema: T, value: unknown): InferOutput<T>;
45
43
  declare function mergeObjects<TBase, TInput>(base: TBase, input: TInput): TBase & TInput;
@@ -177,4 +175,4 @@ declare const WILDCARD = "$";
177
175
  declare const PARAMETER = ":";
178
176
  declare const mimeTypes: Record<string, MimeType>;
179
177
  //#endregion
180
- export { $fetch, App, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, Encoding, Environment, Failure, HttpMethod, InferInput, InferOutput, Issue, Mergeable, Middleware, MimeType, Module, Node, Output, PARAMETER, ParameterNode, PathNode, ROUTER_CONTEXT, Radix, ResponseConfig, Result, Route, Router, RouterContext, SERVER, SERVER_CONTEXT, Schema, Scope, Server, ServerContext, Source, StatusCode, StopEvent, Success, Virtual, WILDCARD, WildcardNode, createApp, createServer, defineContext, defineMiddleware, defineRoute, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, toRoutePath, useCookies, useQuery, useServer, useSetCookies, useUrl };
178
+ export { $fetch, App, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, Encoding, Environment, Failure, HttpMethod, InferInput, InferOutput, Issue, Mergeable, Middleware, MimeType, Module, Node, Output, PARAMETER, ParameterNode, PathNode, ROUTER_CONTEXT, Radix, ResponseConfig, Result, Route, Router, RouterContext, SERVER, SERVER_CONTEXT, Schema, Scope, Server, ServerContext, Source, StatusCode, StopEvent, Success, Virtual, WILDCARD, WildcardNode, createApp, createServer, defineContext, defineMiddleware, defineRoute, isFailure, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, toRoutePath, useCookies, useQuery, useServer, useSetCookies, useUrl };
package/dist/index.js CHANGED
@@ -102,7 +102,7 @@ function useQuery(scope, schema) {
102
102
  }
103
103
  function useCookies(scope, schema) {
104
104
  const { request } = useServer(scope);
105
- const entries = (isClient() ? document.cookie : request.headers.get("Cookie") ?? "").split("; ").reduce((result, cookie) => {
105
+ const entries = (import.meta.client ? document.cookie : request.headers.get("Cookie") ?? "").split("; ").reduce((result, cookie) => {
106
106
  const [name, value] = cookie.split("=");
107
107
  if (name && value) result[name] = decodeURIComponent(value);
108
108
  return result;
@@ -129,7 +129,7 @@ function setCookie(scope, name, value, options) {
129
129
  if (options?.priority) cookie += `; Priority=${options.priority}`;
130
130
  if (options?.sameSite) cookie += `; SameSite=${options.sameSite}`;
131
131
  if (options?.secure) cookie += `; Secure`;
132
- if (isClient()) document.cookie = cookie;
132
+ if (import.meta.client) document.cookie = cookie;
133
133
  else response.headers.append("Set-Cookie", cookie);
134
134
  }
135
135
  function sendText(scope, text, config) {
@@ -286,12 +286,6 @@ var Scope = class extends EventTarget {
286
286
  function defineContext(name) {
287
287
  return name;
288
288
  }
289
- function isClient() {
290
- return typeof window !== "undefined";
291
- }
292
- function isServer() {
293
- return typeof window === "undefined";
294
- }
295
289
  function isFailure(result) {
296
290
  return "issues" in result;
297
291
  }
@@ -349,9 +343,9 @@ const CLIENT = "client";
349
343
  //#endregion
350
344
  //#region src/client/index.ts
351
345
  async function $fetch(scope, input, options) {
352
- const { request, variables } = useServer(scope);
353
346
  let response;
354
- if (request) {
347
+ if (import.meta.server) {
348
+ const { request, variables } = useServer(scope);
355
349
  const next = new Scope();
356
350
  next.setContext(SERVER_CONTEXT, {
357
351
  request: new Request(new URL(input.toString(), request.url), options),
@@ -369,4 +363,4 @@ async function $fetch(scope, input, options) {
369
363
  }
370
364
 
371
365
  //#endregion
372
- export { $fetch, CLIENT, PARAMETER, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, Scope, StopEvent, WILDCARD, createApp, createServer, defineContext, defineMiddleware, defineRoute, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, toRoutePath, useCookies, useQuery, useServer, useSetCookies, useUrl };
366
+ export { $fetch, CLIENT, PARAMETER, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, Scope, StopEvent, WILDCARD, createApp, createServer, defineContext, defineMiddleware, defineRoute, isFailure, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, toRoutePath, useCookies, useQuery, useServer, useSetCookies, useUrl };
@@ -8,7 +8,7 @@ import { existsSync, readFileSync } from "fs";
8
8
 
9
9
  //#region package.json
10
10
  var name = "revojs";
11
- var version = "0.1.4";
11
+ var version = "0.1.6";
12
12
 
13
13
  //#endregion
14
14
  //#region src/server/index.ts
@@ -291,27 +291,31 @@ function entry() {
291
291
  name: "entry",
292
292
  enforce: "pre",
293
293
  sharedDuringBuild: true,
294
- resolveId(source, importer, options) {
295
- if (source === "vite/modulepreload-polyfill") return null;
296
- if (this.environment.name === CLIENT) {
297
- if (importer && entryPath) {
298
- const path = join(dirname(importer), source);
299
- if (existsSync(path)) return path;
300
- }
301
- if (options.isEntry) {
302
- entryName = basename(source);
303
- entryPath = source;
304
- return entryName;
294
+ resolveId: {
295
+ filter: { id: /\.html$/ },
296
+ handler(source, importer, options) {
297
+ if (this.environment.name === CLIENT) {
298
+ if (importer && entryPath) {
299
+ const path = join(dirname(importer), source);
300
+ if (existsSync(path)) return path;
301
+ }
302
+ if (options.isEntry) {
303
+ entryName = basename(source);
304
+ entryPath = source;
305
+ return entryName;
306
+ }
305
307
  }
306
308
  }
307
- return null;
308
309
  },
309
- load(source) {
310
- if (entryName && entryPath && source === entryName) return readFileSync(entryPath, {
311
- encoding: "utf-8",
312
- flag: "r"
313
- });
314
- return null;
310
+ load: {
311
+ filter: { id: /\.html$/ },
312
+ handler(source) {
313
+ if (entryName && entryPath && source === entryName) return readFileSync(entryPath, {
314
+ encoding: "utf-8",
315
+ flag: "r"
316
+ });
317
+ return null;
318
+ }
315
319
  }
316
320
  };
317
321
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revojs",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",
@@ -33,3 +33,8 @@ declare module "#virtual/middlewares" {
33
33
 
34
34
  export default middlewares;
35
35
  }
36
+
37
+ interface ImportMeta {
38
+ readonly server: boolean;
39
+ readonly client: boolean;
40
+ }