@frontal-labs/ontology 0.0.1 → 1.0.1
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 +80 -9
- package/dist/client.d.ts +36 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/constants.d.ts +12 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +8 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2020 -348
- package/dist/index.mjs +2013 -350
- package/dist/schemas.d.ts +53 -5
- package/dist/schemas.d.ts.map +1 -1
- package/dist/sdk.d.ts +575 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +7 -6
- package/src/client.ts +86 -0
- package/src/constants.ts +15 -0
- package/src/index.ts +13 -44
- package/src/schemas.ts +55 -8
- package/src/sdk.ts +883 -0
- package/dist/keys.d.ts +0 -6
- package/dist/keys.d.ts.map +0 -1
- package/dist/service.d.ts +0 -139
- package/dist/service.d.ts.map +0 -1
- package/src/keys.ts +0 -29
- package/src/service.ts +0 -269
package/dist/index.mjs
CHANGED
|
@@ -1,421 +1,2083 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __async = (__this, __arguments, generator) => {
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
var fulfilled = (value) => {
|
|
23
|
-
try {
|
|
24
|
-
step(generator.next(value));
|
|
25
|
-
} catch (e) {
|
|
26
|
-
reject(e);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var rejected = (value) => {
|
|
30
|
-
try {
|
|
31
|
-
step(generator.throw(value));
|
|
32
|
-
} catch (e) {
|
|
33
|
-
reject(e);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
-
});
|
|
39
|
-
};
|
|
1
|
+
// ../core/dist/index.js
|
|
2
|
+
import { z } from "zod";
|
|
40
3
|
|
|
41
|
-
//
|
|
42
|
-
|
|
4
|
+
// ../../node_modules/.bun/@t3-oss+env-core@0.13.11+dcb9db7a51b27bde/node_modules/@t3-oss/env-core/dist/standard.js
|
|
5
|
+
function ensureSynchronous(value, message) {
|
|
6
|
+
if (value instanceof Promise) throw new Error(message);
|
|
7
|
+
}
|
|
8
|
+
function parseWithDictionary(dictionary, value) {
|
|
9
|
+
const result = {};
|
|
10
|
+
const issues = [];
|
|
11
|
+
for (const key in dictionary) {
|
|
12
|
+
const propResult = dictionary[key]["~standard"].validate(value[key]);
|
|
13
|
+
ensureSynchronous(propResult, `Validation must be synchronous, but ${key} returned a Promise.`);
|
|
14
|
+
if (propResult.issues) {
|
|
15
|
+
issues.push(...propResult.issues.map((issue) => ({
|
|
16
|
+
...issue,
|
|
17
|
+
message: issue.message,
|
|
18
|
+
path: [key, ...issue.path ?? []]
|
|
19
|
+
})));
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
result[key] = propResult.value;
|
|
23
|
+
}
|
|
24
|
+
if (issues.length) return { issues };
|
|
25
|
+
return { value: result };
|
|
26
|
+
}
|
|
43
27
|
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
28
|
+
// ../../node_modules/.bun/@t3-oss+env-core@0.13.11+dcb9db7a51b27bde/node_modules/@t3-oss/env-core/dist/index.js
|
|
29
|
+
function createEnv(opts) {
|
|
30
|
+
const runtimeEnv = opts.runtimeEnvStrict ?? opts.runtimeEnv ?? process.env;
|
|
31
|
+
if (opts.emptyStringAsUndefined ?? false) {
|
|
32
|
+
for (const [key, value] of Object.entries(runtimeEnv)) if (value === "") delete runtimeEnv[key];
|
|
33
|
+
}
|
|
34
|
+
if (!!opts.skipValidation) {
|
|
35
|
+
if (opts.extends) for (const preset of opts.extends) preset.skipValidation = true;
|
|
36
|
+
return runtimeEnv;
|
|
37
|
+
}
|
|
38
|
+
const _client = typeof opts.client === "object" ? opts.client : {};
|
|
39
|
+
const _server = typeof opts.server === "object" ? opts.server : {};
|
|
40
|
+
const _shared = typeof opts.shared === "object" ? opts.shared : {};
|
|
41
|
+
const isServer = opts.isServer ?? (typeof window === "undefined" || "Deno" in window);
|
|
42
|
+
const finalSchemaShape = isServer ? {
|
|
43
|
+
..._server,
|
|
44
|
+
..._shared,
|
|
45
|
+
..._client
|
|
46
|
+
} : {
|
|
47
|
+
..._client,
|
|
48
|
+
..._shared
|
|
49
|
+
};
|
|
50
|
+
const parsed = opts.createFinalSchema?.(finalSchemaShape, isServer)?.["~standard"].validate(runtimeEnv) ?? parseWithDictionary(finalSchemaShape, runtimeEnv);
|
|
51
|
+
ensureSynchronous(parsed, "Validation must be synchronous");
|
|
52
|
+
const onValidationError = opts.onValidationError ?? ((issues) => {
|
|
53
|
+
console.error("\u274C Invalid environment variables:", issues);
|
|
54
|
+
throw new Error("Invalid environment variables");
|
|
55
|
+
});
|
|
56
|
+
const onInvalidAccess = opts.onInvalidAccess ?? (() => {
|
|
57
|
+
throw new Error("\u274C Attempted to access a server-side environment variable on the client");
|
|
58
|
+
});
|
|
59
|
+
if (parsed.issues) return onValidationError(parsed.issues);
|
|
60
|
+
const isServerAccess = (prop) => {
|
|
61
|
+
if (!opts.clientPrefix) return true;
|
|
62
|
+
return !prop.startsWith(opts.clientPrefix) && !(prop in _shared);
|
|
63
|
+
};
|
|
64
|
+
const isValidServerAccess = (prop) => {
|
|
65
|
+
return isServer || !isServerAccess(prop);
|
|
66
|
+
};
|
|
67
|
+
const ignoreProp = (prop) => {
|
|
68
|
+
return prop === "__esModule" || prop === "$$typeof";
|
|
69
|
+
};
|
|
70
|
+
const extendedObj = (opts.extends ?? []).reduce((acc, curr) => {
|
|
71
|
+
return Object.assign(acc, curr);
|
|
72
|
+
}, {});
|
|
73
|
+
const fullObj = Object.assign(extendedObj, parsed.value);
|
|
74
|
+
return new Proxy(fullObj, { get(target, prop) {
|
|
75
|
+
if (typeof prop !== "string") return void 0;
|
|
76
|
+
if (ignoreProp(prop)) return void 0;
|
|
77
|
+
if (!isValidServerAccess(prop)) return onInvalidAccess(prop);
|
|
78
|
+
return Reflect.get(target, prop);
|
|
79
|
+
} });
|
|
80
|
+
}
|
|
48
81
|
|
|
49
|
-
//
|
|
50
|
-
import {
|
|
51
|
-
import { z } from "zod";
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"belongsTo",
|
|
70
|
-
"manyToMany"
|
|
71
|
-
]);
|
|
72
|
-
var FieldDefinitionSchema = z.object({
|
|
73
|
-
type: FieldTypeSchema,
|
|
74
|
-
required: z.boolean().default(false),
|
|
75
|
-
primary: z.boolean().default(false),
|
|
76
|
-
unique: z.boolean().default(false),
|
|
77
|
-
default: z.unknown().optional(),
|
|
78
|
-
substrate: z.string().optional(),
|
|
79
|
-
computed: z.boolean().optional(),
|
|
80
|
-
derivedBy: z.string().optional(),
|
|
81
|
-
cache: z.object({
|
|
82
|
-
ttl: z.string()
|
|
83
|
-
}).optional(),
|
|
84
|
-
auto: z.boolean().optional(),
|
|
85
|
-
enum: z.array(z.string()).optional(),
|
|
86
|
-
dimensions: z.number().int().optional(),
|
|
87
|
-
items: z.string().optional(),
|
|
88
|
-
description: z.string().optional()
|
|
89
|
-
}).passthrough();
|
|
90
|
-
var RelationshipDefinitionSchema = z.object({
|
|
91
|
-
name: z.string().optional(),
|
|
92
|
-
type: RelationshipTypeSchema,
|
|
93
|
-
targetEntity: z.string(),
|
|
94
|
-
foreignKey: z.string().optional(),
|
|
95
|
-
substrate: z.string().optional(),
|
|
96
|
-
cascade: z.object({
|
|
97
|
-
delete: z.enum(["hard", "soft", "restrict", "nullify"]),
|
|
98
|
-
update: z.enum(["cascade", "restrict"])
|
|
99
|
-
}).optional(),
|
|
100
|
-
computed: z.record(z.string(), z.unknown()).optional(),
|
|
101
|
-
description: z.string().optional()
|
|
102
|
-
}).passthrough();
|
|
103
|
-
var SubstrateRoutingSchema = z.object({
|
|
104
|
-
operational: z.string().optional(),
|
|
105
|
-
analytical: z.string().optional(),
|
|
106
|
-
semantic: z.string().optional(),
|
|
107
|
-
cache: z.string().optional()
|
|
108
|
-
}).passthrough();
|
|
109
|
-
var SemanticMetadataSchema = z.object({
|
|
110
|
-
description: z.string().optional(),
|
|
111
|
-
lifecycle: z.array(z.string()).optional(),
|
|
112
|
-
criticalFields: z.array(z.string()).optional(),
|
|
113
|
-
significantEvents: z.array(z.string()).optional(),
|
|
114
|
-
tags: z.array(z.string()).optional()
|
|
115
|
-
}).passthrough();
|
|
116
|
-
var IndexDefinitionSchema = z.object({
|
|
117
|
-
name: z.string().optional(),
|
|
118
|
-
fields: z.array(z.string()).min(1),
|
|
82
|
+
// ../core/dist/index.js
|
|
83
|
+
import { z as z2 } from "zod";
|
|
84
|
+
import { z as z3 } from "zod";
|
|
85
|
+
import { z as z4 } from "zod";
|
|
86
|
+
var DEFAULT_BASE_URL = "https://api.frontal.dev/v1";
|
|
87
|
+
var API_KEY_PREFIX = "frt_";
|
|
88
|
+
var BACKOFF_STRATEGIES = [
|
|
89
|
+
"exponential",
|
|
90
|
+
"linear",
|
|
91
|
+
"constant"
|
|
92
|
+
];
|
|
93
|
+
var DEFAULT_RETRY_ON = [429, 500, 502, 503, 504];
|
|
94
|
+
var EXPONENTIAL_BASE = 2;
|
|
95
|
+
var JITTER_MAX = 200;
|
|
96
|
+
var SDK_VERSION = "1.0.1";
|
|
97
|
+
var timestampSchema = z.date().transform((date) => new Date(date));
|
|
98
|
+
var responseMetaSchema = z.object({
|
|
99
|
+
requestId: z.string().min(1),
|
|
100
|
+
timestamp: timestampSchema,
|
|
101
|
+
version: z.string().optional(),
|
|
119
102
|
substrate: z.string().optional(),
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
name: z.string(),
|
|
125
|
-
displayName: z.string().optional(),
|
|
126
|
-
description: z.string().optional(),
|
|
127
|
-
extends: z.string().optional(),
|
|
128
|
-
mixins: z.array(z.string()).optional(),
|
|
129
|
-
fields: z.record(z.string(), FieldDefinitionSchema),
|
|
130
|
-
relationships: z.record(z.string(), RelationshipDefinitionSchema).optional(),
|
|
131
|
-
substrates: SubstrateRoutingSchema.optional(),
|
|
132
|
-
semantics: SemanticMetadataSchema.optional(),
|
|
133
|
-
indexes: z.array(IndexDefinitionSchema).optional(),
|
|
134
|
-
status: z.enum(["draft", "active", "deprecated"]).default("draft")
|
|
103
|
+
latency: z.object({
|
|
104
|
+
total: z.number().int().min(0),
|
|
105
|
+
substrate: z.number().int().min(0).optional()
|
|
106
|
+
}).optional()
|
|
135
107
|
}).strict();
|
|
136
|
-
var
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}).passthrough();
|
|
143
|
-
var MigrationPlanSchema = z.object({
|
|
144
|
-
id: z.string(),
|
|
145
|
-
modelId: z.string(),
|
|
146
|
-
fromVersion: z.number().int(),
|
|
147
|
-
toVersion: z.number().int(),
|
|
148
|
-
changes: z.array(
|
|
149
|
-
z.object({
|
|
150
|
-
type: z.enum([
|
|
151
|
-
"add-field",
|
|
152
|
-
"remove-field",
|
|
153
|
-
"modify-field",
|
|
154
|
-
"add-relationship",
|
|
155
|
-
"remove-relationship"
|
|
156
|
-
]),
|
|
157
|
-
description: z.string(),
|
|
158
|
-
impact: z.enum(["breaking", "non-breaking", "data-loss"]),
|
|
159
|
-
sql: z.string().optional()
|
|
160
|
-
})
|
|
161
|
-
),
|
|
162
|
-
riskLevel: z.enum(["low", "medium", "high", "critical"]),
|
|
163
|
-
estimatedDowntime: z.string().optional(),
|
|
164
|
-
rolloutStrategy: z.enum([
|
|
165
|
-
"zero-downtime",
|
|
166
|
-
"maintenance-window",
|
|
167
|
-
"immediate"
|
|
168
|
-
]),
|
|
169
|
-
createdAt: timestampSchema
|
|
170
|
-
}).passthrough();
|
|
171
|
-
var RuleDefinitionSchema = z.object({
|
|
172
|
-
name: z.string(),
|
|
173
|
-
description: z.string().optional(),
|
|
174
|
-
entityTypes: z.array(z.string()).min(1),
|
|
175
|
-
condition: z.string(),
|
|
176
|
-
action: z.enum(["validate", "transform", "notify"]),
|
|
177
|
-
severity: z.enum(["error", "warning", "info"]),
|
|
178
|
-
enabled: z.boolean().default(true)
|
|
108
|
+
var paginationMetaSchema = z.object({
|
|
109
|
+
cursor: z.string().min(1),
|
|
110
|
+
hasMore: z.boolean(),
|
|
111
|
+
limit: z.number().int().positive().optional(),
|
|
112
|
+
total: z.number().int().min(0).optional(),
|
|
113
|
+
offset: z.number().int().min(0).optional()
|
|
179
114
|
}).strict();
|
|
180
|
-
var
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
relationships: z.record(z.string(), RelationshipDefinitionSchema).optional(),
|
|
185
|
-
appliesTo: z.array(z.string()).optional()
|
|
115
|
+
var errorFieldSchema = z.object({
|
|
116
|
+
field: z.string().describe("Field name"),
|
|
117
|
+
code: z.string().describe("Error code"),
|
|
118
|
+
message: z.string().describe("Error message")
|
|
186
119
|
}).strict();
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
var
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
120
|
+
var docsUrlSchema = z.string().url().refine((url) => /^https?:\/\//.test(url), {
|
|
121
|
+
message: "docs must be an http or https URL"
|
|
122
|
+
});
|
|
123
|
+
var errorResponseSchema = z.object({
|
|
124
|
+
code: z.string().min(1).describe("Error code"),
|
|
125
|
+
message: z.string().min(1).describe("Error message"),
|
|
126
|
+
requestId: z.string().min(1).describe("Request ID"),
|
|
127
|
+
docs: docsUrlSchema.optional().describe("Documentation URL"),
|
|
128
|
+
fields: z.array(errorFieldSchema).optional().describe("Array of error fields")
|
|
129
|
+
}).strict();
|
|
130
|
+
var retryStatusCodeSchema = z.number().int().refine((status) => status === 429 || status >= 500 && status <= 599, {
|
|
131
|
+
message: "Retry status codes must be 429 or 5xx"
|
|
132
|
+
});
|
|
133
|
+
var retryConfigSchema = z.object({
|
|
134
|
+
maxAttempts: z.number().int().positive().default(3),
|
|
135
|
+
baseDelay: z.number().int().positive().default(1e3),
|
|
136
|
+
strategy: z.enum(BACKOFF_STRATEGIES).default("exponential"),
|
|
137
|
+
on: z.array(retryStatusCodeSchema).default(DEFAULT_RETRY_ON),
|
|
138
|
+
jitter: z.boolean().default(true)
|
|
139
|
+
}).strict().default({
|
|
140
|
+
maxAttempts: 3,
|
|
141
|
+
baseDelay: 1e3,
|
|
142
|
+
strategy: "exponential",
|
|
143
|
+
on: DEFAULT_RETRY_ON,
|
|
144
|
+
jitter: true
|
|
145
|
+
});
|
|
146
|
+
var numericValueSchema = z.union([
|
|
147
|
+
z.number(),
|
|
148
|
+
z.literal(Number.POSITIVE_INFINITY),
|
|
149
|
+
z.literal(Number.NEGATIVE_INFINITY)
|
|
150
|
+
]);
|
|
151
|
+
var arrayFilterValueSchema = z.union([
|
|
152
|
+
z.array(z.string()),
|
|
153
|
+
z.array(numericValueSchema)
|
|
154
|
+
]);
|
|
155
|
+
var scalarFilterValueSchema = z.union([
|
|
156
|
+
z.string(),
|
|
157
|
+
numericValueSchema,
|
|
158
|
+
z.boolean(),
|
|
159
|
+
z.date(),
|
|
160
|
+
z.null(),
|
|
161
|
+
arrayFilterValueSchema
|
|
162
|
+
]);
|
|
163
|
+
var comparableValueSchema = z.union([numericValueSchema, z.date()]);
|
|
164
|
+
var filterOperatorSchema = z.object({
|
|
165
|
+
eq: scalarFilterValueSchema.optional(),
|
|
166
|
+
ne: scalarFilterValueSchema.optional(),
|
|
167
|
+
gt: comparableValueSchema.optional(),
|
|
168
|
+
gte: comparableValueSchema.optional(),
|
|
169
|
+
lt: comparableValueSchema.optional(),
|
|
170
|
+
lte: comparableValueSchema.optional(),
|
|
171
|
+
in: arrayFilterValueSchema.optional(),
|
|
172
|
+
nin: arrayFilterValueSchema.optional(),
|
|
173
|
+
contains: z.string().optional(),
|
|
174
|
+
startsWith: z.string().optional(),
|
|
175
|
+
endsWith: z.string().optional()
|
|
176
|
+
}).strict().refine(
|
|
177
|
+
(value) => Object.values(value).some((entry) => entry !== void 0),
|
|
178
|
+
{
|
|
179
|
+
message: "At least one filter operator is required"
|
|
180
|
+
}
|
|
181
|
+
);
|
|
182
|
+
var filterValueSchema = z.union([
|
|
183
|
+
scalarFilterValueSchema,
|
|
184
|
+
filterOperatorSchema
|
|
185
|
+
]);
|
|
186
|
+
var filterConditionsSchema = z.record(z.string(), filterValueSchema);
|
|
187
|
+
var pageResultSchema = z.object({
|
|
188
|
+
data: z.array(z.unknown()),
|
|
189
|
+
meta: responseMetaSchema.optional(),
|
|
190
|
+
pagination: paginationMetaSchema
|
|
191
|
+
}).strict();
|
|
192
|
+
var FrontalError = class extends Error {
|
|
193
|
+
code;
|
|
194
|
+
requestId;
|
|
195
|
+
statusCode;
|
|
196
|
+
docs;
|
|
197
|
+
rateLimit;
|
|
198
|
+
/**
|
|
199
|
+
* @param response - The parsed error response from the API.
|
|
200
|
+
* @param statusCode - The HTTP status code.
|
|
201
|
+
* @param rateLimit - Optional rate-limit headers from the response.
|
|
202
|
+
*/
|
|
203
|
+
constructor(response, statusCode, rateLimit) {
|
|
204
|
+
super(response.message);
|
|
205
|
+
this.name = "FrontalError";
|
|
206
|
+
this.code = response.code;
|
|
207
|
+
this.requestId = response.requestId;
|
|
208
|
+
this.statusCode = statusCode;
|
|
209
|
+
this.docs = response.docs;
|
|
210
|
+
this.rateLimit = rateLimit;
|
|
211
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
212
|
+
if (Error.captureStackTrace) {
|
|
213
|
+
Error.captureStackTrace(this);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
var NotFoundError = class extends FrontalError {
|
|
218
|
+
constructor(r, rateLimit) {
|
|
219
|
+
super(r, 404, rateLimit);
|
|
220
|
+
this.name = "NotFoundError";
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
var UnauthorizedError = class extends FrontalError {
|
|
224
|
+
constructor(r, rateLimit) {
|
|
225
|
+
super(r, 401, rateLimit);
|
|
226
|
+
this.name = "UnauthorizedError";
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
var ForbiddenError = class extends FrontalError {
|
|
230
|
+
constructor(r, rateLimit) {
|
|
231
|
+
super(r, 403, rateLimit);
|
|
232
|
+
this.name = "ForbiddenError";
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
var ValidationError = class extends FrontalError {
|
|
236
|
+
/** Per-field validation errors returned by the API. */
|
|
237
|
+
fields;
|
|
238
|
+
constructor(r, rateLimit) {
|
|
239
|
+
super(r, 400, rateLimit);
|
|
240
|
+
this.name = "ValidationError";
|
|
241
|
+
this.fields = r.fields ?? [];
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
var ConflictError = class extends FrontalError {
|
|
245
|
+
constructor(r, rateLimit) {
|
|
246
|
+
super(r, 409, rateLimit);
|
|
247
|
+
this.name = "ConflictError";
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
var RateLimitError = class extends FrontalError {
|
|
251
|
+
/** Recommended delay in seconds before retrying. */
|
|
252
|
+
retryAfter;
|
|
253
|
+
constructor(r, retryAfter, rateLimit) {
|
|
254
|
+
super(r, 429, rateLimit);
|
|
255
|
+
this.name = "RateLimitError";
|
|
256
|
+
this.retryAfter = retryAfter;
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
var ServiceError = class extends FrontalError {
|
|
260
|
+
constructor(r, status, rateLimit) {
|
|
261
|
+
super(r, status, rateLimit);
|
|
262
|
+
this.name = "ServiceError";
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
var NetworkError = class extends Error {
|
|
266
|
+
constructor(cause) {
|
|
267
|
+
super("Network error \u2014 could not reach Frontal API");
|
|
268
|
+
this.cause = cause;
|
|
269
|
+
this.name = "NetworkError";
|
|
270
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
271
|
+
if (Error.captureStackTrace) {
|
|
272
|
+
Error.captureStackTrace(this, new.target);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
function normalizeErrorBody(body) {
|
|
277
|
+
const parsed = errorResponseSchema.safeParse(body);
|
|
278
|
+
if (parsed.success) return parsed.data;
|
|
279
|
+
const fallback = typeof body === "object" && body !== null ? body : {};
|
|
280
|
+
const code = typeof fallback.code === "string" && fallback.code.length > 0 ? fallback.code : "UNKNOWN_ERROR";
|
|
281
|
+
const hasExplicitCode = typeof fallback.code === "string" && fallback.code.length > 0;
|
|
282
|
+
const message = hasExplicitCode && typeof fallback.message === "string" && fallback.message.length > 0 ? fallback.message : "An unknown error occurred";
|
|
283
|
+
return {
|
|
284
|
+
code,
|
|
285
|
+
message,
|
|
286
|
+
requestId: typeof fallback.requestId === "string" && fallback.requestId.length > 0 ? fallback.requestId : "unknown",
|
|
287
|
+
docs: typeof fallback.docs === "string" ? fallback.docs : void 0,
|
|
288
|
+
fields: Array.isArray(fallback.fields) ? fallback.fields : void 0
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
function parseFrontalError(body, status, retryAfter, rateLimit) {
|
|
292
|
+
const normalized = normalizeErrorBody(body);
|
|
293
|
+
switch (status) {
|
|
294
|
+
case 400:
|
|
295
|
+
return new ValidationError(normalized, rateLimit);
|
|
296
|
+
case 401:
|
|
297
|
+
return new UnauthorizedError(normalized, rateLimit);
|
|
298
|
+
case 403:
|
|
299
|
+
return new ForbiddenError(normalized, rateLimit);
|
|
300
|
+
case 404:
|
|
301
|
+
return new NotFoundError(normalized, rateLimit);
|
|
302
|
+
case 409:
|
|
303
|
+
return new ConflictError(normalized, rateLimit);
|
|
304
|
+
case 429: {
|
|
305
|
+
const parsedRetry = retryAfter ? Number.parseInt(retryAfter, 10) : Number.NaN;
|
|
306
|
+
return new RateLimitError(
|
|
307
|
+
normalized,
|
|
308
|
+
Number.isFinite(parsedRetry) ? parsedRetry : 60,
|
|
309
|
+
rateLimit
|
|
207
310
|
);
|
|
208
|
-
}
|
|
311
|
+
}
|
|
312
|
+
default:
|
|
313
|
+
return new ServiceError(normalized, status, rateLimit);
|
|
209
314
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
315
|
+
}
|
|
316
|
+
var CircuitBreaker = class {
|
|
317
|
+
failures = 0;
|
|
318
|
+
lastFailureTime = 0;
|
|
319
|
+
state = "CLOSED";
|
|
320
|
+
config;
|
|
321
|
+
constructor(config) {
|
|
322
|
+
this.config = config;
|
|
215
323
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
return this.http.post("/ontology/engine/ontologies/validate", body);
|
|
220
|
-
});
|
|
324
|
+
/** Returns the current circuit state. */
|
|
325
|
+
getState() {
|
|
326
|
+
return this.state;
|
|
221
327
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
328
|
+
/** Returns the current consecutive failure count. */
|
|
329
|
+
getFailures() {
|
|
330
|
+
return this.failures;
|
|
331
|
+
}
|
|
332
|
+
reset() {
|
|
333
|
+
this.failures = 0;
|
|
334
|
+
this.state = "CLOSED";
|
|
335
|
+
this.config.onClose?.();
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Executes an async function through the circuit breaker.
|
|
339
|
+
* Throws CircuitBreakerOpenError immediately if the circuit is OPEN
|
|
340
|
+
* and the reset timeout has not elapsed. On success in HALF_OPEN state,
|
|
341
|
+
* resets the circuit to CLOSED.
|
|
342
|
+
*
|
|
343
|
+
* @param fn - The async operation to protect.
|
|
344
|
+
* @throws {CircuitBreakerOpenError} If the circuit is OPEN.
|
|
345
|
+
*/
|
|
346
|
+
async execute(fn) {
|
|
347
|
+
if (this.state === "OPEN") {
|
|
348
|
+
if (Date.now() - this.lastFailureTime > this.config.resetTimeoutMs) {
|
|
349
|
+
this.state = "HALF_OPEN";
|
|
350
|
+
this.config.onHalfOpen?.();
|
|
351
|
+
} else {
|
|
352
|
+
throw new CircuitBreakerOpenError(
|
|
353
|
+
this.config.resetTimeoutMs - (Date.now() - this.lastFailureTime)
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
try {
|
|
358
|
+
const result = await fn();
|
|
359
|
+
if (this.state === "HALF_OPEN") {
|
|
360
|
+
this.reset();
|
|
361
|
+
}
|
|
362
|
+
return result;
|
|
363
|
+
} catch (error) {
|
|
364
|
+
this.failures++;
|
|
365
|
+
this.lastFailureTime = Date.now();
|
|
366
|
+
if (this.failures >= this.config.failureThreshold) {
|
|
367
|
+
this.state = "OPEN";
|
|
368
|
+
this.config.onOpen?.();
|
|
369
|
+
}
|
|
370
|
+
throw error;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
/** Manually forces the circuit into the OPEN state. */
|
|
374
|
+
forceOpen() {
|
|
375
|
+
this.state = "OPEN";
|
|
376
|
+
this.lastFailureTime = Date.now();
|
|
377
|
+
}
|
|
378
|
+
/** Manually resets the circuit to the CLOSED state. */
|
|
379
|
+
forceClose() {
|
|
380
|
+
this.reset();
|
|
226
381
|
}
|
|
227
382
|
};
|
|
228
|
-
var
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
383
|
+
var CircuitBreakerOpenError = class extends Error {
|
|
384
|
+
/** Milliseconds remaining until the circuit transitions to HALF_OPEN. */
|
|
385
|
+
retryAfterMs;
|
|
386
|
+
constructor(retryAfterMs) {
|
|
387
|
+
super(
|
|
388
|
+
`Circuit breaker is open \u2014 retry after ${Math.ceil(retryAfterMs / 1e3)}s`
|
|
389
|
+
);
|
|
390
|
+
this.name = "CircuitBreakerOpenError";
|
|
391
|
+
this.retryAfterMs = retryAfterMs;
|
|
392
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
232
393
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
394
|
+
};
|
|
395
|
+
function computeBaseDelay(attempt, strategy, baseDelay) {
|
|
396
|
+
const normalizedAttempt = Math.floor(attempt);
|
|
397
|
+
switch (strategy) {
|
|
398
|
+
case "linear":
|
|
399
|
+
return Math.max(0, baseDelay * (normalizedAttempt + 1));
|
|
400
|
+
case "constant":
|
|
401
|
+
return baseDelay;
|
|
402
|
+
default:
|
|
403
|
+
return baseDelay * EXPONENTIAL_BASE ** normalizedAttempt;
|
|
238
404
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
405
|
+
}
|
|
406
|
+
function calculateDelay(attempt, strategyOrConfig, baseDelay, withJitter = false) {
|
|
407
|
+
if (typeof strategyOrConfig === "object") {
|
|
408
|
+
const strategy = "strategy" in strategyOrConfig ? strategyOrConfig.strategy : strategyOrConfig.backoff;
|
|
409
|
+
const delayBase = "baseDelay" in strategyOrConfig ? strategyOrConfig.baseDelay : strategyOrConfig.retryDelay;
|
|
410
|
+
const delay2 = computeBaseDelay(attempt, strategy, delayBase);
|
|
411
|
+
const shouldJitter = "jitter" in strategyOrConfig ? Boolean(strategyOrConfig.jitter) : true;
|
|
412
|
+
if (!shouldJitter) return delay2;
|
|
413
|
+
return delay2 + Math.random() * (JITTER_MAX / 2);
|
|
243
414
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
415
|
+
const delay = computeBaseDelay(
|
|
416
|
+
attempt,
|
|
417
|
+
strategyOrConfig,
|
|
418
|
+
Math.max(0, baseDelay ?? 0)
|
|
419
|
+
);
|
|
420
|
+
if (!withJitter) return delay;
|
|
421
|
+
return delay + Math.random() * (JITTER_MAX / 2);
|
|
422
|
+
}
|
|
423
|
+
function snakeToCamel(str) {
|
|
424
|
+
const prefix = str.match(/^_+/)?.[0] ?? "";
|
|
425
|
+
const body = str.slice(prefix.length);
|
|
426
|
+
if (!body) return str;
|
|
427
|
+
return prefix + body.replace(/_([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
428
|
+
}
|
|
429
|
+
function camelToSnake(str) {
|
|
430
|
+
return str.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
|
|
431
|
+
}
|
|
432
|
+
var NEVER_TRANSFORM_KEYS = /* @__PURE__ */ new Set(["$ref", "$schema", "$id"]);
|
|
433
|
+
function isStream(obj) {
|
|
434
|
+
return typeof obj === "object" && obj !== null && (typeof obj.pipe === "function" || typeof obj.getReader === "function");
|
|
435
|
+
}
|
|
436
|
+
function deepTransformKeys(obj, transform, skipKeys) {
|
|
437
|
+
if (obj === null || obj === void 0) return obj;
|
|
438
|
+
if (typeof obj !== "object") return obj;
|
|
439
|
+
if (obj instanceof Date || typeof Buffer !== "undefined" && obj instanceof Buffer || obj instanceof RegExp || obj instanceof FormData || obj instanceof File || obj instanceof Blob)
|
|
440
|
+
return obj;
|
|
441
|
+
if (isStream(obj)) return obj;
|
|
442
|
+
if (Array.isArray(obj)) {
|
|
443
|
+
return obj.map(
|
|
444
|
+
(item) => deepTransformKeys(item, transform, skipKeys)
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
const proto = Object.getPrototypeOf(obj);
|
|
448
|
+
if (proto !== Object.prototype && proto !== null) return obj;
|
|
449
|
+
const result = {};
|
|
450
|
+
for (const key of Object.keys(obj)) {
|
|
451
|
+
const shouldSkip = skipKeys?.has(key) || NEVER_TRANSFORM_KEYS.has(key);
|
|
452
|
+
const newKey = shouldSkip ? key : transform(key);
|
|
453
|
+
result[newKey] = deepTransformKeys(
|
|
454
|
+
obj[key],
|
|
455
|
+
transform,
|
|
456
|
+
skipKeys
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
return result;
|
|
460
|
+
}
|
|
461
|
+
function deepCamelToSnake(obj, skipKeys) {
|
|
462
|
+
return deepTransformKeys(obj, camelToSnake, skipKeys);
|
|
463
|
+
}
|
|
464
|
+
function deepSnakeToCamel(obj, skipKeys) {
|
|
465
|
+
return deepTransformKeys(obj, snakeToCamel, skipKeys);
|
|
466
|
+
}
|
|
467
|
+
var HttpClient = class {
|
|
468
|
+
constructor(config) {
|
|
469
|
+
this.config = config;
|
|
470
|
+
if (config.circuitBreaker) {
|
|
471
|
+
this.breaker = new CircuitBreaker({
|
|
472
|
+
failureThreshold: config.circuitBreaker.failureThreshold,
|
|
473
|
+
resetTimeoutMs: config.circuitBreaker.resetTimeoutMs
|
|
249
474
|
});
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
breaker;
|
|
478
|
+
/**
|
|
479
|
+
* Sends a GET request.
|
|
480
|
+
* @param path - API endpoint path.
|
|
481
|
+
* @param params - Optional query parameters.
|
|
482
|
+
* @param schema - Optional Zod schema for response validation.
|
|
483
|
+
*/
|
|
484
|
+
async get(path, params, schema) {
|
|
485
|
+
return this.request("GET", path, void 0, params, schema);
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Sends a POST request with a JSON body.
|
|
489
|
+
* @param path - API endpoint path.
|
|
490
|
+
* @param body - Request payload (converted to snake_case automatically).
|
|
491
|
+
* @param schema - Optional Zod schema for response validation.
|
|
492
|
+
*/
|
|
493
|
+
async post(path, body, schema) {
|
|
494
|
+
return this.request("POST", path, body ?? {}, void 0, schema);
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Sends a PUT request with a JSON body.
|
|
498
|
+
* @param path - API endpoint path.
|
|
499
|
+
* @param body - Request payload (converted to snake_case automatically).
|
|
500
|
+
* @param schema - Optional Zod schema for response validation.
|
|
501
|
+
*/
|
|
502
|
+
async put(path, body, schema) {
|
|
503
|
+
return this.request("PUT", path, body ?? {}, void 0, schema);
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Sends a PATCH request with a JSON body.
|
|
507
|
+
* @param path - API endpoint path.
|
|
508
|
+
* @param body - Request payload (converted to snake_case automatically).
|
|
509
|
+
* @param schema - Optional Zod schema for response validation.
|
|
510
|
+
*/
|
|
511
|
+
async patch(path, body, schema) {
|
|
512
|
+
return this.request("PATCH", path, body ?? {}, void 0, schema);
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Sends a DELETE request.
|
|
516
|
+
* @param path - API endpoint path.
|
|
517
|
+
* @param params - Optional query parameters.
|
|
518
|
+
* @param schema - Optional Zod schema for response validation.
|
|
519
|
+
*/
|
|
520
|
+
async delete(path, params, schema) {
|
|
521
|
+
return this.request("DELETE", path, {}, params, schema);
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Sends a raw PUT request with a binary/stream body.
|
|
525
|
+
* @param path - API endpoint path.
|
|
526
|
+
* @param body - Binary buffer or readable stream.
|
|
527
|
+
* @param contentType - MIME type of the body.
|
|
528
|
+
* @param headers - Additional request headers.
|
|
529
|
+
* @returns The parsed JSON response with keys converted to camelCase.
|
|
530
|
+
*/
|
|
531
|
+
async putRaw(path, body, contentType, headers = {}) {
|
|
532
|
+
const url = this.buildUrl(path);
|
|
533
|
+
const res = await this.fetchWithTimeout(url, {
|
|
534
|
+
method: "PUT",
|
|
535
|
+
headers: this.buildHeaders({ "Content-Type": contentType, ...headers }),
|
|
536
|
+
body
|
|
250
537
|
});
|
|
538
|
+
if (!res.ok) await this.throwError(res);
|
|
539
|
+
if (res.status === 204) return void 0;
|
|
540
|
+
const json = await res.json();
|
|
541
|
+
return typeof json === "object" && json !== null ? deepSnakeToCamel(json) : json;
|
|
251
542
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
543
|
+
/**
|
|
544
|
+
* Opens a GET SSE stream, yielding parsed server-sent events.
|
|
545
|
+
* @param path - API endpoint path.
|
|
546
|
+
* @param params - Optional query parameters.
|
|
547
|
+
* @yields SSE event objects with `type`, `data`, and optional `id` fields.
|
|
548
|
+
*/
|
|
549
|
+
async *stream(path, params) {
|
|
550
|
+
const url = this.buildUrl(path, params);
|
|
551
|
+
const res = await this.fetchWithTimeout(url, {
|
|
552
|
+
method: "GET",
|
|
553
|
+
headers: this.buildHeaders({ Accept: "text/event-stream" })
|
|
255
554
|
});
|
|
555
|
+
if (!res.ok) await this.throwError(res);
|
|
556
|
+
yield* this.parseSSEResponse(res);
|
|
256
557
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
558
|
+
/**
|
|
559
|
+
* Sends a POST request that returns an SSE stream.
|
|
560
|
+
* @param path - API endpoint path.
|
|
561
|
+
* @param body - Request payload (converted to snake_case automatically).
|
|
562
|
+
* @yields SSE event objects with `type`, `data`, and optional `id` fields.
|
|
563
|
+
*/
|
|
564
|
+
async *postStream(path, body) {
|
|
565
|
+
const url = this.buildUrl(path);
|
|
566
|
+
const res = await this.fetchWithTimeout(url, {
|
|
567
|
+
method: "POST",
|
|
568
|
+
headers: this.buildHeaders({ Accept: "text/event-stream" }),
|
|
569
|
+
body: JSON.stringify(body ?? {})
|
|
261
570
|
});
|
|
571
|
+
if (!res.ok) await this.throwError(res);
|
|
572
|
+
yield* this.parseSSEResponse(res);
|
|
262
573
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
574
|
+
/**
|
|
575
|
+
* Sends a POST request and returns the raw Response object.
|
|
576
|
+
* @param path - API endpoint path.
|
|
577
|
+
* @param body - Request payload.
|
|
578
|
+
* @param headers - Additional request headers.
|
|
579
|
+
* @returns The raw fetch Response (caller must handle parsing).
|
|
580
|
+
*/
|
|
581
|
+
async postRaw(path, body, headers = {}) {
|
|
582
|
+
const url = this.buildUrl(path);
|
|
583
|
+
const res = await this.fetchWithTimeout(url, {
|
|
584
|
+
method: "POST",
|
|
585
|
+
headers: new Headers(this.buildHeaders(headers)),
|
|
586
|
+
body: JSON.stringify(body ?? {})
|
|
269
587
|
});
|
|
588
|
+
if (!res.ok) await this.throwError(res);
|
|
589
|
+
return res;
|
|
270
590
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
591
|
+
/**
|
|
592
|
+
* Sends a POST request with a FormData body (multipart/form-data).
|
|
593
|
+
* Automatically removes the Content-Type header so the browser sets the
|
|
594
|
+
* correct multipart boundary.
|
|
595
|
+
* @param path - API endpoint path.
|
|
596
|
+
* @param formData - FormData payload.
|
|
597
|
+
* @param headers - Additional request headers.
|
|
598
|
+
* @returns The parsed JSON response with keys converted to camelCase.
|
|
599
|
+
*/
|
|
600
|
+
async postFormData(path, formData, headers = {}) {
|
|
601
|
+
const url = this.buildUrl(path);
|
|
602
|
+
const merged = new Headers(this.buildHeaders(headers));
|
|
603
|
+
merged.delete("Content-Type");
|
|
604
|
+
const res = await this.fetchWithTimeout(url, {
|
|
605
|
+
method: "POST",
|
|
606
|
+
headers: merged,
|
|
607
|
+
body: formData
|
|
274
608
|
});
|
|
609
|
+
if (!res.ok) await this.throwError(res);
|
|
610
|
+
const json = await res.json();
|
|
611
|
+
return deepSnakeToCamel(json);
|
|
275
612
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
613
|
+
/**
|
|
614
|
+
* Sends a raw GET request and returns the Response object directly.
|
|
615
|
+
* @param path - API endpoint path.
|
|
616
|
+
* @param params - Optional query parameters.
|
|
617
|
+
* @param headers - Additional request headers.
|
|
618
|
+
* @returns The raw fetch Response (caller must handle parsing).
|
|
619
|
+
*/
|
|
620
|
+
async getRaw(path, params, headers = {}) {
|
|
621
|
+
const url = this.buildUrl(path, params);
|
|
622
|
+
const res = await this.fetchWithTimeout(url, {
|
|
623
|
+
method: "GET",
|
|
624
|
+
headers: this.buildHeaders(headers)
|
|
279
625
|
});
|
|
626
|
+
if (!res.ok) await this.throwError(res);
|
|
627
|
+
return res;
|
|
628
|
+
}
|
|
629
|
+
async *parseSSEResponse(res) {
|
|
630
|
+
if (!res.body) return;
|
|
631
|
+
const reader = res.body.getReader();
|
|
632
|
+
const decoder = new TextDecoder();
|
|
633
|
+
let buffer = "";
|
|
634
|
+
while (true) {
|
|
635
|
+
const { done, value } = await reader.read();
|
|
636
|
+
if (done) break;
|
|
637
|
+
buffer += decoder.decode(value, { stream: true });
|
|
638
|
+
const lines = buffer.split("\n");
|
|
639
|
+
buffer = lines.pop() ?? "";
|
|
640
|
+
let event = {
|
|
641
|
+
type: "message",
|
|
642
|
+
data: null
|
|
643
|
+
};
|
|
644
|
+
for (const rawLine of lines) {
|
|
645
|
+
const line = rawLine.trimEnd();
|
|
646
|
+
if (line.startsWith("id:")) {
|
|
647
|
+
event.id = line.slice(3).trim();
|
|
648
|
+
} else if (line.startsWith("event:")) {
|
|
649
|
+
event.type = line.slice(6).trim();
|
|
650
|
+
} else if (line.startsWith("data:")) {
|
|
651
|
+
const payload = line.slice(5).trim();
|
|
652
|
+
try {
|
|
653
|
+
const parsed = JSON.parse(payload);
|
|
654
|
+
event.data = typeof parsed === "object" && parsed !== null ? deepSnakeToCamel(parsed) : parsed;
|
|
655
|
+
} catch {
|
|
656
|
+
event.data = payload;
|
|
657
|
+
}
|
|
658
|
+
} else if (line === "") {
|
|
659
|
+
if (event.data !== null) yield event;
|
|
660
|
+
event = { type: "message", data: null };
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
async request(method, path, body, params, schema, attempt = 0) {
|
|
666
|
+
const url = this.buildUrl(path, params);
|
|
667
|
+
const requestId = crypto.randomUUID();
|
|
668
|
+
const transformedBody = body !== void 0 && body !== null ? deepCamelToSnake(body) : body;
|
|
669
|
+
const reqInit = {
|
|
670
|
+
method,
|
|
671
|
+
headers: this.buildHeaders({ "X-Request-Id": requestId }),
|
|
672
|
+
...method !== "GET" ? { body: JSON.stringify(transformedBody ?? {}) } : { body: void 0 }
|
|
673
|
+
};
|
|
674
|
+
this.config.logger?.request?.(method, url, reqInit);
|
|
675
|
+
const executeRequest = async () => {
|
|
676
|
+
try {
|
|
677
|
+
return await this.fetchWithTimeout(url, reqInit);
|
|
678
|
+
} catch (error) {
|
|
679
|
+
this.config.logger?.error?.(error);
|
|
680
|
+
throw new NetworkError(error);
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
let res;
|
|
684
|
+
try {
|
|
685
|
+
res = this.breaker ? await this.breaker.execute(executeRequest) : await executeRequest();
|
|
686
|
+
} catch (error) {
|
|
687
|
+
if (error instanceof CircuitBreakerOpenError) {
|
|
688
|
+
throw new Error(
|
|
689
|
+
`Circuit breaker is open. Retry after ${Math.ceil(error.retryAfterMs / 1e3)}s.`
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
throw error;
|
|
693
|
+
}
|
|
694
|
+
this.config.logger?.response?.(res);
|
|
695
|
+
if (!res.ok) {
|
|
696
|
+
const shouldRetry = [429, 500, 502, 503, 504].includes(res.status) && attempt < this.config.maxRetries;
|
|
697
|
+
if (shouldRetry) {
|
|
698
|
+
const retryAfterValue = res.headers.get("Retry-After");
|
|
699
|
+
const retryAfterSeconds = retryAfterValue ? Number.parseInt(retryAfterValue, 10) : Number.NaN;
|
|
700
|
+
const delay = Number.isFinite(retryAfterSeconds) ? retryAfterSeconds * 1e3 : calculateDelay(
|
|
701
|
+
attempt,
|
|
702
|
+
"exponential",
|
|
703
|
+
this.config.retryDelay,
|
|
704
|
+
true
|
|
705
|
+
);
|
|
706
|
+
await sleep(delay);
|
|
707
|
+
return this.request(method, path, body, params, schema, attempt + 1);
|
|
708
|
+
}
|
|
709
|
+
await this.throwError(res);
|
|
710
|
+
}
|
|
711
|
+
if (res.status === 204) return void 0;
|
|
712
|
+
const contentType = (res.headers.get("content-type") || "").toLowerCase();
|
|
713
|
+
const payload = contentType.includes("application/json") ? await res.json() : await res.text();
|
|
714
|
+
const transformedPayload = typeof payload === "object" && payload !== null ? deepSnakeToCamel(payload) : payload;
|
|
715
|
+
if (schema) {
|
|
716
|
+
try {
|
|
717
|
+
const parsed = schema.safeParse(transformedPayload);
|
|
718
|
+
if (!parsed.success) {
|
|
719
|
+
this.config.logger?.error?.(parsed.error);
|
|
720
|
+
throw parsed.error;
|
|
721
|
+
}
|
|
722
|
+
return parsed.data;
|
|
723
|
+
} catch (error) {
|
|
724
|
+
if (error instanceof Error && error.message.includes("_zod")) {
|
|
725
|
+
return transformedPayload;
|
|
726
|
+
}
|
|
727
|
+
throw error;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
return transformedPayload;
|
|
731
|
+
}
|
|
732
|
+
parseRateLimit(res) {
|
|
733
|
+
const limit = res.headers.get("X-RateLimit-Limit");
|
|
734
|
+
const remaining = res.headers.get("X-RateLimit-Remaining");
|
|
735
|
+
const reset = res.headers.get("X-RateLimit-Reset");
|
|
736
|
+
if (limit && remaining && reset) {
|
|
737
|
+
return {
|
|
738
|
+
limit: Number.parseInt(limit, 10),
|
|
739
|
+
remaining: Number.parseInt(remaining, 10),
|
|
740
|
+
reset: Number.parseInt(reset, 10)
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
return void 0;
|
|
744
|
+
}
|
|
745
|
+
async throwError(res) {
|
|
746
|
+
let body;
|
|
747
|
+
try {
|
|
748
|
+
body = await res.json();
|
|
749
|
+
} catch {
|
|
750
|
+
body = {};
|
|
751
|
+
}
|
|
752
|
+
const retryAfter = res.headers.get("Retry-After") ?? void 0;
|
|
753
|
+
const rateLimit = this.parseRateLimit(res);
|
|
754
|
+
throw parseFrontalError(body, res.status, retryAfter, rateLimit);
|
|
755
|
+
}
|
|
756
|
+
buildUrl(path, params) {
|
|
757
|
+
const base = this.config.baseUrl.replace(/\/$/, "");
|
|
758
|
+
let normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
759
|
+
if (base.endsWith("/v1") && normalizedPath.startsWith("/v1/")) {
|
|
760
|
+
if (this.config.debug) {
|
|
761
|
+
console.warn(
|
|
762
|
+
`[SDK] Double /v1/ prefix detected and normalized. The base URL already includes "/v1" but the route "${normalizedPath}" also starts with "/v1/". Write routes without a leading "/v1".`
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
normalizedPath = normalizedPath.slice("/v1".length);
|
|
766
|
+
}
|
|
767
|
+
const url = `${base}${normalizedPath}`;
|
|
768
|
+
const transformedParams = params ? deepCamelToSnake(params) : params;
|
|
769
|
+
if (!transformedParams || Object.keys(transformedParams).length === 0) {
|
|
770
|
+
return url;
|
|
771
|
+
}
|
|
772
|
+
const query = Object.entries(transformedParams).filter(([, value]) => value !== void 0 && value !== null).map(
|
|
773
|
+
([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`
|
|
774
|
+
).join("&");
|
|
775
|
+
return query ? `${url}?${query}` : url;
|
|
776
|
+
}
|
|
777
|
+
buildHeaders(extra = {}) {
|
|
778
|
+
return {
|
|
779
|
+
// The opaque API key (`frt_…`) is the sole public credential. The platform
|
|
780
|
+
// edge validates it and exchanges it for a short-lived JWT before reaching
|
|
781
|
+
// any service — the SDK never sees or sends a JWT.
|
|
782
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
783
|
+
"Content-Type": "application/json",
|
|
784
|
+
Accept: "application/json",
|
|
785
|
+
"User-Agent": "@frontal-labs/core",
|
|
786
|
+
"X-Frontal-Core": `typescript@${SDK_VERSION}`,
|
|
787
|
+
"X-Frontal-Environment": this.config.environment,
|
|
788
|
+
...this.config.headers,
|
|
789
|
+
...extra
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
async fetchWithTimeout(url, init) {
|
|
793
|
+
const controller = new AbortController();
|
|
794
|
+
const timer = setTimeout(() => controller.abort(), this.config.timeout);
|
|
795
|
+
try {
|
|
796
|
+
return await (this.config.fetch ?? fetch)(url, {
|
|
797
|
+
...init,
|
|
798
|
+
signal: controller.signal
|
|
799
|
+
});
|
|
800
|
+
} finally {
|
|
801
|
+
clearTimeout(timer);
|
|
802
|
+
}
|
|
280
803
|
}
|
|
281
804
|
};
|
|
282
|
-
var
|
|
283
|
-
|
|
284
|
-
|
|
805
|
+
var sleep = async (ms) => new Promise((resolve) => {
|
|
806
|
+
setTimeout(resolve, ms);
|
|
807
|
+
});
|
|
808
|
+
var apiKeySchema = z2.string().min(9, "FRONTAL_API_KEY must be at least 9 characters").max(128, "FRONTAL_API_KEY must be at most 128 characters").refine(
|
|
809
|
+
(val) => /^frt_[A-Za-z0-9_]+$/.test(val) || /^fr_typed[A-Za-z0-9_]+$/.test(val),
|
|
810
|
+
"FRONTAL_API_KEY must start with frt_"
|
|
811
|
+
);
|
|
812
|
+
var debugSchema = z2.union([
|
|
813
|
+
z2.literal("true"),
|
|
814
|
+
z2.literal("false"),
|
|
815
|
+
z2.literal("1"),
|
|
816
|
+
z2.literal("0")
|
|
817
|
+
]).optional().default("false").transform((val) => val === "true" || val === "1");
|
|
818
|
+
var env = createEnv({
|
|
819
|
+
server: {
|
|
820
|
+
FRONTAL_ENV: z2.enum(["development", "test", "production"]).default("development"),
|
|
821
|
+
FRONTAL_API_KEY: apiKeySchema.optional(),
|
|
822
|
+
FRONTAL_API_URL: z2.url("FRONTAL_API_URL must be a valid URL").optional(),
|
|
823
|
+
FRONTAL_DEBUG: debugSchema
|
|
824
|
+
},
|
|
825
|
+
runtimeEnv: {
|
|
826
|
+
FRONTAL_ENV: process.env.FRONTAL_ENV,
|
|
827
|
+
FRONTAL_API_KEY: process.env.FRONTAL_API_KEY,
|
|
828
|
+
FRONTAL_API_URL: process.env.FRONTAL_API_URL,
|
|
829
|
+
FRONTAL_DEBUG: process.env.FRONTAL_DEBUG
|
|
830
|
+
},
|
|
831
|
+
emptyStringAsUndefined: true
|
|
832
|
+
});
|
|
833
|
+
var unwrapClientError = (error) => {
|
|
834
|
+
if (error instanceof NetworkError) {
|
|
835
|
+
if (error.cause instanceof Error) {
|
|
836
|
+
throw error.cause;
|
|
837
|
+
}
|
|
838
|
+
throw new Error(String(error.cause));
|
|
285
839
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
840
|
+
throw error;
|
|
841
|
+
};
|
|
842
|
+
var FrontalClient = class {
|
|
843
|
+
config;
|
|
844
|
+
_http;
|
|
845
|
+
/**
|
|
846
|
+
* @param config - Validated client configuration output from clientConfigSchema.
|
|
847
|
+
*/
|
|
848
|
+
constructor(config) {
|
|
849
|
+
Object.defineProperty(this, "config", {
|
|
850
|
+
value: config,
|
|
851
|
+
writable: false,
|
|
852
|
+
enumerable: true
|
|
292
853
|
});
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
854
|
+
const http = new HttpClient(config);
|
|
855
|
+
Object.defineProperty(this, "_http", {
|
|
856
|
+
value: http,
|
|
857
|
+
writable: false,
|
|
858
|
+
enumerable: true
|
|
297
859
|
});
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
860
|
+
Object.defineProperty(this, "httpClient", {
|
|
861
|
+
get() {
|
|
862
|
+
return http;
|
|
863
|
+
},
|
|
864
|
+
enumerable: true
|
|
302
865
|
});
|
|
303
866
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
867
|
+
/** Public accessor for the underlying HttpClient. */
|
|
868
|
+
get httpClient() {
|
|
869
|
+
return this._http;
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* Sends a GET request and optionally validates the response against a schema.
|
|
873
|
+
* @param path - API endpoint path.
|
|
874
|
+
* @param schema - Optional Zod schema for response validation.
|
|
875
|
+
*/
|
|
876
|
+
async get(path, schema) {
|
|
877
|
+
try {
|
|
878
|
+
return await this._http.get(path, void 0, schema);
|
|
879
|
+
} catch (error) {
|
|
880
|
+
throw unwrapClientError(error);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* Sends a POST request with an optional JSON body and response schema.
|
|
885
|
+
* @param path - API endpoint path.
|
|
886
|
+
* @param body - Request payload (converted to snake_case automatically).
|
|
887
|
+
* @param schema - Optional Zod schema for response validation.
|
|
888
|
+
*/
|
|
889
|
+
async post(path, body, schema) {
|
|
890
|
+
try {
|
|
891
|
+
return await this._http.post(path, body, schema);
|
|
892
|
+
} catch (error) {
|
|
893
|
+
throw unwrapClientError(error);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Sends a PUT request with an optional JSON body and response schema.
|
|
898
|
+
* @param path - API endpoint path.
|
|
899
|
+
* @param body - Request payload (converted to snake_case automatically).
|
|
900
|
+
* @param schema - Optional Zod schema for response validation.
|
|
901
|
+
*/
|
|
902
|
+
async put(path, body, schema) {
|
|
903
|
+
try {
|
|
904
|
+
return await this._http.put(path, body, schema);
|
|
905
|
+
} catch (error) {
|
|
906
|
+
throw unwrapClientError(error);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* Sends a PATCH request with an optional JSON body and response schema.
|
|
911
|
+
* @param path - API endpoint path.
|
|
912
|
+
* @param body - Request payload (converted to snake_case automatically).
|
|
913
|
+
* @param schema - Optional Zod schema for response validation.
|
|
914
|
+
*/
|
|
915
|
+
async patch(path, body, schema) {
|
|
916
|
+
try {
|
|
917
|
+
return await this._http.patch(path, body, schema);
|
|
918
|
+
} catch (error) {
|
|
919
|
+
throw unwrapClientError(error);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* Sends a DELETE request with optional query parameters and response schema.
|
|
924
|
+
* @param path - API endpoint path.
|
|
925
|
+
* @param params - Query parameters (converted to snake_case automatically).
|
|
926
|
+
* @param schema - Optional Zod schema for response validation.
|
|
927
|
+
*/
|
|
928
|
+
async delete(path, params, schema) {
|
|
929
|
+
try {
|
|
930
|
+
return await this._http.delete(path, params, schema);
|
|
931
|
+
} catch (error) {
|
|
932
|
+
throw unwrapClientError(error);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* Opens a GET SSE stream and yields parsed server-sent events.
|
|
937
|
+
* @param path - API endpoint path.
|
|
938
|
+
* @param params - Optional query parameters.
|
|
939
|
+
* @yields Objects with `type`, `data`, and optional `id` fields from SSE events.
|
|
940
|
+
*/
|
|
941
|
+
async *stream(path, params) {
|
|
942
|
+
try {
|
|
943
|
+
yield* this._http.stream(path, params);
|
|
944
|
+
} catch (error) {
|
|
945
|
+
throw unwrapClientError(error);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* Sends a raw PUT request with a binary/stream body and custom content type.
|
|
950
|
+
* @param path - API endpoint path.
|
|
951
|
+
* @param body - Binary buffer or readable stream to upload.
|
|
952
|
+
* @param contentType - MIME type of the body.
|
|
953
|
+
* @param headers - Additional request headers.
|
|
954
|
+
* @returns The parsed JSON response (keys converted to camelCase).
|
|
955
|
+
*/
|
|
956
|
+
async putRaw(path, body, contentType, headers = {}) {
|
|
957
|
+
try {
|
|
958
|
+
return await this._http.putRaw(path, body, contentType, headers);
|
|
959
|
+
} catch (error) {
|
|
960
|
+
throw unwrapClientError(error);
|
|
961
|
+
}
|
|
312
962
|
}
|
|
313
963
|
};
|
|
314
|
-
var
|
|
964
|
+
var getDefaultClient = () => {
|
|
965
|
+
if (!env.FRONTAL_API_KEY) {
|
|
966
|
+
throw new Error(
|
|
967
|
+
"FRONTAL_API_KEY environment variable is required. Set it in your environment or pass apiKey explicitly to new FrontalClient()."
|
|
968
|
+
);
|
|
969
|
+
}
|
|
970
|
+
return new FrontalClient({
|
|
971
|
+
apiKey: env.FRONTAL_API_KEY,
|
|
972
|
+
baseUrl: env.FRONTAL_API_URL ?? DEFAULT_BASE_URL,
|
|
973
|
+
timeout: 3e4,
|
|
974
|
+
maxRetries: 3,
|
|
975
|
+
retryDelay: 1e3,
|
|
976
|
+
headers: {},
|
|
977
|
+
environment: env.FRONTAL_ENV,
|
|
978
|
+
debug: env.FRONTAL_DEBUG
|
|
979
|
+
});
|
|
980
|
+
};
|
|
981
|
+
var API_KEY_PATTERN = new RegExp(`^${API_KEY_PREFIX}[A-Za-z0-9_-]+$`);
|
|
982
|
+
var loggerFnSchema = z3.custom(
|
|
983
|
+
(value) => typeof value === "function",
|
|
984
|
+
"Expected function"
|
|
985
|
+
);
|
|
986
|
+
var headersSchema = z3.record(z3.string(), z3.string()).superRefine((headers, ctx) => {
|
|
987
|
+
for (const key of Object.keys(headers)) {
|
|
988
|
+
if (key.trim().length === 0) {
|
|
989
|
+
ctx.addIssue({
|
|
990
|
+
code: z3.ZodIssueCode.custom,
|
|
991
|
+
message: "Header names must be non-empty",
|
|
992
|
+
path: []
|
|
993
|
+
});
|
|
994
|
+
return;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
}).default({});
|
|
998
|
+
var clientConfigSchema = z3.object({
|
|
999
|
+
apiKey: z3.string().min(9, "apiKey is required").regex(API_KEY_PATTERN, `apiKey must start with "${API_KEY_PREFIX}"`),
|
|
1000
|
+
baseUrl: z3.string().url().refine(
|
|
1001
|
+
(value) => value.startsWith("https://") || value.startsWith("http://"),
|
|
1002
|
+
{
|
|
1003
|
+
message: "baseUrl must use http or https"
|
|
1004
|
+
}
|
|
1005
|
+
).default(DEFAULT_BASE_URL),
|
|
1006
|
+
timeout: z3.number().int().positive().default(3e4),
|
|
1007
|
+
maxRetries: z3.number().int().min(0).max(10).default(3),
|
|
1008
|
+
retryDelay: z3.number().int().positive().default(1e3),
|
|
1009
|
+
headers: headersSchema,
|
|
1010
|
+
environment: z3.string().default("production"),
|
|
1011
|
+
debug: z3.boolean().default(false),
|
|
1012
|
+
fetch: z3.custom((value) => typeof value === "function").optional(),
|
|
1013
|
+
logger: z3.object({
|
|
1014
|
+
request: loggerFnSchema.optional(),
|
|
1015
|
+
response: loggerFnSchema.optional(),
|
|
1016
|
+
error: loggerFnSchema.optional()
|
|
1017
|
+
}).optional(),
|
|
1018
|
+
circuitBreaker: z3.object({
|
|
1019
|
+
failureThreshold: z3.number().int().positive().default(5),
|
|
1020
|
+
resetTimeoutMs: z3.number().int().positive().default(3e4)
|
|
1021
|
+
}).optional()
|
|
1022
|
+
}).strict();
|
|
1023
|
+
function asPagePayload(raw) {
|
|
1024
|
+
return raw;
|
|
1025
|
+
}
|
|
1026
|
+
var paginationSchema = z4.object({
|
|
1027
|
+
cursor: z4.string().min(1),
|
|
1028
|
+
hasMore: z4.boolean(),
|
|
1029
|
+
total: z4.number().int().min(0).optional(),
|
|
1030
|
+
limit: z4.number().int().positive().optional(),
|
|
1031
|
+
offset: z4.number().int().min(0).optional()
|
|
1032
|
+
}).strict();
|
|
1033
|
+
function buildPageResult(data, pagination, fetchNext, meta) {
|
|
1034
|
+
let nextPagePromise = null;
|
|
1035
|
+
const page = {
|
|
1036
|
+
data,
|
|
1037
|
+
meta,
|
|
1038
|
+
pagination,
|
|
1039
|
+
_fetchNextPage: fetchNext,
|
|
1040
|
+
async nextPage() {
|
|
1041
|
+
if (!this.pagination.hasMore) return null;
|
|
1042
|
+
if (!nextPagePromise) {
|
|
1043
|
+
nextPagePromise = (async () => {
|
|
1044
|
+
let result = await this._fetchNextPage();
|
|
1045
|
+
if (!result && this._fallbackFetchNextPage) {
|
|
1046
|
+
result = await this._fallbackFetchNextPage();
|
|
1047
|
+
}
|
|
1048
|
+
if (result) {
|
|
1049
|
+
const mutableResult = result;
|
|
1050
|
+
mutableResult._fallbackFetchNextPage = this._fallbackFetchNextPage ?? this._fetchNextPage;
|
|
1051
|
+
}
|
|
1052
|
+
return result;
|
|
1053
|
+
})().finally(() => {
|
|
1054
|
+
nextPagePromise = null;
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
return nextPagePromise;
|
|
1058
|
+
},
|
|
1059
|
+
async all() {
|
|
1060
|
+
const items = [...this.data];
|
|
1061
|
+
let current = this;
|
|
1062
|
+
while (current) {
|
|
1063
|
+
if (!current.pagination.hasMore) break;
|
|
1064
|
+
current = await current.nextPage();
|
|
1065
|
+
if (!current) break;
|
|
1066
|
+
items.push(...current.data);
|
|
1067
|
+
}
|
|
1068
|
+
return items;
|
|
1069
|
+
},
|
|
1070
|
+
[Symbol.asyncIterator]() {
|
|
1071
|
+
let current = this;
|
|
1072
|
+
let index = 0;
|
|
1073
|
+
return {
|
|
1074
|
+
async next() {
|
|
1075
|
+
while (current) {
|
|
1076
|
+
if (index < current.data.length) {
|
|
1077
|
+
return { done: false, value: current.data[index++] };
|
|
1078
|
+
}
|
|
1079
|
+
if (!current.pagination.hasMore) {
|
|
1080
|
+
current = null;
|
|
1081
|
+
break;
|
|
1082
|
+
}
|
|
1083
|
+
current = await current.nextPage();
|
|
1084
|
+
index = 0;
|
|
1085
|
+
}
|
|
1086
|
+
return { done: true, value: void 0 };
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
};
|
|
1091
|
+
return page;
|
|
1092
|
+
}
|
|
1093
|
+
function createPageResult(dataOrRaw, paginationOrFetchNext, fetchNextOrMeta, meta) {
|
|
1094
|
+
if (Array.isArray(dataOrRaw)) {
|
|
1095
|
+
const data = dataOrRaw;
|
|
1096
|
+
const pagination = paginationOrFetchNext;
|
|
1097
|
+
const fetchNextPage2 = fetchNextOrMeta;
|
|
1098
|
+
const fetchNext2 = async () => {
|
|
1099
|
+
if (!fetchNextPage2) return null;
|
|
1100
|
+
return fetchNextPage2.length > 0 ? fetchNextPage2(
|
|
1101
|
+
pagination.cursor
|
|
1102
|
+
) : fetchNextPage2();
|
|
1103
|
+
};
|
|
1104
|
+
return buildPageResult(data, pagination, fetchNext2, meta);
|
|
1105
|
+
}
|
|
1106
|
+
const raw = dataOrRaw;
|
|
1107
|
+
const fetchNextPage = paginationOrFetchNext;
|
|
1108
|
+
const fetchNext = async () => {
|
|
1109
|
+
if (!fetchNextPage) return null;
|
|
1110
|
+
return fetchNextPage.length > 0 ? fetchNextPage(
|
|
1111
|
+
raw.pagination.cursor
|
|
1112
|
+
) : fetchNextPage();
|
|
1113
|
+
};
|
|
1114
|
+
return buildPageResult(
|
|
1115
|
+
Array.isArray(raw.data) ? raw.data : [],
|
|
1116
|
+
raw.pagination,
|
|
1117
|
+
fetchNext,
|
|
1118
|
+
raw.meta
|
|
1119
|
+
);
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
// src/constants.ts
|
|
1123
|
+
var DEFAULT_ONTOLOGY_BASE_URL = "https://api.frontal.dev/v1";
|
|
1124
|
+
var VERSION = "0.0.1";
|
|
1125
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
1126
|
+
var DEFAULT_MAX_RETRIES = 3;
|
|
1127
|
+
var DEFAULT_RETRY_DELAY = 1e3;
|
|
1128
|
+
|
|
1129
|
+
// src/sdk.ts
|
|
1130
|
+
var OntologySdk = class {
|
|
1131
|
+
engine;
|
|
1132
|
+
objects;
|
|
1133
|
+
relationships;
|
|
1134
|
+
schemas;
|
|
1135
|
+
versions;
|
|
1136
|
+
validation;
|
|
1137
|
+
transformations;
|
|
1138
|
+
reasoning;
|
|
1139
|
+
rollouts;
|
|
1140
|
+
rollups;
|
|
1141
|
+
extract;
|
|
1142
|
+
events;
|
|
1143
|
+
/**
|
|
1144
|
+
* @param http - The HTTP client used to make API requests.
|
|
1145
|
+
*/
|
|
315
1146
|
constructor(http) {
|
|
1147
|
+
this.engine = new EngineNamespace(http);
|
|
1148
|
+
this.objects = new ObjectsNamespace(http);
|
|
1149
|
+
this.relationships = new RelationshipsNamespace(http);
|
|
1150
|
+
this.schemas = new SchemasNamespace(http);
|
|
1151
|
+
this.versions = new VersionsNamespace(http);
|
|
1152
|
+
this.validation = new ValidationNamespace(http);
|
|
1153
|
+
this.transformations = new TransformationsNamespace(http);
|
|
1154
|
+
this.reasoning = new ReasoningNamespace(http);
|
|
1155
|
+
this.rollouts = new RolloutsNamespace(http);
|
|
1156
|
+
this.rollups = new RollupsNamespace(http);
|
|
1157
|
+
this.extract = new ExtractNamespace(http);
|
|
1158
|
+
this.events = new EventsNamespace(http);
|
|
1159
|
+
}
|
|
1160
|
+
};
|
|
1161
|
+
var SubdomainBase = class {
|
|
1162
|
+
constructor(http, base) {
|
|
316
1163
|
this.http = http;
|
|
1164
|
+
this.base = base;
|
|
317
1165
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
1166
|
+
/**
|
|
1167
|
+
* Returns the capabilities of this subdomain service.
|
|
1168
|
+
*/
|
|
1169
|
+
capabilities() {
|
|
1170
|
+
return this.http.get(`${this.base}/capabilities`);
|
|
322
1171
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
});
|
|
1172
|
+
/**
|
|
1173
|
+
* Health check for this subdomain service.
|
|
1174
|
+
*/
|
|
1175
|
+
health() {
|
|
1176
|
+
return this.http.get(`${this.base}/health`);
|
|
328
1177
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
1178
|
+
/**
|
|
1179
|
+
* Returns service info/metadata for this subdomain service.
|
|
1180
|
+
*/
|
|
1181
|
+
info() {
|
|
1182
|
+
return this.http.get(`${this.base}/info`);
|
|
333
1183
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
1184
|
+
/**
|
|
1185
|
+
* Lists asynchronous runs for this subdomain.
|
|
1186
|
+
* @param opts - Pagination options.
|
|
1187
|
+
*/
|
|
1188
|
+
async runs(opts = {}) {
|
|
1189
|
+
const raw = await this.http.get(`${this.base}/runs`, opts);
|
|
1190
|
+
return createPageResult(
|
|
1191
|
+
asPagePayload(raw),
|
|
1192
|
+
(c) => this.runs({ ...opts, cursor: c })
|
|
1193
|
+
);
|
|
341
1194
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
1195
|
+
/**
|
|
1196
|
+
* Creates a new asynchronous run.
|
|
1197
|
+
* @param input - The run input payload.
|
|
1198
|
+
*/
|
|
1199
|
+
createRun(input) {
|
|
1200
|
+
return this.http.post(`${this.base}/runs`, input);
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Fetches an asynchronous run by ID.
|
|
1204
|
+
* @param runId - The run ID.
|
|
1205
|
+
*/
|
|
1206
|
+
run(runId) {
|
|
1207
|
+
return this.http.get(`${this.base}/runs/${runId}`);
|
|
346
1208
|
}
|
|
347
1209
|
};
|
|
348
|
-
var
|
|
1210
|
+
var EngineNamespace = class extends SubdomainBase {
|
|
349
1211
|
constructor(http) {
|
|
350
|
-
|
|
1212
|
+
super(http, "/ontology/engine");
|
|
351
1213
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
1214
|
+
/**
|
|
1215
|
+
* Generates an ontology from a description.
|
|
1216
|
+
* @param input - Generation parameters.
|
|
1217
|
+
*/
|
|
1218
|
+
generate(input) {
|
|
1219
|
+
return this.http.post("/ontology/engine/ontologies/generate", input);
|
|
356
1220
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
1221
|
+
/**
|
|
1222
|
+
* Validates an ontology definition.
|
|
1223
|
+
* @param input - The ontology to validate.
|
|
1224
|
+
*/
|
|
1225
|
+
validate(input) {
|
|
1226
|
+
return this.http.post("/ontology/engine/ontologies/validate", input);
|
|
1227
|
+
}
|
|
1228
|
+
/**
|
|
1229
|
+
* Exports an ontology in a standard format.
|
|
1230
|
+
* @param input - Export parameters.
|
|
1231
|
+
*/
|
|
1232
|
+
export(input) {
|
|
1233
|
+
return this.http.post("/ontology/engine/ontologies/export", input);
|
|
1234
|
+
}
|
|
1235
|
+
/**
|
|
1236
|
+
* Exports an ontology as SHACL shapes.
|
|
1237
|
+
* @param input - Export parameters.
|
|
1238
|
+
*/
|
|
1239
|
+
exportShacl(input) {
|
|
1240
|
+
return this.http.post("/ontology/engine/ontologies/export-shacl", input);
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* Infers class definitions from source data.
|
|
1244
|
+
* @param input - Inference parameters.
|
|
1245
|
+
*/
|
|
1246
|
+
inferClasses(input) {
|
|
1247
|
+
return this.http.post("/ontology/engine/ontologies/infer-classes", input);
|
|
1248
|
+
}
|
|
1249
|
+
/**
|
|
1250
|
+
* Infers property definitions from source data.
|
|
1251
|
+
* @param input - Inference parameters.
|
|
1252
|
+
*/
|
|
1253
|
+
inferProperties(input) {
|
|
1254
|
+
return this.http.post(
|
|
1255
|
+
"/ontology/engine/ontologies/infer-properties",
|
|
1256
|
+
input
|
|
1257
|
+
);
|
|
1258
|
+
}
|
|
1259
|
+
/**
|
|
1260
|
+
* Compares two ontology versions.
|
|
1261
|
+
* @param input - Comparison parameters (fromVersion, toVersion).
|
|
1262
|
+
*/
|
|
1263
|
+
compareVersions(input) {
|
|
1264
|
+
return this.http.post(
|
|
1265
|
+
"/ontology/engine/ontologies/compare-versions",
|
|
1266
|
+
input
|
|
1267
|
+
);
|
|
362
1268
|
}
|
|
363
1269
|
};
|
|
364
|
-
var
|
|
1270
|
+
var ObjectsNamespace = class extends SubdomainBase {
|
|
365
1271
|
constructor(http) {
|
|
366
|
-
|
|
1272
|
+
super(http, "/ontology/objects");
|
|
367
1273
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
1274
|
+
/**
|
|
1275
|
+
* Lists object types with pagination.
|
|
1276
|
+
* @param opts - Pagination options.
|
|
1277
|
+
*/
|
|
1278
|
+
async listObjectTypes(opts = {}) {
|
|
1279
|
+
const raw = await this.http.get("/ontology/objects/object-types", opts);
|
|
1280
|
+
return createPageResult(
|
|
1281
|
+
asPagePayload(raw),
|
|
1282
|
+
(c) => this.listObjectTypes({ ...opts, cursor: c })
|
|
1283
|
+
);
|
|
374
1284
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
1285
|
+
/**
|
|
1286
|
+
* Fetches an object type by ID.
|
|
1287
|
+
* @param id - The object type ID.
|
|
1288
|
+
*/
|
|
1289
|
+
getObjectType(id) {
|
|
1290
|
+
return this.http.get(`/ontology/objects/object-types/${id}`);
|
|
379
1291
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
1292
|
+
/**
|
|
1293
|
+
* Creates or updates an object type.
|
|
1294
|
+
* @param id - The object type ID.
|
|
1295
|
+
* @param body - The object type definition.
|
|
1296
|
+
*/
|
|
1297
|
+
putObjectType(id, body) {
|
|
1298
|
+
return this.http.put(`/ontology/objects/object-types/${id}`, body);
|
|
384
1299
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
1300
|
+
/**
|
|
1301
|
+
* Deletes an object type.
|
|
1302
|
+
* @param id - The object type ID.
|
|
1303
|
+
*/
|
|
1304
|
+
deleteObjectType(id) {
|
|
1305
|
+
return this.http.delete(`/ontology/objects/object-types/${id}`);
|
|
389
1306
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
1307
|
+
/**
|
|
1308
|
+
* Lists object instances with pagination.
|
|
1309
|
+
* @param opts - Pagination options.
|
|
1310
|
+
*/
|
|
1311
|
+
async listObjects(opts = {}) {
|
|
1312
|
+
const raw = await this.http.get("/ontology/objects/objects", opts);
|
|
1313
|
+
return createPageResult(
|
|
1314
|
+
asPagePayload(raw),
|
|
1315
|
+
(c) => this.listObjects({ ...opts, cursor: c })
|
|
1316
|
+
);
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1319
|
+
* Fetches an object instance by ID.
|
|
1320
|
+
* @param id - The object ID.
|
|
1321
|
+
*/
|
|
1322
|
+
getObject(id) {
|
|
1323
|
+
return this.http.get(`/ontology/objects/objects/${id}`);
|
|
1324
|
+
}
|
|
1325
|
+
/**
|
|
1326
|
+
* Creates or updates an object instance.
|
|
1327
|
+
* @param id - The object ID.
|
|
1328
|
+
* @param body - The object data.
|
|
1329
|
+
*/
|
|
1330
|
+
putObject(id, body) {
|
|
1331
|
+
return this.http.put(`/ontology/objects/objects/${id}`, body);
|
|
1332
|
+
}
|
|
1333
|
+
/**
|
|
1334
|
+
* Deletes an object instance.
|
|
1335
|
+
* @param id - The object ID.
|
|
1336
|
+
*/
|
|
1337
|
+
deleteObject(id) {
|
|
1338
|
+
return this.http.delete(`/ontology/objects/objects/${id}`);
|
|
1339
|
+
}
|
|
1340
|
+
};
|
|
1341
|
+
var RelationshipsNamespace = class extends SubdomainBase {
|
|
1342
|
+
constructor(http) {
|
|
1343
|
+
super(http, "/ontology/relationships");
|
|
1344
|
+
}
|
|
1345
|
+
/**
|
|
1346
|
+
* Lists relationship types with pagination.
|
|
1347
|
+
* @param opts - Pagination options.
|
|
1348
|
+
*/
|
|
1349
|
+
async listTypes(opts = {}) {
|
|
1350
|
+
const raw = await this.http.get(
|
|
1351
|
+
"/ontology/relationships/relationship-types",
|
|
1352
|
+
opts
|
|
1353
|
+
);
|
|
1354
|
+
return createPageResult(
|
|
1355
|
+
asPagePayload(raw),
|
|
1356
|
+
(c) => this.listTypes({ ...opts, cursor: c })
|
|
1357
|
+
);
|
|
1358
|
+
}
|
|
1359
|
+
/**
|
|
1360
|
+
* Deletes a relationship type.
|
|
1361
|
+
* @param id - The relationship type ID.
|
|
1362
|
+
*/
|
|
1363
|
+
deleteType(id) {
|
|
1364
|
+
return this.http.delete(`/ontology/relationships/relationship-types/${id}`);
|
|
1365
|
+
}
|
|
1366
|
+
/**
|
|
1367
|
+
* Lists relationship instances with pagination.
|
|
1368
|
+
* @param opts - Pagination options.
|
|
1369
|
+
*/
|
|
1370
|
+
async list(opts = {}) {
|
|
1371
|
+
const raw = await this.http.get(
|
|
1372
|
+
"/ontology/relationships/relationships",
|
|
1373
|
+
opts
|
|
1374
|
+
);
|
|
1375
|
+
return createPageResult(
|
|
1376
|
+
asPagePayload(raw),
|
|
1377
|
+
(c) => this.list({ ...opts, cursor: c })
|
|
1378
|
+
);
|
|
1379
|
+
}
|
|
1380
|
+
/**
|
|
1381
|
+
* Fetches a relationship instance by ID.
|
|
1382
|
+
* @param id - The relationship ID.
|
|
1383
|
+
*/
|
|
1384
|
+
get(id) {
|
|
1385
|
+
return this.http.get(`/ontology/relationships/relationships/${id}`);
|
|
1386
|
+
}
|
|
1387
|
+
/**
|
|
1388
|
+
* Creates or updates a relationship instance.
|
|
1389
|
+
* @param id - The relationship ID.
|
|
1390
|
+
* @param body - The relationship data.
|
|
1391
|
+
*/
|
|
1392
|
+
put(id, body) {
|
|
1393
|
+
return this.http.put(`/ontology/relationships/relationships/${id}`, body);
|
|
1394
|
+
}
|
|
1395
|
+
/**
|
|
1396
|
+
* Deletes a relationship instance.
|
|
1397
|
+
* @param id - The relationship ID.
|
|
1398
|
+
*/
|
|
1399
|
+
delete(id) {
|
|
1400
|
+
return this.http.delete(`/ontology/relationships/relationships/${id}`);
|
|
1401
|
+
}
|
|
1402
|
+
};
|
|
1403
|
+
var SchemasNamespace = class extends SubdomainBase {
|
|
1404
|
+
constructor(http) {
|
|
1405
|
+
super(http, "/ontology/schemas");
|
|
1406
|
+
}
|
|
1407
|
+
/**
|
|
1408
|
+
* Lists schema definitions with pagination.
|
|
1409
|
+
* @param opts - Pagination options.
|
|
1410
|
+
*/
|
|
1411
|
+
async list(opts = {}) {
|
|
1412
|
+
const raw = await this.http.get("/ontology/schemas/schemas", opts);
|
|
1413
|
+
return createPageResult(
|
|
1414
|
+
asPagePayload(raw),
|
|
1415
|
+
(c) => this.list({ ...opts, cursor: c })
|
|
1416
|
+
);
|
|
1417
|
+
}
|
|
1418
|
+
/**
|
|
1419
|
+
* Creates a new schema definition.
|
|
1420
|
+
* @param body - The schema definition.
|
|
1421
|
+
*/
|
|
1422
|
+
create(body) {
|
|
1423
|
+
return this.http.post("/ontology/schemas/schemas", body);
|
|
1424
|
+
}
|
|
1425
|
+
/**
|
|
1426
|
+
* Validates a schema definition.
|
|
1427
|
+
* @param body - The schema to validate.
|
|
1428
|
+
*/
|
|
1429
|
+
validate(body) {
|
|
1430
|
+
return this.http.post("/ontology/schemas/schemas/validate", body);
|
|
1431
|
+
}
|
|
1432
|
+
/**
|
|
1433
|
+
* Fetches a schema definition by ID.
|
|
1434
|
+
* @param id - The schema ID.
|
|
1435
|
+
*/
|
|
1436
|
+
get(id) {
|
|
1437
|
+
return this.http.get(`/ontology/schemas/schemas/${id}`);
|
|
1438
|
+
}
|
|
1439
|
+
/**
|
|
1440
|
+
* Deletes a schema definition.
|
|
1441
|
+
* @param id - The schema ID.
|
|
1442
|
+
*/
|
|
1443
|
+
delete(id) {
|
|
1444
|
+
return this.http.delete(`/ontology/schemas/schemas/${id}`);
|
|
1445
|
+
}
|
|
1446
|
+
};
|
|
1447
|
+
var VersionsNamespace = class extends SubdomainBase {
|
|
1448
|
+
constructor(http) {
|
|
1449
|
+
super(http, "/ontology/versions");
|
|
1450
|
+
}
|
|
1451
|
+
/**
|
|
1452
|
+
* Creates a new version.
|
|
1453
|
+
* @param body - Version creation payload.
|
|
1454
|
+
*/
|
|
1455
|
+
create(body) {
|
|
1456
|
+
return this.http.post("/ontology/versions/versions", body);
|
|
1457
|
+
}
|
|
1458
|
+
/**
|
|
1459
|
+
* Compares two versions.
|
|
1460
|
+
* @param body - Comparison parameters.
|
|
1461
|
+
*/
|
|
1462
|
+
compare(body) {
|
|
1463
|
+
return this.http.post("/ontology/versions/versions/compare", body);
|
|
1464
|
+
}
|
|
1465
|
+
/**
|
|
1466
|
+
* Fetches a version by ID.
|
|
1467
|
+
* @param id - The version ID.
|
|
1468
|
+
*/
|
|
1469
|
+
get(id) {
|
|
1470
|
+
return this.http.get(`/ontology/versions/versions/${id}`);
|
|
1471
|
+
}
|
|
1472
|
+
/**
|
|
1473
|
+
* Deletes a version.
|
|
1474
|
+
* @param id - The version ID.
|
|
1475
|
+
*/
|
|
1476
|
+
delete(id) {
|
|
1477
|
+
return this.http.delete(`/ontology/versions/versions/${id}`);
|
|
1478
|
+
}
|
|
1479
|
+
/**
|
|
1480
|
+
* Verifies an audit trail for a version.
|
|
1481
|
+
* @param body - Audit verification payload.
|
|
1482
|
+
*/
|
|
1483
|
+
auditVerify(body) {
|
|
1484
|
+
return this.http.post("/ontology/versions/audit/verify", body);
|
|
1485
|
+
}
|
|
1486
|
+
/**
|
|
1487
|
+
* Lists release bundles with pagination.
|
|
1488
|
+
* @param opts - Pagination options.
|
|
1489
|
+
*/
|
|
1490
|
+
async listReleaseBundles(opts = {}) {
|
|
1491
|
+
const raw = await this.http.get("/ontology/versions/release-bundles", opts);
|
|
1492
|
+
return createPageResult(
|
|
1493
|
+
asPagePayload(raw),
|
|
1494
|
+
(c) => this.listReleaseBundles({ ...opts, cursor: c })
|
|
1495
|
+
);
|
|
1496
|
+
}
|
|
1497
|
+
/**
|
|
1498
|
+
* Creates a new release bundle.
|
|
1499
|
+
* @param body - Release bundle payload.
|
|
1500
|
+
*/
|
|
1501
|
+
createReleaseBundle(body) {
|
|
1502
|
+
return this.http.post("/ontology/versions/release-bundles", body);
|
|
1503
|
+
}
|
|
1504
|
+
/**
|
|
1505
|
+
* Fetches a release bundle by ID.
|
|
1506
|
+
* @param id - The release bundle ID.
|
|
1507
|
+
*/
|
|
1508
|
+
getReleaseBundle(id) {
|
|
1509
|
+
return this.http.get(`/ontology/versions/release-bundles/${id}`);
|
|
1510
|
+
}
|
|
1511
|
+
};
|
|
1512
|
+
var ValidationNamespace = class extends SubdomainBase {
|
|
1513
|
+
constructor(http) {
|
|
1514
|
+
super(http, "/ontology/validation");
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Validates a payload against a schema.
|
|
1518
|
+
* @param body - The payload to validate.
|
|
1519
|
+
*/
|
|
1520
|
+
validatePayload(body) {
|
|
1521
|
+
return this.http.post("/ontology/validation/payloads/validate", body);
|
|
1522
|
+
}
|
|
1523
|
+
/**
|
|
1524
|
+
* Lists validation rules with pagination.
|
|
1525
|
+
* @param opts - Pagination options.
|
|
1526
|
+
*/
|
|
1527
|
+
async listRules(opts = {}) {
|
|
1528
|
+
const raw = await this.http.get("/ontology/validation/rules", opts);
|
|
1529
|
+
return createPageResult(
|
|
1530
|
+
asPagePayload(raw),
|
|
1531
|
+
(c) => this.listRules({ ...opts, cursor: c })
|
|
1532
|
+
);
|
|
1533
|
+
}
|
|
1534
|
+
/**
|
|
1535
|
+
* Creates a validation rule.
|
|
1536
|
+
* @param body - The rule definition.
|
|
1537
|
+
*/
|
|
1538
|
+
createRule(body) {
|
|
1539
|
+
return this.http.post("/ontology/validation/rules", body);
|
|
1540
|
+
}
|
|
1541
|
+
/**
|
|
1542
|
+
* Fetches a validation rule by ID.
|
|
1543
|
+
* @param id - The rule ID.
|
|
1544
|
+
*/
|
|
1545
|
+
getRule(id) {
|
|
1546
|
+
return this.http.get(`/ontology/validation/rules/${id}`);
|
|
1547
|
+
}
|
|
1548
|
+
/**
|
|
1549
|
+
* Deletes a validation rule.
|
|
1550
|
+
* @param id - The rule ID.
|
|
1551
|
+
*/
|
|
1552
|
+
deleteRule(id) {
|
|
1553
|
+
return this.http.delete(`/ontology/validation/rules/${id}`);
|
|
1554
|
+
}
|
|
1555
|
+
};
|
|
1556
|
+
var TransformationsNamespace = class extends SubdomainBase {
|
|
1557
|
+
constructor(http) {
|
|
1558
|
+
super(http, "/ontology/transformations");
|
|
1559
|
+
}
|
|
1560
|
+
/**
|
|
1561
|
+
* Creates a data transformation.
|
|
1562
|
+
* @param body - The transformation definition.
|
|
1563
|
+
*/
|
|
1564
|
+
create(body) {
|
|
1565
|
+
return this.http.post("/ontology/transformations/transformations", body);
|
|
1566
|
+
}
|
|
1567
|
+
};
|
|
1568
|
+
var ReasoningNamespace = class extends SubdomainBase {
|
|
1569
|
+
constructor(http) {
|
|
1570
|
+
super(http, "/ontology/reasoning");
|
|
1571
|
+
}
|
|
1572
|
+
/**
|
|
1573
|
+
* Generates an explanation for a reasoning result.
|
|
1574
|
+
* @param body - Explanation request.
|
|
1575
|
+
*/
|
|
1576
|
+
explain(body) {
|
|
1577
|
+
return this.http.post("/ontology/reasoning/explain", body);
|
|
1578
|
+
}
|
|
1579
|
+
/**
|
|
1580
|
+
* Retrieves facts based on criteria.
|
|
1581
|
+
* @param body - Fact query parameters.
|
|
1582
|
+
*/
|
|
1583
|
+
facts(body) {
|
|
1584
|
+
return this.http.post("/ontology/reasoning/facts", body);
|
|
1585
|
+
}
|
|
1586
|
+
/**
|
|
1587
|
+
* Loads facts into the reasoning graph.
|
|
1588
|
+
* @param body - Facts graph data.
|
|
1589
|
+
*/
|
|
1590
|
+
loadFactsGraph(body) {
|
|
1591
|
+
return this.http.post("/ontology/reasoning/facts/load-graph", body);
|
|
1592
|
+
}
|
|
1593
|
+
/**
|
|
1594
|
+
* Performs forward chaining reasoning.
|
|
1595
|
+
* @param body - Forward reasoning parameters.
|
|
1596
|
+
*/
|
|
1597
|
+
reasonForward(body) {
|
|
1598
|
+
return this.http.post("/ontology/reasoning/reason/forward", body);
|
|
1599
|
+
}
|
|
1600
|
+
/**
|
|
1601
|
+
* Performs backward chaining reasoning.
|
|
1602
|
+
* @param body - Backward reasoning parameters.
|
|
1603
|
+
*/
|
|
1604
|
+
reasonBackward(body) {
|
|
1605
|
+
return this.http.post("/ontology/reasoning/reason/backward", body);
|
|
1606
|
+
}
|
|
1607
|
+
/**
|
|
1608
|
+
* Lists reasoning rules with pagination.
|
|
1609
|
+
* @param opts - Pagination options.
|
|
1610
|
+
*/
|
|
1611
|
+
async listRules(opts = {}) {
|
|
1612
|
+
const raw = await this.http.get("/ontology/reasoning/rules", opts);
|
|
1613
|
+
return createPageResult(
|
|
1614
|
+
asPagePayload(raw),
|
|
1615
|
+
(c) => this.listRules({ ...opts, cursor: c })
|
|
1616
|
+
);
|
|
1617
|
+
}
|
|
1618
|
+
/**
|
|
1619
|
+
* Creates a reasoning rule.
|
|
1620
|
+
* @param body - The rule definition.
|
|
1621
|
+
*/
|
|
1622
|
+
createRule(body) {
|
|
1623
|
+
return this.http.post("/ontology/reasoning/rules", body);
|
|
1624
|
+
}
|
|
1625
|
+
/**
|
|
1626
|
+
* Updates a reasoning rule.
|
|
1627
|
+
* @param id - The rule ID.
|
|
1628
|
+
* @param body - The updated rule fields.
|
|
1629
|
+
*/
|
|
1630
|
+
updateRule(id, body) {
|
|
1631
|
+
return this.http.put(`/ontology/reasoning/rules/${id}`, body);
|
|
1632
|
+
}
|
|
1633
|
+
/**
|
|
1634
|
+
* Deletes a reasoning rule.
|
|
1635
|
+
* @param id - The rule ID.
|
|
1636
|
+
*/
|
|
1637
|
+
deleteRule(id) {
|
|
1638
|
+
return this.http.delete(`/ontology/reasoning/rules/${id}`);
|
|
1639
|
+
}
|
|
1640
|
+
};
|
|
1641
|
+
var RolloutsNamespace = class extends SubdomainBase {
|
|
1642
|
+
constructor(http) {
|
|
1643
|
+
super(http, "/ontology/rollouts");
|
|
1644
|
+
}
|
|
1645
|
+
/**
|
|
1646
|
+
* Lists rollouts with pagination.
|
|
1647
|
+
* @param opts - Pagination options.
|
|
1648
|
+
*/
|
|
1649
|
+
async list(opts = {}) {
|
|
1650
|
+
const raw = await this.http.get("/ontology/rollouts/rollouts", opts);
|
|
1651
|
+
return createPageResult(
|
|
1652
|
+
asPagePayload(raw),
|
|
1653
|
+
(c) => this.list({ ...opts, cursor: c })
|
|
1654
|
+
);
|
|
1655
|
+
}
|
|
1656
|
+
/**
|
|
1657
|
+
* Creates a new rollout.
|
|
1658
|
+
* @param body - Rollout configuration.
|
|
1659
|
+
*/
|
|
1660
|
+
create(body) {
|
|
1661
|
+
return this.http.post("/ontology/rollouts/rollouts", body);
|
|
1662
|
+
}
|
|
1663
|
+
/**
|
|
1664
|
+
* Fetches a rollout by ID.
|
|
1665
|
+
* @param id - The rollout ID.
|
|
1666
|
+
*/
|
|
1667
|
+
get(id) {
|
|
1668
|
+
return this.http.get(`/ontology/rollouts/rollouts/${id}`);
|
|
1669
|
+
}
|
|
1670
|
+
/**
|
|
1671
|
+
* Updates a rollout.
|
|
1672
|
+
* @param id - The rollout ID.
|
|
1673
|
+
* @param body - The updated rollout fields.
|
|
1674
|
+
*/
|
|
1675
|
+
update(id, body) {
|
|
1676
|
+
return this.http.put(`/ontology/rollouts/rollouts/${id}`, body);
|
|
1677
|
+
}
|
|
1678
|
+
/**
|
|
1679
|
+
* Deletes a rollout.
|
|
1680
|
+
* @param id - The rollout ID.
|
|
1681
|
+
*/
|
|
1682
|
+
delete(id) {
|
|
1683
|
+
return this.http.delete(`/ontology/rollouts/rollouts/${id}`);
|
|
1684
|
+
}
|
|
1685
|
+
/**
|
|
1686
|
+
* Starts a rollout.
|
|
1687
|
+
* @param id - The rollout ID.
|
|
1688
|
+
* @param body - Start parameters.
|
|
1689
|
+
*/
|
|
1690
|
+
start(id, body = {}) {
|
|
1691
|
+
return this.http.post(`/ontology/rollouts/rollouts/${id}/start`, body);
|
|
1692
|
+
}
|
|
1693
|
+
/**
|
|
1694
|
+
* Pauses a rollout.
|
|
1695
|
+
* @param id - The rollout ID.
|
|
1696
|
+
* @param body - Pause parameters.
|
|
1697
|
+
*/
|
|
1698
|
+
pause(id, body = {}) {
|
|
1699
|
+
return this.http.post(`/ontology/rollouts/rollouts/${id}/pause`, body);
|
|
1700
|
+
}
|
|
1701
|
+
/**
|
|
1702
|
+
* Resumes a paused rollout.
|
|
1703
|
+
* @param id - The rollout ID.
|
|
1704
|
+
* @param body - Resume parameters.
|
|
1705
|
+
*/
|
|
1706
|
+
resume(id, body = {}) {
|
|
1707
|
+
return this.http.post(`/ontology/rollouts/rollouts/${id}/resume`, body);
|
|
1708
|
+
}
|
|
1709
|
+
/**
|
|
1710
|
+
* Rolls back a rollout.
|
|
1711
|
+
* @param id - The rollout ID.
|
|
1712
|
+
* @param body - Rollback parameters.
|
|
1713
|
+
*/
|
|
1714
|
+
rollback(id, body = {}) {
|
|
1715
|
+
return this.http.post(`/ontology/rollouts/rollouts/${id}/rollback`, body);
|
|
1716
|
+
}
|
|
1717
|
+
/**
|
|
1718
|
+
* Returns the current status of a rollout.
|
|
1719
|
+
* @param id - The rollout ID.
|
|
1720
|
+
*/
|
|
1721
|
+
status(id) {
|
|
1722
|
+
return this.http.get(`/ontology/rollouts/rollouts/${id}/status`);
|
|
1723
|
+
}
|
|
1724
|
+
};
|
|
1725
|
+
var RollupsNamespace = class extends SubdomainBase {
|
|
1726
|
+
constructor(http) {
|
|
1727
|
+
super(http, "/ontology/rollups");
|
|
1728
|
+
}
|
|
1729
|
+
/**
|
|
1730
|
+
* Lists rollups with pagination.
|
|
1731
|
+
* @param opts - Pagination options.
|
|
1732
|
+
*/
|
|
1733
|
+
async list(opts = {}) {
|
|
1734
|
+
const raw = await this.http.get("/ontology/rollups/rollups", opts);
|
|
1735
|
+
return createPageResult(
|
|
1736
|
+
asPagePayload(raw),
|
|
1737
|
+
(c) => this.list({ ...opts, cursor: c })
|
|
1738
|
+
);
|
|
1739
|
+
}
|
|
1740
|
+
/**
|
|
1741
|
+
* Creates a rollup job.
|
|
1742
|
+
* @param body - Rollup configuration.
|
|
1743
|
+
*/
|
|
1744
|
+
create(body) {
|
|
1745
|
+
return this.http.post("/ontology/rollups/rollups", body);
|
|
1746
|
+
}
|
|
1747
|
+
/**
|
|
1748
|
+
* Fetches a rollup by ID.
|
|
1749
|
+
* @param id - The rollup ID.
|
|
1750
|
+
*/
|
|
1751
|
+
get(id) {
|
|
1752
|
+
return this.http.get(`/ontology/rollups/rollups/${id}`);
|
|
1753
|
+
}
|
|
1754
|
+
/**
|
|
1755
|
+
* Updates a rollup.
|
|
1756
|
+
* @param id - The rollup ID.
|
|
1757
|
+
* @param body - The updated rollup fields.
|
|
1758
|
+
*/
|
|
1759
|
+
update(id, body) {
|
|
1760
|
+
return this.http.put(`/ontology/rollups/rollups/${id}`, body);
|
|
1761
|
+
}
|
|
1762
|
+
/**
|
|
1763
|
+
* Deletes a rollup.
|
|
1764
|
+
* @param id - The rollup ID.
|
|
1765
|
+
*/
|
|
1766
|
+
delete(id) {
|
|
1767
|
+
return this.http.delete(`/ontology/rollups/rollups/${id}`);
|
|
1768
|
+
}
|
|
1769
|
+
/**
|
|
1770
|
+
* Executes a rollup.
|
|
1771
|
+
* @param id - The rollup ID.
|
|
1772
|
+
* @param body - Execution parameters.
|
|
1773
|
+
*/
|
|
1774
|
+
execute(id, body = {}) {
|
|
1775
|
+
return this.http.post(`/ontology/rollups/rollups/${id}/execute`, body);
|
|
1776
|
+
}
|
|
1777
|
+
/**
|
|
1778
|
+
* Previews a rollup result without persisting it.
|
|
1779
|
+
* @param id - The rollup ID.
|
|
1780
|
+
* @param body - Preview parameters.
|
|
1781
|
+
*/
|
|
1782
|
+
preview(id, body = {}) {
|
|
1783
|
+
return this.http.post(`/ontology/rollups/rollups/${id}/preview`, body);
|
|
1784
|
+
}
|
|
1785
|
+
/**
|
|
1786
|
+
* Fetches the result of a rollup execution.
|
|
1787
|
+
* @param id - The rollup ID.
|
|
1788
|
+
*/
|
|
1789
|
+
result(id) {
|
|
1790
|
+
return this.http.get(`/ontology/rollups/rollups/${id}/result`);
|
|
1791
|
+
}
|
|
1792
|
+
/**
|
|
1793
|
+
* Fetches the result of a specific rollup execution.
|
|
1794
|
+
* @param executionId - The execution ID.
|
|
1795
|
+
*/
|
|
1796
|
+
executionResult(executionId) {
|
|
1797
|
+
return this.http.get(`/ontology/rollups/rollup-results/${executionId}`);
|
|
1798
|
+
}
|
|
1799
|
+
};
|
|
1800
|
+
var ExtractNamespace = class extends SubdomainBase {
|
|
1801
|
+
constructor(http) {
|
|
1802
|
+
super(http, "/ontology/extract");
|
|
1803
|
+
}
|
|
1804
|
+
/**
|
|
1805
|
+
* Analyzes source data for extraction.
|
|
1806
|
+
* @param body - Analysis parameters.
|
|
1807
|
+
*/
|
|
1808
|
+
analyze(body) {
|
|
1809
|
+
return this.http.post("/ontology/extract/extract/analyze", body);
|
|
1810
|
+
}
|
|
1811
|
+
/**
|
|
1812
|
+
* Extracts architecture from source data.
|
|
1813
|
+
* @param body - Architecture extraction parameters.
|
|
1814
|
+
*/
|
|
1815
|
+
architecture(body) {
|
|
1816
|
+
return this.http.post("/ontology/extract/extract/architecture", body);
|
|
1817
|
+
}
|
|
1818
|
+
/**
|
|
1819
|
+
* Extracts coreference chains from source data.
|
|
1820
|
+
* @param body - Coreference extraction parameters.
|
|
1821
|
+
*/
|
|
1822
|
+
coreferences(body) {
|
|
1823
|
+
return this.http.post("/ontology/extract/extract/coreferences", body);
|
|
1824
|
+
}
|
|
1825
|
+
/**
|
|
1826
|
+
* Extracts entities from source data.
|
|
1827
|
+
* @param body - Entity extraction parameters.
|
|
1828
|
+
*/
|
|
1829
|
+
entities(body) {
|
|
1830
|
+
return this.http.post("/ontology/extract/extract/entities", body);
|
|
1831
|
+
}
|
|
1832
|
+
/**
|
|
1833
|
+
* Extracts events from source data.
|
|
1834
|
+
* @param body - Event extraction parameters.
|
|
1835
|
+
*/
|
|
1836
|
+
events(body) {
|
|
1837
|
+
return this.http.post("/ontology/extract/extract/events", body);
|
|
1838
|
+
}
|
|
1839
|
+
/**
|
|
1840
|
+
* Extracts relations from source data.
|
|
1841
|
+
* @param body - Relation extraction parameters.
|
|
1842
|
+
*/
|
|
1843
|
+
relations(body) {
|
|
1844
|
+
return this.http.post("/ontology/extract/extract/relations", body);
|
|
1845
|
+
}
|
|
1846
|
+
/**
|
|
1847
|
+
* Extracts RDF triplets from source data.
|
|
1848
|
+
* @param body - Triplet extraction parameters.
|
|
1849
|
+
*/
|
|
1850
|
+
triplets(body) {
|
|
1851
|
+
return this.http.post("/ontology/extract/extract/triplets", body);
|
|
1852
|
+
}
|
|
1853
|
+
};
|
|
1854
|
+
var EventsNamespace = class extends SubdomainBase {
|
|
1855
|
+
constructor(http) {
|
|
1856
|
+
super(http, "/ontology/events");
|
|
1857
|
+
}
|
|
1858
|
+
/**
|
|
1859
|
+
* Lists events with pagination.
|
|
1860
|
+
* @param opts - Pagination options.
|
|
1861
|
+
*/
|
|
1862
|
+
async list(opts = {}) {
|
|
1863
|
+
const raw = await this.http.get("/ontology/events/events", opts);
|
|
1864
|
+
return createPageResult(
|
|
1865
|
+
asPagePayload(raw),
|
|
1866
|
+
(c) => this.list({ ...opts, cursor: c })
|
|
1867
|
+
);
|
|
1868
|
+
}
|
|
1869
|
+
/**
|
|
1870
|
+
* Creates a new event.
|
|
1871
|
+
* @param body - The event payload.
|
|
1872
|
+
*/
|
|
1873
|
+
create(body) {
|
|
1874
|
+
return this.http.post("/ontology/events/events", body);
|
|
1875
|
+
}
|
|
1876
|
+
/**
|
|
1877
|
+
* Fetches an event by ID.
|
|
1878
|
+
* @param id - The event ID.
|
|
1879
|
+
*/
|
|
1880
|
+
get(id) {
|
|
1881
|
+
return this.http.get(`/ontology/events/events/${id}`);
|
|
1882
|
+
}
|
|
1883
|
+
/**
|
|
1884
|
+
* Creates an event checkpoint for a consumer.
|
|
1885
|
+
* @param body - Checkpoint data.
|
|
1886
|
+
*/
|
|
1887
|
+
createCheckpoint(body) {
|
|
1888
|
+
return this.http.post("/ontology/events/events/checkpoints", body);
|
|
1889
|
+
}
|
|
1890
|
+
/**
|
|
1891
|
+
* Fetches the checkpoint for a consumer.
|
|
1892
|
+
* @param consumer - The consumer identifier.
|
|
1893
|
+
*/
|
|
1894
|
+
getCheckpoint(consumer) {
|
|
1895
|
+
return this.http.get(`/ontology/events/events/checkpoints/${consumer}`);
|
|
1896
|
+
}
|
|
1897
|
+
/**
|
|
1898
|
+
* Acquires a lease for event processing.
|
|
1899
|
+
* @param body - Lease acquisition parameters.
|
|
1900
|
+
*/
|
|
1901
|
+
acquireLease(body) {
|
|
1902
|
+
return this.http.post("/ontology/events/events/leases/acquire", body);
|
|
1903
|
+
}
|
|
1904
|
+
/**
|
|
1905
|
+
* Acknowledges a lease after processing.
|
|
1906
|
+
* @param body - Lease acknowledgment parameters.
|
|
1907
|
+
*/
|
|
1908
|
+
acknowledgeLease(body) {
|
|
1909
|
+
return this.http.post("/ontology/events/events/leases/acknowledge", body);
|
|
396
1910
|
}
|
|
397
1911
|
};
|
|
398
1912
|
|
|
399
|
-
// src/
|
|
1913
|
+
// src/client.ts
|
|
400
1914
|
function createOntologyClient(clientOrConfig) {
|
|
401
|
-
var _a, _b, _c, _d, _e;
|
|
402
1915
|
if (clientOrConfig instanceof FrontalClient) {
|
|
403
|
-
return new
|
|
1916
|
+
return new OntologySdk(clientOrConfig.httpClient);
|
|
404
1917
|
}
|
|
405
1918
|
const http = new HttpClient({
|
|
406
1919
|
apiKey: clientOrConfig.apiKey,
|
|
407
|
-
baseUrl:
|
|
408
|
-
timeout:
|
|
409
|
-
maxRetries:
|
|
410
|
-
retryDelay:
|
|
1920
|
+
baseUrl: clientOrConfig.baseUrl ?? env.FRONTAL_API_URL ?? DEFAULT_ONTOLOGY_BASE_URL,
|
|
1921
|
+
timeout: clientOrConfig.timeout ?? DEFAULT_TIMEOUT,
|
|
1922
|
+
maxRetries: clientOrConfig.maxRetries ?? DEFAULT_MAX_RETRIES,
|
|
1923
|
+
retryDelay: DEFAULT_RETRY_DELAY,
|
|
411
1924
|
headers: {},
|
|
412
|
-
environment:
|
|
413
|
-
debug: false
|
|
1925
|
+
environment: env.FRONTAL_ENV,
|
|
1926
|
+
debug: env.FRONTAL_DEBUG ?? false
|
|
414
1927
|
});
|
|
415
|
-
return new
|
|
1928
|
+
return new OntologySdk(http);
|
|
416
1929
|
}
|
|
417
|
-
var
|
|
1930
|
+
var _ontologyCache;
|
|
1931
|
+
var ontology = new Proxy({}, {
|
|
1932
|
+
get(_t, prop) {
|
|
1933
|
+
if (!_ontologyCache) {
|
|
1934
|
+
_ontologyCache = createOntologyClient(getDefaultClient());
|
|
1935
|
+
}
|
|
1936
|
+
const inst = _ontologyCache;
|
|
1937
|
+
const val = inst[prop];
|
|
1938
|
+
return typeof val === "function" ? val.bind(inst) : val;
|
|
1939
|
+
}
|
|
1940
|
+
});
|
|
1941
|
+
|
|
1942
|
+
// src/schemas.ts
|
|
1943
|
+
import { z as z5 } from "zod";
|
|
1944
|
+
var FieldTypeSchema = z5.enum([
|
|
1945
|
+
"string",
|
|
1946
|
+
"integer",
|
|
1947
|
+
"float",
|
|
1948
|
+
"boolean",
|
|
1949
|
+
"uuid",
|
|
1950
|
+
"timestamp",
|
|
1951
|
+
"currency",
|
|
1952
|
+
"json",
|
|
1953
|
+
"array",
|
|
1954
|
+
"enum",
|
|
1955
|
+
"vector",
|
|
1956
|
+
"text"
|
|
1957
|
+
]);
|
|
1958
|
+
var RelationshipTypeSchema = z5.enum([
|
|
1959
|
+
"hasOne",
|
|
1960
|
+
"hasMany",
|
|
1961
|
+
"belongsTo",
|
|
1962
|
+
"manyToMany"
|
|
1963
|
+
]);
|
|
1964
|
+
var FieldDefinitionSchema = z5.object({
|
|
1965
|
+
type: FieldTypeSchema,
|
|
1966
|
+
required: z5.boolean().default(false),
|
|
1967
|
+
primary: z5.boolean().default(false),
|
|
1968
|
+
unique: z5.boolean().default(false),
|
|
1969
|
+
default: z5.unknown().optional(),
|
|
1970
|
+
substrate: z5.string().optional(),
|
|
1971
|
+
computed: z5.boolean().optional(),
|
|
1972
|
+
derivedBy: z5.string().optional(),
|
|
1973
|
+
cache: z5.object({
|
|
1974
|
+
ttl: z5.string()
|
|
1975
|
+
}).optional(),
|
|
1976
|
+
auto: z5.boolean().optional(),
|
|
1977
|
+
enum: z5.array(z5.string()).optional(),
|
|
1978
|
+
dimensions: z5.number().int().optional(),
|
|
1979
|
+
items: z5.string().optional(),
|
|
1980
|
+
description: z5.string().optional()
|
|
1981
|
+
}).loose();
|
|
1982
|
+
var RelationshipDefinitionSchema = z5.object({
|
|
1983
|
+
name: z5.string().optional(),
|
|
1984
|
+
type: RelationshipTypeSchema,
|
|
1985
|
+
targetEntity: z5.string(),
|
|
1986
|
+
foreignKey: z5.string().optional(),
|
|
1987
|
+
substrate: z5.string().optional(),
|
|
1988
|
+
cascade: z5.object({
|
|
1989
|
+
delete: z5.enum(["hard", "soft", "restrict", "nullify"]),
|
|
1990
|
+
update: z5.enum(["cascade", "restrict"])
|
|
1991
|
+
}).optional(),
|
|
1992
|
+
computed: z5.record(z5.string(), z5.unknown()).optional(),
|
|
1993
|
+
description: z5.string().optional()
|
|
1994
|
+
}).loose();
|
|
1995
|
+
var SubstrateRoutingSchema = z5.object({
|
|
1996
|
+
operational: z5.string().optional(),
|
|
1997
|
+
analytical: z5.string().optional(),
|
|
1998
|
+
semantic: z5.string().optional(),
|
|
1999
|
+
cache: z5.string().optional()
|
|
2000
|
+
}).loose();
|
|
2001
|
+
var SemanticMetadataSchema = z5.object({
|
|
2002
|
+
description: z5.string().optional(),
|
|
2003
|
+
lifecycle: z5.array(z5.string()).optional(),
|
|
2004
|
+
criticalFields: z5.array(z5.string()).optional(),
|
|
2005
|
+
significantEvents: z5.array(z5.string()).optional(),
|
|
2006
|
+
tags: z5.array(z5.string()).optional()
|
|
2007
|
+
}).loose();
|
|
2008
|
+
var IndexDefinitionSchema = z5.object({
|
|
2009
|
+
name: z5.string().optional(),
|
|
2010
|
+
fields: z5.array(z5.string()).min(1),
|
|
2011
|
+
substrate: z5.string().optional(),
|
|
2012
|
+
unique: z5.boolean().default(false),
|
|
2013
|
+
type: z5.enum(["btree", "hash", "gin", "gist", "brin"]).default("btree")
|
|
2014
|
+
}).loose();
|
|
2015
|
+
var ModelDefinitionSchema = z5.object({
|
|
2016
|
+
name: z5.string(),
|
|
2017
|
+
displayName: z5.string().optional(),
|
|
2018
|
+
description: z5.string().optional(),
|
|
2019
|
+
extends: z5.string().optional(),
|
|
2020
|
+
mixins: z5.array(z5.string()).optional(),
|
|
2021
|
+
fields: z5.record(z5.string(), FieldDefinitionSchema),
|
|
2022
|
+
relationships: z5.record(z5.string(), RelationshipDefinitionSchema).optional(),
|
|
2023
|
+
substrates: SubstrateRoutingSchema.optional(),
|
|
2024
|
+
semantics: SemanticMetadataSchema.optional(),
|
|
2025
|
+
indexes: z5.array(IndexDefinitionSchema).optional(),
|
|
2026
|
+
status: z5.enum(["draft", "active", "deprecated"]).default("draft")
|
|
2027
|
+
}).strict();
|
|
2028
|
+
var ModelSchema = ModelDefinitionSchema.extend({
|
|
2029
|
+
id: z5.string(),
|
|
2030
|
+
version: z5.number().int(),
|
|
2031
|
+
createdAt: timestampSchema,
|
|
2032
|
+
updatedAt: timestampSchema,
|
|
2033
|
+
entityCount: z5.number().int().optional()
|
|
2034
|
+
}).loose();
|
|
2035
|
+
var MigrationPlanSchema = z5.object({
|
|
2036
|
+
id: z5.string(),
|
|
2037
|
+
modelId: z5.string(),
|
|
2038
|
+
fromVersion: z5.number().int(),
|
|
2039
|
+
toVersion: z5.number().int(),
|
|
2040
|
+
changes: z5.array(
|
|
2041
|
+
z5.object({
|
|
2042
|
+
type: z5.enum([
|
|
2043
|
+
"add-field",
|
|
2044
|
+
"remove-field",
|
|
2045
|
+
"modify-field",
|
|
2046
|
+
"add-relationship",
|
|
2047
|
+
"remove-relationship"
|
|
2048
|
+
]),
|
|
2049
|
+
description: z5.string(),
|
|
2050
|
+
impact: z5.enum(["breaking", "non-breaking", "data-loss"]),
|
|
2051
|
+
sql: z5.string().optional()
|
|
2052
|
+
})
|
|
2053
|
+
),
|
|
2054
|
+
riskLevel: z5.enum(["low", "medium", "high", "critical"]),
|
|
2055
|
+
estimatedDowntime: z5.string().optional(),
|
|
2056
|
+
rolloutStrategy: z5.enum([
|
|
2057
|
+
"zero-downtime",
|
|
2058
|
+
"maintenance-window",
|
|
2059
|
+
"immediate"
|
|
2060
|
+
]),
|
|
2061
|
+
createdAt: timestampSchema
|
|
2062
|
+
}).loose();
|
|
2063
|
+
var RuleDefinitionSchema = z5.object({
|
|
2064
|
+
name: z5.string(),
|
|
2065
|
+
description: z5.string().optional(),
|
|
2066
|
+
entityTypes: z5.array(z5.string()).min(1),
|
|
2067
|
+
condition: z5.string(),
|
|
2068
|
+
action: z5.enum(["validate", "transform", "notify"]),
|
|
2069
|
+
severity: z5.enum(["error", "warning", "info"]),
|
|
2070
|
+
enabled: z5.boolean().default(true)
|
|
2071
|
+
}).strict();
|
|
2072
|
+
var MixinDefinitionSchema = z5.object({
|
|
2073
|
+
name: z5.string(),
|
|
2074
|
+
description: z5.string().optional(),
|
|
2075
|
+
fields: z5.record(z5.string(), FieldDefinitionSchema),
|
|
2076
|
+
relationships: z5.record(z5.string(), RelationshipDefinitionSchema).optional(),
|
|
2077
|
+
appliesTo: z5.array(z5.string()).optional()
|
|
2078
|
+
}).strict();
|
|
418
2079
|
export {
|
|
2080
|
+
DEFAULT_ONTOLOGY_BASE_URL,
|
|
419
2081
|
FieldDefinitionSchema,
|
|
420
2082
|
FieldTypeSchema,
|
|
421
2083
|
IndexDefinitionSchema,
|
|
@@ -423,12 +2085,13 @@ export {
|
|
|
423
2085
|
MixinDefinitionSchema,
|
|
424
2086
|
ModelDefinitionSchema,
|
|
425
2087
|
ModelSchema,
|
|
426
|
-
|
|
2088
|
+
OntologySdk,
|
|
427
2089
|
RelationshipDefinitionSchema,
|
|
428
2090
|
RelationshipTypeSchema,
|
|
429
2091
|
RuleDefinitionSchema,
|
|
430
2092
|
SemanticMetadataSchema,
|
|
431
2093
|
SubstrateRoutingSchema,
|
|
2094
|
+
VERSION,
|
|
432
2095
|
createOntologyClient,
|
|
433
2096
|
ontology
|
|
434
2097
|
};
|