@valbuild/server 0.43.1 → 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");
|
@@ -1280,8 +1281,9 @@ class LocalValServer {
|
|
1280
1281
|
}
|
1281
1282
|
};
|
1282
1283
|
}
|
1283
|
-
|
1284
|
-
|
1284
|
+
|
1285
|
+
// const id = randomUUID();
|
1286
|
+
// console.time("patching:" + id);
|
1285
1287
|
for (const moduleId in patchJSON.data) {
|
1286
1288
|
// Then parse/validate
|
1287
1289
|
// TODO: validate all and then fail instead:
|
@@ -1292,7 +1294,8 @@ class LocalValServer {
|
|
1292
1294
|
}
|
1293
1295
|
await this.options.service.patch(moduleId, patch$1.value);
|
1294
1296
|
}
|
1295
|
-
console.timeEnd("patching:" + id);
|
1297
|
+
// console.timeEnd("patching:" + id);
|
1298
|
+
|
1296
1299
|
return {
|
1297
1300
|
status: 200,
|
1298
1301
|
json: {} // no patch ids created
|
@@ -2252,6 +2255,7 @@ class ValFSHost {
|
|
2252
2255
|
}
|
2253
2256
|
|
2254
2257
|
// TODO: find a better name? transformFixesToPatch?
|
2258
|
+
const textEncoder = new TextEncoder();
|
2255
2259
|
async function createFixPatch(config, apply, sourcePath, validationError) {
|
2256
2260
|
async function getImageMetadata() {
|
2257
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;
|
@@ -2259,10 +2263,12 @@ async function createFixPatch(config, apply, sourcePath, validationError) {
|
|
2259
2263
|
// TODO:
|
2260
2264
|
throw Error("Cannot fix image without a file reference");
|
2261
2265
|
}
|
2262
|
-
const
|
2263
|
-
const buffer = fs__default["default"].readFileSync(
|
2264
|
-
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);
|
2265
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")}`));
|
2266
2272
|
return {
|
2267
2273
|
...imageSize,
|
2268
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");
|
@@ -1280,8 +1281,9 @@ class LocalValServer {
|
|
1280
1281
|
}
|
1281
1282
|
};
|
1282
1283
|
}
|
1283
|
-
|
1284
|
-
|
1284
|
+
|
1285
|
+
// const id = randomUUID();
|
1286
|
+
// console.time("patching:" + id);
|
1285
1287
|
for (const moduleId in patchJSON.data) {
|
1286
1288
|
// Then parse/validate
|
1287
1289
|
// TODO: validate all and then fail instead:
|
@@ -1292,7 +1294,8 @@ class LocalValServer {
|
|
1292
1294
|
}
|
1293
1295
|
await this.options.service.patch(moduleId, patch$1.value);
|
1294
1296
|
}
|
1295
|
-
console.timeEnd("patching:" + id);
|
1297
|
+
// console.timeEnd("patching:" + id);
|
1298
|
+
|
1296
1299
|
return {
|
1297
1300
|
status: 200,
|
1298
1301
|
json: {} // no patch ids created
|
@@ -2252,6 +2255,7 @@ class ValFSHost {
|
|
2252
2255
|
}
|
2253
2256
|
|
2254
2257
|
// TODO: find a better name? transformFixesToPatch?
|
2258
|
+
const textEncoder = new TextEncoder();
|
2255
2259
|
async function createFixPatch(config, apply, sourcePath, validationError) {
|
2256
2260
|
async function getImageMetadata() {
|
2257
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;
|
@@ -2259,10 +2263,12 @@ async function createFixPatch(config, apply, sourcePath, validationError) {
|
|
2259
2263
|
// TODO:
|
2260
2264
|
throw Error("Cannot fix image without a file reference");
|
2261
2265
|
}
|
2262
|
-
const
|
2263
|
-
const buffer = fs__default["default"].readFileSync(
|
2264
|
-
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);
|
2265
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")}`));
|
2266
2272
|
return {
|
2267
2273
|
...imageSize,
|
2268
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");
|
@@ -1250,8 +1251,9 @@ class LocalValServer {
|
|
1250
1251
|
}
|
1251
1252
|
};
|
1252
1253
|
}
|
1253
|
-
|
1254
|
-
|
1254
|
+
|
1255
|
+
// const id = randomUUID();
|
1256
|
+
// console.time("patching:" + id);
|
1255
1257
|
for (const moduleId in patchJSON.data) {
|
1256
1258
|
// Then parse/validate
|
1257
1259
|
// TODO: validate all and then fail instead:
|
@@ -1262,7 +1264,8 @@ class LocalValServer {
|
|
1262
1264
|
}
|
1263
1265
|
await this.options.service.patch(moduleId, patch.value);
|
1264
1266
|
}
|
1265
|
-
console.timeEnd("patching:" + id);
|
1267
|
+
// console.timeEnd("patching:" + id);
|
1268
|
+
|
1266
1269
|
return {
|
1267
1270
|
status: 200,
|
1268
1271
|
json: {} // no patch ids created
|
@@ -2222,6 +2225,7 @@ class ValFSHost {
|
|
2222
2225
|
}
|
2223
2226
|
|
2224
2227
|
// TODO: find a better name? transformFixesToPatch?
|
2228
|
+
const textEncoder = new TextEncoder();
|
2225
2229
|
async function createFixPatch(config, apply, sourcePath, validationError) {
|
2226
2230
|
async function getImageMetadata() {
|
2227
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;
|
@@ -2229,10 +2233,12 @@ async function createFixPatch(config, apply, sourcePath, validationError) {
|
|
2229
2233
|
// TODO:
|
2230
2234
|
throw Error("Cannot fix image without a file reference");
|
2231
2235
|
}
|
2232
|
-
const
|
2233
|
-
const buffer = fs.readFileSync(
|
2234
|
-
const sha256 = await Internal.getSHA256Hash(buffer);
|
2236
|
+
const filename = path__default.join(config.projectRoot, maybeRef);
|
2237
|
+
const buffer = fs.readFileSync(filename);
|
2235
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")}`));
|
2236
2242
|
return {
|
2237
2243
|
...imageSize,
|
2238
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",
|