@nordcraft/core 1.0.78 → 1.0.79
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/api/ToddleApiV2.d.ts +2 -2
- package/dist/api/apiTypes.d.ts +1 -1
- package/dist/component/component.types.d.ts +1 -1
- package/dist/component/schemas/action-schema.d.ts +3 -0
- package/dist/component/schemas/action-schema.js +169 -0
- package/dist/component/schemas/action-schema.js.map +1 -0
- package/dist/component/schemas/api-schema.d.ts +3 -0
- package/dist/component/schemas/api-schema.js +174 -0
- package/dist/component/schemas/api-schema.js.map +1 -0
- package/dist/component/schemas/attribute-schema.d.ts +3 -0
- package/dist/component/schemas/attribute-schema.js +12 -0
- package/dist/component/schemas/attribute-schema.js.map +1 -0
- package/dist/component/schemas/component-schema.d.ts +6 -0
- package/dist/component/schemas/component-schema.js +132 -0
- package/dist/component/schemas/component-schema.js.map +1 -0
- package/dist/component/schemas/context-schema.d.ts +3 -0
- package/dist/component/schemas/context-schema.js +20 -0
- package/dist/component/schemas/context-schema.js.map +1 -0
- package/dist/component/schemas/event-schema.d.ts +4 -0
- package/dist/component/schemas/event-schema.js +25 -0
- package/dist/component/schemas/event-schema.js.map +1 -0
- package/dist/component/schemas/formula-schema.d.ts +5 -0
- package/dist/component/schemas/formula-schema.js +203 -0
- package/dist/component/schemas/formula-schema.js.map +1 -0
- package/dist/component/schemas/node-schema.d.ts +3 -0
- package/dist/component/schemas/node-schema.js +159 -0
- package/dist/component/schemas/node-schema.js.map +1 -0
- package/dist/component/schemas/route-schema.d.ts +3 -0
- package/dist/component/schemas/route-schema.js +88 -0
- package/dist/component/schemas/route-schema.js.map +1 -0
- package/dist/component/schemas/variable-schema.d.ts +3 -0
- package/dist/component/schemas/variable-schema.js +8 -0
- package/dist/component/schemas/variable-schema.js.map +1 -0
- package/dist/component/schemas/workflow-schema.d.ts +3 -0
- package/dist/component/schemas/workflow-schema.js +23 -0
- package/dist/component/schemas/workflow-schema.js.map +1 -0
- package/dist/component/schemas/zod-schemas.d.ts +26 -3
- package/dist/component/schemas/zod-schemas.js +4 -1081
- package/dist/component/schemas/zod-schemas.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils/collections.d.ts +1 -1
- package/dist/utils/collections.js.map +1 -1
- package/package.json +1 -1
- package/src/api/apiTypes.ts +1 -1
- package/src/component/component.types.ts +1 -1
- package/src/component/schemas/action-schema.ts +258 -0
- package/src/component/schemas/api-schema.ts +255 -0
- package/src/component/schemas/attribute-schema.ts +15 -0
- package/src/component/schemas/component-schema.ts +174 -0
- package/src/component/schemas/context-schema.ts +21 -0
- package/src/component/schemas/event-schema.ts +35 -0
- package/src/component/schemas/formula-schema.ts +299 -0
- package/src/component/schemas/node-schema.ts +259 -0
- package/src/component/schemas/route-schema.ts +135 -0
- package/src/component/schemas/variable-schema.ts +11 -0
- package/src/component/schemas/workflow-schema.ts +30 -0
- package/src/component/schemas/zod-schemas.ts +4 -1493
- package/src/types.ts +1 -1
- package/src/utils/collections.ts +4 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import type { ComponentAttribute } from '../component.types'
|
|
3
|
+
import { MetadataSchema, SCHEMA_DESCRIPTIONS } from './zod-schemas'
|
|
4
|
+
|
|
5
|
+
export const ComponentAttributeSchema: z.ZodType<ComponentAttribute> = z
|
|
6
|
+
.object({
|
|
7
|
+
'@nordcraft/metadata': MetadataSchema.nullish().describe(
|
|
8
|
+
SCHEMA_DESCRIPTIONS.metadata('component attribute'),
|
|
9
|
+
),
|
|
10
|
+
name: z.string().describe('Name of the component attribute'),
|
|
11
|
+
testValue: z
|
|
12
|
+
.any()
|
|
13
|
+
.describe(SCHEMA_DESCRIPTIONS.testData('component attribute')),
|
|
14
|
+
})
|
|
15
|
+
.describe('Schema for a component attribute.')
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import type { Component, PageComponent } from '../component.types'
|
|
3
|
+
import { ActionModelSchema } from './action-schema'
|
|
4
|
+
import { ComponentAPISchema } from './api-schema'
|
|
5
|
+
import { ComponentAttributeSchema } from './attribute-schema'
|
|
6
|
+
import { ComponentContextSchema } from './context-schema'
|
|
7
|
+
import { ComponentEventSchema } from './event-schema'
|
|
8
|
+
import { ComponentFormulaSchema } from './formula-schema'
|
|
9
|
+
import { NodeModelSchema } from './node-schema'
|
|
10
|
+
import { RouteSchema } from './route-schema'
|
|
11
|
+
import { ComponentVariableSchema } from './variable-schema'
|
|
12
|
+
import { ComponentWorkflowSchema } from './workflow-schema'
|
|
13
|
+
import { SCHEMA_DESCRIPTIONS } from './zod-schemas'
|
|
14
|
+
|
|
15
|
+
const commonComponentSchema = (type: 'component' | 'page') =>
|
|
16
|
+
z
|
|
17
|
+
.object({
|
|
18
|
+
name: z.string().describe(`Name of the ${type}`),
|
|
19
|
+
exported: z
|
|
20
|
+
.boolean()
|
|
21
|
+
.nullish()
|
|
22
|
+
.describe(
|
|
23
|
+
`Whether the ${type} is exported in a package project for use in other projects. Do not change this value. It should be managed by the user.`,
|
|
24
|
+
),
|
|
25
|
+
nodes: z
|
|
26
|
+
.record(z.string(), NodeModelSchema)
|
|
27
|
+
.nullish()
|
|
28
|
+
.describe(
|
|
29
|
+
`All nodes in the ${type}, indexed by their unique IDs. Nodes represent HTML elements, text, slots, or ${type === 'component' ? 'other components' : 'components'}. They defined the UI structure of the ${type}.`,
|
|
30
|
+
),
|
|
31
|
+
variables: z
|
|
32
|
+
.record(z.string(), ComponentVariableSchema)
|
|
33
|
+
.nullish()
|
|
34
|
+
.describe(SCHEMA_DESCRIPTIONS.variables(type)),
|
|
35
|
+
formulas: z
|
|
36
|
+
.record(z.string(), ComponentFormulaSchema)
|
|
37
|
+
.nullish()
|
|
38
|
+
.describe(SCHEMA_DESCRIPTIONS.formulas(type)),
|
|
39
|
+
workflows: z
|
|
40
|
+
.record(z.string(), ComponentWorkflowSchema)
|
|
41
|
+
.nullish()
|
|
42
|
+
.describe(SCHEMA_DESCRIPTIONS.workflows(type)),
|
|
43
|
+
apis: z
|
|
44
|
+
.record(z.string(), ComponentAPISchema)
|
|
45
|
+
.nullish()
|
|
46
|
+
.describe(SCHEMA_DESCRIPTIONS.apis(type)),
|
|
47
|
+
events: z
|
|
48
|
+
.array(ComponentEventSchema)
|
|
49
|
+
.nullish()
|
|
50
|
+
.describe(
|
|
51
|
+
'All events this the component can emit. Events allow the component to communicate with its parent or other components. They can be triggered via actions.',
|
|
52
|
+
),
|
|
53
|
+
contexts: z
|
|
54
|
+
.record(z.string(), ComponentContextSchema)
|
|
55
|
+
.nullish()
|
|
56
|
+
.describe(
|
|
57
|
+
'Defines which contexts this component is subscribed to. Contexts allow the component to access formulas and workflows from other components, enabling reusability and modular design.',
|
|
58
|
+
),
|
|
59
|
+
onLoad: z
|
|
60
|
+
.object({
|
|
61
|
+
trigger: z.literal('Load'),
|
|
62
|
+
actions: z.array(ActionModelSchema),
|
|
63
|
+
})
|
|
64
|
+
.nullish()
|
|
65
|
+
.describe(SCHEMA_DESCRIPTIONS.onLoad(type)),
|
|
66
|
+
onAttributeChange: z
|
|
67
|
+
.object({
|
|
68
|
+
trigger: z.literal('Attribute change'),
|
|
69
|
+
actions: z.array(ActionModelSchema),
|
|
70
|
+
})
|
|
71
|
+
.nullish()
|
|
72
|
+
.describe(SCHEMA_DESCRIPTIONS.onAttributeChange(type)),
|
|
73
|
+
})
|
|
74
|
+
.describe('Schema defining a reusable Nordcraft component.')
|
|
75
|
+
|
|
76
|
+
export const ComponentSchema: z.ZodType<Component> = commonComponentSchema(
|
|
77
|
+
'component',
|
|
78
|
+
).extend({
|
|
79
|
+
attributes: z
|
|
80
|
+
.record(z.string(), ComponentAttributeSchema)
|
|
81
|
+
.nullish()
|
|
82
|
+
.describe(
|
|
83
|
+
'All attributes that can be passed into the component when it is used. Attributes allow for customization and configuration of the component instance. When the value of an attribute changes, any formulas depending on it will automatically recalculate and the onAttributeChange lifecycle event is triggered.',
|
|
84
|
+
),
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
export const PageSchema: z.ZodType<PageComponent> = commonComponentSchema(
|
|
88
|
+
'page',
|
|
89
|
+
).extend({
|
|
90
|
+
attributes: z
|
|
91
|
+
.object({})
|
|
92
|
+
.nullish()
|
|
93
|
+
.describe(
|
|
94
|
+
'Attributes for the page (currently none). Should always be an empty object.',
|
|
95
|
+
),
|
|
96
|
+
route: RouteSchema.describe(
|
|
97
|
+
'Route information for the page, including path segments, query parameters, and metadata such as title and description.',
|
|
98
|
+
),
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
const shallowCommonComponentSchema = (type: 'component' | 'page') =>
|
|
102
|
+
z
|
|
103
|
+
.object({
|
|
104
|
+
name: z.string().describe(`Name of the ${type}`),
|
|
105
|
+
exported: z
|
|
106
|
+
.boolean()
|
|
107
|
+
.nullish()
|
|
108
|
+
.describe(
|
|
109
|
+
`Whether the ${type} is exported in a package project for use in other projects. Do not change this value. It should be managed by the user.`,
|
|
110
|
+
),
|
|
111
|
+
nodes: z
|
|
112
|
+
.record(z.string(), z.any())
|
|
113
|
+
.nullish()
|
|
114
|
+
.describe(
|
|
115
|
+
`All nodes in the ${type}, indexed by their unique IDs. Nodes represent HTML elements, text, slots, or ${type === 'component' ? 'other components' : 'components'}. They defined the UI structure of the ${type}.`,
|
|
116
|
+
),
|
|
117
|
+
variables: z
|
|
118
|
+
.record(z.string(), z.any())
|
|
119
|
+
.nullish()
|
|
120
|
+
.describe(SCHEMA_DESCRIPTIONS.variables(type)),
|
|
121
|
+
formulas: z
|
|
122
|
+
.record(z.string(), z.any())
|
|
123
|
+
.nullish()
|
|
124
|
+
.describe(SCHEMA_DESCRIPTIONS.formulas(type)),
|
|
125
|
+
workflows: z
|
|
126
|
+
.record(z.string(), z.any())
|
|
127
|
+
.nullish()
|
|
128
|
+
.describe(SCHEMA_DESCRIPTIONS.workflows(type)),
|
|
129
|
+
apis: z
|
|
130
|
+
.record(z.string(), z.any())
|
|
131
|
+
.nullish()
|
|
132
|
+
.describe(SCHEMA_DESCRIPTIONS.apis(type)),
|
|
133
|
+
events: z
|
|
134
|
+
.array(z.any())
|
|
135
|
+
.nullish()
|
|
136
|
+
.describe(
|
|
137
|
+
'All events this the component can emit. Events allow the component to communicate with its parent or other components. They can be triggered via actions.',
|
|
138
|
+
),
|
|
139
|
+
contexts: z
|
|
140
|
+
.record(z.string(), z.any())
|
|
141
|
+
.nullish()
|
|
142
|
+
.describe(
|
|
143
|
+
'Defines which contexts this component is subscribed to. Contexts allow the component to access formulas and workflows from other components, enabling reusability and modular design.',
|
|
144
|
+
),
|
|
145
|
+
onLoad: z.any().nullish().describe(SCHEMA_DESCRIPTIONS.onLoad(type)),
|
|
146
|
+
onAttributeChange: z
|
|
147
|
+
.any()
|
|
148
|
+
.nullish()
|
|
149
|
+
.describe(SCHEMA_DESCRIPTIONS.onAttributeChange(type)),
|
|
150
|
+
})
|
|
151
|
+
.describe('Schema defining a reusable Nordcraft component.')
|
|
152
|
+
|
|
153
|
+
export const ShallowComponentSchema: z.ZodType<Component> =
|
|
154
|
+
shallowCommonComponentSchema('component').extend({
|
|
155
|
+
attributes: z
|
|
156
|
+
.record(z.string(), z.any())
|
|
157
|
+
.nullish()
|
|
158
|
+
.describe(
|
|
159
|
+
'All attributes that can be passed into the component when it is used. Attributes allow for customization and configuration of the component instance. When the value of an attribute changes, any formulas depending on it will automatically recalculate and the onAttributeChange lifecycle event is triggered.',
|
|
160
|
+
),
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
export const ShallowPageSchema: z.ZodType<PageComponent> =
|
|
164
|
+
shallowCommonComponentSchema('page').extend({
|
|
165
|
+
attributes: z
|
|
166
|
+
.any()
|
|
167
|
+
.nullish()
|
|
168
|
+
.describe(
|
|
169
|
+
'Attributes for the page (currently none). Should always be an empty object.',
|
|
170
|
+
),
|
|
171
|
+
route: RouteSchema.describe(
|
|
172
|
+
'Route information for the page, including path segments, query parameters, and metadata such as title and description.',
|
|
173
|
+
),
|
|
174
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import type { ComponentContext } from '../component.types'
|
|
3
|
+
|
|
4
|
+
export const ComponentContextSchema: z.ZodType<ComponentContext> = z
|
|
5
|
+
.object({
|
|
6
|
+
package: z
|
|
7
|
+
.string()
|
|
8
|
+
.nullish()
|
|
9
|
+
.describe('Package name of the component providing the context'),
|
|
10
|
+
componentName: z
|
|
11
|
+
.string()
|
|
12
|
+
.nullish()
|
|
13
|
+
.describe('Name of the component providing the context'),
|
|
14
|
+
formulas: z
|
|
15
|
+
.array(z.string())
|
|
16
|
+
.describe('Names of the formulas from the context to subscribe to'),
|
|
17
|
+
workflows: z
|
|
18
|
+
.array(z.string())
|
|
19
|
+
.describe('Names of the workflows from the context to subscribe to'),
|
|
20
|
+
})
|
|
21
|
+
.describe('Schema defining a component context subscription.')
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* eslint-disable inclusive-language/use-inclusive-words */
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import type { ComponentEvent, EventModel } from '../component.types'
|
|
4
|
+
import { ActionModelSchema } from './action-schema'
|
|
5
|
+
import { MetadataSchema, SCHEMA_DESCRIPTIONS } from './zod-schemas'
|
|
6
|
+
|
|
7
|
+
// Event Model
|
|
8
|
+
export const EventModelSchema: z.ZodType<EventModel> = z
|
|
9
|
+
.lazy(() =>
|
|
10
|
+
z.object({
|
|
11
|
+
trigger: z
|
|
12
|
+
.string()
|
|
13
|
+
.describe(
|
|
14
|
+
'Name of the event trigger. Nordcraft does not prefix events with "on", fx a click event is just called: "click".',
|
|
15
|
+
),
|
|
16
|
+
actions: z
|
|
17
|
+
.array(ActionModelSchema)
|
|
18
|
+
.describe('List of actions to execute.'),
|
|
19
|
+
}),
|
|
20
|
+
)
|
|
21
|
+
.describe(
|
|
22
|
+
'Model describing an event. Events are used to define actions that should be executed in response to specific triggers, such as user interactions or lifecycle events.',
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
export const ComponentEventSchema: z.ZodType<ComponentEvent> = z
|
|
26
|
+
.object({
|
|
27
|
+
'@nordcraft/metadata': MetadataSchema.nullish().describe(
|
|
28
|
+
SCHEMA_DESCRIPTIONS.metadata('component event'),
|
|
29
|
+
),
|
|
30
|
+
name: z.string().describe('Name of the component event'),
|
|
31
|
+
dummyEvent: z
|
|
32
|
+
.any()
|
|
33
|
+
.describe(SCHEMA_DESCRIPTIONS.testData('component event')),
|
|
34
|
+
})
|
|
35
|
+
.describe('Schema for a component event.')
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import type {
|
|
3
|
+
AndOperation,
|
|
4
|
+
ApplyOperation,
|
|
5
|
+
ArrayOperation,
|
|
6
|
+
Formula,
|
|
7
|
+
FunctionArgument,
|
|
8
|
+
FunctionOperation,
|
|
9
|
+
ObjectOperation,
|
|
10
|
+
OrOperation,
|
|
11
|
+
PathOperation,
|
|
12
|
+
RecordOperation,
|
|
13
|
+
SwitchOperation,
|
|
14
|
+
ValueOperation,
|
|
15
|
+
ValueOperationValue,
|
|
16
|
+
} from '../../formula/formula'
|
|
17
|
+
import type { ComponentFormula } from '../component.types'
|
|
18
|
+
import { MetadataSchema, SCHEMA_DESCRIPTIONS } from './zod-schemas'
|
|
19
|
+
|
|
20
|
+
// Value Operation
|
|
21
|
+
const ValueOperationValueSchema: z.ZodType<ValueOperationValue> = z.union([
|
|
22
|
+
z.string(),
|
|
23
|
+
z.number(),
|
|
24
|
+
z.boolean(),
|
|
25
|
+
z.null(),
|
|
26
|
+
z.object({}),
|
|
27
|
+
])
|
|
28
|
+
|
|
29
|
+
const ValueOperationSchema: z.ZodType<ValueOperation> = z.object({
|
|
30
|
+
'@nordcraft/metadata': MetadataSchema.nullish().describe(
|
|
31
|
+
SCHEMA_DESCRIPTIONS.metadata('value operation'),
|
|
32
|
+
),
|
|
33
|
+
type: z.literal('value'),
|
|
34
|
+
value: ValueOperationValueSchema.describe('Literal value.'),
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
// Path Operation
|
|
38
|
+
const PathOperationSchema: z.ZodType<PathOperation> = z.object({
|
|
39
|
+
'@nordcraft/metadata': MetadataSchema.nullish().describe(
|
|
40
|
+
SCHEMA_DESCRIPTIONS.metadata('path operation'),
|
|
41
|
+
),
|
|
42
|
+
type: z.literal('path'),
|
|
43
|
+
path: z
|
|
44
|
+
.array(z.string())
|
|
45
|
+
.describe(
|
|
46
|
+
'Path segments for the path operation. Each segment is a string that corresponds to a property name or array index in the Data object passed to the system prompt.',
|
|
47
|
+
),
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
// Formula argument base
|
|
51
|
+
const FormulaArgumentSchema: z.ZodType<FunctionArgument> = z
|
|
52
|
+
.object({
|
|
53
|
+
get formula() {
|
|
54
|
+
return FormulaSchema.describe('Formula for the argument.')
|
|
55
|
+
},
|
|
56
|
+
isFunction: z
|
|
57
|
+
.boolean()
|
|
58
|
+
.nullish()
|
|
59
|
+
.describe(
|
|
60
|
+
'Whether the argument is a function. This will be true on array formulas like map, filter, reduce, etc. formulas.',
|
|
61
|
+
),
|
|
62
|
+
name: z
|
|
63
|
+
.string()
|
|
64
|
+
.describe(
|
|
65
|
+
'The name of the argument. This name corresponds to the argument name from the formula definition.',
|
|
66
|
+
),
|
|
67
|
+
})
|
|
68
|
+
.describe('Argument for formulas in Nordcraft formulas.')
|
|
69
|
+
|
|
70
|
+
// Array Operation
|
|
71
|
+
const ArrayOperationSchema: z.ZodType<ArrayOperation> = z
|
|
72
|
+
.object({
|
|
73
|
+
'@nordcraft/metadata': MetadataSchema.nullish().describe(
|
|
74
|
+
SCHEMA_DESCRIPTIONS.metadata('array operation'),
|
|
75
|
+
),
|
|
76
|
+
type: z.literal('array'),
|
|
77
|
+
get arguments() {
|
|
78
|
+
return z
|
|
79
|
+
.array(z.object({ formula: FormulaSchema }))
|
|
80
|
+
.describe('List of formulas for the array elements.')
|
|
81
|
+
},
|
|
82
|
+
})
|
|
83
|
+
.describe('Model for describing an array in Nordcraft formulas.')
|
|
84
|
+
|
|
85
|
+
// Object Operation
|
|
86
|
+
const ObjectOperationSchema: z.ZodType<ObjectOperation> = z
|
|
87
|
+
.object({
|
|
88
|
+
'@nordcraft/metadata': MetadataSchema.nullish().describe(
|
|
89
|
+
SCHEMA_DESCRIPTIONS.metadata('object operation'),
|
|
90
|
+
),
|
|
91
|
+
type: z.literal('object'),
|
|
92
|
+
get arguments() {
|
|
93
|
+
return z
|
|
94
|
+
.array(FormulaArgumentSchema)
|
|
95
|
+
.nullish()
|
|
96
|
+
.describe(
|
|
97
|
+
'List of key-value pairs for the object. Each entry must have a name and a formula.',
|
|
98
|
+
)
|
|
99
|
+
},
|
|
100
|
+
})
|
|
101
|
+
.describe('Model for describing an object in Nordcraft formulas.')
|
|
102
|
+
|
|
103
|
+
// Record Operation
|
|
104
|
+
const RecordOperationSchema: z.ZodType<RecordOperation> = z
|
|
105
|
+
.object({
|
|
106
|
+
'@nordcraft/metadata': MetadataSchema.nullish(),
|
|
107
|
+
type: z.literal('record'),
|
|
108
|
+
get entries() {
|
|
109
|
+
return z.array(FormulaArgumentSchema)
|
|
110
|
+
},
|
|
111
|
+
label: z.string().nullish(),
|
|
112
|
+
})
|
|
113
|
+
.describe('Deprecated - use Object operation instead.')
|
|
114
|
+
|
|
115
|
+
// And Operation
|
|
116
|
+
const AndOperationSchema: z.ZodType<AndOperation> = z
|
|
117
|
+
.object({
|
|
118
|
+
'@nordcraft/metadata': MetadataSchema.nullish().describe(
|
|
119
|
+
SCHEMA_DESCRIPTIONS.metadata('AND operation'),
|
|
120
|
+
),
|
|
121
|
+
type: z.literal('and'),
|
|
122
|
+
get arguments() {
|
|
123
|
+
return z
|
|
124
|
+
.array(z.object({ formula: FormulaSchema }))
|
|
125
|
+
.describe(
|
|
126
|
+
'List of formulas to evaluate in the AND operation. All formulas must evaluate to a truthy value for the AND operation to return true.',
|
|
127
|
+
)
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
.describe(
|
|
131
|
+
'Model for describing a logical AND operation. The return value is a boolean value.',
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
// Or Operation
|
|
135
|
+
const OrOperationSchema: z.ZodType<OrOperation> = z
|
|
136
|
+
.object({
|
|
137
|
+
'@nordcraft/metadata': MetadataSchema.nullish().describe(
|
|
138
|
+
SCHEMA_DESCRIPTIONS.metadata('OR operation'),
|
|
139
|
+
),
|
|
140
|
+
type: z.literal('or'),
|
|
141
|
+
get arguments() {
|
|
142
|
+
return z
|
|
143
|
+
.array(z.object({ formula: FormulaSchema }))
|
|
144
|
+
.describe(
|
|
145
|
+
'List of formulas to evaluate in the OR operation. At least one formula must evaluate to a truthy value for the OR operation to return true.',
|
|
146
|
+
)
|
|
147
|
+
},
|
|
148
|
+
})
|
|
149
|
+
.describe(
|
|
150
|
+
'Model for describing a logical OR operation. The return value is a boolean value.',
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
// Switch Operation
|
|
154
|
+
const SwitchOperationSchema: z.ZodType<SwitchOperation> = z
|
|
155
|
+
.object({
|
|
156
|
+
'@nordcraft/metadata': MetadataSchema.nullish(),
|
|
157
|
+
type: z.literal('switch'),
|
|
158
|
+
cases: z
|
|
159
|
+
.array(
|
|
160
|
+
z.object({
|
|
161
|
+
get condition() {
|
|
162
|
+
return z
|
|
163
|
+
.lazy(() => FormulaSchema)
|
|
164
|
+
.describe(
|
|
165
|
+
'Condition to evaluate for this case. If truthy, the formula is used.',
|
|
166
|
+
)
|
|
167
|
+
},
|
|
168
|
+
get formula() {
|
|
169
|
+
return z
|
|
170
|
+
.lazy(() => FormulaSchema)
|
|
171
|
+
.describe('Formula to use if the condition is met.')
|
|
172
|
+
},
|
|
173
|
+
}),
|
|
174
|
+
)
|
|
175
|
+
.length(1)
|
|
176
|
+
.describe(
|
|
177
|
+
'Cases for the switch operation. Each case has a condition and a formula. The length of cases cannot exceed 1 at this time as the UI does not currently support this.',
|
|
178
|
+
),
|
|
179
|
+
get default() {
|
|
180
|
+
return FormulaSchema.describe('Default formula if no case matches.')
|
|
181
|
+
},
|
|
182
|
+
})
|
|
183
|
+
.describe(
|
|
184
|
+
'Model for describing a switch operation. A switch operation allows branching logic based on conditions.',
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
// Project Function Operation
|
|
188
|
+
const ProjectFunctionOperationSchema: z.ZodType<FunctionOperation> = z
|
|
189
|
+
.object({
|
|
190
|
+
'@nordcraft/metadata': MetadataSchema.nullish().describe(
|
|
191
|
+
SCHEMA_DESCRIPTIONS.metadata('project formula operation'),
|
|
192
|
+
),
|
|
193
|
+
type: z.literal('function'),
|
|
194
|
+
name: z
|
|
195
|
+
.string()
|
|
196
|
+
.describe(
|
|
197
|
+
'Key of the project formula to be called. This must match the key of the project formulas passed to the system prompt.',
|
|
198
|
+
),
|
|
199
|
+
get arguments() {
|
|
200
|
+
return z.array(FormulaArgumentSchema).describe('Formula arguments.')
|
|
201
|
+
},
|
|
202
|
+
})
|
|
203
|
+
.describe(
|
|
204
|
+
'Model for describing a Project Formula operation. A Project Formula is a user-defined formula that can be reused across the project.',
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
// Built-in Function Operation
|
|
208
|
+
const BuiltInFunctionOperationSchema: z.ZodType<FunctionOperation> = z.object({
|
|
209
|
+
'@nordcraft/metadata': MetadataSchema.nullish().describe(
|
|
210
|
+
SCHEMA_DESCRIPTIONS.metadata('built-in formula operation'),
|
|
211
|
+
),
|
|
212
|
+
type: z.literal('function'),
|
|
213
|
+
name: z
|
|
214
|
+
.string()
|
|
215
|
+
.describe(
|
|
216
|
+
'Key of the built-in formula to be called. This key is always prefixed with "@toddle/" and can be read from the built-in formula definition.',
|
|
217
|
+
),
|
|
218
|
+
get arguments() {
|
|
219
|
+
return z.array(FormulaArgumentSchema).describe('Formula arguments.')
|
|
220
|
+
},
|
|
221
|
+
display_name: z
|
|
222
|
+
.string()
|
|
223
|
+
.nullish()
|
|
224
|
+
.describe(
|
|
225
|
+
'Human readable label for the operation. This should be set from the "name" read from the built-in formula definition.',
|
|
226
|
+
),
|
|
227
|
+
variableArguments: z
|
|
228
|
+
.boolean()
|
|
229
|
+
.nullish()
|
|
230
|
+
.describe(
|
|
231
|
+
'Field defining if the formula accepts variable number of arguments. This value is read from the built-in formula definition.',
|
|
232
|
+
),
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
// Apply Operation
|
|
236
|
+
const ApplyOperationSchema: z.ZodType<ApplyOperation> = z
|
|
237
|
+
.object({
|
|
238
|
+
'@nordcraft/metadata': MetadataSchema.nullish().describe(
|
|
239
|
+
SCHEMA_DESCRIPTIONS.formulas('apply operation'),
|
|
240
|
+
),
|
|
241
|
+
type: z.literal('apply'),
|
|
242
|
+
name: z
|
|
243
|
+
.string()
|
|
244
|
+
.describe(
|
|
245
|
+
'Key of the formula to be applied. This is the key defined in the formulas object found in the same file.',
|
|
246
|
+
),
|
|
247
|
+
arguments: z
|
|
248
|
+
.array(FormulaArgumentSchema)
|
|
249
|
+
.describe('Arguments to pass to the formula being applied.'),
|
|
250
|
+
})
|
|
251
|
+
.describe(
|
|
252
|
+
'Model for describing an Apply operation. An apply operation is used when a formula wants to run another formula defined in the same file.',
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
// Formula - union of all operation types
|
|
256
|
+
export const FormulaSchema: z.ZodType<Formula> = z.lazy(() =>
|
|
257
|
+
z.union([
|
|
258
|
+
BuiltInFunctionOperationSchema,
|
|
259
|
+
ProjectFunctionOperationSchema,
|
|
260
|
+
RecordOperationSchema,
|
|
261
|
+
ObjectOperationSchema,
|
|
262
|
+
ArrayOperationSchema,
|
|
263
|
+
PathOperationSchema,
|
|
264
|
+
SwitchOperationSchema,
|
|
265
|
+
OrOperationSchema,
|
|
266
|
+
AndOperationSchema,
|
|
267
|
+
ValueOperationSchema,
|
|
268
|
+
ApplyOperationSchema,
|
|
269
|
+
]),
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
export const ComponentFormulaSchema: z.ZodType<ComponentFormula> = z.object({
|
|
273
|
+
'@nordcraft/metadata': MetadataSchema.nullish().describe(
|
|
274
|
+
SCHEMA_DESCRIPTIONS.metadata('formula'),
|
|
275
|
+
),
|
|
276
|
+
name: z.string().describe('Name of the formula'),
|
|
277
|
+
formula: FormulaSchema.describe(
|
|
278
|
+
'Contains the "code" that will be executed when this formula is called.',
|
|
279
|
+
),
|
|
280
|
+
arguments: z
|
|
281
|
+
.array(
|
|
282
|
+
z.object({
|
|
283
|
+
name: z.string().describe('Name of the formula argument'),
|
|
284
|
+
testValue: z.any().describe('Test value for the formula argument'),
|
|
285
|
+
}),
|
|
286
|
+
)
|
|
287
|
+
.nullish()
|
|
288
|
+
.describe('List of arguments accepted by the formula.'),
|
|
289
|
+
memoize: z
|
|
290
|
+
.boolean()
|
|
291
|
+
.nullish()
|
|
292
|
+
.describe('Indicates if the formula result should be memoized.'),
|
|
293
|
+
exposeInContext: z
|
|
294
|
+
.boolean()
|
|
295
|
+
.nullish()
|
|
296
|
+
.describe(
|
|
297
|
+
'Indicates if the formula should be exposed in the component context for child components to subscribe to.',
|
|
298
|
+
),
|
|
299
|
+
})
|