@milaboratories/pl-model-middle-layer 1.20.0 → 1.22.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/block_meta/block_components.cjs +19 -26
- package/dist/block_meta/block_components.cjs.map +1 -1
- package/dist/block_meta/block_components.d.ts +46 -428
- package/dist/block_meta/block_components.d.ts.map +1 -1
- package/dist/block_meta/block_components.js +19 -23
- package/dist/block_meta/block_components.js.map +1 -1
- package/dist/block_meta/block_description.cjs +5 -3
- package/dist/block_meta/block_description.cjs.map +1 -1
- package/dist/block_meta/block_description.d.ts +277 -789
- package/dist/block_meta/block_description.d.ts.map +1 -1
- package/dist/block_meta/block_description.js +5 -3
- package/dist/block_meta/block_description.js.map +1 -1
- package/dist/block_meta/block_manifest.cjs +10 -1
- package/dist/block_meta/block_manifest.cjs.map +1 -1
- package/dist/block_meta/block_manifest.d.ts +700 -1278
- package/dist/block_meta/block_manifest.d.ts.map +1 -1
- package/dist/block_meta/block_manifest.js +11 -2
- package/dist/block_meta/block_manifest.js.map +1 -1
- package/dist/block_meta/block_meta.cjs.map +1 -1
- package/dist/block_meta/block_meta.d.ts +92 -174
- package/dist/block_meta/block_meta.d.ts.map +1 -1
- package/dist/block_meta/block_meta.js.map +1 -1
- package/dist/block_meta/content_types.cjs +25 -77
- package/dist/block_meta/content_types.cjs.map +1 -1
- package/dist/block_meta/content_types.d.ts +67 -383
- package/dist/block_meta/content_types.d.ts.map +1 -1
- package/dist/block_meta/content_types.js +26 -64
- package/dist/block_meta/content_types.js.map +1 -1
- package/dist/block_meta/index.d.ts +3 -3
- package/dist/block_registry/block_pack_spec.d.ts +8 -8
- package/dist/block_registry/overview.d.ts +200 -200
- package/dist/block_registry/registry_spec.d.ts +20 -20
- package/dist/index.cjs +1 -18
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/pframe/internal_api/api_factory.cjs.map +1 -1
- package/dist/pframe/internal_api/api_factory.d.ts +36 -2
- package/dist/pframe/internal_api/api_factory.d.ts.map +1 -1
- package/dist/pframe/internal_api/api_factory.js.map +1 -1
- package/dist/pframe/internal_api/api_read.d.ts +40 -3
- package/dist/pframe/internal_api/api_read.d.ts.map +1 -1
- package/dist/pframe/internal_api/index.d.ts +5 -5
- package/dist/pframe/internal_api/pframe.d.ts +21 -3
- package/dist/pframe/internal_api/pframe.d.ts.map +1 -1
- package/dist/pframe/internal_api/table.d.ts +51 -1
- package/dist/pframe/internal_api/table.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/block_meta/block_components.ts +67 -42
- package/src/block_meta/block_description.ts +18 -3
- package/src/block_meta/block_manifest.ts +14 -3
- package/src/block_meta/block_meta.ts +40 -6
- package/src/block_meta/content_types.ts +149 -207
- package/src/pframe/internal_api/api_factory.ts +44 -0
- package/src/pframe/internal_api/api_read.ts +48 -1
- package/src/pframe/internal_api/pframe.ts +23 -2
- package/src/pframe/internal_api/table.ts +54 -0
|
@@ -1,49 +1,74 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { ContentRelativeBinary } from "./content_types";
|
|
3
|
-
import { mapRemoteToAbsolute } from "./content_conversion";
|
|
4
|
-
|
|
5
|
-
export function WorkflowV1<const Content extends z.ZodTypeAny>(contentType: Content) {
|
|
6
|
-
return z.object({
|
|
7
|
-
type: z.literal("workflow-v1"),
|
|
8
|
-
main: contentType.describe("Main workflow"),
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
2
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
contentType
|
|
16
|
-
.transform((value: z.infer<typeof contentType>) => ({
|
|
17
|
-
type: "workflow-v1" as const,
|
|
18
|
-
main: value,
|
|
19
|
-
}))
|
|
20
|
-
.pipe(WorkflowV1(contentType)),
|
|
21
|
-
// structured objects are decoded as union with type descriptor
|
|
22
|
-
z.discriminatedUnion("type", [WorkflowV1(contentType)]),
|
|
23
|
-
]);
|
|
24
|
-
}
|
|
3
|
+
//
|
|
4
|
+
// Workflow + BlockComponents canonical TS types.
|
|
5
|
+
//
|
|
25
6
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Wrapped workflow component, schema version 1. Currently the only workflow
|
|
9
|
+
* schema; carries a single `main` entry pointing at the workflow source.
|
|
10
|
+
*/
|
|
11
|
+
export type WorkflowV1<Content> = {
|
|
12
|
+
type: "workflow-v1";
|
|
13
|
+
main: Content;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Current workflow component shape. Alias to `WorkflowV1` while v1 is the
|
|
18
|
+
* only version — future versions widen this to a discriminated union.
|
|
19
|
+
*/
|
|
20
|
+
export type Workflow<Content> = WorkflowV1<Content>;
|
|
36
21
|
|
|
37
|
-
|
|
38
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Trio of artifacts every block ships: a workflow (Tengo source), a model
|
|
24
|
+
* (compiled JS), and a UI (front-end bundle). `WMContent` carries
|
|
25
|
+
* `workflow.main` and `model` together (they travel as files); `UIContent`
|
|
26
|
+
* carries the UI bundle (a folder when resolved locally, a relative path in
|
|
27
|
+
* manifest form). Parameterizing this lets the same shape express every
|
|
28
|
+
* stage the description passes through: raw `package.json` input (bare
|
|
29
|
+
* strings), manifest form (relative paths stored in the registry), resolved
|
|
30
|
+
* absolute form (local file/folder paths), and the registry-reader output
|
|
31
|
+
* (URLs into registry storage, produced by `blockComponentsManifestToAbsoluteUrl`).
|
|
32
|
+
*/
|
|
33
|
+
export type BlockComponents<WMContent, UIContent> = {
|
|
34
|
+
workflow: Workflow<WMContent>;
|
|
35
|
+
model: WMContent;
|
|
36
|
+
ui: UIContent;
|
|
37
|
+
};
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Builds the zod schema for a wrapped workflow component carrying `content`
|
|
41
|
+
* as the `main` payload. Shared between the `package.json` boundary parser
|
|
42
|
+
* (where `content` is `z.string()`) and the manifest schema (where `content`
|
|
43
|
+
* is `ContentRelative`).
|
|
44
|
+
*/
|
|
45
|
+
export function WorkflowSchemaV1<C extends z.ZodTypeAny>(content: C) {
|
|
46
|
+
return z
|
|
47
|
+
.object({
|
|
48
|
+
type: z.literal("workflow-v1"),
|
|
49
|
+
main: content,
|
|
50
|
+
})
|
|
51
|
+
.strict();
|
|
45
52
|
}
|
|
46
|
-
export type BlockComponentsAbsolute = z.infer<ReturnType<typeof BlockComponentsAbsoluteUrl>>;
|
|
47
53
|
|
|
48
|
-
//
|
|
49
|
-
//
|
|
54
|
+
//
|
|
55
|
+
// `package.json` boundary schema. The workflow field accepts either a bare
|
|
56
|
+
// string (treated as `main`) or the wrapped object form; both normalize to
|
|
57
|
+
// the canonical wrapped shape.
|
|
58
|
+
//
|
|
59
|
+
|
|
60
|
+
const WorkflowDescriptionRaw = z.union([
|
|
61
|
+
z.string().transform<WorkflowV1<string>>((value) => ({
|
|
62
|
+
type: "workflow-v1",
|
|
63
|
+
main: value,
|
|
64
|
+
})),
|
|
65
|
+
WorkflowSchemaV1(z.string()),
|
|
66
|
+
]) satisfies z.ZodType<Workflow<string>, z.ZodTypeDef, any>;
|
|
67
|
+
|
|
68
|
+
export type BlockComponentsDescriptionRaw = BlockComponents<string, string>;
|
|
69
|
+
|
|
70
|
+
export const BlockComponentsDescriptionRaw = z.object({
|
|
71
|
+
workflow: WorkflowDescriptionRaw,
|
|
72
|
+
model: z.string(),
|
|
73
|
+
ui: z.string(),
|
|
74
|
+
}) satisfies z.ZodType<BlockComponentsDescriptionRaw, z.ZodTypeDef, any>;
|
|
@@ -6,9 +6,24 @@ import { BlockPackId } from "./block_id";
|
|
|
6
6
|
import { toMerged } from "es-toolkit";
|
|
7
7
|
import type { BlockCodeKnownFeatureFlags } from "@milaboratories/pl-model-common";
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
/**
|
|
10
|
+
* Block-pack description: a `BlockPackId`, the typed `components` and `meta`
|
|
11
|
+
* payloads, and optional `featureFlags`. The two type parameters let the same
|
|
12
|
+
* shape carry every form a description travels in — `package.json` source,
|
|
13
|
+
* relative-path manifest, absolute-path resolved.
|
|
14
|
+
*/
|
|
15
|
+
export type BlockPackDescription<Components, Meta> = {
|
|
16
|
+
id: BlockPackId;
|
|
17
|
+
components: Components;
|
|
18
|
+
meta: Meta;
|
|
19
|
+
featureFlags?: BlockCodeKnownFeatureFlags;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Description as it appears in the root block `package.json`. `file:`-prefixed
|
|
24
|
+
* strings become `ContentRelative`; bare text strings become
|
|
25
|
+
* `ContentExplicitString`. See `DescriptionContentText`/`DescriptionContentBinary`.
|
|
26
|
+
*/
|
|
12
27
|
export const BlockPackDescriptionFromPackageJsonRaw = z.object({
|
|
13
28
|
components: BlockComponentsDescriptionRaw,
|
|
14
29
|
meta: BlockPackMetaDescriptionRaw,
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { BlockComponents } from "./block_components";
|
|
2
|
+
import type { BlockComponents } from "./block_components";
|
|
3
|
+
import { WorkflowSchemaV1 } from "./block_components";
|
|
3
4
|
import { ContentRelative, ContentRelativeBinary, ContentRelativeText } from "./content_types";
|
|
4
5
|
import { CreateBlockPackDescriptionSchema } from "./block_description";
|
|
5
6
|
import { BlockPackMeta } from "./block_meta";
|
|
6
7
|
import { toMerged } from "es-toolkit";
|
|
7
8
|
import type { BlockPackId } from "./block_id";
|
|
8
9
|
|
|
9
|
-
export
|
|
10
|
-
|
|
10
|
+
export type BlockComponentsManifest = BlockComponents<ContentRelative, ContentRelative>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Block-components shape stored in a manifest. The consolidator always writes
|
|
14
|
+
* the wrapped `{type: "workflow-v1", main: ...}` form, so the manifest schema
|
|
15
|
+
* accepts the wrapped form only.
|
|
16
|
+
*/
|
|
17
|
+
export const BlockComponentsManifest = z.object({
|
|
18
|
+
workflow: WorkflowSchemaV1(ContentRelative),
|
|
19
|
+
model: ContentRelative,
|
|
20
|
+
ui: ContentRelative,
|
|
21
|
+
}) satisfies z.ZodType<BlockComponentsManifest>;
|
|
11
22
|
|
|
12
23
|
export const BlockPackMetaManifest = BlockPackMeta(ContentRelativeText, ContentRelativeBinary);
|
|
13
24
|
export type BlockPackMetaManifest = z.infer<typeof BlockPackMetaManifest>;
|
|
@@ -16,6 +16,44 @@ export const BlockPlatform = z.enum([
|
|
|
16
16
|
]);
|
|
17
17
|
export type BlockPlatform = z.infer<typeof BlockPlatform>;
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Static metadata a block author ships: title, descriptions, logos, social
|
|
21
|
+
* links, and capability requirements. Parameterized by the carriers used for
|
|
22
|
+
* long-string fields (`LongString`) and binary fields (`Binary`); the same
|
|
23
|
+
* shape carries `package.json` form (loose strings), manifest form (relative
|
|
24
|
+
* paths), and embedded form (inlined base64 or bytes).
|
|
25
|
+
*
|
|
26
|
+
* Forward-compatibility: the boundary zod schemas (`BlockPackMeta(...)` and
|
|
27
|
+
* `organization`) use `.passthrough()` so that unknown sibling fields survive
|
|
28
|
+
* parse/round-trip verbatim. A registry mutator that predates a new meta
|
|
29
|
+
* field must not silently strip it (otherwise mark-stable / refresh-overview
|
|
30
|
+
* / restore-overview would quietly undo publishes). Code consuming these
|
|
31
|
+
* objects sees only the known fields listed below; the schemas guard the
|
|
32
|
+
* round-trip behavior. Combined with the `require-latest @platforma-sdk/block-tools`
|
|
33
|
+
* CI gate, this future-proofs every subsequent field addition.
|
|
34
|
+
*/
|
|
35
|
+
export type BlockPackMeta<LongString, Binary> = {
|
|
36
|
+
title: string;
|
|
37
|
+
description: string;
|
|
38
|
+
longDescription?: LongString;
|
|
39
|
+
changelog?: LongString;
|
|
40
|
+
logo?: Binary;
|
|
41
|
+
url?: string;
|
|
42
|
+
docs?: string;
|
|
43
|
+
support?: string;
|
|
44
|
+
tags?: string[];
|
|
45
|
+
organization: {
|
|
46
|
+
name: string;
|
|
47
|
+
url: string;
|
|
48
|
+
logo?: Binary;
|
|
49
|
+
};
|
|
50
|
+
marketplaceRanking?: number;
|
|
51
|
+
deprecated?: boolean;
|
|
52
|
+
termsOfServiceUrl?: string;
|
|
53
|
+
supportedPlatforms?: BlockPlatform[];
|
|
54
|
+
requiredCapabilities?: string[];
|
|
55
|
+
};
|
|
56
|
+
|
|
19
57
|
export function BlockPackMeta<
|
|
20
58
|
const LongStringType extends z.ZodTypeAny,
|
|
21
59
|
const BinaryType extends z.ZodTypeAny,
|
|
@@ -71,12 +109,8 @@ export function BlockPackMeta<
|
|
|
71
109
|
requiredCapabilities: z.array(z.string()).optional(),
|
|
72
110
|
})
|
|
73
111
|
.passthrough();
|
|
74
|
-
// `.passthrough()`
|
|
75
|
-
//
|
|
76
|
-
// would strip that field on every registry-mutating command (mark-stable,
|
|
77
|
-
// refresh-registry, restore-overview-from-snapshot) — silently undoing
|
|
78
|
-
// publishes. Combined with the `require-latest @platforma-sdk/block-tools`
|
|
79
|
-
// CI gate, this future-proofs the schema for all subsequent field additions.
|
|
112
|
+
// `.passthrough()` is intentional — see forward-compat note on
|
|
113
|
+
// `BlockPackMeta` type above.
|
|
80
114
|
}
|
|
81
115
|
|
|
82
116
|
export const BlockPackMetaDescriptionRaw = BlockPackMeta(
|
|
@@ -1,249 +1,191 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
|
|
3
3
|
//
|
|
4
|
-
//
|
|
4
|
+
// Canonical content types. TypeScript is the source of truth. The zod
|
|
5
|
+
// schemas below are boundary validators pegged to these types via
|
|
6
|
+
// `satisfies`; they exist only to parse external data (`package.json`,
|
|
7
|
+
// registry manifests, registry overview files).
|
|
5
8
|
//
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
/** Inlined plain string (e.g. a short text snippet or markdown body). */
|
|
11
|
+
export type ContentExplicitString = {
|
|
12
|
+
type: "explicit-string";
|
|
13
|
+
content: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** Inlined binary blob carried as base64 (e.g. a serialized logo image). */
|
|
17
|
+
export type ContentExplicitBase64 = {
|
|
18
|
+
type: "explicit-base64";
|
|
19
|
+
/** MIME type used to interpret `content`. */
|
|
20
|
+
mimeType: string;
|
|
21
|
+
/** Base64-encoded binary payload. */
|
|
22
|
+
content: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** Inlined binary blob carried as raw bytes. Wire form only; not used in JSON. */
|
|
26
|
+
export type ContentExplicitBytes = {
|
|
27
|
+
type: "explicit-bytes";
|
|
28
|
+
/** MIME type used to interpret `content`. */
|
|
29
|
+
mimeType: string;
|
|
30
|
+
content: Uint8Array;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** Reference to a file by path relative to the carrying structure. */
|
|
34
|
+
export type ContentRelative = {
|
|
35
|
+
type: "relative";
|
|
36
|
+
path: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** Reference to a file at an absolute local path. */
|
|
40
|
+
export type ContentAbsoluteFile = {
|
|
41
|
+
type: "absolute-file";
|
|
42
|
+
file: string;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Reference to a folder at an absolute local path. Used for UI bundles
|
|
47
|
+
* delivered as folders; the desktop "add block" dialog reads such folders on
|
|
48
|
+
* demand instead of pulling every UI bundle eagerly.
|
|
49
|
+
*/
|
|
50
|
+
export type ContentAbsoluteFolder = {
|
|
51
|
+
type: "absolute-folder";
|
|
52
|
+
folder: string;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** Reference to a file by remote URL (e.g. served from the registry). */
|
|
56
|
+
export type ContentAbsoluteUrl = {
|
|
57
|
+
type: "absolute-url";
|
|
58
|
+
url: string;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** Canonical union of every content carrier shape used across the platform. */
|
|
62
|
+
export type Content =
|
|
63
|
+
| ContentExplicitString
|
|
64
|
+
| ContentExplicitBase64
|
|
65
|
+
| ContentExplicitBytes
|
|
66
|
+
| ContentRelative
|
|
67
|
+
| ContentAbsoluteFile
|
|
68
|
+
| ContentAbsoluteFolder
|
|
69
|
+
| ContentAbsoluteUrl;
|
|
14
70
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
.string()
|
|
20
|
-
.regex(/\w+\/[-+.\w]+/)
|
|
21
|
-
.describe("MIME type to interpret content"),
|
|
22
|
-
content: z.string().base64().describe("Base64 encoded binary value"),
|
|
23
|
-
})
|
|
24
|
-
.strict();
|
|
25
|
-
export type ContentExplicitBase64 = z.infer<typeof ContentExplicitBase64>;
|
|
71
|
+
//
|
|
72
|
+
// Slot-specific content unions. Each names a set of carriers allowed in a
|
|
73
|
+
// particular stage of the pipeline (boundary input, manifest, resolved).
|
|
74
|
+
//
|
|
26
75
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
76
|
+
/** Inlined or relative-path content (text/binary inlined, or relative path). */
|
|
77
|
+
export type ContentExplicitOrRelative =
|
|
78
|
+
| ContentExplicitString
|
|
79
|
+
| ContentExplicitBase64
|
|
80
|
+
| ContentRelative;
|
|
81
|
+
|
|
82
|
+
/** Any locally-resolvable content (inlined, relative path, or absolute file). */
|
|
83
|
+
export type ContentAnyLocal =
|
|
84
|
+
| ContentExplicitString
|
|
85
|
+
| ContentExplicitBase64
|
|
86
|
+
| ContentRelative
|
|
87
|
+
| ContentAbsoluteFile;
|
|
88
|
+
|
|
89
|
+
/** Text content available locally (inlined, relative path, or absolute file). */
|
|
90
|
+
export type ContentAnyTextLocal = ContentExplicitString | ContentRelative | ContentAbsoluteFile;
|
|
91
|
+
|
|
92
|
+
/** Binary content available locally (inlined base64, relative path, or absolute file). */
|
|
93
|
+
export type ContentAnyBinaryLocal = ContentExplicitBase64 | ContentRelative | ContentAbsoluteFile;
|
|
94
|
+
|
|
95
|
+
/** Binary content fully resolved (inlined base64 or absolute file). */
|
|
96
|
+
export type ContentAbsoluteBinaryLocal = ContentExplicitBase64 | ContentAbsoluteFile;
|
|
97
|
+
|
|
98
|
+
/** Text content fully resolved (inlined string or absolute file). */
|
|
99
|
+
export type ContentAbsoluteTextLocal = ContentExplicitString | ContentAbsoluteFile;
|
|
100
|
+
|
|
101
|
+
/** Binary content in manifest form (inlined base64 or path relative to the manifest). */
|
|
102
|
+
export type ContentRelativeBinary = ContentExplicitBase64 | ContentRelative;
|
|
103
|
+
|
|
104
|
+
/** Text content in manifest form (inlined string or path relative to the manifest). */
|
|
105
|
+
export type ContentRelativeText = ContentExplicitString | ContentRelative;
|
|
106
|
+
|
|
107
|
+
//
|
|
108
|
+
// Zod schemas — boundary validators only. The TS types above are the source
|
|
109
|
+
// of truth; each schema is pegged via `satisfies z.ZodType<T>`. Only the
|
|
110
|
+
// schemas referenced by sibling boundary files (`block_meta.ts`,
|
|
111
|
+
// `block_manifest.ts`) are exported.
|
|
112
|
+
//
|
|
38
113
|
|
|
39
114
|
const absPathRegex = new RegExp(`^(/|[A-Z]:\\\\)`);
|
|
40
115
|
|
|
41
|
-
|
|
116
|
+
const contentExplicitStringSchema = z
|
|
42
117
|
.object({
|
|
43
|
-
type: z.literal("
|
|
44
|
-
|
|
45
|
-
.string()
|
|
46
|
-
.regex(absPathRegex, "path to file must be absolute")
|
|
47
|
-
.describe("Absolute address of the file in local file system"),
|
|
118
|
+
type: z.literal("explicit-string"),
|
|
119
|
+
content: z.string(),
|
|
48
120
|
})
|
|
49
|
-
.strict()
|
|
50
|
-
export type ContentAbsoluteFile = z.infer<typeof ContentAbsoluteFile>;
|
|
121
|
+
.strict() satisfies z.ZodType<ContentExplicitString>;
|
|
51
122
|
|
|
52
|
-
export const
|
|
123
|
+
export const ContentExplicitBase64 = z
|
|
53
124
|
.object({
|
|
54
|
-
type: z.literal("
|
|
55
|
-
|
|
125
|
+
type: z.literal("explicit-base64"),
|
|
126
|
+
mimeType: z.string().regex(/\w+\/[-+.\w]+/),
|
|
127
|
+
content: z.string().base64(),
|
|
56
128
|
})
|
|
57
|
-
.strict()
|
|
58
|
-
export type ContentAbsoluteUrl = z.infer<typeof ContentAbsoluteUrl>;
|
|
59
|
-
|
|
60
|
-
//
|
|
61
|
-
// Special content types
|
|
62
|
-
//
|
|
129
|
+
.strict() satisfies z.ZodType<ContentExplicitBase64>;
|
|
63
130
|
|
|
64
131
|
export const ContentExplicitBytes = z
|
|
65
132
|
.object({
|
|
66
133
|
type: z.literal("explicit-bytes"),
|
|
67
|
-
mimeType: z
|
|
68
|
-
|
|
69
|
-
.regex(/\w+\/[-+.\w]+/)
|
|
70
|
-
.describe("MIME type to interpret content"),
|
|
71
|
-
content: z.instanceof(Uint8Array).describe("Raw content"),
|
|
134
|
+
mimeType: z.string().regex(/\w+\/[-+.\w]+/),
|
|
135
|
+
content: z.instanceof(Uint8Array),
|
|
72
136
|
})
|
|
73
|
-
.strict()
|
|
74
|
-
export type ContentExplicitBytes = z.infer<typeof ContentExplicitBytes>;
|
|
137
|
+
.strict() satisfies z.ZodType<ContentExplicitBytes>;
|
|
75
138
|
|
|
76
|
-
export const
|
|
139
|
+
export const ContentRelative = z
|
|
77
140
|
.object({
|
|
78
|
-
type: z.literal("
|
|
79
|
-
|
|
80
|
-
.string()
|
|
81
|
-
.regex(absPathRegex, "path to folder must be absolute")
|
|
82
|
-
.describe("Absolute address of the folder in local file system"),
|
|
141
|
+
type: z.literal("relative"),
|
|
142
|
+
path: z.string(),
|
|
83
143
|
})
|
|
84
|
-
.strict()
|
|
85
|
-
export type ContentAbsoluteFolder = z.infer<typeof ContentAbsoluteFolder>;
|
|
86
|
-
|
|
87
|
-
//
|
|
88
|
-
// Unions
|
|
89
|
-
//
|
|
144
|
+
.strict() satisfies z.ZodType<ContentRelative>;
|
|
90
145
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
]);
|
|
98
|
-
export type ContentAny = z.infer<typeof ContentAny>;
|
|
99
|
-
|
|
100
|
-
export const ContentExplicitOrRelative = z.discriminatedUnion("type", [
|
|
101
|
-
ContentExplicitString,
|
|
102
|
-
ContentExplicitBase64,
|
|
103
|
-
ContentRelative,
|
|
104
|
-
]);
|
|
105
|
-
export type ContentExplicitOrRelative = z.infer<typeof ContentExplicitOrRelative>;
|
|
106
|
-
|
|
107
|
-
export const ContentAnyLocal = z.discriminatedUnion("type", [
|
|
108
|
-
ContentExplicitString,
|
|
109
|
-
ContentExplicitBase64,
|
|
110
|
-
ContentRelative,
|
|
111
|
-
ContentAbsoluteFile,
|
|
112
|
-
]);
|
|
113
|
-
export type ContentAnyLocal = z.infer<typeof ContentAnyLocal>;
|
|
146
|
+
const contentAbsoluteFileSchema = z
|
|
147
|
+
.object({
|
|
148
|
+
type: z.literal("absolute-file"),
|
|
149
|
+
file: z.string().regex(absPathRegex, "path to file must be absolute"),
|
|
150
|
+
})
|
|
151
|
+
.strict() satisfies z.ZodType<ContentAbsoluteFile>;
|
|
114
152
|
|
|
115
|
-
export const
|
|
116
|
-
ContentExplicitString,
|
|
153
|
+
export const ContentRelativeBinary = z.discriminatedUnion("type", [
|
|
117
154
|
ContentExplicitBase64,
|
|
118
155
|
ContentRelative,
|
|
119
|
-
|
|
120
|
-
]);
|
|
121
|
-
export type ContentAnyRemote = z.infer<typeof ContentAnyRemote>;
|
|
122
|
-
|
|
123
|
-
//
|
|
124
|
-
// Narrow types with relative option
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
// export const ContentAnyBinaryRemote = z.discriminatedUnion('type', [
|
|
128
|
-
// ContentExplicitBase64,
|
|
129
|
-
// ContentRelative,
|
|
130
|
-
// ContentAbsoluteUrl
|
|
131
|
-
// ]);
|
|
132
|
-
// export type ContentAnyBinaryRemote = z.infer<typeof ContentAnyBinaryRemote>;
|
|
156
|
+
]) satisfies z.ZodType<ContentRelativeBinary>;
|
|
133
157
|
|
|
134
|
-
export const
|
|
135
|
-
|
|
136
|
-
ContentRelative,
|
|
137
|
-
ContentAbsoluteFile,
|
|
138
|
-
]);
|
|
139
|
-
export type ContentAnyBinaryLocal = z.infer<typeof ContentAnyBinaryLocal>;
|
|
140
|
-
|
|
141
|
-
// export const ContentAnyTextRemote = z.discriminatedUnion('type', [
|
|
142
|
-
// ContentExplicitString,
|
|
143
|
-
// ContentRelative,
|
|
144
|
-
// ContentAbsoluteUrl
|
|
145
|
-
// ]);
|
|
146
|
-
// export type ContentAnyTextRemote = z.infer<typeof ContentAnyTextRemote>;
|
|
147
|
-
|
|
148
|
-
export const ContentAnyTextLocal = z.discriminatedUnion("type", [
|
|
149
|
-
ContentExplicitString,
|
|
158
|
+
export const ContentRelativeText = z.discriminatedUnion("type", [
|
|
159
|
+
contentExplicitStringSchema,
|
|
150
160
|
ContentRelative,
|
|
151
|
-
|
|
152
|
-
]);
|
|
153
|
-
export type ContentAnyTextLocal = z.infer<typeof ContentAnyTextLocal>;
|
|
161
|
+
]) satisfies z.ZodType<ContentRelativeText>;
|
|
154
162
|
|
|
155
163
|
//
|
|
156
|
-
//
|
|
157
|
-
//
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
ContentExplicitBase64,
|
|
161
|
-
ContentAbsoluteUrl,
|
|
162
|
-
]);
|
|
163
|
-
export type ContentAbsoluteBinaryRemote = z.infer<typeof ContentAbsoluteBinaryRemote>;
|
|
164
|
-
|
|
165
|
-
export const ContentAbsoluteBinaryLocal = z.discriminatedUnion("type", [
|
|
166
|
-
ContentExplicitBase64,
|
|
167
|
-
ContentAbsoluteFile,
|
|
168
|
-
]);
|
|
169
|
-
export type ContentAbsoluteBinaryLocal = z.infer<typeof ContentAbsoluteBinaryLocal>;
|
|
170
|
-
|
|
171
|
-
export const ContentAbsoluteTextRemote = z.discriminatedUnion("type", [
|
|
172
|
-
ContentExplicitString,
|
|
173
|
-
ContentAbsoluteUrl,
|
|
174
|
-
]);
|
|
175
|
-
export type ContentAbsoluteTextRemote = z.infer<typeof ContentAbsoluteTextRemote>;
|
|
176
|
-
|
|
177
|
-
export const ContentAbsoluteTextLocal = z.discriminatedUnion("type", [
|
|
178
|
-
ContentExplicitString,
|
|
179
|
-
ContentAbsoluteFile,
|
|
180
|
-
]);
|
|
181
|
-
export type ContentAbsoluteTextLocal = z.infer<typeof ContentAbsoluteTextLocal>;
|
|
182
|
-
|
|
164
|
+
// Boundary normalizing transforms — parse the loose forms authors write in
|
|
165
|
+
// `package.json`. Bare strings with the `file:` prefix become a
|
|
166
|
+
// `ContentRelative`; bare strings without the prefix become a
|
|
167
|
+
// `ContentExplicitString` (text only).
|
|
183
168
|
//
|
|
184
|
-
// Narrow relative types
|
|
185
|
-
//
|
|
186
|
-
|
|
187
|
-
export const ContentRelativeBinary = z.discriminatedUnion("type", [
|
|
188
|
-
ContentExplicitBase64,
|
|
189
|
-
ContentRelative,
|
|
190
|
-
]);
|
|
191
|
-
export type ContentRelativeBinary = z.infer<typeof ContentRelativeBinary>;
|
|
192
|
-
|
|
193
|
-
export const ContentRelativeText = z.discriminatedUnion("type", [
|
|
194
|
-
ContentExplicitString,
|
|
195
|
-
ContentRelative,
|
|
196
|
-
]);
|
|
197
|
-
export type ContentRelativeText = z.infer<typeof ContentRelativeText>;
|
|
198
|
-
|
|
199
|
-
// export function ConstructContent(
|
|
200
|
-
// contentType: 'text',
|
|
201
|
-
// contextType: 'local'
|
|
202
|
-
// ): typeof ContentAnyTextLocal;
|
|
203
|
-
// export function ConstructContent(
|
|
204
|
-
// contentType: 'text',
|
|
205
|
-
// contextType: 'remote'
|
|
206
|
-
// ): typeof ContentAnyTextRemote;
|
|
207
|
-
// export function ConstructContent(
|
|
208
|
-
// contentType: 'binary',
|
|
209
|
-
// contextType: 'local'
|
|
210
|
-
// ): typeof ContentAnyBinaryLocal;
|
|
211
|
-
// export function ConstructContent(
|
|
212
|
-
// contentType: 'binary',
|
|
213
|
-
// contextType: 'remote'
|
|
214
|
-
// ): typeof ContentAnyBinaryRemote;
|
|
215
|
-
// export function ConstructContent(
|
|
216
|
-
// contentType: ContentType,
|
|
217
|
-
// contextType: ContextType
|
|
218
|
-
// ):
|
|
219
|
-
// | typeof ContentAnyTextLocal
|
|
220
|
-
// | typeof ContentAnyTextRemote
|
|
221
|
-
// | typeof ContentAnyBinaryLocal
|
|
222
|
-
// | typeof ContentAnyBinaryRemote;
|
|
223
|
-
// export function ConstructContent(contentType: ContentType, contextType: ContextType) {
|
|
224
|
-
// return contentType === 'text'
|
|
225
|
-
// ? contextType === 'local'
|
|
226
|
-
// ? ContentAnyTextLocal
|
|
227
|
-
// : ContentAnyTextRemote
|
|
228
|
-
// : contextType === 'local'
|
|
229
|
-
// ? ContentAnyBinaryLocal
|
|
230
|
-
// : ContentAnyBinaryRemote;
|
|
231
|
-
// }
|
|
232
169
|
|
|
233
170
|
export const DescriptionContentBinary = z.union([
|
|
234
171
|
z
|
|
235
172
|
.string()
|
|
236
173
|
.startsWith("file:")
|
|
237
|
-
.transform<ContentRelativeBinary>((value) => ({
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
174
|
+
.transform<ContentRelativeBinary>((value) => ({
|
|
175
|
+
type: "relative",
|
|
176
|
+
path: value.slice(5),
|
|
177
|
+
})),
|
|
178
|
+
z.discriminatedUnion("type", [ContentExplicitBase64, ContentRelative, contentAbsoluteFileSchema]),
|
|
179
|
+
]) satisfies z.ZodType<ContentAnyBinaryLocal, z.ZodTypeDef, any>;
|
|
241
180
|
|
|
242
181
|
export const DescriptionContentText = z.union([
|
|
243
182
|
z.string().transform<ContentRelativeText>((value) => {
|
|
244
183
|
if (value.startsWith("file:")) return { type: "relative", path: value.slice(5) };
|
|
245
|
-
|
|
184
|
+
return { type: "explicit-string", content: value };
|
|
246
185
|
}),
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
186
|
+
z.discriminatedUnion("type", [
|
|
187
|
+
contentExplicitStringSchema,
|
|
188
|
+
ContentRelative,
|
|
189
|
+
contentAbsoluteFileSchema,
|
|
190
|
+
]),
|
|
191
|
+
]) satisfies z.ZodType<ContentAnyTextLocal, z.ZodTypeDef, any>;
|