pasika 0.10.14 → 0.10.15
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.
|
@@ -1093,6 +1093,7 @@ function parseModule(file) {
|
|
|
1093
1093
|
const isTsx = file.endsWith(".tsx") || file.endsWith(".jsx");
|
|
1094
1094
|
const sourceFile = ts2.createSourceFile(file, text, ts2.ScriptTarget.Latest, true, ts2.ScriptKind.TSX);
|
|
1095
1095
|
const imports = [];
|
|
1096
|
+
const reexports = [];
|
|
1096
1097
|
const exports = [];
|
|
1097
1098
|
const addImport = (specifierNode, names, node) => {
|
|
1098
1099
|
if (!ts2.isStringLiteral(specifierNode)) return;
|
|
@@ -1118,6 +1119,13 @@ function parseModule(file) {
|
|
|
1118
1119
|
}
|
|
1119
1120
|
}
|
|
1120
1121
|
addImport(statement.moduleSpecifier, names, statement);
|
|
1122
|
+
if (ts2.isStringLiteral(statement.moduleSpecifier)) {
|
|
1123
|
+
reexports.push({
|
|
1124
|
+
specifier: statement.moduleSpecifier.text,
|
|
1125
|
+
names,
|
|
1126
|
+
line: lineOf(sourceFile, statement)
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1121
1129
|
}
|
|
1122
1130
|
if (statement.exportClause && ts2.isNamedExports(statement.exportClause)) {
|
|
1123
1131
|
for (const element of statement.exportClause.elements) {
|
|
@@ -1160,7 +1168,7 @@ function parseModule(file) {
|
|
|
1160
1168
|
});
|
|
1161
1169
|
}
|
|
1162
1170
|
}
|
|
1163
|
-
return { file: path6.resolve(file), imports, exports };
|
|
1171
|
+
return { file: path6.resolve(file), imports, reexports, exports };
|
|
1164
1172
|
}
|
|
1165
1173
|
|
|
1166
1174
|
// eslint/project/index.ts
|
|
@@ -1245,6 +1253,28 @@ function build(sourceRoot, files) {
|
|
|
1245
1253
|
}
|
|
1246
1254
|
}
|
|
1247
1255
|
}
|
|
1256
|
+
let changed = true;
|
|
1257
|
+
while (changed) {
|
|
1258
|
+
changed = false;
|
|
1259
|
+
for (const [file, module] of modules) {
|
|
1260
|
+
for (const reexport of module.reexports) {
|
|
1261
|
+
const target = resolveSpecifier(file, reexport.specifier, sourceRoot);
|
|
1262
|
+
if (!target || !modules.has(target)) continue;
|
|
1263
|
+
const names = reexport.names.length > 0 ? reexport.names : modules.get(target)?.exports.map((entry) => entry.name) ?? [];
|
|
1264
|
+
for (const name of names) {
|
|
1265
|
+
const sourceConsumers = symbolConsumers.get(symbolKey(file, name));
|
|
1266
|
+
if (sourceConsumers === void 0) continue;
|
|
1267
|
+
const targetConsumers = symbolConsumers.get(symbolKey(target, name)) ?? /* @__PURE__ */ new Set();
|
|
1268
|
+
for (const consumer of sourceConsumers) {
|
|
1269
|
+
if (targetConsumers.has(consumer)) continue;
|
|
1270
|
+
targetConsumers.add(consumer);
|
|
1271
|
+
changed = true;
|
|
1272
|
+
}
|
|
1273
|
+
symbolConsumers.set(symbolKey(target, name), targetConsumers);
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1248
1278
|
return { sourceRoot, modules, consumers, symbolConsumers };
|
|
1249
1279
|
}
|
|
1250
1280
|
var cache;
|
|
@@ -1763,6 +1793,7 @@ var supportFilePlacementRule = {
|
|
|
1763
1793
|
if (supportFolder === void 0 || !SUPPORT_FOLDERS2.has(supportFolder)) return {};
|
|
1764
1794
|
const index = getProjectIndex(sourceRoot);
|
|
1765
1795
|
if (!index) return {};
|
|
1796
|
+
let placement = resolveSupportPlacement(supportFile, supportFolder, index);
|
|
1766
1797
|
const groupedExportKind = EXPORT_KIND_BY_SUPPORT_FOLDER.get(supportFolder);
|
|
1767
1798
|
if (groupedExportKind !== void 0) {
|
|
1768
1799
|
const utilityExports = index.modules.get(supportFile)?.exports.filter((entry) => entry.kind === groupedExportKind) ?? [];
|
|
@@ -1789,8 +1820,9 @@ var supportFilePlacementRule = {
|
|
|
1789
1820
|
}
|
|
1790
1821
|
};
|
|
1791
1822
|
}
|
|
1823
|
+
const [firstPlacement] = placements;
|
|
1824
|
+
if (firstPlacement !== void 0) placement = firstPlacement.placement;
|
|
1792
1825
|
}
|
|
1793
|
-
const placement = resolveSupportPlacement(supportFile, supportFolder, index);
|
|
1794
1826
|
if (!placement || sameFolder2(currentFolder, placement.expectedFolder)) return {};
|
|
1795
1827
|
if (isConfigModule(segmentsOf(supportFile, sourceRoot)) && CONFIG_OWNED_FOLDERS.has(supportFolder)) {
|
|
1796
1828
|
if (placement.reason !== "config-module") return {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare function responseEnvelope<TSchema extends z.ZodType>(dataSchema: TSchema): z.ZodType<{
|
|
4
|
+
success: true;
|
|
5
|
+
data: z.output<TSchema>;
|
|
6
|
+
} | {
|
|
7
|
+
success: false;
|
|
8
|
+
data: null;
|
|
9
|
+
message: string;
|
|
10
|
+
}, {
|
|
11
|
+
success: true;
|
|
12
|
+
data: z.input<TSchema>;
|
|
13
|
+
} | {
|
|
14
|
+
success: false;
|
|
15
|
+
data: null;
|
|
16
|
+
message: string;
|
|
17
|
+
}>;
|
|
18
|
+
declare function responseEnvelope(dataSchema: z.ZodType): z.ZodType;
|
|
19
|
+
|
|
20
|
+
export { responseEnvelope };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// helpers/response-envelope.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
function responseEnvelope(dataSchema) {
|
|
4
|
+
return z.discriminatedUnion("success", [
|
|
5
|
+
z.object({
|
|
6
|
+
success: z.literal(true),
|
|
7
|
+
data: dataSchema
|
|
8
|
+
}),
|
|
9
|
+
z.object({
|
|
10
|
+
success: z.literal(false),
|
|
11
|
+
data: z.null(),
|
|
12
|
+
message: z.string()
|
|
13
|
+
})
|
|
14
|
+
]);
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
responseEnvelope
|
|
18
|
+
};
|
|
@@ -4,7 +4,6 @@ import { z } from 'zod';
|
|
|
4
4
|
/** Whatever a handler's own response needs to carry; a failure never inherits it. */
|
|
5
5
|
type ResponseHeaders = Headers | Record<string, string>;
|
|
6
6
|
type HandlerResult<TData> = {
|
|
7
|
-
message: string;
|
|
8
7
|
data: TData;
|
|
9
8
|
status?: number;
|
|
10
9
|
headers?: ResponseHeaders;
|
|
@@ -15,7 +14,7 @@ type HandlerResult<TData> = {
|
|
|
15
14
|
};
|
|
16
15
|
/**
|
|
17
16
|
* Turns a handler's result, or a failure thrown under it, into a response: the data
|
|
18
|
-
* goes through the response schema, an `HttpError` becomes `{ data: null, message }`
|
|
17
|
+
* goes through the response schema, an `HttpError` becomes `{ success: false, data: null, message }`
|
|
19
18
|
* at its own status and is never cached, and anything else stays an error.
|
|
20
19
|
*
|
|
21
20
|
* A handler whose own response is not JSON calls it with the handler alone and returns
|
|
@@ -17,12 +17,12 @@ function withResponse(responseSchemaOrHandler, handler) {
|
|
|
17
17
|
const { body, status: status2, headers: headers2 } = result;
|
|
18
18
|
return new NextResponse(streamBody.parse(body), { status: status2, headers: headers2 });
|
|
19
19
|
}
|
|
20
|
-
const {
|
|
21
|
-
return NextResponse.json({ data: schema.parse(data)
|
|
20
|
+
const { data, status, headers } = result;
|
|
21
|
+
return NextResponse.json({ success: true, data: schema.parse(data) }, { status, headers });
|
|
22
22
|
} catch (error) {
|
|
23
23
|
if (error instanceof HttpError) {
|
|
24
24
|
return NextResponse.json(
|
|
25
|
-
{ data: null, message: error.message },
|
|
25
|
+
{ success: false, data: null, message: error.message },
|
|
26
26
|
{ status: error.status, headers: { "Cache-Control": "no-store" } }
|
|
27
27
|
);
|
|
28
28
|
}
|
|
@@ -44,11 +44,7 @@ async function zodFetch(options) {
|
|
|
44
44
|
throw new HttpError("The upstream answered without a body to decode.", BAD_GATEWAY);
|
|
45
45
|
}
|
|
46
46
|
const decoded = JSON.parse(body);
|
|
47
|
-
|
|
48
|
-
data: options.responseSchema,
|
|
49
|
-
message: z.string()
|
|
50
|
-
});
|
|
51
|
-
return responseEnvelopeSchema.parse(decoded).data;
|
|
47
|
+
return options.responseSchema.parse(decoded);
|
|
52
48
|
}
|
|
53
49
|
export {
|
|
54
50
|
zodFetch
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pasika",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.15",
|
|
4
4
|
"description": "Reusable agent setup package",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
"types": "./dist/helpers/http-error.d.ts",
|
|
22
22
|
"import": "./dist/helpers/http-error.js"
|
|
23
23
|
},
|
|
24
|
+
"./response-envelope": {
|
|
25
|
+
"types": "./dist/helpers/response-envelope.d.ts",
|
|
26
|
+
"import": "./dist/helpers/response-envelope.js"
|
|
27
|
+
},
|
|
24
28
|
"./zod-fetch": {
|
|
25
29
|
"types": "./dist/helpers/zod-fetch.d.ts",
|
|
26
30
|
"import": "./dist/helpers/zod-fetch.js"
|