veryfront 0.1.283 → 0.1.285
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/esm/deno.d.ts +0 -8
- package/esm/deno.js +8 -11
- package/esm/src/agent/agent-service.d.ts +28 -6
- package/esm/src/agent/agent-service.d.ts.map +1 -1
- package/esm/src/agent/agent-service.js +23 -1
- package/esm/src/agent/index.d.ts +1 -1
- package/esm/src/agent/index.d.ts.map +1 -1
- package/esm/src/embedding/resolve.d.ts.map +1 -1
- package/esm/src/embedding/resolve.js +15 -2
- package/esm/src/embedding/veryfront-cloud/provider.d.ts.map +1 -1
- package/esm/src/embedding/veryfront-cloud/provider.js +2 -7
- package/esm/src/extensions/contracts.js +3 -1
- package/esm/src/extensions/interfaces/ai-provider.d.ts +50 -0
- package/esm/src/extensions/interfaces/ai-provider.d.ts.map +1 -0
- package/esm/src/extensions/interfaces/ai-provider.js +13 -0
- package/esm/src/extensions/interfaces/code-parser.d.ts +11 -0
- package/esm/src/extensions/interfaces/code-parser.d.ts.map +1 -1
- package/esm/src/extensions/interfaces/css-processor.d.ts +41 -22
- package/esm/src/extensions/interfaces/css-processor.d.ts.map +1 -1
- package/esm/src/extensions/interfaces/css-processor.js +10 -1
- package/esm/src/extensions/interfaces/index.d.ts +5 -4
- package/esm/src/extensions/interfaces/index.d.ts.map +1 -1
- package/esm/src/extensions/interfaces/index.js +1 -0
- package/esm/src/extensions/interfaces/schema-validator.d.ts +84 -5
- package/esm/src/extensions/interfaces/schema-validator.d.ts.map +1 -1
- package/esm/src/extensions/interfaces/schema-validator.js +5 -0
- package/esm/src/extensions/loader.d.ts +7 -0
- package/esm/src/extensions/loader.d.ts.map +1 -1
- package/esm/src/extensions/loader.js +12 -0
- package/esm/src/extensions/orchestrate.d.ts +2 -0
- package/esm/src/extensions/orchestrate.d.ts.map +1 -1
- package/esm/src/extensions/orchestrate.js +3 -0
- package/esm/src/extensions/recommendations.d.ts.map +1 -1
- package/esm/src/extensions/recommendations.js +4 -1
- package/esm/src/extensions/registries/ai-provider-registry.d.ts +11 -0
- package/esm/src/extensions/registries/ai-provider-registry.d.ts.map +1 -0
- package/esm/src/extensions/registries/ai-provider-registry.js +40 -0
- package/esm/src/html/styles-builder/plugin-loader.d.ts.map +1 -1
- package/esm/src/html/styles-builder/plugin-loader.js +4 -16
- package/esm/src/html/styles-builder/tailwind-compiler-cache.d.ts +8 -2
- package/esm/src/html/styles-builder/tailwind-compiler-cache.d.ts.map +1 -1
- package/esm/src/html/styles-builder/tailwind-compiler-cache.js +20 -3
- package/esm/src/provider/model-registry.d.ts.map +1 -1
- package/esm/src/provider/model-registry.js +33 -6
- package/esm/src/provider/runtime-loader/provider-embedding-responses.d.ts +1 -0
- package/esm/src/provider/runtime-loader/provider-embedding-responses.d.ts.map +1 -1
- package/esm/src/provider/runtime-loader/provider-embedding-responses.js +1 -1
- package/esm/src/provider/runtime-loader/provider-http.d.ts +9 -0
- package/esm/src/provider/runtime-loader/provider-http.d.ts.map +1 -1
- package/esm/src/provider/runtime-loader/provider-http.js +2 -2
- package/esm/src/provider/runtime-loader.d.ts +120 -9
- package/esm/src/provider/runtime-loader.d.ts.map +1 -1
- package/esm/src/provider/runtime-loader.js +13 -943
- package/esm/src/provider/veryfront-cloud/provider.d.ts.map +1 -1
- package/esm/src/provider/veryfront-cloud/provider.js +30 -15
- package/esm/src/sandbox/index.d.ts +1 -1
- package/esm/src/sandbox/index.d.ts.map +1 -1
- package/esm/src/sandbox/index.js +1 -1
- package/esm/src/sandbox/lazy-sandbox.d.ts +3 -0
- package/esm/src/sandbox/lazy-sandbox.d.ts.map +1 -1
- package/esm/src/sandbox/lazy-sandbox.js +22 -1
- package/esm/src/schemas/define.d.ts +31 -0
- package/esm/src/schemas/define.d.ts.map +1 -0
- package/esm/src/schemas/define.js +42 -0
- package/esm/src/schemas/index.d.ts +7 -2
- package/esm/src/schemas/index.d.ts.map +1 -1
- package/esm/src/schemas/index.js +10 -2
- package/esm/src/schemas/zod-adapter.d.ts +25 -0
- package/esm/src/schemas/zod-adapter.d.ts.map +1 -0
- package/esm/src/schemas/zod-adapter.js +120 -0
- package/esm/src/server/bootstrap.d.ts.map +1 -1
- package/esm/src/server/bootstrap.js +5 -0
- package/esm/src/transforms/plugins/babel-node-positions.d.ts +6 -7
- package/esm/src/transforms/plugins/babel-node-positions.d.ts.map +1 -1
- package/esm/src/transforms/plugins/babel-node-positions.js +10 -123
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +1 -6
- package/src/deno.js +8 -11
- package/src/src/agent/agent-service.ts +91 -7
- package/src/src/agent/index.ts +4 -0
- package/src/src/embedding/resolve.ts +18 -7
- package/src/src/embedding/veryfront-cloud/provider.ts +4 -10
- package/src/src/extensions/contracts.ts +3 -3
- package/src/src/extensions/interfaces/ai-provider.ts +54 -0
- package/src/src/extensions/interfaces/code-parser.ts +12 -0
- package/src/src/extensions/interfaces/css-processor.ts +43 -22
- package/src/src/extensions/interfaces/index.ts +15 -11
- package/src/src/extensions/interfaces/schema-validator.ts +112 -5
- package/src/src/extensions/loader.ts +14 -0
- package/src/src/extensions/orchestrate.ts +5 -0
- package/src/src/extensions/recommendations.ts +4 -1
- package/src/src/extensions/registries/ai-provider-registry.ts +53 -0
- package/src/src/html/styles-builder/plugin-loader.ts +4 -16
- package/src/src/html/styles-builder/tailwind-compiler-cache.ts +27 -6
- package/src/src/provider/model-registry.ts +34 -15
- package/src/src/provider/runtime-loader/provider-embedding-responses.ts +1 -1
- package/src/src/provider/runtime-loader/provider-http.ts +2 -2
- package/src/src/provider/runtime-loader.ts +41 -1189
- package/src/src/provider/veryfront-cloud/provider.ts +35 -19
- package/src/src/sandbox/index.ts +5 -1
- package/src/src/sandbox/lazy-sandbox.ts +25 -1
- package/src/src/schemas/define.ts +48 -0
- package/src/src/schemas/index.ts +13 -2
- package/src/src/schemas/zod-adapter.ts +180 -0
- package/src/src/server/bootstrap.ts +5 -0
- package/src/src/transforms/plugins/babel-node-positions.ts +11 -173
- package/src/src/utils/version-constant.ts +1 -1
- package/esm/src/extensions/interfaces/ai-model-provider.d.ts +0 -94
- package/esm/src/extensions/interfaces/ai-model-provider.d.ts.map +0 -1
- package/esm/src/extensions/interfaces/ai-model-provider.js +0 -8
- package/src/src/extensions/interfaces/ai-model-provider.ts +0 -100
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../../src/src/provider/veryfront-cloud/provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../../src/src/provider/veryfront-cloud/provider.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQhD,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CA2DvE"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { createError, toError } from "../../errors/veryfront-error.js";
|
|
2
|
-
import {
|
|
2
|
+
import { createGoogleModelRuntime } from "../runtime-loader.js";
|
|
3
|
+
import { tryResolve } from "../../extensions/contracts.js";
|
|
4
|
+
import { AIProviderRegistryName } from "../../extensions/interfaces/index.js";
|
|
3
5
|
import { createVeryfrontCloudFetch, getVeryfrontCloudGatewayBaseUrl, parseVeryfrontCloudModelId, requireVeryfrontCloudBootstrap, } from "./shared.js";
|
|
4
6
|
export function createVeryfrontCloudModel(modelId) {
|
|
5
7
|
const { provider, modelId: upstreamModelId } = parseVeryfrontCloudModelId(modelId, "language");
|
|
@@ -7,13 +9,20 @@ export function createVeryfrontCloudModel(modelId) {
|
|
|
7
9
|
const baseURL = getVeryfrontCloudGatewayBaseUrl(apiBaseUrl, provider);
|
|
8
10
|
const fetch = createVeryfrontCloudFetch(apiToken, projectSlug);
|
|
9
11
|
switch (provider) {
|
|
10
|
-
case "anthropic":
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
case "anthropic": {
|
|
13
|
+
const registry = tryResolve(AIProviderRegistryName);
|
|
14
|
+
const anthropic = registry?.get("anthropic");
|
|
15
|
+
if (anthropic) {
|
|
16
|
+
return anthropic.createModel(upstreamModelId, {
|
|
17
|
+
credential: apiToken,
|
|
18
|
+
authToken: apiToken,
|
|
19
|
+
baseURL,
|
|
20
|
+
name: "veryfront-cloud",
|
|
21
|
+
fetch,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
throw new Error("Anthropic provider not installed. Add @veryfront/ext-anthropic to use anthropic/* models via veryfront-cloud.");
|
|
25
|
+
}
|
|
17
26
|
case "google":
|
|
18
27
|
return createGoogleModelRuntime({
|
|
19
28
|
apiKey: apiToken,
|
|
@@ -22,13 +31,19 @@ export function createVeryfrontCloudModel(modelId) {
|
|
|
22
31
|
fetch,
|
|
23
32
|
}, upstreamModelId);
|
|
24
33
|
case "openai":
|
|
25
|
-
case "moonshotai":
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
case "moonshotai": {
|
|
35
|
+
const registry = tryResolve(AIProviderRegistryName);
|
|
36
|
+
const openai = registry?.get("openai");
|
|
37
|
+
if (openai) {
|
|
38
|
+
return openai.createModel(upstreamModelId, {
|
|
39
|
+
credential: apiToken,
|
|
40
|
+
baseURL,
|
|
41
|
+
name: "veryfront-cloud",
|
|
42
|
+
fetch,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
throw new Error("OpenAI provider not installed. Add @veryfront/ext-openai to use openai/moonshotai models via veryfront-cloud.");
|
|
46
|
+
}
|
|
32
47
|
default: {
|
|
33
48
|
const _exhaustive = provider;
|
|
34
49
|
throw toError(createError({
|
|
@@ -18,5 +18,5 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import "../../_dnt.polyfills.js";
|
|
20
20
|
export { type CommandJob, type CommandJobHeartbeatStatus, type CommandJobOutput, type CommandJobStatus, type ExecOptions, type ExecResult, type ExecStreamEvent, Sandbox, type SandboxAttachment, type SandboxListOptions, type SandboxListResult, type SandboxOptions, type SandboxSession, } from "./sandbox.js";
|
|
21
|
-
export { LazySandbox, type LazySandboxOptions } from "./lazy-sandbox.js";
|
|
21
|
+
export { LazySandbox, type LazySandboxOptions, resolveDefaultSandboxRuntimeEndpoint, } from "./lazy-sandbox.js";
|
|
22
22
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/sandbox/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,yBAAyB,CAAC;AAGjC,OAAO,EACL,KAAK,UAAU,EACf,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,OAAO,EACP,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,cAAc,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/sandbox/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,yBAAyB,CAAC;AAGjC,OAAO,EACL,KAAK,UAAU,EACf,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,OAAO,EACP,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,cAAc,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,WAAW,EACX,KAAK,kBAAkB,EACvB,oCAAoC,GACrC,MAAM,mBAAmB,CAAC"}
|
package/esm/src/sandbox/index.js
CHANGED
|
@@ -14,6 +14,9 @@ export interface LazySandboxOptions extends SandboxOptions {
|
|
|
14
14
|
sessionId: string;
|
|
15
15
|
}) => string;
|
|
16
16
|
}
|
|
17
|
+
export declare function resolveDefaultSandboxRuntimeEndpoint(input: {
|
|
18
|
+
endpoint: string;
|
|
19
|
+
}): string;
|
|
17
20
|
/** Lazily provisions sandbox sessions and keeps them alive while in use. */
|
|
18
21
|
export declare class LazySandbox {
|
|
19
22
|
private readonly apiUrl;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-sandbox.d.ts","sourceRoot":"","sources":["../../../src/src/sandbox/lazy-sandbox.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lazy-sandbox.d.ts","sourceRoot":"","sources":["../../../src/src/sandbox/lazy-sandbox.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as dntShim from "../../_dnt.shims.js";
|
|
2
2
|
import { REQUEST_ERROR } from "../errors/index.js";
|
|
3
|
+
import { getHostEnv } from "../platform/compat/process.js";
|
|
3
4
|
import { resolveSandboxApiUrl, resolveSandboxAuthToken, } from "./sandbox.js";
|
|
4
5
|
const DEFAULT_STARTUP_TIMEOUT_MS = 180_000;
|
|
5
6
|
const DEFAULT_POLL_INTERVAL_MS = 2_000;
|
|
@@ -15,6 +16,25 @@ const REPROVISIONABLE_EXEC_START_ERROR_CODES = new Set([
|
|
|
15
16
|
"ENOTFOUND",
|
|
16
17
|
"EHOSTUNREACH",
|
|
17
18
|
]);
|
|
19
|
+
const VERYFRONT_SANDBOX_PUBLIC_HOST_PATTERN = /^([a-z0-9-]+)\.sandbox\.veryfront\.[a-z0-9.-]+$/i;
|
|
20
|
+
export function resolveDefaultSandboxRuntimeEndpoint(input) {
|
|
21
|
+
if (!getHostEnv("KUBERNETES_SERVICE_HOST")) {
|
|
22
|
+
return input.endpoint;
|
|
23
|
+
}
|
|
24
|
+
let hostname;
|
|
25
|
+
try {
|
|
26
|
+
hostname = new URL(input.endpoint).hostname;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return input.endpoint;
|
|
30
|
+
}
|
|
31
|
+
const match = hostname.match(VERYFRONT_SANDBOX_PUBLIC_HOST_PATTERN);
|
|
32
|
+
const shortId = match?.[1];
|
|
33
|
+
if (!shortId) {
|
|
34
|
+
return input.endpoint;
|
|
35
|
+
}
|
|
36
|
+
return `http://sandbox.veryfront-sandbox-${shortId}.svc.cluster.local`;
|
|
37
|
+
}
|
|
18
38
|
/** Lazily provisions sandbox sessions and keeps them alive while in use. */
|
|
19
39
|
export class LazySandbox {
|
|
20
40
|
apiUrl;
|
|
@@ -494,7 +514,8 @@ export class LazySandbox {
|
|
|
494
514
|
resolveRuntimeEndpoint() {
|
|
495
515
|
const endpoint = this.requireEndpoint();
|
|
496
516
|
const sessionId = this.requireSessionId();
|
|
497
|
-
return this.resolveRuntimeEndpointOption?.({ endpoint, sessionId }) ??
|
|
517
|
+
return this.resolveRuntimeEndpointOption?.({ endpoint, sessionId }) ??
|
|
518
|
+
resolveDefaultSandboxRuntimeEndpoint({ endpoint });
|
|
498
519
|
}
|
|
499
520
|
requireSessionId() {
|
|
500
521
|
if (!this.sessionId) {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy schema factory.
|
|
3
|
+
*
|
|
4
|
+
* `defineSchema(factory)` returns a memoized getter that resolves the
|
|
5
|
+
* `SchemaValidator` extension contract on first call and materializes the
|
|
6
|
+
* schema via the provided factory. This indirection lets core modules declare
|
|
7
|
+
* schemas without importing zod directly — a real validator (typically
|
|
8
|
+
* `@veryfront/ext-zod`) must be registered in the contract registry before
|
|
9
|
+
* the schema is first accessed.
|
|
10
|
+
*
|
|
11
|
+
* @module schemas/define
|
|
12
|
+
*/
|
|
13
|
+
import type { Schema, SchemaFactory } from "../extensions/interfaces/index.js";
|
|
14
|
+
/**
|
|
15
|
+
* Wrap a schema factory so that it is built lazily on first call.
|
|
16
|
+
*
|
|
17
|
+
* @param factory - Receives a `SchemaValidator` and returns a `Schema<T>`.
|
|
18
|
+
* @returns A zero-arg getter that caches and returns the built schema.
|
|
19
|
+
* @throws Error when no `SchemaValidator` contract is registered.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const getUserSchema = defineSchema((v) =>
|
|
24
|
+
* v.object({ id: v.string().uuid(), name: v.string().min(1) })
|
|
25
|
+
* );
|
|
26
|
+
*
|
|
27
|
+
* const user = getUserSchema().parse(input);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function defineSchema<T>(factory: SchemaFactory<T>): () => Schema<T>;
|
|
31
|
+
//# sourceMappingURL=define.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../../../src/src/schemas/define.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EACV,MAAM,EACN,aAAa,EAEd,MAAM,mCAAmC,CAAC;AAE3C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,MAAM,MAAM,CAAC,CAAC,CAAC,CAW1E"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy schema factory.
|
|
3
|
+
*
|
|
4
|
+
* `defineSchema(factory)` returns a memoized getter that resolves the
|
|
5
|
+
* `SchemaValidator` extension contract on first call and materializes the
|
|
6
|
+
* schema via the provided factory. This indirection lets core modules declare
|
|
7
|
+
* schemas without importing zod directly — a real validator (typically
|
|
8
|
+
* `@veryfront/ext-zod`) must be registered in the contract registry before
|
|
9
|
+
* the schema is first accessed.
|
|
10
|
+
*
|
|
11
|
+
* @module schemas/define
|
|
12
|
+
*/
|
|
13
|
+
import { tryResolve } from "../extensions/contracts.js";
|
|
14
|
+
/**
|
|
15
|
+
* Wrap a schema factory so that it is built lazily on first call.
|
|
16
|
+
*
|
|
17
|
+
* @param factory - Receives a `SchemaValidator` and returns a `Schema<T>`.
|
|
18
|
+
* @returns A zero-arg getter that caches and returns the built schema.
|
|
19
|
+
* @throws Error when no `SchemaValidator` contract is registered.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const getUserSchema = defineSchema((v) =>
|
|
24
|
+
* v.object({ id: v.string().uuid(), name: v.string().min(1) })
|
|
25
|
+
* );
|
|
26
|
+
*
|
|
27
|
+
* const user = getUserSchema().parse(input);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function defineSchema(factory) {
|
|
31
|
+
let cached;
|
|
32
|
+
return () => {
|
|
33
|
+
if (cached)
|
|
34
|
+
return cached;
|
|
35
|
+
const v = tryResolve("SchemaValidator");
|
|
36
|
+
if (!v) {
|
|
37
|
+
throw new Error("SchemaValidator contract unresolved — install ext-zod");
|
|
38
|
+
}
|
|
39
|
+
cached = factory(v);
|
|
40
|
+
return cached;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reusable
|
|
3
|
-
* pagination) and primitives (file paths, hex colors, semver, timestamps)
|
|
2
|
+
* Reusable validation schemas — common types (email, slug, URL, UUID,
|
|
3
|
+
* pagination) and primitives (file paths, hex colors, semver, timestamps),
|
|
4
|
+
* plus the `defineSchema` lazy-factory helper.
|
|
5
|
+
*
|
|
6
|
+
* Importing this module also registers the default zod-backed
|
|
7
|
+
* `SchemaValidator` adapter so that `defineSchema(...)` works out of the box.
|
|
4
8
|
*
|
|
5
9
|
* @module schemas
|
|
6
10
|
*/
|
|
11
|
+
export { defineSchema } from "./define.js";
|
|
7
12
|
export { CommonSchemas, type DateRange, type Email, type Pagination, type PhoneNumber, type Slug, type StrongPassword, type Url, type Uuid, } from "./common.js";
|
|
8
13
|
export { type AbsolutePath, absolutePath, type FilePath, filePath, type HexColor, hexColor, type JsonValue, jsonValue, type NonEmptyString, nonEmptyString, type NonNegativeInt, nonNegativeInt, type PortNumber, portNumber, type PositiveInt, positiveInt, type Semver, semver, type Timestamp, timestamp, } from "./primitives.js";
|
|
9
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/schemas/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/schemas/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EACL,aAAa,EACb,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,IAAI,EACT,KAAK,cAAc,EACnB,KAAK,GAAG,EACR,KAAK,IAAI,GACV,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,KAAK,YAAY,EACjB,YAAY,EACZ,KAAK,QAAQ,EACb,QAAQ,EACR,KAAK,QAAQ,EACb,QAAQ,EACR,KAAK,SAAS,EACd,SAAS,EACT,KAAK,cAAc,EACnB,cAAc,EACd,KAAK,cAAc,EACnB,cAAc,EACd,KAAK,UAAU,EACf,UAAU,EACV,KAAK,WAAW,EAChB,WAAW,EACX,KAAK,MAAM,EACX,MAAM,EACN,KAAK,SAAS,EACd,SAAS,GACV,MAAM,iBAAiB,CAAC"}
|
package/esm/src/schemas/index.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reusable
|
|
3
|
-
* pagination) and primitives (file paths, hex colors, semver, timestamps)
|
|
2
|
+
* Reusable validation schemas — common types (email, slug, URL, UUID,
|
|
3
|
+
* pagination) and primitives (file paths, hex colors, semver, timestamps),
|
|
4
|
+
* plus the `defineSchema` lazy-factory helper.
|
|
5
|
+
*
|
|
6
|
+
* Importing this module also registers the default zod-backed
|
|
7
|
+
* `SchemaValidator` adapter so that `defineSchema(...)` works out of the box.
|
|
4
8
|
*
|
|
5
9
|
* @module schemas
|
|
6
10
|
*/
|
|
11
|
+
import { registerZodAdapter } from "./zod-adapter.js";
|
|
12
|
+
// Register the default SchemaValidator implementation once at module load.
|
|
13
|
+
registerZodAdapter();
|
|
14
|
+
export { defineSchema } from "./define.js";
|
|
7
15
|
export { CommonSchemas, } from "./common.js";
|
|
8
16
|
export { absolutePath, filePath, hexColor, jsonValue, nonEmptyString, nonNegativeInt, portNumber, positiveInt, semver, timestamp, } from "./primitives.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod-backed `SchemaValidator` adapter.
|
|
3
|
+
*
|
|
4
|
+
* This is the default (core-provided) implementation of the
|
|
5
|
+
* `SchemaValidator` contract. It thinly wraps zod so that core modules can
|
|
6
|
+
* declare schemas through the extension-neutral DSL while still getting zod's
|
|
7
|
+
* runtime behavior.
|
|
8
|
+
*
|
|
9
|
+
* The entire zod surface used by the contract is confined to this file; when
|
|
10
|
+
* `@veryfront/ext-zod` takes over in Phase B this file will be deleted and
|
|
11
|
+
* the `"zod"` import map entry removed.
|
|
12
|
+
*
|
|
13
|
+
* @module schemas/zod-adapter
|
|
14
|
+
*/
|
|
15
|
+
import type { SchemaValidator } from "../extensions/interfaces/index.js";
|
|
16
|
+
/** The zod-backed `SchemaValidator` singleton registered by `registerZodAdapter`. */
|
|
17
|
+
export declare const zodAdapter: SchemaValidator;
|
|
18
|
+
/**
|
|
19
|
+
* Register the zod adapter as the default `SchemaValidator` implementation.
|
|
20
|
+
*
|
|
21
|
+
* Called once at core bootstrap (`src/schemas/index.ts` side-effect import).
|
|
22
|
+
* Phase B will delete this function when `@veryfront/ext-zod` takes over.
|
|
23
|
+
*/
|
|
24
|
+
export declare function registerZodAdapter(): void;
|
|
25
|
+
//# sourceMappingURL=zod-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod-adapter.d.ts","sourceRoot":"","sources":["../../../src/src/schemas/zod-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EAGV,eAAe,EAIhB,MAAM,mCAAmC,CAAC;AAoF3C,qFAAqF;AACrF,eAAO,MAAM,UAAU,EAAE,eA4DxB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod-backed `SchemaValidator` adapter.
|
|
3
|
+
*
|
|
4
|
+
* This is the default (core-provided) implementation of the
|
|
5
|
+
* `SchemaValidator` contract. It thinly wraps zod so that core modules can
|
|
6
|
+
* declare schemas through the extension-neutral DSL while still getting zod's
|
|
7
|
+
* runtime behavior.
|
|
8
|
+
*
|
|
9
|
+
* The entire zod surface used by the contract is confined to this file; when
|
|
10
|
+
* `@veryfront/ext-zod` takes over in Phase B this file will be deleted and
|
|
11
|
+
* the `"zod"` import map entry removed.
|
|
12
|
+
*
|
|
13
|
+
* @module schemas/zod-adapter
|
|
14
|
+
*/
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
import { register } from "../extensions/contracts.js";
|
|
17
|
+
/** Unwrap our opaque Schema<T> back to the underlying zod schema. */
|
|
18
|
+
function toZod(schema) {
|
|
19
|
+
return schema.__zod;
|
|
20
|
+
}
|
|
21
|
+
/** Wrap a zod schema as an opaque Schema<T> with chainables routed through zod. */
|
|
22
|
+
function wrap(zs) {
|
|
23
|
+
// The wrapper fakes the full Schema<T> surface; unsupported chainables on
|
|
24
|
+
// unsuitable kinds (e.g. calling `.email()` on a number) throw at runtime
|
|
25
|
+
// just like zod would.
|
|
26
|
+
// deno-lint-ignore no-explicit-any -- safe within this adapter
|
|
27
|
+
const anyZs = zs;
|
|
28
|
+
const s = {
|
|
29
|
+
_output: undefined,
|
|
30
|
+
optional: () => wrap(zs.optional()),
|
|
31
|
+
nullable: () => wrap(zs.nullable()),
|
|
32
|
+
nullish: () => wrap(zs.nullish()),
|
|
33
|
+
default: (value) => wrap(anyZs.default(value)),
|
|
34
|
+
describe: (description) => wrap(zs.describe(description)),
|
|
35
|
+
refine: (check, message) => wrap(zs.refine(check, message)),
|
|
36
|
+
transform: (fn) => wrap(zs.transform(fn)),
|
|
37
|
+
strict: () => wrap(anyZs.strict()),
|
|
38
|
+
passthrough: () => wrap(anyZs.passthrough()),
|
|
39
|
+
partial: () => wrap(anyZs.partial()),
|
|
40
|
+
extend: (shape) => {
|
|
41
|
+
const zodShape = toZodShape(shape);
|
|
42
|
+
return wrap(anyZs.extend(zodShape));
|
|
43
|
+
},
|
|
44
|
+
merge: (other) => wrap(anyZs.merge(toZod(other))),
|
|
45
|
+
min: (value, message) => wrap(anyZs.min(value, message)),
|
|
46
|
+
max: (value, message) => wrap(anyZs.max(value, message)),
|
|
47
|
+
int: (message) => wrap(anyZs.int(message)),
|
|
48
|
+
positive: (message) => wrap(anyZs.positive(message)),
|
|
49
|
+
nonnegative: (message) => wrap(anyZs.nonnegative(message)),
|
|
50
|
+
regex: (pattern, message) => wrap(anyZs.regex(pattern, message)),
|
|
51
|
+
email: (message) => wrap(anyZs.email(message)),
|
|
52
|
+
url: (message) => wrap(anyZs.url(message)),
|
|
53
|
+
uuid: (message) => wrap(anyZs.uuid(message)),
|
|
54
|
+
datetime: (message) => wrap(anyZs.datetime(message)),
|
|
55
|
+
parse: (data) => zs.parse(data),
|
|
56
|
+
safeParse: (data) => {
|
|
57
|
+
const res = zs.safeParse(data);
|
|
58
|
+
if (res.success)
|
|
59
|
+
return { success: true, data: res.data };
|
|
60
|
+
const issues = res.error.issues.map((issue) => ({
|
|
61
|
+
path: issue.path,
|
|
62
|
+
message: issue.message,
|
|
63
|
+
code: issue.code,
|
|
64
|
+
}));
|
|
65
|
+
return { success: false, issues, error: res.error };
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
// Attach the underlying zod schema for adapter round-trips without
|
|
69
|
+
// widening the public Schema<T> surface.
|
|
70
|
+
s.__zod = zs;
|
|
71
|
+
return s;
|
|
72
|
+
}
|
|
73
|
+
function toZodShape(shape) {
|
|
74
|
+
const out = {};
|
|
75
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
76
|
+
out[key] = toZod(value);
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
const coerce = {
|
|
81
|
+
string: () => wrap(z.coerce.string()),
|
|
82
|
+
number: () => wrap(z.coerce.number()),
|
|
83
|
+
boolean: () => wrap(z.coerce.boolean()),
|
|
84
|
+
date: () => wrap(z.coerce.date()),
|
|
85
|
+
};
|
|
86
|
+
/** The zod-backed `SchemaValidator` singleton registered by `registerZodAdapter`. */
|
|
87
|
+
export const zodAdapter = {
|
|
88
|
+
string: () => wrap(z.string()),
|
|
89
|
+
number: () => wrap(z.number()),
|
|
90
|
+
boolean: () => wrap(z.boolean()),
|
|
91
|
+
date: () => wrap(z.date()),
|
|
92
|
+
null: () => wrap(z.null()),
|
|
93
|
+
unknown: () => wrap(z.unknown()),
|
|
94
|
+
// deno-lint-ignore no-explicit-any -- contract mirrors zod's `any` constructor
|
|
95
|
+
any: () => wrap(z.any()),
|
|
96
|
+
object: (shape) => wrap(z.object(toZodShape(shape))),
|
|
97
|
+
array: (element) => wrap(z.array(toZod(element))),
|
|
98
|
+
record: (keys, values) => wrap(z.record(toZod(keys), toZod(values))),
|
|
99
|
+
union: (schemas) => {
|
|
100
|
+
const zodSchemas = schemas.map((s) => toZod(s));
|
|
101
|
+
return wrap(z.union(zodSchemas));
|
|
102
|
+
},
|
|
103
|
+
discriminatedUnion: (discriminator, schemas) => {
|
|
104
|
+
const zodSchemas = schemas.map((s) => toZod(s));
|
|
105
|
+
return wrap(z.discriminatedUnion(discriminator, zodSchemas));
|
|
106
|
+
},
|
|
107
|
+
literal: (value) => wrap(z.literal(value)),
|
|
108
|
+
enum: (values) => wrap(z.enum(values)),
|
|
109
|
+
coerce,
|
|
110
|
+
validate: (schema, data) => schema.safeParse(data),
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Register the zod adapter as the default `SchemaValidator` implementation.
|
|
114
|
+
*
|
|
115
|
+
* Called once at core bootstrap (`src/schemas/index.ts` side-effect import).
|
|
116
|
+
* Phase B will delete this function when `@veryfront/ext-zod` takes over.
|
|
117
|
+
*/
|
|
118
|
+
export function registerZodAdapter() {
|
|
119
|
+
register("SchemaValidator", zodAdapter);
|
|
120
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../../src/src/server/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,EAAE,KAAK,eAAe,EAAqC,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../../src/src/server/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,EAAE,KAAK,eAAe,EAAqC,MAAM,wBAAwB,CAAC;AAmCjG,MAAM,WAAW,eAAe;IAC9B,8DAA8D;IAC9D,OAAO,EAAE,cAAc,CAAC;IAExB,2BAA2B;IAC3B,MAAM,EAAE,eAAe,CAAC;IAExB,wCAAwC;IACxC,cAAc,EAAE,OAAO,CAAC;IAExB,+BAA+B;IAC/B,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;OAIG;IACH,eAAe,EAAE,eAAe,CAAC;IAEjC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AA2CD;;;;;;;;GAQG;AACH,wBAAsB,sBAAsB,CAC1C,WAAW,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,EAC3C,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,GAClC,OAAO,CAAC,eAAe,CAAC,CAO1B;AAkDD,wBAAsB,SAAS,CAC7B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC,CA+I1B;AAED,wBAAsB,YAAY,CAChC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC,CAa1B;AAED,wBAAsB,aAAa,CACjC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC,CAyB1B"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { clearConfigCache, getConfig } from "../config/index.js";
|
|
2
2
|
import { orchestrateExtensions, tryResolve } from "../extensions/index.js";
|
|
3
|
+
import { AIProviderRegistryName } from "../extensions/interfaces/index.js";
|
|
4
|
+
import { createAIProviderRegistry } from "../extensions/registries/ai-provider-registry.js";
|
|
3
5
|
import { setGlobalActiveSpanAccessor, setGlobalMetricsAPI, setGlobalTracerProvider, } from "../observability/tracing/api-shim.js";
|
|
4
6
|
import { getEnvironmentConfig, refreshEnvironmentConfig, } from "../config/environment-config.js";
|
|
5
7
|
import { getErrorMessage } from "../errors/veryfront-error.js";
|
|
@@ -130,6 +132,7 @@ export async function bootstrap(projectDir, adapter) {
|
|
|
130
132
|
projectDir,
|
|
131
133
|
config,
|
|
132
134
|
logger: bootstrapLog,
|
|
135
|
+
primeContracts: { [AIProviderRegistryName]: createAIProviderRegistry() },
|
|
133
136
|
});
|
|
134
137
|
wireTracingShim();
|
|
135
138
|
return {
|
|
@@ -161,6 +164,7 @@ export async function bootstrap(projectDir, adapter) {
|
|
|
161
164
|
projectDir,
|
|
162
165
|
config,
|
|
163
166
|
logger: bootstrapLog,
|
|
167
|
+
primeContracts: { [AIProviderRegistryName]: createAIProviderRegistry() },
|
|
164
168
|
});
|
|
165
169
|
wireTracingShim();
|
|
166
170
|
return {
|
|
@@ -215,6 +219,7 @@ export async function bootstrap(projectDir, adapter) {
|
|
|
215
219
|
projectDir,
|
|
216
220
|
config,
|
|
217
221
|
logger: bootstrapLog,
|
|
222
|
+
primeContracts: { [AIProviderRegistryName]: createAIProviderRegistry() },
|
|
218
223
|
}), fsDispose);
|
|
219
224
|
wireTracingShim();
|
|
220
225
|
return {
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Shim over the `CodeParser` contract's `injectJsxNodePositions()` method.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* The actual Babel-based implementation lives in `@veryfront/ext-babel`.
|
|
5
|
+
* Core modules continue to import from this path; the shim resolves the
|
|
6
|
+
* contract at call time. Position injection powers Studio Navigator only —
|
|
7
|
+
* if `ext-babel` is not installed we return the source unchanged rather
|
|
8
|
+
* than fail the SSR path.
|
|
6
9
|
*/
|
|
7
10
|
interface TransformOptions {
|
|
8
11
|
filePath: string;
|
|
9
12
|
}
|
|
10
|
-
/**
|
|
11
|
-
* Transform TSX source to inject position data attributes into JSX elements.
|
|
12
|
-
* This enables Studio Navigator to map rendered elements back to source positions.
|
|
13
|
-
*/
|
|
14
13
|
export declare function injectNodePositions(source: string, options: TransformOptions): string;
|
|
15
14
|
export {};
|
|
16
15
|
//# sourceMappingURL=babel-node-positions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"babel-node-positions.d.ts","sourceRoot":"","sources":["../../../../src/src/transforms/plugins/babel-node-positions.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"babel-node-positions.d.ts","sourceRoot":"","sources":["../../../../src/src/transforms/plugins/babel-node-positions.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,UAAU,gBAAgB;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAIrF"}
|
|
@@ -1,129 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Shim over the `CodeParser` contract's `injectJsxNodePositions()` method.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import * as generateModule from "@babel/generator";
|
|
10
|
-
import * as t from "@babel/types";
|
|
11
|
-
function resolveDefaultExport(mod) {
|
|
12
|
-
const m = mod;
|
|
13
|
-
if (typeof m.default === "function")
|
|
14
|
-
return m.default;
|
|
15
|
-
const nested = m.default;
|
|
16
|
-
if (typeof nested?.default === "function")
|
|
17
|
-
return nested.default;
|
|
18
|
-
return mod;
|
|
19
|
-
}
|
|
20
|
-
const traverse = resolveDefaultExport(traverseModule);
|
|
21
|
-
const generate = resolveDefaultExport(generateModule);
|
|
22
|
-
const SKIPPED_ELEMENTS = new Set([
|
|
23
|
-
"html",
|
|
24
|
-
"head",
|
|
25
|
-
"title",
|
|
26
|
-
"body",
|
|
27
|
-
"link",
|
|
28
|
-
"base",
|
|
29
|
-
"meta",
|
|
30
|
-
"script",
|
|
31
|
-
"style",
|
|
32
|
-
"noscript",
|
|
33
|
-
"template",
|
|
34
|
-
"svg",
|
|
35
|
-
"path",
|
|
36
|
-
"circle",
|
|
37
|
-
"ellipse",
|
|
38
|
-
"line",
|
|
39
|
-
"polygon",
|
|
40
|
-
"polyline",
|
|
41
|
-
"rect",
|
|
42
|
-
"g",
|
|
43
|
-
"defs",
|
|
44
|
-
"linearGradient",
|
|
45
|
-
"radialGradient",
|
|
46
|
-
"stop",
|
|
47
|
-
"text",
|
|
48
|
-
"tspan",
|
|
49
|
-
"use",
|
|
50
|
-
"filter",
|
|
51
|
-
]);
|
|
52
|
-
function getElementName(openingElement) {
|
|
53
|
-
const { name } = openingElement;
|
|
54
|
-
if (t.isJSXIdentifier(name))
|
|
55
|
-
return name.name;
|
|
56
|
-
if (!t.isJSXMemberExpression(name))
|
|
57
|
-
return "DynamicComponent";
|
|
58
|
-
const parts = [];
|
|
59
|
-
let current = name;
|
|
60
|
-
while (t.isJSXMemberExpression(current)) {
|
|
61
|
-
if (t.isJSXIdentifier(current.property))
|
|
62
|
-
parts.unshift(current.property.name);
|
|
63
|
-
current = current.object;
|
|
64
|
-
}
|
|
65
|
-
if (t.isJSXIdentifier(current))
|
|
66
|
-
parts.unshift(current.name);
|
|
67
|
-
return parts.length ? parts.join(".") : "MemberExpression";
|
|
68
|
-
}
|
|
69
|
-
function isFragment(openingElement) {
|
|
70
|
-
const { name } = openingElement;
|
|
71
|
-
if (t.isJSXMemberExpression(name)) {
|
|
72
|
-
return (t.isJSXIdentifier(name.object) &&
|
|
73
|
-
name.object.name === "React" &&
|
|
74
|
-
t.isJSXIdentifier(name.property) &&
|
|
75
|
-
name.property.name === "Fragment");
|
|
76
|
-
}
|
|
77
|
-
return t.isJSXIdentifier(name) && name.name === "Fragment";
|
|
78
|
-
}
|
|
79
|
-
function hasPositionAttribute(attributes) {
|
|
80
|
-
return attributes.some((attr) => {
|
|
81
|
-
if (!t.isJSXAttribute(attr) || !t.isJSXIdentifier(attr.name))
|
|
82
|
-
return false;
|
|
83
|
-
return attr.name.name === "data-node-line" || attr.name.name === "data-vf-id";
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Transform TSX source to inject position data attributes into JSX elements.
|
|
88
|
-
* This enables Studio Navigator to map rendered elements back to source positions.
|
|
4
|
+
* The actual Babel-based implementation lives in `@veryfront/ext-babel`.
|
|
5
|
+
* Core modules continue to import from this path; the shim resolves the
|
|
6
|
+
* contract at call time. Position injection powers Studio Navigator only —
|
|
7
|
+
* if `ext-babel` is not installed we return the source unchanged rather
|
|
8
|
+
* than fail the SSR path.
|
|
89
9
|
*/
|
|
10
|
+
import { tryResolve } from "../../extensions/contracts.js";
|
|
90
11
|
export function injectNodePositions(source, options) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (!options.filePath)
|
|
94
|
-
return source;
|
|
95
|
-
try {
|
|
96
|
-
const ast = parser.parse(source, {
|
|
97
|
-
sourceType: "module",
|
|
98
|
-
plugins: ["typescript", "jsx"],
|
|
99
|
-
});
|
|
100
|
-
let nodeCounter = 0;
|
|
101
|
-
traverse(ast, {
|
|
102
|
-
JSXElement: {
|
|
103
|
-
enter(path) {
|
|
104
|
-
const openingElement = path.node.openingElement;
|
|
105
|
-
const elementName = getElementName(openingElement);
|
|
106
|
-
if (SKIPPED_ELEMENTS.has(elementName.toLowerCase()))
|
|
107
|
-
return;
|
|
108
|
-
if (isFragment(openingElement))
|
|
109
|
-
return;
|
|
110
|
-
if (hasPositionAttribute(openingElement.attributes))
|
|
111
|
-
return;
|
|
112
|
-
const loc = openingElement.loc;
|
|
113
|
-
if (!loc)
|
|
114
|
-
return;
|
|
115
|
-
const nodeId = `node-${nodeCounter++}`;
|
|
116
|
-
openingElement.attributes.push(t.jsxAttribute(t.jsxIdentifier("data-node-id"), t.stringLiteral(nodeId)), t.jsxAttribute(t.jsxIdentifier("data-node-file"), t.stringLiteral(options.filePath)), t.jsxAttribute(t.jsxIdentifier("data-node-name"), t.stringLiteral(elementName)), t.jsxAttribute(t.jsxIdentifier("data-node-line"), t.stringLiteral(String(loc.start.line))), t.jsxAttribute(t.jsxIdentifier("data-node-column"), t.stringLiteral(String(loc.start.column))));
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
return generate(ast, {
|
|
121
|
-
retainLines: true,
|
|
122
|
-
compact: false,
|
|
123
|
-
}).code;
|
|
124
|
-
}
|
|
125
|
-
catch (_) {
|
|
126
|
-
/* expected: source may not be parseable TSX/JSX */
|
|
12
|
+
const parser = tryResolve("CodeParser");
|
|
13
|
+
if (!parser)
|
|
127
14
|
return source;
|
|
128
|
-
|
|
15
|
+
return parser.injectJsxNodePositions(source, options);
|
|
129
16
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.285";
|
|
2
2
|
//# sourceMappingURL=version-constant.d.ts.map
|