@valbuild/server 0.13.11 → 0.14.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.
@@ -1,8 +1,8 @@
1
1
  import { QuickJSRuntime } from "quickjs-emscripten";
2
2
  import { Patch } from "@valbuild/core/patch";
3
- import { ValSourceFileHandler } from "./ValSourceFileHandler";
4
- import { IValFSHost } from "./ValFSHost";
5
- import { SerializedModuleContent } from "./SerializedModuleContent";
3
+ import { ValSourceFileHandler } from "./ValSourceFileHandler.js";
4
+ import { IValFSHost } from "./ValFSHost.js";
5
+ import { SerializedModuleContent } from "./SerializedModuleContent.js";
6
6
  import { ModuleId, ModulePath } from "@valbuild/core";
7
7
  export type ServiceOptions = {
8
8
  /**
@@ -1,5 +1,5 @@
1
1
  import ts from "typescript";
2
- import { ValFS } from "./ValFS";
2
+ import { ValFS } from "./ValFS.js";
3
3
  /**
4
4
  * An implementation of methods in the various ts.*Host interfaces
5
5
  * that uses ValFS to resolve modules and read/write files.
@@ -1,6 +1,6 @@
1
1
  import ts from "typescript";
2
- import type { IValFSHost } from "./ValFSHost";
3
- import { ValSourceFileHandler } from "./ValSourceFileHandler";
2
+ import type { IValFSHost } from "./ValFSHost.js";
3
+ import { ValSourceFileHandler } from "./ValSourceFileHandler.js";
4
4
  export declare const createModuleLoader: (rootDir: string, host?: IValFSHost) => ValModuleLoader;
5
5
  export declare class ValModuleLoader {
6
6
  readonly projectRoot: string;
@@ -1,5 +1,5 @@
1
1
  import ts from "typescript";
2
- import { IValFSHost } from "./ValFSHost";
2
+ import { IValFSHost } from "./ValFSHost.js";
3
3
  export declare class ValSourceFileHandler {
4
4
  private readonly projectRoot;
5
5
  private readonly compilerOptions;
@@ -1,3 +1,3 @@
1
1
  import { RequestHandler } from "express";
2
- import { ValServer } from "./ValServer";
2
+ import { ValServer } from "./ValServer.js";
3
3
  export declare function createRequestHandler(valServer: ValServer): RequestHandler;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import type { RequestListener } from "node:http";
3
- import { ServiceOptions } from "./Service";
3
+ import { ServiceOptions } from "./Service.js";
4
4
  type Opts = ValServerOverrides & ServiceOptions;
5
5
  type ValServerOverrides = Partial<{
6
6
  /**
@@ -1,12 +1,12 @@
1
- export type { ServiceOptions } from "./Service";
2
- export { createService, Service } from "./Service";
3
- export { createRequestHandler } from "./createRequestHandler";
4
- export { createRequestListener } from "./hosting";
5
- export { ValModuleLoader } from "./ValModuleLoader";
6
- export { getCompilerOptions } from "./getCompilerOptions";
7
- export { ValSourceFileHandler } from "./ValSourceFileHandler";
8
- export { ValFSHost } from "./ValFSHost";
9
- export type { IValFSHost } from "./ValFSHost";
10
- export type { ValFS } from "./ValFS";
11
- export { patchSourceFile } from "./patchValFile";
12
- export { formatSyntaxErrorTree } from "./patch/ts/syntax";
1
+ export type { ServiceOptions } from "./Service.js";
2
+ export { createService, Service } from "./Service.js";
3
+ export { createRequestHandler } from "./createRequestHandler.js";
4
+ export { createRequestListener } from "./hosting.js";
5
+ export { ValModuleLoader } from "./ValModuleLoader.js";
6
+ export { getCompilerOptions } from "./getCompilerOptions.js";
7
+ export { ValSourceFileHandler } from "./ValSourceFileHandler.js";
8
+ export { ValFSHost } from "./ValFSHost.js";
9
+ export type { IValFSHost } from "./ValFSHost.js";
10
+ export type { ValFS } from "./ValFS.js";
11
+ export { patchSourceFile } from "./patchValFile.js";
12
+ export { formatSyntaxErrorTree } from "./patch/ts/syntax.js";
@@ -1,9 +1,9 @@
1
1
  import { Patch, PatchError } from "@valbuild/core/patch";
2
2
  import { result } from "@valbuild/core/fp";
3
- import { type ValSyntaxErrorTree } from "./patch/ts/syntax";
4
- import { ValSourceFileHandler } from "./ValSourceFileHandler";
3
+ import { type ValSyntaxErrorTree } from "./patch/ts/syntax.js";
4
+ import { ValSourceFileHandler } from "./ValSourceFileHandler.js";
5
5
  import { QuickJSRuntime } from "quickjs-emscripten";
6
6
  import ts from "typescript";
7
- import { SerializedModuleContent } from "./SerializedModuleContent";
7
+ import { SerializedModuleContent } from "./SerializedModuleContent.js";
8
8
  export declare const patchValFile: (id: string, valConfigPath: string, patch: Patch, sourceFileHandler: ValSourceFileHandler, runtime: QuickJSRuntime) => Promise<SerializedModuleContent>;
9
9
  export declare const patchSourceFile: (sourceFile: ts.SourceFile, patch: Patch) => result.Result<ts.SourceFile, ValSyntaxErrorTree | PatchError>;
@@ -824,22 +824,16 @@ async function newValQuickJSRuntime(quickJSModule, moduleLoader, {
824
824
  runtime.setMemoryLimit(memoryLimit);
825
825
  runtime.setModuleLoader(modulePath => {
826
826
  try {
827
- // Special cases for next package:
827
+ // Special cases to avoid loading the React packages since currently React does not have a ESM build:
828
828
  // TODO: this is not stable, find a better way to do this
829
- if (modulePath === "./autoTagJSX") {
830
- return {
831
- value: ""
832
- }; // ignore this module, it's only used in the browser
833
- }
834
-
835
829
  if (modulePath === "@valbuild/react") {
836
830
  return {
837
831
  value: "export const useVal = () => { throw Error(`Cannot use 'useVal' in this type of file`) }; export function ValProvider() { throw Error(`Cannot use 'ValProvider' in this type of file`) }; export function ValRichText() { throw Error(`Cannot use 'ValRichText' in this type of file`)};"
838
832
  };
839
833
  }
840
- if (modulePath === "./ValRichText") {
834
+ if (modulePath === "@valbuild/react/stega") {
841
835
  return {
842
- value: "export function ValRichText() { throw Error(`Cannot use 'ValRichText' in this type of file`)};"
836
+ value: "export const useVal = () => { throw Error(`Cannot use 'useVal' in this type of file`) }; export const fetchVal = () => { throw Error(`Cannot use 'fetchVal' in this type of file`) }; export const autoTagJSX = () => { /* ignore */ };"
843
837
  };
844
838
  }
845
839
  return {
@@ -847,22 +841,17 @@ async function newValQuickJSRuntime(quickJSModule, moduleLoader, {
847
841
  };
848
842
  } catch (e) {
849
843
  return {
850
- error: Error(`Could not resolve module: ${modulePath}'`)
844
+ error: Error(`Could not resolve module: '${modulePath}': `)
851
845
  };
852
846
  }
853
847
  }, (baseModuleName, requestedName) => {
854
848
  try {
855
- if (requestedName === "./autoTagJSX") {
856
- return {
857
- value: requestedName
858
- };
859
- }
860
849
  if (requestedName === "@valbuild/react") {
861
850
  return {
862
851
  value: requestedName
863
852
  };
864
853
  }
865
- if (requestedName === "./ValRichText") {
854
+ if (requestedName === "@valbuild/react/stega") {
866
855
  return {
867
856
  value: requestedName
868
857
  };
@@ -824,22 +824,16 @@ async function newValQuickJSRuntime(quickJSModule, moduleLoader, {
824
824
  runtime.setMemoryLimit(memoryLimit);
825
825
  runtime.setModuleLoader(modulePath => {
826
826
  try {
827
- // Special cases for next package:
827
+ // Special cases to avoid loading the React packages since currently React does not have a ESM build:
828
828
  // TODO: this is not stable, find a better way to do this
829
- if (modulePath === "./autoTagJSX") {
830
- return {
831
- value: ""
832
- }; // ignore this module, it's only used in the browser
833
- }
834
-
835
829
  if (modulePath === "@valbuild/react") {
836
830
  return {
837
831
  value: "export const useVal = () => { throw Error(`Cannot use 'useVal' in this type of file`) }; export function ValProvider() { throw Error(`Cannot use 'ValProvider' in this type of file`) }; export function ValRichText() { throw Error(`Cannot use 'ValRichText' in this type of file`)};"
838
832
  };
839
833
  }
840
- if (modulePath === "./ValRichText") {
834
+ if (modulePath === "@valbuild/react/stega") {
841
835
  return {
842
- value: "export function ValRichText() { throw Error(`Cannot use 'ValRichText' in this type of file`)};"
836
+ value: "export const useVal = () => { throw Error(`Cannot use 'useVal' in this type of file`) }; export const fetchVal = () => { throw Error(`Cannot use 'fetchVal' in this type of file`) }; export const autoTagJSX = () => { /* ignore */ };"
843
837
  };
844
838
  }
845
839
  return {
@@ -847,22 +841,17 @@ async function newValQuickJSRuntime(quickJSModule, moduleLoader, {
847
841
  };
848
842
  } catch (e) {
849
843
  return {
850
- error: Error(`Could not resolve module: ${modulePath}'`)
844
+ error: Error(`Could not resolve module: '${modulePath}': `)
851
845
  };
852
846
  }
853
847
  }, (baseModuleName, requestedName) => {
854
848
  try {
855
- if (requestedName === "./autoTagJSX") {
856
- return {
857
- value: requestedName
858
- };
859
- }
860
849
  if (requestedName === "@valbuild/react") {
861
850
  return {
862
851
  value: requestedName
863
852
  };
864
853
  }
865
- if (requestedName === "./ValRichText") {
854
+ if (requestedName === "@valbuild/react/stega") {
866
855
  return {
867
856
  value: requestedName
868
857
  };
@@ -811,22 +811,16 @@ async function newValQuickJSRuntime(quickJSModule, moduleLoader, {
811
811
  runtime.setMemoryLimit(memoryLimit);
812
812
  runtime.setModuleLoader(modulePath => {
813
813
  try {
814
- // Special cases for next package:
814
+ // Special cases to avoid loading the React packages since currently React does not have a ESM build:
815
815
  // TODO: this is not stable, find a better way to do this
816
- if (modulePath === "./autoTagJSX") {
817
- return {
818
- value: ""
819
- }; // ignore this module, it's only used in the browser
820
- }
821
-
822
816
  if (modulePath === "@valbuild/react") {
823
817
  return {
824
818
  value: "export const useVal = () => { throw Error(`Cannot use 'useVal' in this type of file`) }; export function ValProvider() { throw Error(`Cannot use 'ValProvider' in this type of file`) }; export function ValRichText() { throw Error(`Cannot use 'ValRichText' in this type of file`)};"
825
819
  };
826
820
  }
827
- if (modulePath === "./ValRichText") {
821
+ if (modulePath === "@valbuild/react/stega") {
828
822
  return {
829
- value: "export function ValRichText() { throw Error(`Cannot use 'ValRichText' in this type of file`)};"
823
+ value: "export const useVal = () => { throw Error(`Cannot use 'useVal' in this type of file`) }; export const fetchVal = () => { throw Error(`Cannot use 'fetchVal' in this type of file`) }; export const autoTagJSX = () => { /* ignore */ };"
830
824
  };
831
825
  }
832
826
  return {
@@ -834,22 +828,17 @@ async function newValQuickJSRuntime(quickJSModule, moduleLoader, {
834
828
  };
835
829
  } catch (e) {
836
830
  return {
837
- error: Error(`Could not resolve module: ${modulePath}'`)
831
+ error: Error(`Could not resolve module: '${modulePath}': `)
838
832
  };
839
833
  }
840
834
  }, (baseModuleName, requestedName) => {
841
835
  try {
842
- if (requestedName === "./autoTagJSX") {
843
- return {
844
- value: requestedName
845
- };
846
- }
847
836
  if (requestedName === "@valbuild/react") {
848
837
  return {
849
838
  value: requestedName
850
839
  };
851
840
  }
852
- if (requestedName === "./ValRichText") {
841
+ if (requestedName === "@valbuild/react/stega") {
853
842
  return {
854
843
  value: requestedName
855
844
  };
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "./package.json": "./package.json"
13
13
  },
14
14
  "types": "dist/valbuild-server.cjs.d.ts",
15
- "version": "0.13.11",
15
+ "version": "0.14.0",
16
16
  "scripts": {
17
17
  "typecheck": "tsc --noEmit",
18
18
  "test": "jest",
@@ -25,7 +25,7 @@
25
25
  "concurrently": "^7.6.0"
26
26
  },
27
27
  "dependencies": {
28
- "@valbuild/core": "~0.13.4",
28
+ "@valbuild/core": "~0.14.0",
29
29
  "@valbuild/ui": "~0.13.4",
30
30
  "express": "^4.18.2",
31
31
  "quickjs-emscripten": "^0.21.1",
@@ -20,40 +20,33 @@ export async function newValQuickJSRuntime(
20
20
  runtime.setModuleLoader(
21
21
  (modulePath) => {
22
22
  try {
23
- // Special cases for next package:
23
+ // Special cases to avoid loading the React packages since currently React does not have a ESM build:
24
24
  // TODO: this is not stable, find a better way to do this
25
- if (modulePath === "./autoTagJSX") {
26
- return { value: "" }; // ignore this module, it's only used in the browser
27
- }
28
25
  if (modulePath === "@valbuild/react") {
29
26
  return {
30
27
  value:
31
28
  "export const useVal = () => { throw Error(`Cannot use 'useVal' in this type of file`) }; export function ValProvider() { throw Error(`Cannot use 'ValProvider' in this type of file`) }; export function ValRichText() { throw Error(`Cannot use 'ValRichText' in this type of file`)};",
32
29
  };
33
30
  }
34
-
35
- if (modulePath === "./ValRichText") {
31
+ if (modulePath === "@valbuild/react/stega") {
36
32
  return {
37
33
  value:
38
- "export function ValRichText() { throw Error(`Cannot use 'ValRichText' in this type of file`)};",
34
+ "export const useVal = () => { throw Error(`Cannot use 'useVal' in this type of file`) }; export const fetchVal = () => { throw Error(`Cannot use 'fetchVal' in this type of file`) }; export const autoTagJSX = () => { /* ignore */ };",
39
35
  };
40
36
  }
41
37
  return { value: moduleLoader.getModule(modulePath) };
42
38
  } catch (e) {
43
39
  return {
44
- error: Error(`Could not resolve module: ${modulePath}'`),
40
+ error: Error(`Could not resolve module: '${modulePath}': `),
45
41
  };
46
42
  }
47
43
  },
48
44
  (baseModuleName, requestedName): JSModuleNormalizeResult => {
49
45
  try {
50
- if (requestedName === "./autoTagJSX") {
51
- return { value: requestedName };
52
- }
53
46
  if (requestedName === "@valbuild/react") {
54
47
  return { value: requestedName };
55
48
  }
56
- if (requestedName === "./ValRichText") {
49
+ if (requestedName === "@valbuild/react/stega") {
57
50
  return { value: requestedName };
58
51
  }
59
52
  const modulePath = moduleLoader.resolveModulePath(
@@ -1,22 +0,0 @@
1
- import express from "express";
2
- import { Service } from "./Service";
3
- import { ValServer } from "./ValServer";
4
- export type LocalValServerOptions = {
5
- service: Service;
6
- };
7
- export declare class LocalValServer implements ValServer {
8
- readonly options: LocalValServerOptions;
9
- constructor(options: LocalValServerOptions);
10
- session(_req: express.Request, res: express.Response): Promise<void>;
11
- getIds(req: express.Request<{
12
- 0: string;
13
- }>, res: express.Response): Promise<void>;
14
- patchIds(req: express.Request<{
15
- 0: string;
16
- }>, res: express.Response): Promise<void>;
17
- private badRequest;
18
- commit(req: express.Request, res: express.Response): Promise<void>;
19
- authorize(req: express.Request, res: express.Response): Promise<void>;
20
- callback(req: express.Request, res: express.Response): Promise<void>;
21
- logout(req: express.Request, res: express.Response): Promise<void>;
22
- }
@@ -1,52 +0,0 @@
1
- import express from "express";
2
- import { ValServer } from "./ValServer";
3
- import { z } from "zod";
4
- export type ProxyValServerOptions = {
5
- apiKey: string;
6
- route: string;
7
- valSecret: string;
8
- valBuildUrl: string;
9
- gitCommit: string;
10
- gitBranch: string;
11
- };
12
- export declare class ProxyValServer implements ValServer {
13
- readonly options: ProxyValServerOptions;
14
- constructor(options: ProxyValServerOptions);
15
- authorize(req: express.Request, res: express.Response): Promise<void>;
16
- callback(req: express.Request, res: express.Response): Promise<void>;
17
- logout(_req: express.Request, res: express.Response): Promise<void>;
18
- withAuth<T>(req: express.Request, res: express.Response, handler: (data: IntegratedServerJwtPayload) => Promise<T>): Promise<T | undefined>;
19
- session(req: express.Request, res: express.Response): Promise<void>;
20
- getIds(req: express.Request<{
21
- 0: string;
22
- }>, res: express.Response): Promise<void>;
23
- patchIds(req: express.Request<{
24
- 0: string;
25
- }>, res: express.Response): Promise<void>;
26
- commit(req: express.Request, res: express.Response): Promise<void>;
27
- private getAuthHeaders;
28
- private consumeCode;
29
- private getAuthorizeUrl;
30
- private getAppErrorUrl;
31
- }
32
- declare const IntegratedServerJwtPayload: z.ZodObject<{
33
- sub: z.ZodString;
34
- exp: z.ZodNumber;
35
- token: z.ZodString;
36
- org: z.ZodString;
37
- project: z.ZodString;
38
- }, "strip", z.ZodTypeAny, {
39
- project: string;
40
- sub: string;
41
- exp: number;
42
- token: string;
43
- org: string;
44
- }, {
45
- project: string;
46
- sub: string;
47
- exp: number;
48
- token: string;
49
- org: string;
50
- }>;
51
- export type IntegratedServerJwtPayload = z.infer<typeof IntegratedServerJwtPayload>;
52
- export {};
@@ -1,7 +0,0 @@
1
- import { QuickJSWASMModule } from "quickjs-emscripten";
2
- import { ValModuleLoader } from "./ValModuleLoader";
3
- export declare function newValQuickJSRuntime(quickJSModule: Pick<QuickJSWASMModule, "newRuntime">, moduleLoader: ValModuleLoader, { maxStackSize, // TODO: these were randomly chosen, we should figure out what the right values are:
4
- memoryLimit, }?: {
5
- maxStackSize?: number;
6
- memoryLimit?: number;
7
- }): Promise<import("quickjs-emscripten").QuickJSRuntime>;
@@ -1,4 +0,0 @@
1
- import { SourcePath } from "@valbuild/core/src/val";
2
- export declare function getPathFromParams(params: {
3
- 0: string;
4
- }): SourcePath;
@@ -1,3 +0,0 @@
1
- export declare function decodeJwt(token: string, secretKey?: string): unknown | null;
2
- export declare function getExpire(): number;
3
- export declare function encodeJwt(payload: object, sessionKey: string): string;
@@ -1,27 +0,0 @@
1
- import ts from "typescript";
2
- import { result, array } from "@valbuild/core/fp";
3
- import { ValSyntaxErrorTree } from "./syntax";
4
- import { Ops, PatchError, JSONValue } from "@valbuild/core/patch";
5
- type TSOpsResult<T> = result.Result<T, PatchError | ValSyntaxErrorTree>;
6
- declare module "typescript" {
7
- interface PrinterOptions {
8
- /**
9
- * Internal option that stops printing unnecessary ASCII escape sequences
10
- * in strings, though it might have unintended effects. Might be useful?
11
- */
12
- neverAsciiEscape?: boolean;
13
- }
14
- }
15
- export declare function getFromNode(node: ts.Expression, key: string): TSOpsResult<ts.Expression | undefined>;
16
- export declare class TSOps implements Ops<ts.SourceFile, ValSyntaxErrorTree> {
17
- private findRoot;
18
- constructor(findRoot: (document: ts.SourceFile) => result.Result<ts.Expression, ValSyntaxErrorTree>);
19
- get(document: ts.SourceFile, path: string[]): TSOpsResult<JSONValue>;
20
- add(document: ts.SourceFile, path: string[], value: JSONValue): TSOpsResult<ts.SourceFile>;
21
- remove(document: ts.SourceFile, path: array.NonEmptyArray<string>): TSOpsResult<ts.SourceFile>;
22
- replace(document: ts.SourceFile, path: string[], value: JSONValue): TSOpsResult<ts.SourceFile>;
23
- move(document: ts.SourceFile, from: array.NonEmptyArray<string>, path: string[]): TSOpsResult<ts.SourceFile>;
24
- copy(document: ts.SourceFile, from: string[], path: string[]): TSOpsResult<ts.SourceFile>;
25
- test(document: ts.SourceFile, path: string[], value: JSONValue): TSOpsResult<boolean>;
26
- }
27
- export {};
@@ -1,8 +0,0 @@
1
- import ts from "typescript";
2
- import { result } from "@valbuild/core/fp";
3
- import { ValSyntaxErrorTree } from "./syntax";
4
- export type ValModuleAnalysis = {
5
- schema: ts.Expression;
6
- source: ts.Expression;
7
- };
8
- export declare function analyzeValModule(sourceFile: ts.SourceFile): result.Result<ValModuleAnalysis, ValSyntaxErrorTree>;
@@ -1,4 +0,0 @@
1
- import type { PatchJSON as PatchJSONT } from "@valbuild/core/patch";
2
- import z from "zod";
3
- export declare const PatchJSON: z.ZodType<PatchJSONT>;
4
- export type PatchJSON = PatchJSONT;
@@ -1,3 +0,0 @@
1
- import { QuickJSRuntime } from "quickjs-emscripten";
2
- import { SerializedModuleContent } from "./SerializedModuleContent";
3
- export declare const readValFile: (id: string, valConfigPath: string, runtime: QuickJSRuntime) => Promise<SerializedModuleContent>;