@valbuild/server 0.62.3 → 0.62.5

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.
@@ -39,12 +39,11 @@ export declare class ValServer {
39
39
  }): Promise<ValServerRedirectResult<VAL_ENABLE_COOKIE_NAME>>;
40
40
  authorize(query: {
41
41
  redirect_to?: string;
42
- }): Promise<ValServerRedirectResult<VAL_STATE_COOKIE>>;
42
+ }): Promise<ValServerRedirectResult<VAL_STATE_COOKIE | VAL_ENABLE_COOKIE_NAME>>;
43
43
  callback(query: {
44
44
  code?: string;
45
45
  state?: string;
46
46
  }, cookies: ValCookies<"val_state">): Promise<ValServerRedirectResult<"val_state" | "val_session" | "val_enable">>;
47
- log(): Promise<ValServerResult<VAL_SESSION_COOKIE | VAL_STATE_COOKIE>>;
48
47
  session(cookies: ValCookies<VAL_SESSION_COOKIE>): Promise<ValServerJsonResult<ValSession>>;
49
48
  private consumeCode;
50
49
  private getAuthorizeUrl;
@@ -1541,7 +1541,7 @@ class ValOps {
1541
1541
  error: new patch.PatchError(`Module at path: '${path}' not found`)
1542
1542
  });
1543
1543
  }
1544
- const source = sources[path];
1544
+ patchedSources[path] = sources[path];
1545
1545
  for (const {
1546
1546
  patchId
1547
1547
  } of patches) {
@@ -1576,7 +1576,9 @@ class ValOps {
1576
1576
  applicableOps.push(op);
1577
1577
  }
1578
1578
  }
1579
- const patchRes = patch.applyPatch(source, jsonOps, applicableOps.concat(...Object.values(fileFixOps)));
1579
+ const patchRes = patch.applyPatch(patch.deepClone(patchedSources[path]),
1580
+ // applyPatch mutates the source. On add operations it will add multiple items? There is something strange going on. DeepClone seems to fix, but is that the right?
1581
+ jsonOps, applicableOps.concat(...Object.values(fileFixOps)));
1580
1582
  if (fp.result.isErr(patchRes)) {
1581
1583
  if (!errors[path]) {
1582
1584
  errors[path] = [];
@@ -3350,8 +3352,10 @@ class ValServer {
3350
3352
  const token = crypto.randomUUID();
3351
3353
  const redirectUrl = new URL(query.redirect_to);
3352
3354
  const appAuthorizeUrl = this.getAuthorizeUrl(`${redirectUrl.origin}/${this.options.route}`, token);
3355
+ await this.callbacks.onEnable(true);
3353
3356
  return {
3354
3357
  cookies: {
3358
+ [internal.VAL_ENABLE_COOKIE_NAME]: ENABLE_COOKIE_VALUE,
3355
3359
  [internal.VAL_STATE_COOKIE]: {
3356
3360
  value: createStateCookie({
3357
3361
  redirect_to: query.redirect_to,
@@ -3456,19 +3460,6 @@ class ValServer {
3456
3460
  redirectTo: callbackReqSuccess.redirect_uri || "/"
3457
3461
  };
3458
3462
  }
3459
- async log() {
3460
- return {
3461
- status: 200,
3462
- cookies: {
3463
- [internal.VAL_SESSION_COOKIE]: {
3464
- value: null
3465
- },
3466
- [internal.VAL_STATE_COOKIE]: {
3467
- value: null
3468
- }
3469
- }
3470
- };
3471
- }
3472
3463
  async session(cookies) {
3473
3464
  if (this.serverOps instanceof ValOpsFS) {
3474
3465
  return {
@@ -3981,6 +3972,22 @@ class ValServer {
3981
3972
  ...analysis,
3982
3973
  ...patches
3983
3974
  });
3975
+ if (preparedCommit.hasErrors) {
3976
+ console.error("Failed to create commit", {
3977
+ sourceFilePatchErrors: preparedCommit.sourceFilePatchErrors,
3978
+ binaryFilePatchErrors: preparedCommit.binaryFilePatchErrors
3979
+ });
3980
+ return {
3981
+ status: 400,
3982
+ json: {
3983
+ message: "Failed to create commit",
3984
+ details: {
3985
+ sourceFilePatchErrors: preparedCommit.sourceFilePatchErrors,
3986
+ binaryFilePatchErrors: preparedCommit.binaryFilePatchErrors
3987
+ }
3988
+ }
3989
+ };
3990
+ }
3984
3991
  if (this.serverOps instanceof ValOpsFS) {
3985
3992
  await this.serverOps.saveFiles(preparedCommit);
3986
3993
  return {
@@ -1541,7 +1541,7 @@ class ValOps {
1541
1541
  error: new patch.PatchError(`Module at path: '${path}' not found`)
1542
1542
  });
1543
1543
  }
1544
- const source = sources[path];
1544
+ patchedSources[path] = sources[path];
1545
1545
  for (const {
1546
1546
  patchId
1547
1547
  } of patches) {
@@ -1576,7 +1576,9 @@ class ValOps {
1576
1576
  applicableOps.push(op);
1577
1577
  }
1578
1578
  }
1579
- const patchRes = patch.applyPatch(source, jsonOps, applicableOps.concat(...Object.values(fileFixOps)));
1579
+ const patchRes = patch.applyPatch(patch.deepClone(patchedSources[path]),
1580
+ // applyPatch mutates the source. On add operations it will add multiple items? There is something strange going on. DeepClone seems to fix, but is that the right?
1581
+ jsonOps, applicableOps.concat(...Object.values(fileFixOps)));
1580
1582
  if (fp.result.isErr(patchRes)) {
1581
1583
  if (!errors[path]) {
1582
1584
  errors[path] = [];
@@ -3350,8 +3352,10 @@ class ValServer {
3350
3352
  const token = crypto.randomUUID();
3351
3353
  const redirectUrl = new URL(query.redirect_to);
3352
3354
  const appAuthorizeUrl = this.getAuthorizeUrl(`${redirectUrl.origin}/${this.options.route}`, token);
3355
+ await this.callbacks.onEnable(true);
3353
3356
  return {
3354
3357
  cookies: {
3358
+ [internal.VAL_ENABLE_COOKIE_NAME]: ENABLE_COOKIE_VALUE,
3355
3359
  [internal.VAL_STATE_COOKIE]: {
3356
3360
  value: createStateCookie({
3357
3361
  redirect_to: query.redirect_to,
@@ -3456,19 +3460,6 @@ class ValServer {
3456
3460
  redirectTo: callbackReqSuccess.redirect_uri || "/"
3457
3461
  };
3458
3462
  }
3459
- async log() {
3460
- return {
3461
- status: 200,
3462
- cookies: {
3463
- [internal.VAL_SESSION_COOKIE]: {
3464
- value: null
3465
- },
3466
- [internal.VAL_STATE_COOKIE]: {
3467
- value: null
3468
- }
3469
- }
3470
- };
3471
- }
3472
3463
  async session(cookies) {
3473
3464
  if (this.serverOps instanceof ValOpsFS) {
3474
3465
  return {
@@ -3981,6 +3972,22 @@ class ValServer {
3981
3972
  ...analysis,
3982
3973
  ...patches
3983
3974
  });
3975
+ if (preparedCommit.hasErrors) {
3976
+ console.error("Failed to create commit", {
3977
+ sourceFilePatchErrors: preparedCommit.sourceFilePatchErrors,
3978
+ binaryFilePatchErrors: preparedCommit.binaryFilePatchErrors
3979
+ });
3980
+ return {
3981
+ status: 400,
3982
+ json: {
3983
+ message: "Failed to create commit",
3984
+ details: {
3985
+ sourceFilePatchErrors: preparedCommit.sourceFilePatchErrors,
3986
+ binaryFilePatchErrors: preparedCommit.binaryFilePatchErrors
3987
+ }
3988
+ }
3989
+ };
3990
+ }
3984
3991
  if (this.serverOps instanceof ValOpsFS) {
3985
3992
  await this.serverOps.saveFiles(preparedCommit);
3986
3993
  return {
@@ -2,7 +2,7 @@ import { newQuickJSWASMModule } from 'quickjs-emscripten';
2
2
  import ts from 'typescript';
3
3
  import { result, pipe } from '@valbuild/core/fp';
4
4
  import { FILE_REF_PROP, FILE_REF_SUBTYPE_TAG, RT_IMAGE_TAG, VAL_EXTENSION, derefPatch, Internal, Schema, ImageSchema, FileSchema } from '@valbuild/core';
5
- import { deepEqual, isNotRoot, PatchError, parseAndValidateArrayIndex, applyPatch, JSONOps, sourceToPatchPath } from '@valbuild/core/patch';
5
+ import { deepEqual, isNotRoot, PatchError, parseAndValidateArrayIndex, applyPatch, JSONOps, deepClone, sourceToPatchPath } from '@valbuild/core/patch';
6
6
  import * as fsPath from 'path';
7
7
  import fsPath__default from 'path';
8
8
  import fs, { promises } from 'fs';
@@ -1511,7 +1511,7 @@ class ValOps {
1511
1511
  error: new PatchError(`Module at path: '${path}' not found`)
1512
1512
  });
1513
1513
  }
1514
- const source = sources[path];
1514
+ patchedSources[path] = sources[path];
1515
1515
  for (const {
1516
1516
  patchId
1517
1517
  } of patches) {
@@ -1546,7 +1546,9 @@ class ValOps {
1546
1546
  applicableOps.push(op);
1547
1547
  }
1548
1548
  }
1549
- const patchRes = applyPatch(source, jsonOps, applicableOps.concat(...Object.values(fileFixOps)));
1549
+ const patchRes = applyPatch(deepClone(patchedSources[path]),
1550
+ // applyPatch mutates the source. On add operations it will add multiple items? There is something strange going on. DeepClone seems to fix, but is that the right?
1551
+ jsonOps, applicableOps.concat(...Object.values(fileFixOps)));
1550
1552
  if (result.isErr(patchRes)) {
1551
1553
  if (!errors[path]) {
1552
1554
  errors[path] = [];
@@ -3320,8 +3322,10 @@ class ValServer {
3320
3322
  const token = crypto.randomUUID();
3321
3323
  const redirectUrl = new URL(query.redirect_to);
3322
3324
  const appAuthorizeUrl = this.getAuthorizeUrl(`${redirectUrl.origin}/${this.options.route}`, token);
3325
+ await this.callbacks.onEnable(true);
3323
3326
  return {
3324
3327
  cookies: {
3328
+ [VAL_ENABLE_COOKIE_NAME]: ENABLE_COOKIE_VALUE,
3325
3329
  [VAL_STATE_COOKIE$1]: {
3326
3330
  value: createStateCookie({
3327
3331
  redirect_to: query.redirect_to,
@@ -3426,19 +3430,6 @@ class ValServer {
3426
3430
  redirectTo: callbackReqSuccess.redirect_uri || "/"
3427
3431
  };
3428
3432
  }
3429
- async log() {
3430
- return {
3431
- status: 200,
3432
- cookies: {
3433
- [VAL_SESSION_COOKIE$1]: {
3434
- value: null
3435
- },
3436
- [VAL_STATE_COOKIE$1]: {
3437
- value: null
3438
- }
3439
- }
3440
- };
3441
- }
3442
3433
  async session(cookies) {
3443
3434
  if (this.serverOps instanceof ValOpsFS) {
3444
3435
  return {
@@ -3951,6 +3942,22 @@ class ValServer {
3951
3942
  ...analysis,
3952
3943
  ...patches
3953
3944
  });
3945
+ if (preparedCommit.hasErrors) {
3946
+ console.error("Failed to create commit", {
3947
+ sourceFilePatchErrors: preparedCommit.sourceFilePatchErrors,
3948
+ binaryFilePatchErrors: preparedCommit.binaryFilePatchErrors
3949
+ });
3950
+ return {
3951
+ status: 400,
3952
+ json: {
3953
+ message: "Failed to create commit",
3954
+ details: {
3955
+ sourceFilePatchErrors: preparedCommit.sourceFilePatchErrors,
3956
+ binaryFilePatchErrors: preparedCommit.binaryFilePatchErrors
3957
+ }
3958
+ }
3959
+ };
3960
+ }
3954
3961
  if (this.serverOps instanceof ValOpsFS) {
3955
3962
  await this.serverOps.saveFiles(preparedCommit);
3956
3963
  return {
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.62.3",
15
+ "version": "0.62.5",
16
16
  "scripts": {
17
17
  "typecheck": "tsc --noEmit",
18
18
  "test": "jest",
@@ -22,9 +22,9 @@
22
22
  "@types/jest": "^29.2.5"
23
23
  },
24
24
  "dependencies": {
25
- "@valbuild/core": "~0.62.3",
26
- "@valbuild/shared": "~0.62.3",
27
- "@valbuild/ui": "~0.62.3",
25
+ "@valbuild/core": "~0.62.5",
26
+ "@valbuild/shared": "~0.62.5",
27
+ "@valbuild/ui": "~0.62.5",
28
28
  "image-size": "^1.0.2",
29
29
  "minimatch": "^3.0.4",
30
30
  "quickjs-emscripten": "^0.21.1",