@valbuild/server 0.43.0 → 0.44.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.
@@ -7,12 +7,12 @@ var ts = require('typescript');
|
|
7
7
|
var fp = require('@valbuild/core/fp');
|
8
8
|
var core = require('@valbuild/core');
|
9
9
|
var patch = require('@valbuild/core/patch');
|
10
|
-
var crypto = require('crypto');
|
11
10
|
var path = require('path');
|
12
11
|
var fs = require('fs');
|
13
12
|
var sucrase = require('sucrase');
|
14
13
|
var z = require('zod');
|
15
14
|
var internal = require('@valbuild/shared/internal');
|
15
|
+
var crypto = require('crypto');
|
16
16
|
var server = require('@valbuild/ui/server');
|
17
17
|
var sizeOf = require('image-size');
|
18
18
|
|
@@ -37,10 +37,10 @@ function _interopNamespace(e) {
|
|
37
37
|
}
|
38
38
|
|
39
39
|
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
40
|
-
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
41
40
|
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
42
41
|
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
43
42
|
var z__default = /*#__PURE__*/_interopDefault(z);
|
43
|
+
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
44
44
|
var sizeOf__default = /*#__PURE__*/_interopDefault(sizeOf);
|
45
45
|
|
46
46
|
class ValSyntaxError {
|
@@ -624,8 +624,8 @@ const ops = new TSOps(document => {
|
|
624
624
|
|
625
625
|
// TODO: rename to patchValFiles since we may write multiple files
|
626
626
|
const patchValFile = async (id, valConfigPath, patch$1, sourceFileHandler, runtime) => {
|
627
|
-
const timeId =
|
628
|
-
console.time("patchValFile" + timeId);
|
627
|
+
// const timeId = randomUUID();
|
628
|
+
// console.time("patchValFile" + timeId);
|
629
629
|
const filePath = sourceFileHandler.resolveSourceModulePath(valConfigPath, `.${id}.val`);
|
630
630
|
const sourceFile = sourceFileHandler.getSourceFile(filePath);
|
631
631
|
if (!sourceFile) {
|
@@ -661,8 +661,9 @@ const patchValFile = async (id, valConfigPath, patch$1, sourceFileHandler, runti
|
|
661
661
|
}
|
662
662
|
}
|
663
663
|
sourceFileHandler.writeSourceFile(newSourceFile.value);
|
664
|
-
console.timeEnd("patchValFile" + timeId);
|
664
|
+
// console.timeEnd("patchValFile" + timeId);
|
665
665
|
};
|
666
|
+
|
666
667
|
function convertDataUrlToBase64(dataUrl) {
|
667
668
|
const base64 = dataUrl.slice(dataUrl.indexOf(",") + 1);
|
668
669
|
return Buffer.from(base64, "base64");
|
@@ -730,7 +731,6 @@ globalThis.valModule = {
|
|
730
731
|
} else {
|
731
732
|
result.value.dispose();
|
732
733
|
const valModule = context.getProp(context.global, "valModule").consume(context.dump);
|
733
|
-
console.log(valModule);
|
734
734
|
if (!valModule) {
|
735
735
|
fatalErrors.push(`Could not find any modules at: ${id}`);
|
736
736
|
} else if (valModule.defaultExport === false) {
|
@@ -1281,8 +1281,9 @@ class LocalValServer {
|
|
1281
1281
|
}
|
1282
1282
|
};
|
1283
1283
|
}
|
1284
|
-
|
1285
|
-
|
1284
|
+
|
1285
|
+
// const id = randomUUID();
|
1286
|
+
// console.time("patching:" + id);
|
1286
1287
|
for (const moduleId in patchJSON.data) {
|
1287
1288
|
// Then parse/validate
|
1288
1289
|
// TODO: validate all and then fail instead:
|
@@ -1293,7 +1294,8 @@ class LocalValServer {
|
|
1293
1294
|
}
|
1294
1295
|
await this.options.service.patch(moduleId, patch$1.value);
|
1295
1296
|
}
|
1296
|
-
console.timeEnd("patching:" + id);
|
1297
|
+
// console.timeEnd("patching:" + id);
|
1298
|
+
|
1297
1299
|
return {
|
1298
1300
|
status: 200,
|
1299
1301
|
json: {} // no patch ids created
|
@@ -2253,6 +2255,7 @@ class ValFSHost {
|
|
2253
2255
|
}
|
2254
2256
|
|
2255
2257
|
// TODO: find a better name? transformFixesToPatch?
|
2258
|
+
const textEncoder = new TextEncoder();
|
2256
2259
|
async function createFixPatch(config, apply, sourcePath, validationError) {
|
2257
2260
|
async function getImageMetadata() {
|
2258
2261
|
const maybeRef = validationError.value && typeof validationError.value === "object" && core.FILE_REF_PROP in validationError.value && typeof validationError.value[core.FILE_REF_PROP] === "string" ? validationError.value[core.FILE_REF_PROP] : undefined;
|
@@ -2260,10 +2263,12 @@ async function createFixPatch(config, apply, sourcePath, validationError) {
|
|
2260
2263
|
// TODO:
|
2261
2264
|
throw Error("Cannot fix image without a file reference");
|
2262
2265
|
}
|
2263
|
-
const
|
2264
|
-
const buffer = fs__default["default"].readFileSync(
|
2265
|
-
const sha256 = await core.Internal.getSHA256Hash(buffer);
|
2266
|
+
const filename = path__namespace["default"].join(config.projectRoot, maybeRef);
|
2267
|
+
const buffer = fs__default["default"].readFileSync(filename);
|
2266
2268
|
const imageSize = sizeOf__default["default"](buffer);
|
2269
|
+
const sha256 = core.Internal.getSHA256Hash(textEncoder.encode(
|
2270
|
+
// TODO: we should probably store the mimetype in the metadata and reuse it here
|
2271
|
+
`data:${imageSize.type ? internal.imageTypeToMimeType(imageSize.type) : internal.filenameToMimeType(filename)};base64,${buffer.toString("base64")}`));
|
2267
2272
|
return {
|
2268
2273
|
...imageSize,
|
2269
2274
|
sha256
|
@@ -7,12 +7,12 @@ var ts = require('typescript');
|
|
7
7
|
var fp = require('@valbuild/core/fp');
|
8
8
|
var core = require('@valbuild/core');
|
9
9
|
var patch = require('@valbuild/core/patch');
|
10
|
-
var crypto = require('crypto');
|
11
10
|
var path = require('path');
|
12
11
|
var fs = require('fs');
|
13
12
|
var sucrase = require('sucrase');
|
14
13
|
var z = require('zod');
|
15
14
|
var internal = require('@valbuild/shared/internal');
|
15
|
+
var crypto = require('crypto');
|
16
16
|
var server = require('@valbuild/ui/server');
|
17
17
|
var sizeOf = require('image-size');
|
18
18
|
|
@@ -37,10 +37,10 @@ function _interopNamespace(e) {
|
|
37
37
|
}
|
38
38
|
|
39
39
|
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
40
|
-
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
41
40
|
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
42
41
|
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
43
42
|
var z__default = /*#__PURE__*/_interopDefault(z);
|
43
|
+
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
44
44
|
var sizeOf__default = /*#__PURE__*/_interopDefault(sizeOf);
|
45
45
|
|
46
46
|
class ValSyntaxError {
|
@@ -624,8 +624,8 @@ const ops = new TSOps(document => {
|
|
624
624
|
|
625
625
|
// TODO: rename to patchValFiles since we may write multiple files
|
626
626
|
const patchValFile = async (id, valConfigPath, patch$1, sourceFileHandler, runtime) => {
|
627
|
-
const timeId =
|
628
|
-
console.time("patchValFile" + timeId);
|
627
|
+
// const timeId = randomUUID();
|
628
|
+
// console.time("patchValFile" + timeId);
|
629
629
|
const filePath = sourceFileHandler.resolveSourceModulePath(valConfigPath, `.${id}.val`);
|
630
630
|
const sourceFile = sourceFileHandler.getSourceFile(filePath);
|
631
631
|
if (!sourceFile) {
|
@@ -661,8 +661,9 @@ const patchValFile = async (id, valConfigPath, patch$1, sourceFileHandler, runti
|
|
661
661
|
}
|
662
662
|
}
|
663
663
|
sourceFileHandler.writeSourceFile(newSourceFile.value);
|
664
|
-
console.timeEnd("patchValFile" + timeId);
|
664
|
+
// console.timeEnd("patchValFile" + timeId);
|
665
665
|
};
|
666
|
+
|
666
667
|
function convertDataUrlToBase64(dataUrl) {
|
667
668
|
const base64 = dataUrl.slice(dataUrl.indexOf(",") + 1);
|
668
669
|
return Buffer.from(base64, "base64");
|
@@ -730,7 +731,6 @@ globalThis.valModule = {
|
|
730
731
|
} else {
|
731
732
|
result.value.dispose();
|
732
733
|
const valModule = context.getProp(context.global, "valModule").consume(context.dump);
|
733
|
-
console.log(valModule);
|
734
734
|
if (!valModule) {
|
735
735
|
fatalErrors.push(`Could not find any modules at: ${id}`);
|
736
736
|
} else if (valModule.defaultExport === false) {
|
@@ -1281,8 +1281,9 @@ class LocalValServer {
|
|
1281
1281
|
}
|
1282
1282
|
};
|
1283
1283
|
}
|
1284
|
-
|
1285
|
-
|
1284
|
+
|
1285
|
+
// const id = randomUUID();
|
1286
|
+
// console.time("patching:" + id);
|
1286
1287
|
for (const moduleId in patchJSON.data) {
|
1287
1288
|
// Then parse/validate
|
1288
1289
|
// TODO: validate all and then fail instead:
|
@@ -1293,7 +1294,8 @@ class LocalValServer {
|
|
1293
1294
|
}
|
1294
1295
|
await this.options.service.patch(moduleId, patch$1.value);
|
1295
1296
|
}
|
1296
|
-
console.timeEnd("patching:" + id);
|
1297
|
+
// console.timeEnd("patching:" + id);
|
1298
|
+
|
1297
1299
|
return {
|
1298
1300
|
status: 200,
|
1299
1301
|
json: {} // no patch ids created
|
@@ -2253,6 +2255,7 @@ class ValFSHost {
|
|
2253
2255
|
}
|
2254
2256
|
|
2255
2257
|
// TODO: find a better name? transformFixesToPatch?
|
2258
|
+
const textEncoder = new TextEncoder();
|
2256
2259
|
async function createFixPatch(config, apply, sourcePath, validationError) {
|
2257
2260
|
async function getImageMetadata() {
|
2258
2261
|
const maybeRef = validationError.value && typeof validationError.value === "object" && core.FILE_REF_PROP in validationError.value && typeof validationError.value[core.FILE_REF_PROP] === "string" ? validationError.value[core.FILE_REF_PROP] : undefined;
|
@@ -2260,10 +2263,12 @@ async function createFixPatch(config, apply, sourcePath, validationError) {
|
|
2260
2263
|
// TODO:
|
2261
2264
|
throw Error("Cannot fix image without a file reference");
|
2262
2265
|
}
|
2263
|
-
const
|
2264
|
-
const buffer = fs__default["default"].readFileSync(
|
2265
|
-
const sha256 = await core.Internal.getSHA256Hash(buffer);
|
2266
|
+
const filename = path__namespace["default"].join(config.projectRoot, maybeRef);
|
2267
|
+
const buffer = fs__default["default"].readFileSync(filename);
|
2266
2268
|
const imageSize = sizeOf__default["default"](buffer);
|
2269
|
+
const sha256 = core.Internal.getSHA256Hash(textEncoder.encode(
|
2270
|
+
// TODO: we should probably store the mimetype in the metadata and reuse it here
|
2271
|
+
`data:${imageSize.type ? internal.imageTypeToMimeType(imageSize.type) : internal.filenameToMimeType(filename)};base64,${buffer.toString("base64")}`));
|
2267
2272
|
return {
|
2268
2273
|
...imageSize,
|
2269
2274
|
sha256
|
@@ -3,13 +3,13 @@ import ts from 'typescript';
|
|
3
3
|
import { result, pipe } from '@valbuild/core/fp';
|
4
4
|
import { FILE_REF_PROP, VAL_EXTENSION, derefPatch, Internal, Schema } from '@valbuild/core';
|
5
5
|
import { deepEqual, isNotRoot, PatchError, parseAndValidateArrayIndex, applyPatch, parsePatch, sourceToPatchPath } from '@valbuild/core/patch';
|
6
|
-
import crypto, { randomUUID } from 'crypto';
|
7
6
|
import * as path from 'path';
|
8
7
|
import path__default from 'path';
|
9
8
|
import fs, { promises } from 'fs';
|
10
9
|
import { transform } from 'sucrase';
|
11
10
|
import z, { z as z$1 } from 'zod';
|
12
|
-
import { VAL_ENABLE_COOKIE_NAME, VAL_STATE_COOKIE as VAL_STATE_COOKIE$1, VAL_SESSION_COOKIE as VAL_SESSION_COOKIE$1 } from '@valbuild/shared/internal';
|
11
|
+
import { VAL_ENABLE_COOKIE_NAME, VAL_STATE_COOKIE as VAL_STATE_COOKIE$1, VAL_SESSION_COOKIE as VAL_SESSION_COOKIE$1, imageTypeToMimeType, filenameToMimeType } from '@valbuild/shared/internal';
|
12
|
+
import crypto from 'crypto';
|
13
13
|
import { createUIRequestHandler } from '@valbuild/ui/server';
|
14
14
|
import sizeOf from 'image-size';
|
15
15
|
|
@@ -594,8 +594,8 @@ const ops = new TSOps(document => {
|
|
594
594
|
|
595
595
|
// TODO: rename to patchValFiles since we may write multiple files
|
596
596
|
const patchValFile = async (id, valConfigPath, patch, sourceFileHandler, runtime) => {
|
597
|
-
const timeId = randomUUID();
|
598
|
-
console.time("patchValFile" + timeId);
|
597
|
+
// const timeId = randomUUID();
|
598
|
+
// console.time("patchValFile" + timeId);
|
599
599
|
const filePath = sourceFileHandler.resolveSourceModulePath(valConfigPath, `.${id}.val`);
|
600
600
|
const sourceFile = sourceFileHandler.getSourceFile(filePath);
|
601
601
|
if (!sourceFile) {
|
@@ -631,8 +631,9 @@ const patchValFile = async (id, valConfigPath, patch, sourceFileHandler, runtime
|
|
631
631
|
}
|
632
632
|
}
|
633
633
|
sourceFileHandler.writeSourceFile(newSourceFile.value);
|
634
|
-
console.timeEnd("patchValFile" + timeId);
|
634
|
+
// console.timeEnd("patchValFile" + timeId);
|
635
635
|
};
|
636
|
+
|
636
637
|
function convertDataUrlToBase64(dataUrl) {
|
637
638
|
const base64 = dataUrl.slice(dataUrl.indexOf(",") + 1);
|
638
639
|
return Buffer.from(base64, "base64");
|
@@ -700,7 +701,6 @@ globalThis.valModule = {
|
|
700
701
|
} else {
|
701
702
|
result.value.dispose();
|
702
703
|
const valModule = context.getProp(context.global, "valModule").consume(context.dump);
|
703
|
-
console.log(valModule);
|
704
704
|
if (!valModule) {
|
705
705
|
fatalErrors.push(`Could not find any modules at: ${id}`);
|
706
706
|
} else if (valModule.defaultExport === false) {
|
@@ -1251,8 +1251,9 @@ class LocalValServer {
|
|
1251
1251
|
}
|
1252
1252
|
};
|
1253
1253
|
}
|
1254
|
-
|
1255
|
-
|
1254
|
+
|
1255
|
+
// const id = randomUUID();
|
1256
|
+
// console.time("patching:" + id);
|
1256
1257
|
for (const moduleId in patchJSON.data) {
|
1257
1258
|
// Then parse/validate
|
1258
1259
|
// TODO: validate all and then fail instead:
|
@@ -1263,7 +1264,8 @@ class LocalValServer {
|
|
1263
1264
|
}
|
1264
1265
|
await this.options.service.patch(moduleId, patch.value);
|
1265
1266
|
}
|
1266
|
-
console.timeEnd("patching:" + id);
|
1267
|
+
// console.timeEnd("patching:" + id);
|
1268
|
+
|
1267
1269
|
return {
|
1268
1270
|
status: 200,
|
1269
1271
|
json: {} // no patch ids created
|
@@ -2223,6 +2225,7 @@ class ValFSHost {
|
|
2223
2225
|
}
|
2224
2226
|
|
2225
2227
|
// TODO: find a better name? transformFixesToPatch?
|
2228
|
+
const textEncoder = new TextEncoder();
|
2226
2229
|
async function createFixPatch(config, apply, sourcePath, validationError) {
|
2227
2230
|
async function getImageMetadata() {
|
2228
2231
|
const maybeRef = validationError.value && typeof validationError.value === "object" && FILE_REF_PROP in validationError.value && typeof validationError.value[FILE_REF_PROP] === "string" ? validationError.value[FILE_REF_PROP] : undefined;
|
@@ -2230,10 +2233,12 @@ async function createFixPatch(config, apply, sourcePath, validationError) {
|
|
2230
2233
|
// TODO:
|
2231
2234
|
throw Error("Cannot fix image without a file reference");
|
2232
2235
|
}
|
2233
|
-
const
|
2234
|
-
const buffer = fs.readFileSync(
|
2235
|
-
const sha256 = await Internal.getSHA256Hash(buffer);
|
2236
|
+
const filename = path__default.join(config.projectRoot, maybeRef);
|
2237
|
+
const buffer = fs.readFileSync(filename);
|
2236
2238
|
const imageSize = sizeOf(buffer);
|
2239
|
+
const sha256 = Internal.getSHA256Hash(textEncoder.encode(
|
2240
|
+
// TODO: we should probably store the mimetype in the metadata and reuse it here
|
2241
|
+
`data:${imageSize.type ? imageTypeToMimeType(imageSize.type) : filenameToMimeType(filename)};base64,${buffer.toString("base64")}`));
|
2237
2242
|
return {
|
2238
2243
|
...imageSize,
|
2239
2244
|
sha256
|
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.
|
15
|
+
"version": "0.44.0",
|
16
16
|
"scripts": {
|
17
17
|
"typecheck": "tsc --noEmit",
|
18
18
|
"test": "jest",
|
@@ -24,9 +24,9 @@
|
|
24
24
|
"concurrently": "^7.6.0"
|
25
25
|
},
|
26
26
|
"dependencies": {
|
27
|
-
"@valbuild/core": "~0.
|
28
|
-
"@valbuild/shared": "~0.
|
29
|
-
"@valbuild/ui": "~0.
|
27
|
+
"@valbuild/core": "~0.44.0",
|
28
|
+
"@valbuild/shared": "~0.44.0",
|
29
|
+
"@valbuild/ui": "~0.44.0",
|
30
30
|
"express": "^4.18.2",
|
31
31
|
"image-size": "^1.0.2",
|
32
32
|
"queue": "^6.0.2",
|