@xpert-ai/plugin-sdk 3.23.0 → 3.25.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/_object_without_properties_loose.cjs.js +16 -0
- package/_object_without_properties_loose.esm.js +14 -0
- package/analytics-result.cjs.js +212 -0
- package/analytics-result.esm.js +201 -0
- package/analytics.cjs.default.js +1 -0
- package/analytics.cjs.js +17 -0
- package/analytics.cjs.mjs +2 -0
- package/analytics.d.ts +1 -0
- package/analytics.esm.js +2 -0
- package/artifact-document.cjs.default.js +1 -0
- package/artifact-document.cjs.js +581 -0
- package/artifact-document.cjs.mjs +2 -0
- package/artifact-document.d.ts +1 -0
- package/artifact-document.esm.js +563 -0
- package/data-workbench.cjs.js +23 -6
- package/data-workbench.esm.js +23 -6
- package/docs/README.md +8 -0
- package/docs/analytics.md +108 -0
- package/docs/artifact-documents.md +74 -0
- package/docs/artifact-drafts.md +24 -0
- package/docs/artifact-presentations.md +43 -0
- package/docs/json-encoded-schema.md +19 -0
- package/docs/mcp-client.md +63 -0
- package/docs/provider-credential-validation.md +34 -0
- package/docs/rest-client.md +24 -0
- package/docs/workspace-dataset-pipelines.md +120 -0
- package/docs/workspace-file-tools.md +66 -0
- package/index.cjs.js +555 -108
- package/index.esm.js +573 -172
- package/model-provider-toolset.cjs.js +1 -1
- package/model-provider-toolset.esm.js +1 -1
- package/model-provider.cjs.js +47 -1
- package/model-provider.esm.js +41 -2
- package/package.json +14 -2
- package/src/analytics.d.ts +3 -0
- package/src/artifact-document.d.ts +5 -0
- package/src/index.d.ts +2 -0
- package/src/lib/agent/handoff/agent-runtime-message.contract.d.ts +80 -80
- package/src/lib/agent/middleware/capabilities/assistant-task.d.ts +36 -1
- package/src/lib/agent/runtime/dispatch.d.ts +284 -284
- package/src/lib/agent/runtime/index.d.ts +1 -0
- package/src/lib/agent/runtime/pipeline-scope.d.ts +110 -0
- package/src/lib/agent/runtime/types.d.ts +4 -2
- package/src/lib/ai-model/ai-model-provider.interface.d.ts +3 -1
- package/src/lib/ai-model/utils/limits.d.ts +4 -2
- package/src/lib/artifact-document/dependencies.d.ts +101 -0
- package/src/lib/artifact-document/host.d.ts +30 -0
- package/src/lib/artifact-document/protocol.d.ts +60 -0
- package/src/lib/artifact-document/runtime.d.ts +4 -0
- package/src/lib/artifact-document/sha256.d.ts +2 -0
- package/src/lib/artifact-presentation/index.d.ts +35 -0
- package/src/lib/core/index.d.ts +1 -0
- package/src/lib/core/json-encoded-schema.d.ts +15 -0
- package/src/lib/data/analytics/analytics-payload.d.ts +3 -0
- package/src/lib/data/analytics/analytics-provider.d.ts +74 -0
- package/src/lib/data/analytics/analytics-result.d.ts +4 -0
- package/src/lib/data/analytics/analytics.registry.d.ts +10 -0
- package/src/lib/data/analytics/analytics.schema.d.ts +206 -0
- package/src/lib/data/analytics/index.d.ts +5 -0
- package/src/lib/data/datasource/index.d.ts +1 -0
- package/src/lib/data/datasource/types.d.ts +1 -1
- package/src/lib/data/datasource/workbench-adapter.d.ts +11 -1
- package/src/lib/data/datasource/workbench-sql.d.ts +12 -0
- package/src/lib/project-pipeline/adapters.d.ts +87 -0
- package/src/lib/project-pipeline/capability.d.ts +100 -0
- package/src/lib/project-pipeline/index.d.ts +5 -0
- package/src/lib/project-pipeline/projection.d.ts +71 -0
- package/src/lib/project-pipeline/registry.d.ts +509 -0
- package/src/lib/project-pipeline/runtime-registry.d.ts +45 -0
- package/src/lib/project-pipeline/scoped-registry.d.ts +10 -0
- package/src/lib/project-task/index.d.ts +6 -0
- package/src/lib/project-type/index.d.ts +17 -1
- package/src/lib/rag/types.d.ts +1 -1
- package/src/lib/runtime/capabilities/artifact-drafts.d.ts +29 -0
- package/src/lib/runtime/capabilities/artifacts.d.ts +12 -0
- package/src/lib/runtime/capabilities/index.d.ts +3 -0
- package/src/lib/runtime/capabilities/mcp-client-runtime.d.ts +41 -0
- package/src/lib/runtime/capabilities/rest-client-runtime.d.ts +34 -0
- package/src/lib/runtime/capabilities/sandbox-jobs.d.ts +36 -2
- package/src/lib/runtime/index.d.ts +2 -0
- package/src/lib/runtime/mutation-evidence.d.ts +7 -0
- package/src/lib/runtime/workspace-file-tools.d.ts +11 -0
- package/src/lib/sandbox/file-edits.d.ts +4 -0
- package/src/lib/sandbox/protocol.d.ts +7 -1
- package/src/lib/sandbox/runtime-provider.d.ts +4 -0
- package/src/lib/sandbox/sandbox.d.ts +2 -8
- package/src/lib/tool-provider/adapters.d.ts +1 -1
- package/src/lib/tool-provider/types.d.ts +2 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function _object_without_properties_loose(source, excluded) {
|
|
4
|
+
if (source == null) return {};
|
|
5
|
+
var target = {};
|
|
6
|
+
var sourceKeys = Object.keys(source);
|
|
7
|
+
var key, i;
|
|
8
|
+
for(i = 0; i < sourceKeys.length; i++){
|
|
9
|
+
key = sourceKeys[i];
|
|
10
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
11
|
+
target[key] = source[key];
|
|
12
|
+
}
|
|
13
|
+
return target;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports._object_without_properties_loose = _object_without_properties_loose;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function _object_without_properties_loose(source, excluded) {
|
|
2
|
+
if (source == null) return {};
|
|
3
|
+
var target = {};
|
|
4
|
+
var sourceKeys = Object.keys(source);
|
|
5
|
+
var key, i;
|
|
6
|
+
for(i = 0; i < sourceKeys.length; i++){
|
|
7
|
+
key = sourceKeys[i];
|
|
8
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
9
|
+
target[key] = source[key];
|
|
10
|
+
}
|
|
11
|
+
return target;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { _object_without_properties_loose as _ };
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var v3 = require('zod/v3');
|
|
4
|
+
|
|
5
|
+
const key = v3.z.string().regex(/^[A-Za-z][A-Za-z0-9_.-]{0,79}$/);
|
|
6
|
+
const value = v3.z.union([
|
|
7
|
+
v3.z.string().max(4000),
|
|
8
|
+
v3.z.number().finite(),
|
|
9
|
+
v3.z.boolean(),
|
|
10
|
+
v3.z.null()
|
|
11
|
+
]);
|
|
12
|
+
const json = v3.z.lazy(()=>v3.z.union([
|
|
13
|
+
v3.z.string().max(32000),
|
|
14
|
+
v3.z.number().finite(),
|
|
15
|
+
v3.z.boolean(),
|
|
16
|
+
v3.z.null(),
|
|
17
|
+
v3.z.array(json).max(1000),
|
|
18
|
+
v3.z.record(json)
|
|
19
|
+
]));
|
|
20
|
+
const analyticsOptionsSchema = v3.z.record(json);
|
|
21
|
+
const analyticsFieldSchema = v3.z.object({
|
|
22
|
+
id: key,
|
|
23
|
+
sourceField: v3.z.string().min(1).max(256),
|
|
24
|
+
label: v3.z.string().min(1).max(160),
|
|
25
|
+
logicalType: v3.z.enum([
|
|
26
|
+
'string',
|
|
27
|
+
'boolean',
|
|
28
|
+
'int64',
|
|
29
|
+
'float64',
|
|
30
|
+
'decimal',
|
|
31
|
+
'date',
|
|
32
|
+
'timestamp'
|
|
33
|
+
]),
|
|
34
|
+
nullable: v3.z.boolean(),
|
|
35
|
+
role: v3.z.enum([
|
|
36
|
+
'dimension',
|
|
37
|
+
'measure',
|
|
38
|
+
'time',
|
|
39
|
+
'identifier'
|
|
40
|
+
]),
|
|
41
|
+
semanticRef: v3.z.string().max(512).optional(),
|
|
42
|
+
unit: v3.z.string().max(80).optional()
|
|
43
|
+
}).strict();
|
|
44
|
+
const analyticsParameterSchema = v3.z.object({
|
|
45
|
+
name: key,
|
|
46
|
+
controlId: key,
|
|
47
|
+
type: v3.z.enum([
|
|
48
|
+
'string',
|
|
49
|
+
'number',
|
|
50
|
+
'boolean',
|
|
51
|
+
'date'
|
|
52
|
+
]),
|
|
53
|
+
required: v3.z.boolean(),
|
|
54
|
+
defaultValue: value.optional(),
|
|
55
|
+
allowedValues: v3.z.array(value).max(200).optional()
|
|
56
|
+
}).strict();
|
|
57
|
+
const analyticsBindingObjectSchema = v3.z.object({
|
|
58
|
+
schemaVersion: v3.z.literal(1),
|
|
59
|
+
id: key,
|
|
60
|
+
dataSourceId: v3.z.string().uuid(),
|
|
61
|
+
providerId: v3.z.string().min(1).max(160),
|
|
62
|
+
operation: key,
|
|
63
|
+
contractVersion: v3.z.number().int().positive(),
|
|
64
|
+
payload: json,
|
|
65
|
+
parameters: v3.z.array(analyticsParameterSchema).max(24),
|
|
66
|
+
output: v3.z.object({
|
|
67
|
+
datasetId: key,
|
|
68
|
+
fields: v3.z.array(analyticsFieldSchema).min(1).max(80),
|
|
69
|
+
grain: v3.z.array(key).max(20)
|
|
70
|
+
}).strict()
|
|
71
|
+
}).strict();
|
|
72
|
+
const analyticsBindingSchema = analyticsBindingObjectSchema.superRefine((binding, ctx)=>{
|
|
73
|
+
const fields = binding.output.fields.map((field)=>field.id);
|
|
74
|
+
const names = binding.parameters.map((parameter)=>parameter.name);
|
|
75
|
+
if (new Set(fields).size !== fields.length || new Set(names).size !== names.length) ctx.addIssue({
|
|
76
|
+
code: 'custom',
|
|
77
|
+
message: 'Duplicate field or parameter identifier'
|
|
78
|
+
});
|
|
79
|
+
if (new Set(binding.output.grain).size !== binding.output.grain.length || binding.output.grain.some((field)=>!fields.includes(field))) ctx.addIssue({
|
|
80
|
+
code: 'custom',
|
|
81
|
+
message: 'Grain references an undeclared field'
|
|
82
|
+
});
|
|
83
|
+
if (new TextEncoder().encode(JSON.stringify(binding.payload)).byteLength > 64000) ctx.addIssue({
|
|
84
|
+
code: 'custom',
|
|
85
|
+
message: 'Query payload exceeds limit'
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
const analyticsQueryRequestSchema = v3.z.object({
|
|
89
|
+
binding: analyticsBindingSchema,
|
|
90
|
+
controls: v3.z.record(key, value).default({})
|
|
91
|
+
}).strict();
|
|
92
|
+
const analyticsDiscoveryRequestSchema = v3.z.object({
|
|
93
|
+
dataSourceId: v3.z.string().uuid(),
|
|
94
|
+
providerId: v3.z.string().min(1).max(160),
|
|
95
|
+
request: json.default({})
|
|
96
|
+
}).strict().refine((value)=>new TextEncoder().encode(JSON.stringify(value)).byteLength <= 16000, 'Discovery request exceeds limit');
|
|
97
|
+
const analyticsDiscoveryResultSchema = v3.z.object({
|
|
98
|
+
schemaVersion: v3.z.literal(1),
|
|
99
|
+
items: v3.z.array(v3.z.object({
|
|
100
|
+
id: v3.z.string().min(1).max(512),
|
|
101
|
+
name: v3.z.string().min(1).max(512),
|
|
102
|
+
kind: v3.z.enum([
|
|
103
|
+
'collection',
|
|
104
|
+
'dataset'
|
|
105
|
+
]),
|
|
106
|
+
description: v3.z.string().max(4000).optional(),
|
|
107
|
+
inspectRequest: json.optional(),
|
|
108
|
+
metadata: json
|
|
109
|
+
}).strict()).max(50),
|
|
110
|
+
nextRequest: json.optional(),
|
|
111
|
+
queryContract: v3.z.object({
|
|
112
|
+
operation: key,
|
|
113
|
+
contractVersion: v3.z.number().int().positive(),
|
|
114
|
+
payloadSchema: json,
|
|
115
|
+
instructions: v3.z.string().max(8000)
|
|
116
|
+
}).strict()
|
|
117
|
+
}).strict().refine((value)=>new TextEncoder().encode(JSON.stringify(value)).byteLength <= 128000, 'Discovery response exceeds limit');
|
|
118
|
+
|
|
119
|
+
function resolveAnalyticsParameters(binding, controls) {
|
|
120
|
+
const allowed = new Set(binding.parameters.map((parameter)=>parameter.controlId));
|
|
121
|
+
if (Object.keys(controls).some((name)=>!allowed.has(name))) throw new Error('ANALYTICS_UNKNOWN_CONTROL');
|
|
122
|
+
const result = {};
|
|
123
|
+
for (const parameter of binding.parameters){
|
|
124
|
+
const value = Object.prototype.hasOwnProperty.call(controls, parameter.controlId) ? controls[parameter.controlId] : parameter.defaultValue;
|
|
125
|
+
if (value === undefined || value === null) {
|
|
126
|
+
if (parameter.required) throw new Error('ANALYTICS_PARAMETER_REQUIRED');
|
|
127
|
+
result[parameter.name] = null;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const valid = parameter.type === 'date' ? typeof value === 'string' && validDate(value) : typeof value === parameter.type && (typeof value !== 'number' || Number.isFinite(value));
|
|
131
|
+
if (!valid || parameter.allowedValues && !parameter.allowedValues.includes(value)) throw new Error('ANALYTICS_PARAMETER_INVALID');
|
|
132
|
+
result[parameter.name] = value;
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
function normalizeAnalyticsResult(binding, result, executionId, maxRows) {
|
|
137
|
+
if (result.rows.length > maxRows) throw new Error('ANALYTICS_ROW_LIMIT');
|
|
138
|
+
const fields = binding.output.fields;
|
|
139
|
+
const keys = fields.map((field)=>{
|
|
140
|
+
const matches = result.columns.filter((column)=>field.semanticRef ? column.semanticRef === field.semanticRef : column.key === field.sourceField);
|
|
141
|
+
if (matches.length !== 1) throw new Error('ANALYTICS_FIELD_MISSING_OR_AMBIGUOUS');
|
|
142
|
+
return matches[0].key;
|
|
143
|
+
});
|
|
144
|
+
const rows = result.rows.map((row)=>Object.fromEntries(fields.map((field, index)=>{
|
|
145
|
+
const cell = row[keys[index]];
|
|
146
|
+
if (cell === undefined || !validCell(field, cell)) throw new Error('ANALYTICS_FIELD_TYPE_MISMATCH');
|
|
147
|
+
return [
|
|
148
|
+
field.id,
|
|
149
|
+
cell
|
|
150
|
+
];
|
|
151
|
+
})));
|
|
152
|
+
if (new TextEncoder().encode(JSON.stringify(rows)).byteLength > 2000000) throw new Error('ANALYTICS_RESULT_TOO_LARGE');
|
|
153
|
+
if (result.completeness.returnedRows !== rows.length) throw new Error('ANALYTICS_ROW_COUNT_MISMATCH');
|
|
154
|
+
if (result.completeness.totalRows !== undefined && (!Number.isSafeInteger(result.completeness.totalRows) || result.completeness.totalRows < rows.length)) throw new Error('ANALYTICS_TOTAL_COUNT_INVALID');
|
|
155
|
+
if (result.completeness.truncated && result.completeness.scope === 'full_query_result') throw new Error('ANALYTICS_COMPLETENESS_INVALID');
|
|
156
|
+
if (!Number.isFinite(Date.parse(result.sourceFetchedAt))) throw new Error('ANALYTICS_FRESHNESS_INVALID');
|
|
157
|
+
if (binding.output.grain.length && new Set(rows.map((row)=>JSON.stringify(binding.output.grain.map((key)=>row[key])))).size !== rows.length) throw new Error('ANALYTICS_GRAIN_MISMATCH');
|
|
158
|
+
return {
|
|
159
|
+
schema: 'xpert.analytics.dataset/v1',
|
|
160
|
+
datasetId: binding.output.datasetId,
|
|
161
|
+
fields,
|
|
162
|
+
rows,
|
|
163
|
+
grain: binding.output.grain,
|
|
164
|
+
completeness: result.completeness,
|
|
165
|
+
freshness: {
|
|
166
|
+
executedAt: new Date().toISOString(),
|
|
167
|
+
sourceFetchedAt: result.sourceFetchedAt,
|
|
168
|
+
dataAsOf: result.dataAsOf
|
|
169
|
+
},
|
|
170
|
+
provenance: {
|
|
171
|
+
executionId,
|
|
172
|
+
bindingId: binding.id,
|
|
173
|
+
providerId: binding.providerId,
|
|
174
|
+
sourceVersion: result.sourceVersion,
|
|
175
|
+
upstreamExecutionId: result.upstreamExecutionId,
|
|
176
|
+
auditRef: result.auditRef
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function validDate(value) {
|
|
181
|
+
return /^\d{4}-\d{2}-\d{2}$/.test(value) && Number.isFinite(Date.parse(value)) && new Date(value).toISOString().slice(0, 10) === value;
|
|
182
|
+
}
|
|
183
|
+
function validCell(field, cell) {
|
|
184
|
+
if (cell === null) return field.nullable;
|
|
185
|
+
switch(field.logicalType){
|
|
186
|
+
case 'string':
|
|
187
|
+
return typeof cell === 'string';
|
|
188
|
+
case 'boolean':
|
|
189
|
+
return typeof cell === 'boolean';
|
|
190
|
+
case 'float64':
|
|
191
|
+
return typeof cell === 'number' && Number.isFinite(cell);
|
|
192
|
+
case 'int64':
|
|
193
|
+
return typeof cell === 'string' && /^-?\d{1,19}$/.test(cell) && BigInt(cell) >= -(2n ** 63n) && BigInt(cell) < 2n ** 63n;
|
|
194
|
+
case 'decimal':
|
|
195
|
+
return typeof cell === 'string' && /^-?\d+(\.\d+)?$/.test(cell);
|
|
196
|
+
case 'date':
|
|
197
|
+
return typeof cell === 'string' && validDate(cell);
|
|
198
|
+
case 'timestamp':
|
|
199
|
+
return typeof cell === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/.test(cell) && validDate(cell.slice(0, 10)) && Number.isFinite(Date.parse(cell));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
exports.analyticsBindingObjectSchema = analyticsBindingObjectSchema;
|
|
204
|
+
exports.analyticsBindingSchema = analyticsBindingSchema;
|
|
205
|
+
exports.analyticsDiscoveryRequestSchema = analyticsDiscoveryRequestSchema;
|
|
206
|
+
exports.analyticsDiscoveryResultSchema = analyticsDiscoveryResultSchema;
|
|
207
|
+
exports.analyticsFieldSchema = analyticsFieldSchema;
|
|
208
|
+
exports.analyticsOptionsSchema = analyticsOptionsSchema;
|
|
209
|
+
exports.analyticsParameterSchema = analyticsParameterSchema;
|
|
210
|
+
exports.analyticsQueryRequestSchema = analyticsQueryRequestSchema;
|
|
211
|
+
exports.normalizeAnalyticsResult = normalizeAnalyticsResult;
|
|
212
|
+
exports.resolveAnalyticsParameters = resolveAnalyticsParameters;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { z } from 'zod/v3';
|
|
2
|
+
|
|
3
|
+
const key = z.string().regex(/^[A-Za-z][A-Za-z0-9_.-]{0,79}$/);
|
|
4
|
+
const value = z.union([
|
|
5
|
+
z.string().max(4000),
|
|
6
|
+
z.number().finite(),
|
|
7
|
+
z.boolean(),
|
|
8
|
+
z.null()
|
|
9
|
+
]);
|
|
10
|
+
const json = z.lazy(()=>z.union([
|
|
11
|
+
z.string().max(32000),
|
|
12
|
+
z.number().finite(),
|
|
13
|
+
z.boolean(),
|
|
14
|
+
z.null(),
|
|
15
|
+
z.array(json).max(1000),
|
|
16
|
+
z.record(json)
|
|
17
|
+
]));
|
|
18
|
+
const analyticsOptionsSchema = z.record(json);
|
|
19
|
+
const analyticsFieldSchema = z.object({
|
|
20
|
+
id: key,
|
|
21
|
+
sourceField: z.string().min(1).max(256),
|
|
22
|
+
label: z.string().min(1).max(160),
|
|
23
|
+
logicalType: z.enum([
|
|
24
|
+
'string',
|
|
25
|
+
'boolean',
|
|
26
|
+
'int64',
|
|
27
|
+
'float64',
|
|
28
|
+
'decimal',
|
|
29
|
+
'date',
|
|
30
|
+
'timestamp'
|
|
31
|
+
]),
|
|
32
|
+
nullable: z.boolean(),
|
|
33
|
+
role: z.enum([
|
|
34
|
+
'dimension',
|
|
35
|
+
'measure',
|
|
36
|
+
'time',
|
|
37
|
+
'identifier'
|
|
38
|
+
]),
|
|
39
|
+
semanticRef: z.string().max(512).optional(),
|
|
40
|
+
unit: z.string().max(80).optional()
|
|
41
|
+
}).strict();
|
|
42
|
+
const analyticsParameterSchema = z.object({
|
|
43
|
+
name: key,
|
|
44
|
+
controlId: key,
|
|
45
|
+
type: z.enum([
|
|
46
|
+
'string',
|
|
47
|
+
'number',
|
|
48
|
+
'boolean',
|
|
49
|
+
'date'
|
|
50
|
+
]),
|
|
51
|
+
required: z.boolean(),
|
|
52
|
+
defaultValue: value.optional(),
|
|
53
|
+
allowedValues: z.array(value).max(200).optional()
|
|
54
|
+
}).strict();
|
|
55
|
+
const analyticsBindingObjectSchema = z.object({
|
|
56
|
+
schemaVersion: z.literal(1),
|
|
57
|
+
id: key,
|
|
58
|
+
dataSourceId: z.string().uuid(),
|
|
59
|
+
providerId: z.string().min(1).max(160),
|
|
60
|
+
operation: key,
|
|
61
|
+
contractVersion: z.number().int().positive(),
|
|
62
|
+
payload: json,
|
|
63
|
+
parameters: z.array(analyticsParameterSchema).max(24),
|
|
64
|
+
output: z.object({
|
|
65
|
+
datasetId: key,
|
|
66
|
+
fields: z.array(analyticsFieldSchema).min(1).max(80),
|
|
67
|
+
grain: z.array(key).max(20)
|
|
68
|
+
}).strict()
|
|
69
|
+
}).strict();
|
|
70
|
+
const analyticsBindingSchema = analyticsBindingObjectSchema.superRefine((binding, ctx)=>{
|
|
71
|
+
const fields = binding.output.fields.map((field)=>field.id);
|
|
72
|
+
const names = binding.parameters.map((parameter)=>parameter.name);
|
|
73
|
+
if (new Set(fields).size !== fields.length || new Set(names).size !== names.length) ctx.addIssue({
|
|
74
|
+
code: 'custom',
|
|
75
|
+
message: 'Duplicate field or parameter identifier'
|
|
76
|
+
});
|
|
77
|
+
if (new Set(binding.output.grain).size !== binding.output.grain.length || binding.output.grain.some((field)=>!fields.includes(field))) ctx.addIssue({
|
|
78
|
+
code: 'custom',
|
|
79
|
+
message: 'Grain references an undeclared field'
|
|
80
|
+
});
|
|
81
|
+
if (new TextEncoder().encode(JSON.stringify(binding.payload)).byteLength > 64000) ctx.addIssue({
|
|
82
|
+
code: 'custom',
|
|
83
|
+
message: 'Query payload exceeds limit'
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
const analyticsQueryRequestSchema = z.object({
|
|
87
|
+
binding: analyticsBindingSchema,
|
|
88
|
+
controls: z.record(key, value).default({})
|
|
89
|
+
}).strict();
|
|
90
|
+
const analyticsDiscoveryRequestSchema = z.object({
|
|
91
|
+
dataSourceId: z.string().uuid(),
|
|
92
|
+
providerId: z.string().min(1).max(160),
|
|
93
|
+
request: json.default({})
|
|
94
|
+
}).strict().refine((value)=>new TextEncoder().encode(JSON.stringify(value)).byteLength <= 16000, 'Discovery request exceeds limit');
|
|
95
|
+
const analyticsDiscoveryResultSchema = z.object({
|
|
96
|
+
schemaVersion: z.literal(1),
|
|
97
|
+
items: z.array(z.object({
|
|
98
|
+
id: z.string().min(1).max(512),
|
|
99
|
+
name: z.string().min(1).max(512),
|
|
100
|
+
kind: z.enum([
|
|
101
|
+
'collection',
|
|
102
|
+
'dataset'
|
|
103
|
+
]),
|
|
104
|
+
description: z.string().max(4000).optional(),
|
|
105
|
+
inspectRequest: json.optional(),
|
|
106
|
+
metadata: json
|
|
107
|
+
}).strict()).max(50),
|
|
108
|
+
nextRequest: json.optional(),
|
|
109
|
+
queryContract: z.object({
|
|
110
|
+
operation: key,
|
|
111
|
+
contractVersion: z.number().int().positive(),
|
|
112
|
+
payloadSchema: json,
|
|
113
|
+
instructions: z.string().max(8000)
|
|
114
|
+
}).strict()
|
|
115
|
+
}).strict().refine((value)=>new TextEncoder().encode(JSON.stringify(value)).byteLength <= 128000, 'Discovery response exceeds limit');
|
|
116
|
+
|
|
117
|
+
function resolveAnalyticsParameters(binding, controls) {
|
|
118
|
+
const allowed = new Set(binding.parameters.map((parameter)=>parameter.controlId));
|
|
119
|
+
if (Object.keys(controls).some((name)=>!allowed.has(name))) throw new Error('ANALYTICS_UNKNOWN_CONTROL');
|
|
120
|
+
const result = {};
|
|
121
|
+
for (const parameter of binding.parameters){
|
|
122
|
+
const value = Object.prototype.hasOwnProperty.call(controls, parameter.controlId) ? controls[parameter.controlId] : parameter.defaultValue;
|
|
123
|
+
if (value === undefined || value === null) {
|
|
124
|
+
if (parameter.required) throw new Error('ANALYTICS_PARAMETER_REQUIRED');
|
|
125
|
+
result[parameter.name] = null;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const valid = parameter.type === 'date' ? typeof value === 'string' && validDate(value) : typeof value === parameter.type && (typeof value !== 'number' || Number.isFinite(value));
|
|
129
|
+
if (!valid || parameter.allowedValues && !parameter.allowedValues.includes(value)) throw new Error('ANALYTICS_PARAMETER_INVALID');
|
|
130
|
+
result[parameter.name] = value;
|
|
131
|
+
}
|
|
132
|
+
return result;
|
|
133
|
+
}
|
|
134
|
+
function normalizeAnalyticsResult(binding, result, executionId, maxRows) {
|
|
135
|
+
if (result.rows.length > maxRows) throw new Error('ANALYTICS_ROW_LIMIT');
|
|
136
|
+
const fields = binding.output.fields;
|
|
137
|
+
const keys = fields.map((field)=>{
|
|
138
|
+
const matches = result.columns.filter((column)=>field.semanticRef ? column.semanticRef === field.semanticRef : column.key === field.sourceField);
|
|
139
|
+
if (matches.length !== 1) throw new Error('ANALYTICS_FIELD_MISSING_OR_AMBIGUOUS');
|
|
140
|
+
return matches[0].key;
|
|
141
|
+
});
|
|
142
|
+
const rows = result.rows.map((row)=>Object.fromEntries(fields.map((field, index)=>{
|
|
143
|
+
const cell = row[keys[index]];
|
|
144
|
+
if (cell === undefined || !validCell(field, cell)) throw new Error('ANALYTICS_FIELD_TYPE_MISMATCH');
|
|
145
|
+
return [
|
|
146
|
+
field.id,
|
|
147
|
+
cell
|
|
148
|
+
];
|
|
149
|
+
})));
|
|
150
|
+
if (new TextEncoder().encode(JSON.stringify(rows)).byteLength > 2000000) throw new Error('ANALYTICS_RESULT_TOO_LARGE');
|
|
151
|
+
if (result.completeness.returnedRows !== rows.length) throw new Error('ANALYTICS_ROW_COUNT_MISMATCH');
|
|
152
|
+
if (result.completeness.totalRows !== undefined && (!Number.isSafeInteger(result.completeness.totalRows) || result.completeness.totalRows < rows.length)) throw new Error('ANALYTICS_TOTAL_COUNT_INVALID');
|
|
153
|
+
if (result.completeness.truncated && result.completeness.scope === 'full_query_result') throw new Error('ANALYTICS_COMPLETENESS_INVALID');
|
|
154
|
+
if (!Number.isFinite(Date.parse(result.sourceFetchedAt))) throw new Error('ANALYTICS_FRESHNESS_INVALID');
|
|
155
|
+
if (binding.output.grain.length && new Set(rows.map((row)=>JSON.stringify(binding.output.grain.map((key)=>row[key])))).size !== rows.length) throw new Error('ANALYTICS_GRAIN_MISMATCH');
|
|
156
|
+
return {
|
|
157
|
+
schema: 'xpert.analytics.dataset/v1',
|
|
158
|
+
datasetId: binding.output.datasetId,
|
|
159
|
+
fields,
|
|
160
|
+
rows,
|
|
161
|
+
grain: binding.output.grain,
|
|
162
|
+
completeness: result.completeness,
|
|
163
|
+
freshness: {
|
|
164
|
+
executedAt: new Date().toISOString(),
|
|
165
|
+
sourceFetchedAt: result.sourceFetchedAt,
|
|
166
|
+
dataAsOf: result.dataAsOf
|
|
167
|
+
},
|
|
168
|
+
provenance: {
|
|
169
|
+
executionId,
|
|
170
|
+
bindingId: binding.id,
|
|
171
|
+
providerId: binding.providerId,
|
|
172
|
+
sourceVersion: result.sourceVersion,
|
|
173
|
+
upstreamExecutionId: result.upstreamExecutionId,
|
|
174
|
+
auditRef: result.auditRef
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function validDate(value) {
|
|
179
|
+
return /^\d{4}-\d{2}-\d{2}$/.test(value) && Number.isFinite(Date.parse(value)) && new Date(value).toISOString().slice(0, 10) === value;
|
|
180
|
+
}
|
|
181
|
+
function validCell(field, cell) {
|
|
182
|
+
if (cell === null) return field.nullable;
|
|
183
|
+
switch(field.logicalType){
|
|
184
|
+
case 'string':
|
|
185
|
+
return typeof cell === 'string';
|
|
186
|
+
case 'boolean':
|
|
187
|
+
return typeof cell === 'boolean';
|
|
188
|
+
case 'float64':
|
|
189
|
+
return typeof cell === 'number' && Number.isFinite(cell);
|
|
190
|
+
case 'int64':
|
|
191
|
+
return typeof cell === 'string' && /^-?\d{1,19}$/.test(cell) && BigInt(cell) >= -(2n ** 63n) && BigInt(cell) < 2n ** 63n;
|
|
192
|
+
case 'decimal':
|
|
193
|
+
return typeof cell === 'string' && /^-?\d+(\.\d+)?$/.test(cell);
|
|
194
|
+
case 'date':
|
|
195
|
+
return typeof cell === 'string' && validDate(cell);
|
|
196
|
+
case 'timestamp':
|
|
197
|
+
return typeof cell === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/.test(cell) && validDate(cell.slice(0, 10)) && Number.isFinite(Date.parse(cell));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export { analyticsBindingObjectSchema as a, analyticsBindingSchema as b, analyticsDiscoveryRequestSchema as c, analyticsDiscoveryResultSchema as d, analyticsFieldSchema as e, analyticsOptionsSchema as f, analyticsParameterSchema as g, analyticsQueryRequestSchema as h, normalizeAnalyticsResult as n, resolveAnalyticsParameters as r };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports._default = require('./analytics.cjs.js').default;
|
package/analytics.cjs.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var analyticsResult = require('./analytics-result.cjs.js');
|
|
4
|
+
require('zod/v3');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
exports.analyticsBindingObjectSchema = analyticsResult.analyticsBindingObjectSchema;
|
|
9
|
+
exports.analyticsBindingSchema = analyticsResult.analyticsBindingSchema;
|
|
10
|
+
exports.analyticsDiscoveryRequestSchema = analyticsResult.analyticsDiscoveryRequestSchema;
|
|
11
|
+
exports.analyticsDiscoveryResultSchema = analyticsResult.analyticsDiscoveryResultSchema;
|
|
12
|
+
exports.analyticsFieldSchema = analyticsResult.analyticsFieldSchema;
|
|
13
|
+
exports.analyticsOptionsSchema = analyticsResult.analyticsOptionsSchema;
|
|
14
|
+
exports.analyticsParameterSchema = analyticsResult.analyticsParameterSchema;
|
|
15
|
+
exports.analyticsQueryRequestSchema = analyticsResult.analyticsQueryRequestSchema;
|
|
16
|
+
exports.normalizeAnalyticsResult = analyticsResult.normalizeAnalyticsResult;
|
|
17
|
+
exports.resolveAnalyticsParameters = analyticsResult.resolveAnalyticsParameters;
|
package/analytics.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/analytics";
|
package/analytics.esm.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { a as analyticsBindingObjectSchema, b as analyticsBindingSchema, c as analyticsDiscoveryRequestSchema, d as analyticsDiscoveryResultSchema, e as analyticsFieldSchema, f as analyticsOptionsSchema, g as analyticsParameterSchema, h as analyticsQueryRequestSchema, n as normalizeAnalyticsResult, r as resolveAnalyticsParameters } from './analytics-result.esm.js';
|
|
2
|
+
import 'zod/v3';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports._default = require('./artifact-document.cjs.js').default;
|