@sanity/agent-directives 0.0.5 → 0.0.7
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/README.md +98 -33
- package/dist/_chunks-dts/index.d.ts +134 -0
- package/dist/_chunks-dts/index.d.ts.map +1 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +66 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/formatters.d.ts +2 -0
- package/dist/lib/formatters.js +11 -0
- package/dist/lib/formatters.js.map +1 -0
- package/dist/lib/react.d.ts +1127 -0
- package/dist/lib/react.d.ts.map +1 -0
- package/dist/lib/react.js +100 -0
- package/dist/lib/react.js.map +1 -0
- package/dist/lib/string.d.ts +72 -0
- package/dist/lib/string.d.ts.map +1 -0
- package/dist/lib/string.js +80 -0
- package/dist/lib/string.js.map +1 -0
- package/package.json +24 -25
- package/dist/formatters.d.ts +0 -8
- package/dist/formatters.d.ts.map +0 -1
- package/dist/formatters.js +0 -27
- package/dist/formatters.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/react.d.ts +0 -62
- package/dist/react.d.ts.map +0 -1
- package/dist/react.js +0 -194
- package/dist/react.js.map +0 -1
- package/dist/schemas.d.ts +0 -118
- package/dist/schemas.d.ts.map +0 -1
- package/dist/schemas.js +0 -35
- package/dist/schemas.js.map +0 -1
- package/dist/string.d.ts +0 -34
- package/dist/string.d.ts.map +0 -1
- package/dist/string.js +0 -65
- package/dist/string.js.map +0 -1
package/README.md
CHANGED
|
@@ -14,28 +14,42 @@ pnpm add @sanity/agent-directives
|
|
|
14
14
|
// kit.ts
|
|
15
15
|
import { createDirectiveKit } from "@sanity/agent-directives/react";
|
|
16
16
|
|
|
17
|
-
export const { defineDirective } = createDirectiveKit({
|
|
18
|
-
useApplication: useThreadApplication,
|
|
17
|
+
export const { defineDirective } = createDirectiveKit<Application>({
|
|
18
|
+
useApplication: (source) => useThreadApplication(source),
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
// Document.tsx
|
|
22
|
-
export const
|
|
23
|
-
|
|
24
|
-
})
|
|
21
|
+
// directives/Document.tsx
|
|
22
|
+
export const DocumentDirective = defineDirective(
|
|
23
|
+
"document",
|
|
24
|
+
({ id, application }) => {
|
|
25
|
+
return <DocumentCard id={id} application={application} />;
|
|
26
|
+
},
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
// directives/Changes.tsx - no application needed
|
|
30
|
+
export const ChangesDirective = defineDirective(
|
|
31
|
+
"changes",
|
|
32
|
+
({ createdCount, updatedCount }) => (
|
|
33
|
+
<ChangesCard created={createdCount} updated={updatedCount} />
|
|
34
|
+
),
|
|
35
|
+
{ requiresContext: false },
|
|
36
|
+
);
|
|
25
37
|
|
|
26
38
|
// AgentMessage.tsx
|
|
27
39
|
import { remarkAgentDirectives } from "@sanity/agent-directives/react";
|
|
28
40
|
import ReactMarkdown from "react-markdown";
|
|
29
41
|
|
|
42
|
+
const components = {
|
|
43
|
+
Document: DocumentDirective,
|
|
44
|
+
Changes: ChangesDirective,
|
|
45
|
+
// directive names are converted to PascalCase
|
|
46
|
+
};
|
|
47
|
+
|
|
30
48
|
function AgentMessage({ content }: { content: string }) {
|
|
31
49
|
return (
|
|
32
50
|
<ReactMarkdown
|
|
33
51
|
remarkPlugins={[remarkAgentDirectives]}
|
|
34
|
-
components={
|
|
35
|
-
Document: DocumentDirective,
|
|
36
|
-
Release: ReleaseDirective,
|
|
37
|
-
// ...
|
|
38
|
-
}}
|
|
52
|
+
components={components}
|
|
39
53
|
>
|
|
40
54
|
{content}
|
|
41
55
|
</ReactMarkdown>
|
|
@@ -43,29 +57,68 @@ function AgentMessage({ content }: { content: string }) {
|
|
|
43
57
|
}
|
|
44
58
|
```
|
|
45
59
|
|
|
46
|
-
##
|
|
60
|
+
## Server-side Usage
|
|
47
61
|
|
|
48
62
|
```ts
|
|
49
63
|
// kit.ts
|
|
50
|
-
import {
|
|
64
|
+
import {
|
|
65
|
+
createDirectiveKit,
|
|
66
|
+
createRemarkRenderer,
|
|
67
|
+
} from "@sanity/agent-directives/string";
|
|
68
|
+
|
|
69
|
+
interface MyContext {
|
|
70
|
+
accessToken: string;
|
|
71
|
+
applications: Application[];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface MyOutput {
|
|
75
|
+
text?: string;
|
|
76
|
+
blocks?: Block[];
|
|
77
|
+
}
|
|
51
78
|
|
|
52
79
|
export const { defineDirective, renderDirective } = createDirectiveKit<
|
|
53
|
-
|
|
54
|
-
|
|
80
|
+
MyContext,
|
|
81
|
+
MyOutput
|
|
55
82
|
>();
|
|
56
83
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"document",
|
|
60
|
-
async ({ id, _context }) => {
|
|
61
|
-
const doc = await fetchDocument(id, _context.accessToken);
|
|
62
|
-
return { blocks: [linkButton(doc.title, url)] };
|
|
63
|
-
},
|
|
84
|
+
export const remarkRenderDirectives = createRemarkRenderer<MyContext, Block>(
|
|
85
|
+
renderDirective,
|
|
64
86
|
);
|
|
87
|
+
|
|
88
|
+
// directives/document.ts
|
|
89
|
+
defineDirective("document", async ({ props, context }) => {
|
|
90
|
+
const doc = await fetchDocument(props.id, context.accessToken);
|
|
91
|
+
return { blocks: [linkButton(doc.title, url)] };
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// directives/changes.ts - simple text output
|
|
95
|
+
defineDirective("changes", ({ props }) => {
|
|
96
|
+
return {
|
|
97
|
+
text: `Created: ${props.createdCount}, Updated: ${props.updatedCount}`,
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// markdown.ts
|
|
102
|
+
import remarkDirective from "remark-directive";
|
|
103
|
+
|
|
104
|
+
async function toMarkdown(content: string, context: MyContext) {
|
|
105
|
+
const collector = { blocks: [] };
|
|
106
|
+
|
|
107
|
+
const processor = unified()
|
|
108
|
+
.use(remarkParse)
|
|
109
|
+
.use(remarkDirective)
|
|
110
|
+
.use(remarkRenderDirectives, context, collector)
|
|
111
|
+
.use(remarkStringify);
|
|
112
|
+
|
|
113
|
+
const file = await processor.process(content);
|
|
114
|
+
return { text: String(file), blocks: collector.blocks };
|
|
115
|
+
}
|
|
65
116
|
```
|
|
66
117
|
|
|
67
118
|
## Formatters
|
|
68
119
|
|
|
120
|
+
For generating directive strings (agent backend):
|
|
121
|
+
|
|
69
122
|
```ts
|
|
70
123
|
import { createDocumentDirective } from "@sanity/agent-directives/formatters";
|
|
71
124
|
|
|
@@ -75,23 +128,35 @@ createDocumentDirective({ id: "doc-123", type: "article" });
|
|
|
75
128
|
|
|
76
129
|
## Adding a New Directive
|
|
77
130
|
|
|
78
|
-
|
|
131
|
+
Edit `src/schemas.ts`:
|
|
79
132
|
|
|
80
133
|
```ts
|
|
134
|
+
// 1. Add schema
|
|
81
135
|
export const MyDirectiveSchema = z.object({
|
|
82
136
|
id: z.string(),
|
|
83
|
-
|
|
137
|
+
title: z.string().optional(),
|
|
84
138
|
});
|
|
85
|
-
```
|
|
86
139
|
|
|
87
|
-
2. Add to
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
140
|
+
// 2. Add to DirectiveSchemas
|
|
141
|
+
export const DirectiveSchemas = {
|
|
142
|
+
// ...existing
|
|
143
|
+
my: MyDirectiveSchema,
|
|
144
|
+
} as const;
|
|
145
|
+
|
|
146
|
+
// 3. Add to DIRECTIVE_NAMES
|
|
147
|
+
export const DIRECTIVE_NAMES = {
|
|
148
|
+
// ...existing
|
|
149
|
+
my: "my",
|
|
150
|
+
} as const;
|
|
151
|
+
|
|
152
|
+
// 4. Add type
|
|
153
|
+
export type MyDirectiveProps = z.infer<typeof MyDirectiveSchema>;
|
|
154
|
+
|
|
155
|
+
// 5. Add to DirectivePropsMap
|
|
156
|
+
export interface DirectivePropsMap {
|
|
157
|
+
// ...existing
|
|
158
|
+
my: MyDirectiveProps;
|
|
94
159
|
}
|
|
95
160
|
```
|
|
96
161
|
|
|
97
|
-
|
|
162
|
+
Then define the render function in your client using `defineDirective('my', ...)`.
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const DocumentDirectiveSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
type: z.ZodOptional<z.ZodString>;
|
|
5
|
+
source: z.ZodOptional<z.ZodString>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
id: string;
|
|
8
|
+
type?: string | undefined;
|
|
9
|
+
source?: string | undefined;
|
|
10
|
+
}, {
|
|
11
|
+
id: string;
|
|
12
|
+
type?: string | undefined;
|
|
13
|
+
source?: string | undefined;
|
|
14
|
+
}>;
|
|
15
|
+
declare const ReleaseDirectiveSchema: z.ZodObject<{
|
|
16
|
+
id: z.ZodString;
|
|
17
|
+
source: z.ZodOptional<z.ZodString>;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
id: string;
|
|
20
|
+
source?: string | undefined;
|
|
21
|
+
}, {
|
|
22
|
+
id: string;
|
|
23
|
+
source?: string | undefined;
|
|
24
|
+
}>;
|
|
25
|
+
declare const ResourceDirectiveSchema: z.ZodObject<{
|
|
26
|
+
source: z.ZodString;
|
|
27
|
+
}, "strip", z.ZodTypeAny, {
|
|
28
|
+
source: string;
|
|
29
|
+
}, {
|
|
30
|
+
source: string;
|
|
31
|
+
}>;
|
|
32
|
+
declare const SetDirectiveSchema: z.ZodObject<{
|
|
33
|
+
id: z.ZodString;
|
|
34
|
+
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
id: string;
|
|
36
|
+
}, {
|
|
37
|
+
id: string;
|
|
38
|
+
}>;
|
|
39
|
+
declare const ChangesDirectiveSchema: z.ZodObject<{
|
|
40
|
+
createdCount: z.ZodNumber;
|
|
41
|
+
updatedCount: z.ZodNumber;
|
|
42
|
+
}, "strip", z.ZodTypeAny, {
|
|
43
|
+
createdCount: number;
|
|
44
|
+
updatedCount: number;
|
|
45
|
+
}, {
|
|
46
|
+
createdCount: number;
|
|
47
|
+
updatedCount: number;
|
|
48
|
+
}>;
|
|
49
|
+
declare const DirectiveSchemas: {
|
|
50
|
+
readonly document: z.ZodObject<{
|
|
51
|
+
id: z.ZodString;
|
|
52
|
+
type: z.ZodOptional<z.ZodString>;
|
|
53
|
+
source: z.ZodOptional<z.ZodString>;
|
|
54
|
+
}, "strip", z.ZodTypeAny, {
|
|
55
|
+
id: string;
|
|
56
|
+
type?: string | undefined;
|
|
57
|
+
source?: string | undefined;
|
|
58
|
+
}, {
|
|
59
|
+
id: string;
|
|
60
|
+
type?: string | undefined;
|
|
61
|
+
source?: string | undefined;
|
|
62
|
+
}>;
|
|
63
|
+
readonly release: z.ZodObject<{
|
|
64
|
+
id: z.ZodString;
|
|
65
|
+
source: z.ZodOptional<z.ZodString>;
|
|
66
|
+
}, "strip", z.ZodTypeAny, {
|
|
67
|
+
id: string;
|
|
68
|
+
source?: string | undefined;
|
|
69
|
+
}, {
|
|
70
|
+
id: string;
|
|
71
|
+
source?: string | undefined;
|
|
72
|
+
}>;
|
|
73
|
+
readonly resource: z.ZodObject<{
|
|
74
|
+
source: z.ZodString;
|
|
75
|
+
}, "strip", z.ZodTypeAny, {
|
|
76
|
+
source: string;
|
|
77
|
+
}, {
|
|
78
|
+
source: string;
|
|
79
|
+
}>;
|
|
80
|
+
readonly set: z.ZodObject<{
|
|
81
|
+
id: z.ZodString;
|
|
82
|
+
}, "strip", z.ZodTypeAny, {
|
|
83
|
+
id: string;
|
|
84
|
+
}, {
|
|
85
|
+
id: string;
|
|
86
|
+
}>;
|
|
87
|
+
readonly changes: z.ZodObject<{
|
|
88
|
+
createdCount: z.ZodNumber;
|
|
89
|
+
updatedCount: z.ZodNumber;
|
|
90
|
+
}, "strip", z.ZodTypeAny, {
|
|
91
|
+
createdCount: number;
|
|
92
|
+
updatedCount: number;
|
|
93
|
+
}, {
|
|
94
|
+
createdCount: number;
|
|
95
|
+
updatedCount: number;
|
|
96
|
+
}>;
|
|
97
|
+
};
|
|
98
|
+
declare const DIRECTIVE_NAMES: {
|
|
99
|
+
readonly document: "document";
|
|
100
|
+
readonly release: "release";
|
|
101
|
+
readonly resource: "resource";
|
|
102
|
+
readonly set: "set";
|
|
103
|
+
readonly changes: "changes";
|
|
104
|
+
};
|
|
105
|
+
type DirectiveName = (typeof DIRECTIVE_NAMES)[keyof typeof DIRECTIVE_NAMES];
|
|
106
|
+
type DocumentDirectiveProps = z.infer<typeof DocumentDirectiveSchema>;
|
|
107
|
+
type ReleaseDirectiveProps = z.infer<typeof ReleaseDirectiveSchema>;
|
|
108
|
+
type ResourceDirectiveProps = z.infer<typeof ResourceDirectiveSchema>;
|
|
109
|
+
type SetDirectiveProps = z.infer<typeof SetDirectiveSchema>;
|
|
110
|
+
type ChangesDirectiveProps = z.infer<typeof ChangesDirectiveSchema>;
|
|
111
|
+
interface DirectivePropsMap {
|
|
112
|
+
document: DocumentDirectiveProps;
|
|
113
|
+
release: ReleaseDirectiveProps;
|
|
114
|
+
resource: ResourceDirectiveProps;
|
|
115
|
+
set: SetDirectiveProps;
|
|
116
|
+
changes: ChangesDirectiveProps;
|
|
117
|
+
}
|
|
118
|
+
interface DefineDirectiveOptions {
|
|
119
|
+
/**
|
|
120
|
+
* Whether this directive requires context/application to render.
|
|
121
|
+
* If true (default), the directive won't render without context.
|
|
122
|
+
*/
|
|
123
|
+
requiresContext?: boolean;
|
|
124
|
+
/** @deprecated Use `requiresContext` instead */
|
|
125
|
+
requiresApplication?: boolean;
|
|
126
|
+
}
|
|
127
|
+
declare function formatDirective(name: DirectiveName, props: Record<string, unknown>): string;
|
|
128
|
+
declare function createDocumentDirective(props: DocumentDirectiveProps): string;
|
|
129
|
+
declare function createReleaseDirective(props: ReleaseDirectiveProps): string;
|
|
130
|
+
declare function createResourceDirective(props: ResourceDirectiveProps): string;
|
|
131
|
+
declare function createSetDirective(props: SetDirectiveProps): string;
|
|
132
|
+
declare function createChangesDirective(props: ChangesDirectiveProps): string;
|
|
133
|
+
export { createDocumentDirective as _, DirectiveName as a, createSetDirective as b, DocumentDirectiveProps as c, ReleaseDirectiveSchema as d, ResourceDirectiveProps as f, createChangesDirective as g, SetDirectiveSchema as h, DefineDirectiveOptions as i, DocumentDirectiveSchema as l, SetDirectiveProps as m, ChangesDirectiveSchema as n, DirectivePropsMap as o, ResourceDirectiveSchema as p, DIRECTIVE_NAMES as r, DirectiveSchemas as s, ChangesDirectiveProps as t, ReleaseDirectiveProps as u, createReleaseDirective as v, formatDirective as x, createResourceDirective as y };
|
|
134
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/_internal/index.ts"],"mappings":";cASa,uBAAA,EAAuB,CAAA,CAAA,SAAA;;;;;;;;;;;;;cAMvB,sBAAA,EAAsB,CAAA,CAAA,SAAA;;;;;;;;;;cAKtB,uBAAA,EAAuB,CAAA,CAAA,SAAA;;;;;;;cAIvB,kBAAA,EAAkB,CAAA,CAAA,SAAA;;;;;;;cAIlB,sBAAA,EAAsB,CAAA,CAAA,SAAA;;;;;;;;;;cAKtB,gBAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAQA,eAAA;EAAA;;;;;;KAYD,aAAA,WAAwB,eAAA,eAA8B,eAAA;AAAA,KAEtD,sBAAA,GAAyB,CAAA,CAAE,KAAA,QAAa,uBAAA;AAAA,KACxC,qBAAA,GAAwB,CAAA,CAAE,KAAA,QAAa,sBAAA;AAAA,KACvC,sBAAA,GAAyB,CAAA,CAAE,KAAA,QAAa,uBAAA;AAAA,KACxC,iBAAA,GAAoB,CAAA,CAAE,KAAA,QAAa,kBAAA;AAAA,KACnC,qBAAA,GAAwB,CAAA,CAAE,KAAA,QAAa,sBAAA;AAAA,UAElC,iBAAA;EACf,QAAA,EAAU,sBAAA;EACV,OAAA,EAAS,qBAAA;EACT,QAAA,EAAU,sBAAA;EACV,GAAA,EAAK,iBAAA;EACL,OAAA,EAAS,qBAAA;AAAA;AAAA,UAGM,sBAAA;;;;;EAKf,eAAA;;EAEA,mBAAA;AAAA;AAAA,iBAcc,eAAA,CAAgB,IAAA,EAAM,aAAA,EAAe,KAAA,EAAO,MAAA;AAAA,iBAK5C,uBAAA,CAAwB,KAAA,EAAO,sBAAA;AAAA,iBAI/B,sBAAA,CAAuB,KAAA,EAAO,qBAAA;AAAA,iBAI9B,uBAAA,CAAwB,KAAA,EAAO,sBAAA;AAAA,iBAI/B,kBAAA,CAAmB,KAAA,EAAO,iBAAA;AAAA,iBAI1B,sBAAA,CAAuB,KAAA,EAAO,qBAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export { type ChangesDirectiveProps, ChangesDirectiveSchema, DIRECTIVE_NAMES, type DirectiveName, type DirectivePropsMap, DirectiveSchemas, type DocumentDirectiveProps, DocumentDirectiveSchema, type ReleaseDirectiveProps, ReleaseDirectiveSchema, type ResourceDirectiveProps, ResourceDirectiveSchema, type SetDirectiveProps, SetDirectiveSchema,
|
|
3
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
import { _ as createDocumentDirective, a as DirectiveName, b as createSetDirective, c as DocumentDirectiveProps, d as ReleaseDirectiveSchema, f as ResourceDirectiveProps, g as createChangesDirective, h as SetDirectiveSchema, i as DefineDirectiveOptions, l as DocumentDirectiveSchema, m as SetDirectiveProps, n as ChangesDirectiveSchema, o as DirectivePropsMap, p as ResourceDirectiveSchema, r as DIRECTIVE_NAMES, s as DirectiveSchemas, t as ChangesDirectiveProps, u as ReleaseDirectiveProps, v as createReleaseDirective, x as formatDirective, y as createResourceDirective } from "./_chunks-dts/index.js";
|
|
2
|
+
export { type ChangesDirectiveProps, ChangesDirectiveSchema, DIRECTIVE_NAMES, type DefineDirectiveOptions, type DirectiveName, type DirectivePropsMap, DirectiveSchemas, type DocumentDirectiveProps, DocumentDirectiveSchema, type ReleaseDirectiveProps, ReleaseDirectiveSchema, type ResourceDirectiveProps, ResourceDirectiveSchema, type SetDirectiveProps, SetDirectiveSchema, createChangesDirective, createDocumentDirective, createReleaseDirective, createResourceDirective, createSetDirective, formatDirective };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const DocumentDirectiveSchema = z.object({
|
|
3
|
+
id: z.string(),
|
|
4
|
+
type: z.string().optional(),
|
|
5
|
+
source: z.string().optional()
|
|
6
|
+
}), ReleaseDirectiveSchema = z.object({
|
|
7
|
+
id: z.string(),
|
|
8
|
+
source: z.string().optional()
|
|
9
|
+
}), ResourceDirectiveSchema = z.object({
|
|
10
|
+
source: z.string()
|
|
11
|
+
}), SetDirectiveSchema = z.object({
|
|
12
|
+
id: z.string()
|
|
13
|
+
}), ChangesDirectiveSchema = z.object({
|
|
14
|
+
createdCount: z.coerce.number().min(0),
|
|
15
|
+
updatedCount: z.coerce.number().min(0)
|
|
16
|
+
}), DirectiveSchemas = {
|
|
17
|
+
document: DocumentDirectiveSchema,
|
|
18
|
+
release: ReleaseDirectiveSchema,
|
|
19
|
+
resource: ResourceDirectiveSchema,
|
|
20
|
+
set: SetDirectiveSchema,
|
|
21
|
+
changes: ChangesDirectiveSchema
|
|
22
|
+
}, DIRECTIVE_NAMES = {
|
|
23
|
+
document: "document",
|
|
24
|
+
release: "release",
|
|
25
|
+
resource: "resource",
|
|
26
|
+
set: "set",
|
|
27
|
+
changes: "changes"
|
|
28
|
+
};
|
|
29
|
+
function buildAttributes(params) {
|
|
30
|
+
return Object.entries(params).filter(([, value]) => value != null).map(([key, value]) => `${key}="${value}"`).join(" ");
|
|
31
|
+
}
|
|
32
|
+
function formatDirective(name, props) {
|
|
33
|
+
const attrs = buildAttributes(props);
|
|
34
|
+
return attrs ? `::${name}{${attrs}}` : `::${name}`;
|
|
35
|
+
}
|
|
36
|
+
function createDocumentDirective(props) {
|
|
37
|
+
return formatDirective(DIRECTIVE_NAMES.document, props);
|
|
38
|
+
}
|
|
39
|
+
function createReleaseDirective(props) {
|
|
40
|
+
return formatDirective(DIRECTIVE_NAMES.release, props);
|
|
41
|
+
}
|
|
42
|
+
function createResourceDirective(props) {
|
|
43
|
+
return formatDirective(DIRECTIVE_NAMES.resource, props);
|
|
44
|
+
}
|
|
45
|
+
function createSetDirective(props) {
|
|
46
|
+
return formatDirective(DIRECTIVE_NAMES.set, props);
|
|
47
|
+
}
|
|
48
|
+
function createChangesDirective(props) {
|
|
49
|
+
return formatDirective(DIRECTIVE_NAMES.changes, props);
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
ChangesDirectiveSchema,
|
|
53
|
+
DIRECTIVE_NAMES,
|
|
54
|
+
DirectiveSchemas,
|
|
55
|
+
DocumentDirectiveSchema,
|
|
56
|
+
ReleaseDirectiveSchema,
|
|
57
|
+
ResourceDirectiveSchema,
|
|
58
|
+
SetDirectiveSchema,
|
|
59
|
+
createChangesDirective,
|
|
60
|
+
createDocumentDirective,
|
|
61
|
+
createReleaseDirective,
|
|
62
|
+
createResourceDirective,
|
|
63
|
+
createSetDirective,
|
|
64
|
+
formatDirective
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/_internal/index.ts"],"sourcesContent":["// This internal module contains all shared code that both the main index\n// and sub-exports can import without causing self-referencing issues with pkg-utils\n\nimport { z } from 'zod'\n\n// ============================================================================\n// Schemas\n// ============================================================================\n\nexport const DocumentDirectiveSchema = z.object({\n id: z.string(),\n type: z.string().optional(),\n source: z.string().optional(),\n})\n\nexport const ReleaseDirectiveSchema = z.object({\n id: z.string(),\n source: z.string().optional(),\n})\n\nexport const ResourceDirectiveSchema = z.object({\n source: z.string(),\n})\n\nexport const SetDirectiveSchema = z.object({\n id: z.string(),\n})\n\nexport const ChangesDirectiveSchema = z.object({\n createdCount: z.coerce.number().min(0),\n updatedCount: z.coerce.number().min(0),\n})\n\nexport const DirectiveSchemas = {\n document: DocumentDirectiveSchema,\n release: ReleaseDirectiveSchema,\n resource: ResourceDirectiveSchema,\n set: SetDirectiveSchema,\n changes: ChangesDirectiveSchema,\n} as const\n\nexport const DIRECTIVE_NAMES = {\n document: 'document',\n release: 'release',\n resource: 'resource',\n set: 'set',\n changes: 'changes',\n} as const\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport type DirectiveName = (typeof DIRECTIVE_NAMES)[keyof typeof DIRECTIVE_NAMES]\n\nexport type DocumentDirectiveProps = z.infer<typeof DocumentDirectiveSchema>\nexport type ReleaseDirectiveProps = z.infer<typeof ReleaseDirectiveSchema>\nexport type ResourceDirectiveProps = z.infer<typeof ResourceDirectiveSchema>\nexport type SetDirectiveProps = z.infer<typeof SetDirectiveSchema>\nexport type ChangesDirectiveProps = z.infer<typeof ChangesDirectiveSchema>\n\nexport interface DirectivePropsMap {\n document: DocumentDirectiveProps\n release: ReleaseDirectiveProps\n resource: ResourceDirectiveProps\n set: SetDirectiveProps\n changes: ChangesDirectiveProps\n}\n\nexport interface DefineDirectiveOptions {\n /**\n * Whether this directive requires context/application to render.\n * If true (default), the directive won't render without context.\n */\n requiresContext?: boolean\n /** @deprecated Use `requiresContext` instead */\n requiresApplication?: boolean\n}\n\n// ============================================================================\n// Formatter Functions\n// ============================================================================\n\nfunction buildAttributes(params: Record<string, unknown>): string {\n return Object.entries(params)\n .filter(([, value]) => value !== undefined && value !== null)\n .map(([key, value]) => `${key}=\"${value}\"`)\n .join(' ')\n}\n\nexport function formatDirective(name: DirectiveName, props: Record<string, unknown>): string {\n const attrs = buildAttributes(props)\n return attrs ? `::${name}{${attrs}}` : `::${name}`\n}\n\nexport function createDocumentDirective(props: DocumentDirectiveProps): string {\n return formatDirective(DIRECTIVE_NAMES.document, props)\n}\n\nexport function createReleaseDirective(props: ReleaseDirectiveProps): string {\n return formatDirective(DIRECTIVE_NAMES.release, props)\n}\n\nexport function createResourceDirective(props: ResourceDirectiveProps): string {\n return formatDirective(DIRECTIVE_NAMES.resource, props)\n}\n\nexport function createSetDirective(props: SetDirectiveProps): string {\n return formatDirective(DIRECTIVE_NAMES.set, props)\n}\n\nexport function createChangesDirective(props: ChangesDirectiveProps): string {\n return formatDirective(DIRECTIVE_NAMES.changes, props)\n}\n"],"names":[],"mappings":";AASO,MAAM,0BAA0B,EAAE,OAAO;AAAA,EAC9C,IAAI,EAAE,OAAA;AAAA,EACN,MAAM,EAAE,OAAA,EAAS,SAAA;AAAA,EACjB,QAAQ,EAAE,OAAA,EAAS,SAAA;AACrB,CAAC,GAEY,yBAAyB,EAAE,OAAO;AAAA,EAC7C,IAAI,EAAE,OAAA;AAAA,EACN,QAAQ,EAAE,OAAA,EAAS,SAAA;AACrB,CAAC,GAEY,0BAA0B,EAAE,OAAO;AAAA,EAC9C,QAAQ,EAAE,OAAA;AACZ,CAAC,GAEY,qBAAqB,EAAE,OAAO;AAAA,EACzC,IAAI,EAAE,OAAA;AACR,CAAC,GAEY,yBAAyB,EAAE,OAAO;AAAA,EAC7C,cAAc,EAAE,OAAO,OAAA,EAAS,IAAI,CAAC;AAAA,EACrC,cAAc,EAAE,OAAO,OAAA,EAAS,IAAI,CAAC;AACvC,CAAC,GAEY,mBAAmB;AAAA,EAC9B,UAAU;AAAA,EACV,SAAS;AAAA,EACT,UAAU;AAAA,EACV,KAAK;AAAA,EACL,SAAS;AACX,GAEa,kBAAkB;AAAA,EAC7B,UAAU;AAAA,EACV,SAAS;AAAA,EACT,UAAU;AAAA,EACV,KAAK;AAAA,EACL,SAAS;AACX;AAoCA,SAAS,gBAAgB,QAAyC;AAChE,SAAO,OAAO,QAAQ,MAAM,EACzB,OAAO,CAAC,CAAA,EAAG,KAAK,MAA6B,SAAU,IAAI,EAC3D,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,GAAG,GAAG,KAAK,KAAK,GAAG,EACzC,KAAK,GAAG;AACb;AAEO,SAAS,gBAAgB,MAAqB,OAAwC;AAC3F,QAAM,QAAQ,gBAAgB,KAAK;AACnC,SAAO,QAAQ,KAAK,IAAI,IAAI,KAAK,MAAM,KAAK,IAAI;AAClD;AAEO,SAAS,wBAAwB,OAAuC;AAC7E,SAAO,gBAAgB,gBAAgB,UAAU,KAAK;AACxD;AAEO,SAAS,uBAAuB,OAAsC;AAC3E,SAAO,gBAAgB,gBAAgB,SAAS,KAAK;AACvD;AAEO,SAAS,wBAAwB,OAAuC;AAC7E,SAAO,gBAAgB,gBAAgB,UAAU,KAAK;AACxD;AAEO,SAAS,mBAAmB,OAAkC;AACnE,SAAO,gBAAgB,gBAAgB,KAAK,KAAK;AACnD;AAEO,SAAS,uBAAuB,OAAsC;AAC3E,SAAO,gBAAgB,gBAAgB,SAAS,KAAK;AACvD;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as createDocumentDirective, a as DirectiveName, b as createSetDirective, c as DocumentDirectiveProps, f as ResourceDirectiveProps, g as createChangesDirective, m as SetDirectiveProps, r as DIRECTIVE_NAMES, t as ChangesDirectiveProps, u as ReleaseDirectiveProps, v as createReleaseDirective, x as formatDirective, y as createResourceDirective } from "../_chunks-dts/index.js";
|
|
2
|
+
export { type ChangesDirectiveProps, DIRECTIVE_NAMES, type DirectiveName, type DocumentDirectiveProps, type ReleaseDirectiveProps, type ResourceDirectiveProps, type SetDirectiveProps, createChangesDirective, createDocumentDirective, createReleaseDirective, createResourceDirective, createSetDirective, formatDirective };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DIRECTIVE_NAMES, createChangesDirective, createDocumentDirective, createReleaseDirective, createResourceDirective, createSetDirective, formatDirective } from "../index.js";
|
|
2
|
+
export {
|
|
3
|
+
DIRECTIVE_NAMES,
|
|
4
|
+
createChangesDirective,
|
|
5
|
+
createDocumentDirective,
|
|
6
|
+
createReleaseDirective,
|
|
7
|
+
createResourceDirective,
|
|
8
|
+
createSetDirective,
|
|
9
|
+
formatDirective
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=formatters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|