@takeshape/schema 11.98.6 → 11.99.2
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/agents.d.ts +21 -7
- package/dist/agents.js +98 -65
- package/dist/builtin-schema.js +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/migration/types.d.ts +6 -3
- package/dist/migration/types.js +3 -1
- package/dist/models/agent.d.ts +3 -0
- package/dist/models/agent.js +29 -0
- package/dist/models/project-schema.d.ts +17 -0
- package/dist/models/project-schema.js +112 -0
- package/dist/models/query.d.ts +2 -8
- package/dist/models/query.js +16 -4
- package/dist/models/runtime-schema.d.ts +3 -7
- package/dist/models/runtime-schema.js +9 -86
- package/dist/models/shape.d.ts +2 -10
- package/dist/models/shape.js +7 -4
- package/dist/models/types.d.ts +28 -4
- package/dist/models/user-schema.d.ts +7 -0
- package/dist/models/user-schema.js +9 -0
- package/dist/project-schema/latest.d.ts +33 -38
- package/dist/project-schema/v3.48.0.d.ts +33 -38
- package/dist/project-schema/v3.49.0.d.ts +33 -38
- package/dist/project-schema/v3.50.0.d.ts +33 -38
- package/dist/project-schema/v3.51.0.d.ts +33 -38
- package/dist/project-schema/v3.52.0.d.ts +33 -38
- package/dist/project-schema/v3.53.0.d.ts +33 -38
- package/dist/project-schema/v3.54.0.d.ts +33 -38
- package/dist/project-schema/v3.55.0.d.ts +33 -38
- package/dist/refs.js +1 -1
- package/dist/resolvers/takeshape/assets/asset-image-params.d.ts +1 -1
- package/dist/schema-util.d.ts +5 -4
- package/dist/schema-util.js +44 -3
- package/dist/schemas/project-schema/experimental.json +101 -131
- package/dist/util/mcp.d.ts +3 -2
- package/dist/util/mcp.js +1 -1
- package/dist/util/patch-schema.d.ts +1 -1
- package/dist/util/patch-schema.js +4 -3
- package/dist/validate/ai.d.ts +6 -0
- package/dist/validate/ai.js +183 -0
- package/dist/validate/types.d.ts +1 -0
- package/dist/validate/types.js +1 -0
- package/dist/validate/util.d.ts +3 -0
- package/dist/validate/util.js +28 -0
- package/dist/validate/validate.d.ts +1 -0
- package/dist/validate/validate.js +14 -164
- package/examples/latest/agent-schema.json +24 -10
- package/examples/source/agent-schema.json +23 -9
- package/package.json +5 -5
package/dist/agents.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AgentJSON, AgentMap, GuardJSON, GuardMap, ProjectSchemaJSON, QueryJSON } from './project-schema/index.ts';
|
|
2
|
+
export declare const START_AGENT_EXECUTION = "START";
|
|
2
3
|
/**
|
|
3
4
|
* Special transition destination ID for agent transitions that end the agent execution.
|
|
4
5
|
*/
|
|
5
|
-
export declare const END_AGENT_EXECUTION = "
|
|
6
|
+
export declare const END_AGENT_EXECUTION = "END";
|
|
6
7
|
/**
|
|
7
8
|
* Special history strategy ID that indicates the history should be cleared.
|
|
8
9
|
*/
|
|
9
10
|
export declare const CLEAR_HISTORY_STRATEGY_ID = "clearHistory";
|
|
10
|
-
export declare const BUILT_IN_CHAT_ARGS: AgentAPIArgument[];
|
|
11
|
-
export declare const BUILT_IN_CHAT_ARG_NAMES: string[];
|
|
12
11
|
export type AgentEndTransition = {
|
|
13
12
|
type: 'done' | 'progress';
|
|
14
13
|
originStateId: string;
|
|
@@ -16,18 +15,24 @@ export type AgentEndTransition = {
|
|
|
16
15
|
export declare const getAgentEndTransitions: (agent: AgentJSON, includeSuspend?: boolean) => AgentEndTransition[];
|
|
17
16
|
export declare const getAgentEndStates: (agent: AgentJSON, includeSuspend?: boolean) => Set<string>;
|
|
18
17
|
export declare const getInspectAgentSessionQueryName: (agentName: string) => string;
|
|
19
|
-
export declare
|
|
20
|
-
export declare function
|
|
21
|
-
export declare const createArgs: (agent: AgentJSON) => Args | undefined;
|
|
18
|
+
export declare function getAgentQueries(agents: AgentMap): Pick<ProjectSchemaJSON, 'queries' | 'mutations'>;
|
|
19
|
+
export declare function isValidAgentMutation(projectSchema: ProjectSchemaJSON, name: string): boolean;
|
|
22
20
|
export declare function addAiQueries(projectSchema: ProjectSchemaJSON): ProjectSchemaJSON;
|
|
23
21
|
/**
|
|
24
22
|
* Where guards live in the schema.
|
|
25
23
|
*/
|
|
26
24
|
export declare const GUARDS_SCHEMA_PATH: readonly ["ai-experimental", "guards"];
|
|
25
|
+
export declare const AGENTS_SCHEMA_PATH: readonly ["ai-experimental", "agents"];
|
|
27
26
|
/**
|
|
28
27
|
* Check if a guard is enabled.
|
|
29
28
|
*/
|
|
30
29
|
export declare const isGuardEnabled: (guard: GuardJSON | undefined) => boolean;
|
|
30
|
+
export declare function getGuardMap(schema: ProjectSchemaJSON): GuardMap | undefined;
|
|
31
|
+
export declare function getGuards(schema: ProjectSchemaJSON): (GuardJSON & {
|
|
32
|
+
id: string;
|
|
33
|
+
})[];
|
|
34
|
+
export declare function setGuardMap<S extends Partial<ProjectSchemaJSON>>(schema: S, guards: GuardMap): S;
|
|
35
|
+
export declare function setGuard<S extends Partial<ProjectSchemaJSON>>(schema: S, id: string, guard: GuardJSON): S;
|
|
31
36
|
/**
|
|
32
37
|
* Get a guard configuration from the project schema.
|
|
33
38
|
*/
|
|
@@ -36,3 +41,12 @@ export declare function getGuardConfig(schema: ProjectSchemaJSON, guardId: strin
|
|
|
36
41
|
* Get a guard configuration from the project schema, but only if it is enabled.
|
|
37
42
|
*/
|
|
38
43
|
export declare function getEnabledGuardConfig(schema: ProjectSchemaJSON, guardId: string): GuardJSON | undefined;
|
|
44
|
+
export declare function getAgentMap(projectSchema: Pick<ProjectSchemaJSON, 'ai-experimental'>): AgentMap | undefined;
|
|
45
|
+
export declare function getAgents(projectSchema: Pick<ProjectSchemaJSON, 'ai-experimental'>): (AgentJSON & {
|
|
46
|
+
name: string;
|
|
47
|
+
})[] | undefined;
|
|
48
|
+
export declare function setAgentMap<S extends Partial<ProjectSchemaJSON>>(projectSchema: S, agents: AgentMap): S;
|
|
49
|
+
export declare function setAgent<S extends Partial<ProjectSchemaJSON>>(projectSchema: S, name: string, agent: AgentJSON): S;
|
|
50
|
+
export declare function getAgent(projectSchema: ProjectSchemaJSON, name: string): AgentJSON | undefined;
|
|
51
|
+
export declare function ensureAgent(projectSchema: ProjectSchemaJSON, name: string): AgentJSON;
|
|
52
|
+
export declare function isAgentQuery(query: QueryJSON, agentName: string): boolean;
|
package/dist/agents.js
CHANGED
|
@@ -1,35 +1,22 @@
|
|
|
1
|
+
import set from 'lodash/fp/set.js';
|
|
1
2
|
import get from 'lodash/get.js';
|
|
2
3
|
import uniq from 'lodash/uniq.js';
|
|
3
|
-
import uniqBy from 'lodash/uniqBy.js';
|
|
4
4
|
import upperFirst from 'lodash/upperFirst.js';
|
|
5
|
+
export const START_AGENT_EXECUTION = 'START';
|
|
5
6
|
/**
|
|
6
7
|
* Special transition destination ID for agent transitions that end the agent execution.
|
|
7
8
|
*/
|
|
8
|
-
export const END_AGENT_EXECUTION = '
|
|
9
|
+
export const END_AGENT_EXECUTION = 'END';
|
|
9
10
|
/**
|
|
10
11
|
* Special history strategy ID that indicates the history should be cleared.
|
|
11
12
|
*/
|
|
12
13
|
export const CLEAR_HISTORY_STRATEGY_ID = 'clearHistory';
|
|
13
|
-
export const BUILT_IN_CHAT_ARGS = [
|
|
14
|
-
{
|
|
15
|
-
argName: 'input',
|
|
16
|
-
argDescription: 'Input text for the agent',
|
|
17
|
-
argType: 'string',
|
|
18
|
-
required: true
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
argName: 'sessionId',
|
|
22
|
-
argDescription: 'Session ID to continue existing session with this agent',
|
|
23
|
-
argType: 'sessionId'
|
|
24
|
-
}
|
|
25
|
-
];
|
|
26
|
-
export const BUILT_IN_CHAT_ARG_NAMES = BUILT_IN_CHAT_ARGS.map((arg) => arg.argName);
|
|
27
14
|
const transitionCanEnd = (transition, includeSuspend = false) => {
|
|
28
15
|
if (!transition || transition.length === 0) {
|
|
29
16
|
return true;
|
|
30
17
|
}
|
|
31
18
|
for (const step of transition) {
|
|
32
|
-
if (includeSuspend && step.suspend) {
|
|
19
|
+
if (includeSuspend && step.type === 'suspend') {
|
|
33
20
|
return true;
|
|
34
21
|
}
|
|
35
22
|
if (step.destination === END_AGENT_EXECUTION) {
|
|
@@ -59,41 +46,10 @@ export const getAgentEndStates = (agent, includeSuspend = false) => {
|
|
|
59
46
|
export const getInspectAgentSessionQueryName = (agentName) => {
|
|
60
47
|
return `inspect${upperFirst(agentName)}`;
|
|
61
48
|
};
|
|
62
|
-
export
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
let apiArguments = uniqBy(api.arguments ?? [], (arg) => arg.argName);
|
|
67
|
-
if (api.type === 'chat') {
|
|
68
|
-
apiArguments = removeBuiltInArgs(apiArguments).concat(BUILT_IN_CHAT_ARGS);
|
|
69
|
-
}
|
|
70
|
-
return apiArguments;
|
|
71
|
-
}
|
|
72
|
-
export const createArgs = (agent) => {
|
|
73
|
-
const apiArguments = getAgentApiArgs(agent.api);
|
|
74
|
-
return apiArguments.length > 0
|
|
75
|
-
? {
|
|
76
|
-
type: 'object',
|
|
77
|
-
properties: apiArguments.reduce((acc, argument) => {
|
|
78
|
-
acc[argument.argName] = {
|
|
79
|
-
type: argument.argType === 'sessionId' ? 'string' : argument.argType,
|
|
80
|
-
description: argument.argDescription
|
|
81
|
-
};
|
|
82
|
-
return acc;
|
|
83
|
-
}, {}),
|
|
84
|
-
required: apiArguments.filter((arg) => arg.required).map((arg) => arg.argName)
|
|
85
|
-
}
|
|
86
|
-
: undefined;
|
|
87
|
-
};
|
|
88
|
-
export function addAiQueries(projectSchema) {
|
|
89
|
-
const agents = projectSchema['ai-experimental']?.agents;
|
|
90
|
-
if (!agents) {
|
|
91
|
-
return projectSchema;
|
|
92
|
-
}
|
|
93
|
-
const newSchema = {
|
|
94
|
-
...projectSchema,
|
|
95
|
-
queries: { ...projectSchema.queries },
|
|
96
|
-
mutations: { ...projectSchema.mutations }
|
|
49
|
+
export function getAgentQueries(agents) {
|
|
50
|
+
const result = {
|
|
51
|
+
queries: {},
|
|
52
|
+
mutations: {}
|
|
97
53
|
};
|
|
98
54
|
for (const [agentName, agent] of Object.entries(agents)) {
|
|
99
55
|
// Get valid return types based on states that could possibly be the end state
|
|
@@ -111,20 +67,25 @@ export function addAiQueries(projectSchema) {
|
|
|
111
67
|
return 'JSON';
|
|
112
68
|
}));
|
|
113
69
|
const shape = returnTypes.length === 0 ? 'string' : returnTypes.length === 1 ? returnTypes[0] : 'JSON';
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
70
|
+
for (const inputConfig of agent.api.inputs) {
|
|
71
|
+
if (inputConfig.type === 'mutation') {
|
|
72
|
+
const mutationName = inputConfig.name;
|
|
73
|
+
if (result.mutations[mutationName] !== undefined) {
|
|
74
|
+
throw new Error(`Schema already has a mutation with the name "${mutationName}"`);
|
|
75
|
+
}
|
|
76
|
+
result.mutations[mutationName] = {
|
|
77
|
+
description: agent.description,
|
|
78
|
+
args: inputConfig.args,
|
|
79
|
+
shape,
|
|
80
|
+
resolver: {
|
|
81
|
+
name: 'ai:runAgent',
|
|
82
|
+
agentName
|
|
83
|
+
}
|
|
84
|
+
};
|
|
124
85
|
}
|
|
125
|
-
}
|
|
86
|
+
}
|
|
126
87
|
if (shape === 'TSChatResponse') {
|
|
127
|
-
|
|
88
|
+
result.queries[getInspectAgentSessionQueryName(agentName)] ||= {
|
|
128
89
|
description: `Inspect a session for the ${agentName} agent`,
|
|
129
90
|
args: {
|
|
130
91
|
type: 'object',
|
|
@@ -143,18 +104,60 @@ export function addAiQueries(projectSchema) {
|
|
|
143
104
|
};
|
|
144
105
|
}
|
|
145
106
|
}
|
|
146
|
-
return
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
export function isValidAgentMutation(projectSchema, name) {
|
|
110
|
+
for (const agent of Object.values(getAgentMap(projectSchema) ?? {})) {
|
|
111
|
+
for (const input of agent.api.inputs) {
|
|
112
|
+
if (input.type === 'mutation' && input.name === name) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
export function addAiQueries(projectSchema) {
|
|
120
|
+
const agents = getAgentMap(projectSchema);
|
|
121
|
+
if (!agents) {
|
|
122
|
+
return projectSchema;
|
|
123
|
+
}
|
|
124
|
+
const aiQueries = getAgentQueries(agents);
|
|
125
|
+
return {
|
|
126
|
+
...projectSchema,
|
|
127
|
+
queries: {
|
|
128
|
+
...projectSchema.queries,
|
|
129
|
+
...aiQueries.queries
|
|
130
|
+
},
|
|
131
|
+
mutations: {
|
|
132
|
+
...projectSchema.mutations,
|
|
133
|
+
...aiQueries.mutations
|
|
134
|
+
}
|
|
135
|
+
};
|
|
147
136
|
}
|
|
148
137
|
/**
|
|
149
138
|
* Where guards live in the schema.
|
|
150
139
|
*/
|
|
151
140
|
export const GUARDS_SCHEMA_PATH = ['ai-experimental', 'guards'];
|
|
141
|
+
export const AGENTS_SCHEMA_PATH = ['ai-experimental', 'agents'];
|
|
152
142
|
/**
|
|
153
143
|
* Check if a guard is enabled.
|
|
154
144
|
*/
|
|
155
145
|
export const isGuardEnabled = (guard) => {
|
|
156
146
|
return Boolean(guard && guard.enabled !== false);
|
|
157
147
|
};
|
|
148
|
+
export function getGuardMap(schema) {
|
|
149
|
+
return schema['ai-experimental']?.guards;
|
|
150
|
+
}
|
|
151
|
+
export function getGuards(schema) {
|
|
152
|
+
const guards = getGuardMap(schema);
|
|
153
|
+
return guards ? Object.entries(guards).map(([id, guard]) => ({ id, ...guard })) : [];
|
|
154
|
+
}
|
|
155
|
+
export function setGuardMap(schema, guards) {
|
|
156
|
+
return set(GUARDS_SCHEMA_PATH, guards, schema);
|
|
157
|
+
}
|
|
158
|
+
export function setGuard(schema, id, guard) {
|
|
159
|
+
return set([...GUARDS_SCHEMA_PATH, id], guard, schema);
|
|
160
|
+
}
|
|
158
161
|
/**
|
|
159
162
|
* Get a guard configuration from the project schema.
|
|
160
163
|
*/
|
|
@@ -170,3 +173,33 @@ export function getEnabledGuardConfig(schema, guardId) {
|
|
|
170
173
|
return config;
|
|
171
174
|
}
|
|
172
175
|
}
|
|
176
|
+
export function getAgentMap(projectSchema) {
|
|
177
|
+
return projectSchema['ai-experimental']?.agents;
|
|
178
|
+
}
|
|
179
|
+
export function getAgents(projectSchema) {
|
|
180
|
+
const agentMap = getAgentMap(projectSchema);
|
|
181
|
+
return agentMap && Object.entries(agentMap).map(([name, agent]) => ({ name, ...agent }));
|
|
182
|
+
}
|
|
183
|
+
export function setAgentMap(projectSchema, agents) {
|
|
184
|
+
return set(AGENTS_SCHEMA_PATH, agents, projectSchema);
|
|
185
|
+
}
|
|
186
|
+
export function setAgent(projectSchema, name, agent) {
|
|
187
|
+
return set([...AGENTS_SCHEMA_PATH, name], agent, projectSchema);
|
|
188
|
+
}
|
|
189
|
+
export function getAgent(projectSchema, name) {
|
|
190
|
+
return getAgentMap(projectSchema)?.[name];
|
|
191
|
+
}
|
|
192
|
+
export function ensureAgent(projectSchema, name) {
|
|
193
|
+
const agent = getAgent(projectSchema, name);
|
|
194
|
+
if (!agent) {
|
|
195
|
+
throw new Error(`Agent "${name}" not found`);
|
|
196
|
+
}
|
|
197
|
+
return agent;
|
|
198
|
+
}
|
|
199
|
+
export function isAgentQuery(query, agentName) {
|
|
200
|
+
const resolver = query.resolver;
|
|
201
|
+
if ('agentName' in resolver) {
|
|
202
|
+
return resolver.agentName === agentName;
|
|
203
|
+
}
|
|
204
|
+
return false;
|
|
205
|
+
}
|
package/dist/builtin-schema.js
CHANGED
|
@@ -310,6 +310,18 @@ export const builtInShapes = {
|
|
|
310
310
|
}
|
|
311
311
|
}
|
|
312
312
|
},
|
|
313
|
+
TSGenerateArgs: {
|
|
314
|
+
id: 'TSGenerateArgs',
|
|
315
|
+
name: 'TSGenerateArgs',
|
|
316
|
+
title: 'Generate Args',
|
|
317
|
+
schema: {
|
|
318
|
+
type: 'object',
|
|
319
|
+
properties: {
|
|
320
|
+
input: { type: 'string' }
|
|
321
|
+
},
|
|
322
|
+
required: ['input']
|
|
323
|
+
}
|
|
324
|
+
},
|
|
313
325
|
TSChatArgs: {
|
|
314
326
|
id: 'TSChatArgs',
|
|
315
327
|
name: 'TSChatArgs',
|
package/dist/index.d.ts
CHANGED
|
@@ -11,8 +11,10 @@ export * from './get-is-leaf.ts';
|
|
|
11
11
|
export * from './interfaces.ts';
|
|
12
12
|
export * from './migration/index.ts';
|
|
13
13
|
export type { ProjectSchemaUpdate } from './migration/types.ts';
|
|
14
|
+
export { AGENTS_UPDATE_KEY, GUARDS_UPDATE_KEY, MCP_TOOLS_UPDATE_KEY } from './migration/types.ts';
|
|
14
15
|
export * from './mocks.ts';
|
|
15
16
|
export * from './models/runtime-schema.ts';
|
|
17
|
+
export * from './models/user-schema.ts';
|
|
16
18
|
export * from './patterns.ts';
|
|
17
19
|
export * from './project-schema/index.ts';
|
|
18
20
|
export * from './project-schema/migrate.ts';
|
package/dist/index.js
CHANGED
|
@@ -9,8 +9,10 @@ export * from "./flatten-templates.js";
|
|
|
9
9
|
export * from "./get-is-leaf.js";
|
|
10
10
|
export * from "./interfaces.js";
|
|
11
11
|
export * from "./migration/index.js";
|
|
12
|
+
export { AGENTS_UPDATE_KEY, GUARDS_UPDATE_KEY, MCP_TOOLS_UPDATE_KEY } from "./migration/types.js";
|
|
12
13
|
export * from "./mocks.js";
|
|
13
14
|
export * from "./models/runtime-schema.js";
|
|
15
|
+
export * from "./models/user-schema.js";
|
|
14
16
|
export * from "./patterns.js";
|
|
15
17
|
export * from "./project-schema/index.js";
|
|
16
18
|
export * from "./project-schema/migrate.js";
|
|
@@ -5,13 +5,16 @@ export type ProjectSchemaMigrationContext = {
|
|
|
5
5
|
encryptFn: EncryptFn;
|
|
6
6
|
decryptFn: SafeDecryptFn;
|
|
7
7
|
};
|
|
8
|
+
export declare const AGENTS_UPDATE_KEY = "ai-experimental.agents";
|
|
9
|
+
export declare const GUARDS_UPDATE_KEY = "ai-experimental.guards";
|
|
10
|
+
export declare const MCP_TOOLS_UPDATE_KEY = "ai-experimental.mcp.tools";
|
|
8
11
|
export type ProjectSchemaUpdate = {
|
|
9
12
|
queries?: Record<string, QueryJSON | null>;
|
|
10
13
|
mutations?: Record<string, QueryJSON | null>;
|
|
11
14
|
shapes?: Record<string, ShapeJSON | null>;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
[AGENTS_UPDATE_KEY]?: Record<string, AgentJSON | null>;
|
|
16
|
+
[GUARDS_UPDATE_KEY]?: Record<string, GuardJSON | null>;
|
|
17
|
+
[MCP_TOOLS_UPDATE_KEY]?: Record<string, ToolJSON | null>;
|
|
15
18
|
forms?: Record<string, FormConfig | null>;
|
|
16
19
|
workflows?: Record<string, Workflow | null>;
|
|
17
20
|
services?: Record<string, ServiceConfigJSON | null>;
|
package/dist/migration/types.js
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isAgentQuery } from "../agents.js";
|
|
2
|
+
function queryPredicate(agentName) {
|
|
3
|
+
return (query) => isAgentQuery(query.json, agentName);
|
|
4
|
+
}
|
|
5
|
+
class AgentImpl {
|
|
6
|
+
#schema;
|
|
7
|
+
#agentName;
|
|
8
|
+
#agent;
|
|
9
|
+
constructor(parent, name, agent) {
|
|
10
|
+
this.#schema = parent;
|
|
11
|
+
this.#agentName = name;
|
|
12
|
+
this.#agent = agent;
|
|
13
|
+
}
|
|
14
|
+
get name() {
|
|
15
|
+
return this.#agentName;
|
|
16
|
+
}
|
|
17
|
+
getMutations() {
|
|
18
|
+
return this.#schema.getLocalMutations().filter(queryPredicate(this.name));
|
|
19
|
+
}
|
|
20
|
+
getQueries() {
|
|
21
|
+
return this.#schema.getLocalQueries().filter(queryPredicate(this.name));
|
|
22
|
+
}
|
|
23
|
+
get json() {
|
|
24
|
+
return this.#agent;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function createAgent(parent, name, agent) {
|
|
28
|
+
return new AgentImpl(parent, name, agent);
|
|
29
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ProjectSchemaJSON, PropertySchema } from '../project-schema/index.ts';
|
|
2
|
+
import type { ServiceLayers } from '../types/types.ts';
|
|
3
|
+
import type { Agent, ProjectSchema, Query, Shape } from './types.ts';
|
|
4
|
+
export declare class ProjectSchemaImpl implements ProjectSchema {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(projectSchemaJson: ProjectSchemaJSON, layers: ServiceLayers);
|
|
7
|
+
getShape(rawShapeRef: string): Shape | undefined;
|
|
8
|
+
getQuery(rawQueryRef: string): Query | undefined;
|
|
9
|
+
ensureQuery(ref: string): Query;
|
|
10
|
+
getLocalQueries(): Query[];
|
|
11
|
+
getLocalMutations(): Query[];
|
|
12
|
+
getAgents(): Agent[];
|
|
13
|
+
ensureAgent(name: string): Agent;
|
|
14
|
+
getAgent(name: string): Agent | undefined;
|
|
15
|
+
dereferenceSchema(propertySchema: PropertySchema): PropertySchema;
|
|
16
|
+
get json(): ProjectSchemaJSON;
|
|
17
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { getAgent, getAgentMap } from "../agents.js";
|
|
2
|
+
import { dereferenceSchema, getQuery, normalizePropertyRef, normalizeRefExpression, parsePropertyRef, parseRef, refItemToNamespacedShapeName } from "../refs.js";
|
|
3
|
+
import { getShape } from "../util/shapes.js";
|
|
4
|
+
import { createAgent } from "./agent.js";
|
|
5
|
+
import { createQuery } from './query.js';
|
|
6
|
+
import { createShape } from './shape.js';
|
|
7
|
+
export class ProjectSchemaImpl {
|
|
8
|
+
#projectSchemaJson;
|
|
9
|
+
#layers;
|
|
10
|
+
#shapeCache;
|
|
11
|
+
#queryCache;
|
|
12
|
+
#agentCache;
|
|
13
|
+
constructor(projectSchemaJson, layers) {
|
|
14
|
+
this.#projectSchemaJson = projectSchemaJson;
|
|
15
|
+
this.#layers = layers;
|
|
16
|
+
this.#shapeCache = new Map();
|
|
17
|
+
this.#queryCache = new Map();
|
|
18
|
+
this.#agentCache = new Map();
|
|
19
|
+
}
|
|
20
|
+
getShape(rawShapeRef) {
|
|
21
|
+
const shapeRef = normalizeRefExpression(this.#projectSchemaJson, rawShapeRef);
|
|
22
|
+
let shape = this.#shapeCache.get(shapeRef);
|
|
23
|
+
if (!shape) {
|
|
24
|
+
const refItem = parseRef(this.#projectSchemaJson, rawShapeRef);
|
|
25
|
+
if (refItem) {
|
|
26
|
+
const namespacedName = refItemToNamespacedShapeName(this.#projectSchemaJson, refItem);
|
|
27
|
+
const shapeJson = getShape(this.#projectSchemaJson, namespacedName);
|
|
28
|
+
if (shapeJson) {
|
|
29
|
+
shape = createShape(this, refItem, shapeJson);
|
|
30
|
+
this.#shapeCache.set(shapeRef, shape);
|
|
31
|
+
}
|
|
32
|
+
else if (refItem.layerId !== 'local') {
|
|
33
|
+
const layerSchema = this.#layers[refItem.layerId]?.schema;
|
|
34
|
+
if (layerSchema) {
|
|
35
|
+
const shapeJson = getShape(layerSchema, namespacedName);
|
|
36
|
+
if (shapeJson) {
|
|
37
|
+
shape = createShape(this, refItem, shapeJson);
|
|
38
|
+
this.#shapeCache.set(shapeRef, shape);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return shape;
|
|
45
|
+
}
|
|
46
|
+
getQuery(rawQueryRef) {
|
|
47
|
+
const queryRef = normalizePropertyRef(rawQueryRef);
|
|
48
|
+
let query = this.#queryCache.get(queryRef);
|
|
49
|
+
if (!query) {
|
|
50
|
+
const queryEntry = getQuery(this.#projectSchemaJson, queryRef);
|
|
51
|
+
if (queryEntry) {
|
|
52
|
+
query = createQuery(this, queryEntry);
|
|
53
|
+
this.#queryCache.set(queryRef, query);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const parsedRef = parsePropertyRef(queryRef);
|
|
57
|
+
if (parsedRef && parsedRef.layerId !== 'local') {
|
|
58
|
+
const layerSchema = this.#layers[parsedRef.layerId]?.schema;
|
|
59
|
+
if (layerSchema) {
|
|
60
|
+
const queryEntry = getQuery(layerSchema, parsedRef.propertyName);
|
|
61
|
+
if (queryEntry) {
|
|
62
|
+
query = createQuery(this, { ...queryEntry, ref: parsedRef });
|
|
63
|
+
this.#queryCache.set(queryRef, query);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return query;
|
|
70
|
+
}
|
|
71
|
+
ensureQuery(ref) {
|
|
72
|
+
const query = this.getQuery(ref);
|
|
73
|
+
if (!query) {
|
|
74
|
+
throw new Error(`Query "${ref}" not found`);
|
|
75
|
+
}
|
|
76
|
+
return query;
|
|
77
|
+
}
|
|
78
|
+
getLocalQueries() {
|
|
79
|
+
return Object.keys(this.#projectSchemaJson.queries).map((queryName) => this.ensureQuery(`Query.${queryName}`));
|
|
80
|
+
}
|
|
81
|
+
getLocalMutations() {
|
|
82
|
+
return Object.keys(this.#projectSchemaJson.mutations).map((queryName) => this.ensureQuery(`Mutation.${queryName}`));
|
|
83
|
+
}
|
|
84
|
+
getAgents() {
|
|
85
|
+
const agents = getAgentMap(this.#projectSchemaJson);
|
|
86
|
+
return agents ? Object.keys(agents).map((name) => this.ensureAgent(name)) : [];
|
|
87
|
+
}
|
|
88
|
+
ensureAgent(name) {
|
|
89
|
+
const agent = this.getAgent(name);
|
|
90
|
+
if (!agent) {
|
|
91
|
+
throw new Error(`Agent "${name}" not found`);
|
|
92
|
+
}
|
|
93
|
+
return agent;
|
|
94
|
+
}
|
|
95
|
+
getAgent(name) {
|
|
96
|
+
let agent = this.#agentCache.get(name);
|
|
97
|
+
if (!agent) {
|
|
98
|
+
const agentJson = getAgent(this.#projectSchemaJson, name);
|
|
99
|
+
if (agentJson) {
|
|
100
|
+
agent = createAgent(this, name, agentJson);
|
|
101
|
+
this.#agentCache.set(name, agent);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return agent;
|
|
105
|
+
}
|
|
106
|
+
dereferenceSchema(propertySchema) {
|
|
107
|
+
return dereferenceSchema(this.#projectSchemaJson, propertySchema);
|
|
108
|
+
}
|
|
109
|
+
get json() {
|
|
110
|
+
return this.#projectSchemaJson;
|
|
111
|
+
}
|
|
112
|
+
}
|
package/dist/models/query.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import type { ObjectSchema } from '../project-schema/latest.ts';
|
|
2
1
|
import { type QueryEntry } from '../refs.ts';
|
|
3
|
-
import type {
|
|
4
|
-
export declare
|
|
5
|
-
#private;
|
|
6
|
-
constructor(parent: ReferenceResolver, entry: QueryEntry);
|
|
7
|
-
get ref(): string;
|
|
8
|
-
get argsSchema(): ObjectSchema | undefined;
|
|
9
|
-
}
|
|
2
|
+
import type { ProjectSchema, Query } from './types.ts';
|
|
3
|
+
export declare function createQuery(parent: ProjectSchema, entry: QueryEntry): Query;
|
package/dist/models/query.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { serializePropertyRef } from "../refs.js";
|
|
2
|
-
|
|
3
|
-
#
|
|
2
|
+
class QueryImpl {
|
|
3
|
+
#schema;
|
|
4
4
|
#name;
|
|
5
5
|
#query;
|
|
6
6
|
#ref;
|
|
7
7
|
constructor(parent, entry) {
|
|
8
|
-
this.#
|
|
8
|
+
this.#schema = parent;
|
|
9
9
|
this.#name = entry.name;
|
|
10
10
|
this.#query = entry.query;
|
|
11
11
|
this.#ref = entry.ref;
|
|
@@ -19,8 +19,20 @@ export class Query {
|
|
|
19
19
|
if (typeof args === 'object') {
|
|
20
20
|
return args;
|
|
21
21
|
}
|
|
22
|
-
return this.#
|
|
22
|
+
return this.#schema.getShape(args)?.getObjectSchema();
|
|
23
23
|
}
|
|
24
24
|
return undefined;
|
|
25
25
|
}
|
|
26
|
+
get type() {
|
|
27
|
+
return this.#ref.shapeName === 'Mutation' ? 'mutation' : 'query';
|
|
28
|
+
}
|
|
29
|
+
get name() {
|
|
30
|
+
return this.#name;
|
|
31
|
+
}
|
|
32
|
+
get json() {
|
|
33
|
+
return this.#query;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function createQuery(parent, entry) {
|
|
37
|
+
return new QueryImpl(parent, entry);
|
|
26
38
|
}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import type { ProjectSchemaJSON } from '../project-schema/index.ts';
|
|
2
2
|
import type { ServiceLayers } from '../types/types.ts';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export declare class RuntimeSchema {
|
|
6
|
-
#private;
|
|
3
|
+
import { ProjectSchemaImpl } from './project-schema.ts';
|
|
4
|
+
export declare class RuntimeSchema extends ProjectSchemaImpl {
|
|
7
5
|
private constructor();
|
|
8
6
|
static buildSchema(userSchema: ProjectSchemaJSON, layers: ServiceLayers): RuntimeSchema;
|
|
7
|
+
static safeBuildSchema(userSchema: ProjectSchemaJSON, layers: ServiceLayers): RuntimeSchema | undefined;
|
|
9
8
|
static fromJson(runtimeSchema: ProjectSchemaJSON, layers: ServiceLayers): RuntimeSchema;
|
|
10
|
-
getQuery(ref: string): Query | undefined;
|
|
11
|
-
getShape(ref: string): Shape | undefined;
|
|
12
|
-
get json(): ProjectSchemaJSON;
|
|
13
9
|
}
|