@valbuild/core 0.21.2 → 0.23.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.
- package/dist/declarations/src/ValApi.d.ts +2 -1
- package/dist/declarations/src/index.d.ts +21 -3
- package/dist/declarations/src/module.d.ts +11 -5
- package/dist/declarations/src/patch/deref.d.ts +0 -3
- package/dist/declarations/src/patch/operation.d.ts +2 -0
- package/dist/declarations/src/schema/string.d.ts +5 -1
- package/dist/{index-75b79c89.cjs.prod.js → index-30eee5ec.cjs.prod.js} +47 -43
- package/dist/{index-067cff4a.cjs.prod.js → index-425d164d.cjs.prod.js} +1 -1
- package/dist/{index-31991dd7.cjs.dev.js → index-43369070.cjs.dev.js} +47 -43
- package/dist/{index-4bb14a92.esm.js → index-499b9e87.esm.js} +47 -43
- package/dist/{index-d17f9503.cjs.dev.js → index-a0f36fe3.cjs.dev.js} +1 -1
- package/dist/{index-870205b5.esm.js → index-f0475164.esm.js} +1 -1
- package/dist/{ops-9b396073.esm.js → ops-1225f750.esm.js} +5 -2
- package/dist/{ops-0f7617a0.cjs.dev.js → ops-558f07b7.cjs.dev.js} +5 -2
- package/dist/{ops-451ffb3f.cjs.prod.js → ops-b263963e.cjs.prod.js} +5 -2
- package/dist/valbuild-core.cjs.dev.js +251 -240
- package/dist/valbuild-core.cjs.prod.js +251 -240
- package/dist/valbuild-core.esm.js +252 -241
- package/expr/dist/valbuild-core-expr.cjs.dev.js +2 -2
- package/expr/dist/valbuild-core-expr.cjs.prod.js +2 -2
- package/expr/dist/valbuild-core-expr.esm.js +2 -2
- package/package.json +1 -1
- package/patch/dist/valbuild-core-patch.cjs.dev.js +13 -3
- package/patch/dist/valbuild-core-patch.cjs.prod.js +13 -3
- package/patch/dist/valbuild-core-patch.esm.js +14 -4
- package/src/ValApi.ts +9 -13
- package/src/index.ts +23 -3
- package/src/module.ts +40 -14
- package/src/patch/deref.test.ts +130 -132
- package/src/patch/deref.ts +12 -17
- package/src/patch/operation.ts +2 -0
- package/src/patch/parse.ts +15 -1
- package/src/schema/image.ts +5 -3
- package/src/schema/string.ts +27 -2
package/src/patch/deref.ts
CHANGED
@@ -38,7 +38,6 @@ function derefPath(
|
|
38
38
|
export type DerefPatchResult = {
|
39
39
|
dereferencedPatch: Patch;
|
40
40
|
fileUpdates: { [path: string]: string };
|
41
|
-
remotePatches: { [ref: string]: Patch };
|
42
41
|
};
|
43
42
|
|
44
43
|
export function derefPatch<D, E>(
|
@@ -46,9 +45,6 @@ export function derefPatch<D, E>(
|
|
46
45
|
document: D,
|
47
46
|
ops: Ops<D, E>
|
48
47
|
): result.Result<DerefPatchResult, E | PatchError> {
|
49
|
-
const remotePatches: {
|
50
|
-
[ref: string]: Patch;
|
51
|
-
} = {};
|
52
48
|
const fileUpdates: {
|
53
49
|
[file: string]: string;
|
54
50
|
} = {};
|
@@ -84,15 +80,15 @@ export function derefPatch<D, E>(
|
|
84
80
|
);
|
85
81
|
}
|
86
82
|
fileUpdates[value[FILE_REF_PROP]] = op.value;
|
87
|
-
|
88
|
-
if (!remotePatches[value[REMOTE_REF_PROP]]) {
|
89
|
-
|
90
|
-
}
|
91
|
-
remotePatches[value[REMOTE_REF_PROP]].push({
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
});
|
83
|
+
// } else if (isRemote(value)) {
|
84
|
+
// if (!remotePatches[value[REMOTE_REF_PROP]]) {
|
85
|
+
// remotePatches[value[REMOTE_REF_PROP]] = [];
|
86
|
+
// }
|
87
|
+
// remotePatches[value[REMOTE_REF_PROP]].push({
|
88
|
+
// op: "replace",
|
89
|
+
// path: referencedPath,
|
90
|
+
// value: op.value,
|
91
|
+
// });
|
96
92
|
} else {
|
97
93
|
return result.err(
|
98
94
|
new PatchError(
|
@@ -109,8 +105,8 @@ export function derefPatch<D, E>(
|
|
109
105
|
dereferencedPatch.push(op);
|
110
106
|
}
|
111
107
|
} else if (op.op === "file") {
|
112
|
-
if (op.
|
113
|
-
return result.err(new PatchError(`Path must start with public`));
|
108
|
+
if (!op.filePath.startsWith("/public")) {
|
109
|
+
return result.err(new PatchError(`Path must start with /public`));
|
114
110
|
}
|
115
111
|
if (typeof op.value !== "string") {
|
116
112
|
return result.err(
|
@@ -119,7 +115,7 @@ export function derefPatch<D, E>(
|
|
119
115
|
)
|
120
116
|
);
|
121
117
|
}
|
122
|
-
fileUpdates[
|
118
|
+
fileUpdates[op.filePath] = op.value;
|
123
119
|
} else {
|
124
120
|
const maybeDerefRes = derefPath(op.path);
|
125
121
|
if (result.isErr(maybeDerefRes)) {
|
@@ -134,7 +130,6 @@ export function derefPatch<D, E>(
|
|
134
130
|
}
|
135
131
|
|
136
132
|
return result.ok({
|
137
|
-
remotePatches,
|
138
133
|
fileUpdates,
|
139
134
|
dereferencedPatch,
|
140
135
|
});
|
package/src/patch/operation.ts
CHANGED
@@ -37,6 +37,7 @@ export type OperationJSON =
|
|
37
37
|
| {
|
38
38
|
op: "file";
|
39
39
|
path: string;
|
40
|
+
filePath: string;
|
40
41
|
value: JSONValue;
|
41
42
|
};
|
42
43
|
|
@@ -80,5 +81,6 @@ export type Operation =
|
|
80
81
|
| {
|
81
82
|
op: "file";
|
82
83
|
path: string[];
|
84
|
+
filePath: string;
|
83
85
|
value: JSONValue;
|
84
86
|
};
|
package/src/patch/parse.ts
CHANGED
@@ -95,7 +95,6 @@ export function parseOperation(
|
|
95
95
|
const path = parseJSONPointer(operation.path);
|
96
96
|
|
97
97
|
switch (operation.op) {
|
98
|
-
case "file":
|
99
98
|
case "add":
|
100
99
|
case "replace":
|
101
100
|
case "test":
|
@@ -112,6 +111,21 @@ export function parseOperation(
|
|
112
111
|
value: operation.value,
|
113
112
|
}))
|
114
113
|
);
|
114
|
+
case "file":
|
115
|
+
return pipe(
|
116
|
+
path,
|
117
|
+
result.mapErr(
|
118
|
+
(error: string): array.NonEmptyArray<StaticPatchIssue> => [
|
119
|
+
createIssueAtPath(["path"])(error),
|
120
|
+
]
|
121
|
+
),
|
122
|
+
result.map((path: string[]) => ({
|
123
|
+
op: operation.op,
|
124
|
+
path,
|
125
|
+
filePath: operation.filePath,
|
126
|
+
value: operation.value,
|
127
|
+
}))
|
128
|
+
);
|
115
129
|
case "remove":
|
116
130
|
return pipe(
|
117
131
|
path,
|
package/src/schema/image.ts
CHANGED
@@ -122,10 +122,12 @@ export const convertFileSource = (
|
|
122
122
|
): { url: string; metadata?: ImageMetadata } => {
|
123
123
|
// TODO: /public should be configurable
|
124
124
|
if (!src[FILE_REF_PROP].startsWith("/public")) {
|
125
|
-
|
126
|
-
|
127
|
-
|
125
|
+
return {
|
126
|
+
url: src[FILE_REF_PROP] + `?sha256=${src.metadata?.sha256}`,
|
127
|
+
metadata: src.metadata,
|
128
|
+
};
|
128
129
|
}
|
130
|
+
|
129
131
|
return {
|
130
132
|
url:
|
131
133
|
src[FILE_REF_PROP].slice("/public".length) +
|
package/src/schema/string.ts
CHANGED
@@ -15,6 +15,9 @@ export type SerializedStringSchema = {
|
|
15
15
|
raw: boolean;
|
16
16
|
};
|
17
17
|
|
18
|
+
const brand = Symbol("string");
|
19
|
+
export type RawString = string & { readonly [brand]: "raw" };
|
20
|
+
|
18
21
|
export class StringSchema<Src extends string | null> extends Schema<Src> {
|
19
22
|
constructor(
|
20
23
|
readonly options?: StringOptions,
|
@@ -35,6 +38,24 @@ export class StringSchema<Src extends string | null> extends Schema<Src> {
|
|
35
38
|
],
|
36
39
|
} as ValidationErrors;
|
37
40
|
}
|
41
|
+
const errors = [];
|
42
|
+
if (this.options?.maxLength && src.length > this.options.maxLength) {
|
43
|
+
errors.push({
|
44
|
+
message: `Expected string to be at most ${this.options.maxLength} characters long, got ${src.length}`,
|
45
|
+
value: src,
|
46
|
+
});
|
47
|
+
}
|
48
|
+
if (this.options?.minLength && src.length < this.options.minLength) {
|
49
|
+
errors.push({
|
50
|
+
message: `Expected string to be at least ${this.options.minLength} characters long, got ${src.length}`,
|
51
|
+
value: src,
|
52
|
+
});
|
53
|
+
}
|
54
|
+
if (errors.length > 0) {
|
55
|
+
return {
|
56
|
+
[path]: errors,
|
57
|
+
} as ValidationErrors;
|
58
|
+
}
|
38
59
|
return false;
|
39
60
|
}
|
40
61
|
|
@@ -49,8 +70,12 @@ export class StringSchema<Src extends string | null> extends Schema<Src> {
|
|
49
70
|
return new StringSchema<Src | null>(this.options, true, this.isRaw);
|
50
71
|
}
|
51
72
|
|
52
|
-
raw(): StringSchema<Src> {
|
53
|
-
return new StringSchema<Src>(
|
73
|
+
raw(): StringSchema<Src extends null ? RawString | null : RawString> {
|
74
|
+
return new StringSchema<Src extends null ? RawString | null : RawString>(
|
75
|
+
this.options,
|
76
|
+
this.opt,
|
77
|
+
true
|
78
|
+
);
|
54
79
|
}
|
55
80
|
|
56
81
|
serialize(): SerializedSchema {
|