@frontal-labs/ontology 0.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 +32 -0
- package/dist/constants.d.ts +9 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +468 -0
- package/dist/index.mjs +434 -0
- package/dist/keys.d.ts +6 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/schemas.d.ts +426 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/service.d.ts +139 -0
- package/dist/service.d.ts.map +1 -0
- package/package.json +80 -0
- package/src/constants.ts +9 -0
- package/src/index.ts +45 -0
- package/src/keys.ts +29 -0
- package/src/schemas.ts +191 -0
- package/src/service.ts +269 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
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
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/index.ts
|
|
42
|
+
import { FrontalClient, getDefaultClient, HttpClient } from "@frontal-labs/core";
|
|
43
|
+
|
|
44
|
+
// src/service.ts
|
|
45
|
+
import {
|
|
46
|
+
createPageResult
|
|
47
|
+
} from "@frontal-labs/core";
|
|
48
|
+
|
|
49
|
+
// src/schemas.ts
|
|
50
|
+
import { timestampSchema } from "@frontal-labs/core";
|
|
51
|
+
import { z } from "zod";
|
|
52
|
+
var FieldTypeSchema = z.enum([
|
|
53
|
+
"string",
|
|
54
|
+
"integer",
|
|
55
|
+
"float",
|
|
56
|
+
"boolean",
|
|
57
|
+
"uuid",
|
|
58
|
+
"timestamp",
|
|
59
|
+
"currency",
|
|
60
|
+
"json",
|
|
61
|
+
"array",
|
|
62
|
+
"enum",
|
|
63
|
+
"vector",
|
|
64
|
+
"text"
|
|
65
|
+
]);
|
|
66
|
+
var RelationshipTypeSchema = z.enum([
|
|
67
|
+
"hasOne",
|
|
68
|
+
"hasMany",
|
|
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),
|
|
119
|
+
substrate: z.string().optional(),
|
|
120
|
+
unique: z.boolean().default(false),
|
|
121
|
+
type: z.enum(["btree", "hash", "gin", "gist", "brin"]).default("btree")
|
|
122
|
+
}).passthrough();
|
|
123
|
+
var ModelDefinitionSchema = z.object({
|
|
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")
|
|
135
|
+
}).strict();
|
|
136
|
+
var ModelSchema = ModelDefinitionSchema.extend({
|
|
137
|
+
id: z.string(),
|
|
138
|
+
version: z.number().int(),
|
|
139
|
+
createdAt: timestampSchema,
|
|
140
|
+
updatedAt: timestampSchema,
|
|
141
|
+
entityCount: z.number().int().optional()
|
|
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)
|
|
179
|
+
}).strict();
|
|
180
|
+
var MixinDefinitionSchema = z.object({
|
|
181
|
+
name: z.string(),
|
|
182
|
+
description: z.string().optional(),
|
|
183
|
+
fields: z.record(z.string(), FieldDefinitionSchema),
|
|
184
|
+
relationships: z.record(z.string(), RelationshipDefinitionSchema).optional(),
|
|
185
|
+
appliesTo: z.array(z.string()).optional()
|
|
186
|
+
}).strict();
|
|
187
|
+
|
|
188
|
+
// src/service.ts
|
|
189
|
+
var asPagePayload = (raw) => raw;
|
|
190
|
+
var OntologyService = class {
|
|
191
|
+
constructor(http) {
|
|
192
|
+
this.http = http;
|
|
193
|
+
this.migrations = new MigrationsNamespace(this.http);
|
|
194
|
+
this.rules = new RulesNamespace(this.http);
|
|
195
|
+
this.mixins = new MixinsNamespace(this.http);
|
|
196
|
+
this.generation = new GenerationNamespace(this.http);
|
|
197
|
+
}
|
|
198
|
+
use(name) {
|
|
199
|
+
return new ModelAccessor(name, this.http);
|
|
200
|
+
}
|
|
201
|
+
list() {
|
|
202
|
+
return __async(this, arguments, function* (opts = {}) {
|
|
203
|
+
const raw = yield this.http.get("/ontology/engine/runs", opts);
|
|
204
|
+
return createPageResult(
|
|
205
|
+
asPagePayload(raw),
|
|
206
|
+
(cursor) => this.list(__spreadProps(__spreadValues({}, opts), { cursor }))
|
|
207
|
+
);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
create(definition) {
|
|
211
|
+
return __async(this, null, function* () {
|
|
212
|
+
const body = ModelDefinitionSchema.parse(definition);
|
|
213
|
+
return this.http.post("/ontology/engine/runs", body);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
validate(definition) {
|
|
217
|
+
return __async(this, null, function* () {
|
|
218
|
+
const body = ModelDefinitionSchema.parse(definition);
|
|
219
|
+
return this.http.post("/ontology/engine/ontologies/validate", body);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
checkIntegrity() {
|
|
223
|
+
return __async(this, null, function* () {
|
|
224
|
+
return this.http.get("/ontology/engine/health");
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
var ModelAccessor = class {
|
|
229
|
+
constructor(_name, http) {
|
|
230
|
+
this._name = _name;
|
|
231
|
+
this.http = http;
|
|
232
|
+
}
|
|
233
|
+
get(version) {
|
|
234
|
+
return __async(this, null, function* () {
|
|
235
|
+
const params = version ? { version } : void 0;
|
|
236
|
+
return this.http.get("/ontology/engine/runs", params);
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
update(definition) {
|
|
240
|
+
return __async(this, null, function* () {
|
|
241
|
+
return this.http.post("/ontology/engine/runs", definition);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
delete(force = false) {
|
|
245
|
+
return __async(this, null, function* () {
|
|
246
|
+
return this.http.post("/ontology/engine/runs", {
|
|
247
|
+
action: "delete-model",
|
|
248
|
+
force
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
relationships() {
|
|
253
|
+
return __async(this, null, function* () {
|
|
254
|
+
return this.http.get("/ontology/engine/runs");
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
addRelationship(definition) {
|
|
258
|
+
return __async(this, null, function* () {
|
|
259
|
+
const body = RelationshipDefinitionSchema.parse(definition);
|
|
260
|
+
return this.http.post("/ontology/engine/runs", body);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
removeRelationship(relationshipId) {
|
|
264
|
+
return __async(this, null, function* () {
|
|
265
|
+
return this.http.post("/ontology/engine/runs", {
|
|
266
|
+
action: "delete-relationship",
|
|
267
|
+
relationshipId
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
validateData() {
|
|
272
|
+
return __async(this, null, function* () {
|
|
273
|
+
return this.http.post("/ontology/engine/ontologies/validate");
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
versions() {
|
|
277
|
+
return __async(this, null, function* () {
|
|
278
|
+
return this.http.get("/ontology/engine/runs");
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
var MigrationsNamespace = class {
|
|
283
|
+
constructor(http) {
|
|
284
|
+
this.http = http;
|
|
285
|
+
}
|
|
286
|
+
plan(request) {
|
|
287
|
+
return __async(this, null, function* () {
|
|
288
|
+
return this.http.post(
|
|
289
|
+
"/ontology/engine/ontologies/compare-versions",
|
|
290
|
+
request
|
|
291
|
+
);
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
apply(planId, strategy = "zero-downtime") {
|
|
295
|
+
return __async(this, null, function* () {
|
|
296
|
+
return this.http.post("/ontology/engine/runs", { planId, strategy });
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
rollback(_migrationId) {
|
|
300
|
+
return __async(this, null, function* () {
|
|
301
|
+
return this.http.post("/ontology/engine/runs");
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
history() {
|
|
305
|
+
return __async(this, arguments, function* (opts = {}) {
|
|
306
|
+
const raw = yield this.http.get("/ontology/engine/runs", opts);
|
|
307
|
+
return createPageResult(
|
|
308
|
+
asPagePayload(raw),
|
|
309
|
+
(cursor) => this.history(__spreadProps(__spreadValues({}, opts), { cursor }))
|
|
310
|
+
);
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
var RulesNamespace = class {
|
|
315
|
+
constructor(http) {
|
|
316
|
+
this.http = http;
|
|
317
|
+
}
|
|
318
|
+
list() {
|
|
319
|
+
return __async(this, null, function* () {
|
|
320
|
+
return this.http.get("/ontology/engine/runs");
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
create(definition) {
|
|
324
|
+
return __async(this, null, function* () {
|
|
325
|
+
const body = RuleDefinitionSchema.parse(definition);
|
|
326
|
+
return this.http.post("/ontology/engine/runs", body);
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
update(_ruleId, definition) {
|
|
330
|
+
return __async(this, null, function* () {
|
|
331
|
+
return this.http.post("/ontology/engine/runs", definition);
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
delete(ruleId) {
|
|
335
|
+
return __async(this, null, function* () {
|
|
336
|
+
return this.http.post("/ontology/engine/runs", {
|
|
337
|
+
action: "delete-rule",
|
|
338
|
+
ruleId
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
evaluate(opts) {
|
|
343
|
+
return __async(this, null, function* () {
|
|
344
|
+
return this.http.post("/ontology/engine/ontologies/validate", opts);
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
var MixinsNamespace = class {
|
|
349
|
+
constructor(http) {
|
|
350
|
+
this.http = http;
|
|
351
|
+
}
|
|
352
|
+
list() {
|
|
353
|
+
return __async(this, null, function* () {
|
|
354
|
+
return this.http.get("/ontology/engine/runs");
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
create(definition) {
|
|
358
|
+
return __async(this, null, function* () {
|
|
359
|
+
const body = MixinDefinitionSchema.parse(definition);
|
|
360
|
+
return this.http.post("/ontology/engine/runs", body);
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
var GenerationNamespace = class {
|
|
365
|
+
constructor(http) {
|
|
366
|
+
this.http = http;
|
|
367
|
+
}
|
|
368
|
+
generate(description, opts) {
|
|
369
|
+
return __async(this, null, function* () {
|
|
370
|
+
return this.http.post("/ontology/engine/ontologies/generate", __spreadValues({
|
|
371
|
+
description
|
|
372
|
+
}, opts));
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
infer(opts) {
|
|
376
|
+
return __async(this, null, function* () {
|
|
377
|
+
return this.http.post("/ontology/engine/ontologies/infer-classes", opts);
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
suggestions() {
|
|
381
|
+
return __async(this, arguments, function* (opts = {}) {
|
|
382
|
+
return this.http.get("/ontology/engine/runs", opts);
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
acceptSuggestion(_suggestionId) {
|
|
386
|
+
return __async(this, null, function* () {
|
|
387
|
+
return this.http.post("/ontology/engine/runs");
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
rejectSuggestion(_suggestionId, reason) {
|
|
391
|
+
return __async(this, null, function* () {
|
|
392
|
+
return this.http.post("/ontology/engine/runs", {
|
|
393
|
+
reason
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
// src/index.ts
|
|
400
|
+
function createOntologyClient(clientOrConfig) {
|
|
401
|
+
var _a, _b, _c, _d, _e;
|
|
402
|
+
if (clientOrConfig instanceof FrontalClient) {
|
|
403
|
+
return new OntologyService(clientOrConfig._http);
|
|
404
|
+
}
|
|
405
|
+
const http = new HttpClient({
|
|
406
|
+
apiKey: clientOrConfig.apiKey,
|
|
407
|
+
baseUrl: (_c = (_b = (_a = clientOrConfig.baseUrl) != null ? _a : process.env.FRONTAL_ONTOLOGY_API_URL) != null ? _b : process.env.FRONTAL_API_URL) != null ? _c : "https://api.frontal.dev/v1",
|
|
408
|
+
timeout: (_d = clientOrConfig.timeout) != null ? _d : 3e4,
|
|
409
|
+
maxRetries: (_e = clientOrConfig.maxRetries) != null ? _e : 3,
|
|
410
|
+
retryDelay: 1e3,
|
|
411
|
+
headers: {},
|
|
412
|
+
environment: "production",
|
|
413
|
+
debug: false
|
|
414
|
+
});
|
|
415
|
+
return new OntologyService(http);
|
|
416
|
+
}
|
|
417
|
+
var ontology = new OntologyService(getDefaultClient()._http);
|
|
418
|
+
export {
|
|
419
|
+
FieldDefinitionSchema,
|
|
420
|
+
FieldTypeSchema,
|
|
421
|
+
IndexDefinitionSchema,
|
|
422
|
+
MigrationPlanSchema,
|
|
423
|
+
MixinDefinitionSchema,
|
|
424
|
+
ModelDefinitionSchema,
|
|
425
|
+
ModelSchema,
|
|
426
|
+
OntologyService,
|
|
427
|
+
RelationshipDefinitionSchema,
|
|
428
|
+
RelationshipTypeSchema,
|
|
429
|
+
RuleDefinitionSchema,
|
|
430
|
+
SemanticMetadataSchema,
|
|
431
|
+
SubstrateRoutingSchema,
|
|
432
|
+
createOntologyClient,
|
|
433
|
+
ontology
|
|
434
|
+
};
|
package/dist/keys.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,GAAG;;;;EAyBd,CAAC"}
|