@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 ADDED
@@ -0,0 +1,32 @@
1
+ # @frontal-labs/ontology
2
+
3
+ Ontology and model management APIs for schema, rules, and migrations.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @frontal-labs/ontology @frontal-labs/core
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { FrontalClient } from "@frontal-labs/core";
15
+ import { createOntologyClient } from "@frontal-labs/ontology";
16
+
17
+ const client = new FrontalClient({
18
+ apiKey: process.env.FRONTAL_API_KEY!,
19
+ baseUrl: process.env.FRONTAL_API_URL ?? "https://api.frontal.dev/v1",
20
+ });
21
+
22
+ const ontology = createOntologyClient(client);
23
+
24
+ const models = await ontology.list({ limit: 10 });
25
+ await ontology.create({ name: "invoice", fields: [{ name: "amount", type: "number", required: true }] });
26
+ ```
27
+
28
+ ## Configuration
29
+
30
+ - `FRONTAL_API_KEY`
31
+ - `FRONTAL_ONTOLOGY_API_URL` (optional)
32
+ - `FRONTAL_API_URL` (fallback)
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Default base URL for Frontal Ontology services.
3
+ */
4
+ export declare const DEFAULT_ONTOLOGY_BASE_URL = "https://api.frontal.dev/v1";
5
+ /**
6
+ * Package version.
7
+ */
8
+ export declare const VERSION = "0.0.1";
9
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,yBAAyB,+BAA+B,CAAC;AAEtE;;GAEG;AACH,eAAO,MAAM,OAAO,UAAU,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { FrontalClient } from "@frontal-labs/core";
2
+ import { OntologyService } from "./service";
3
+ /** Config for standalone usage without @frontal-labs/core */
4
+ export interface OntologyClientConfig {
5
+ apiKey: string;
6
+ baseUrl?: string;
7
+ timeout?: number;
8
+ maxRetries?: number;
9
+ }
10
+ /** Create from a FrontalClient instance */
11
+ export declare function createOntologyClient(client: FrontalClient): OntologyService;
12
+ /** Create standalone with just config */
13
+ export declare function createOntologyClient(config: OntologyClientConfig): OntologyService;
14
+ export declare const ontology: OntologyService;
15
+ export * from "./schemas";
16
+ export { OntologyService } from "./service";
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAgC,MAAM,oBAAoB,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,6DAA6D;AAC7D,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,2CAA2C;AAC3C,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,GAAG,eAAe,CAAC;AAC7E,yCAAyC;AACzC,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,oBAAoB,GAC3B,eAAe,CAAC;AAyBnB,eAAO,MAAM,QAAQ,iBAAgD,CAAC;AAEtE,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,468 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
+ var __export = (target, all) => {
24
+ for (var name in all)
25
+ __defProp(target, name, { get: all[name], enumerable: true });
26
+ };
27
+ var __copyProps = (to, from, except, desc) => {
28
+ if (from && typeof from === "object" || typeof from === "function") {
29
+ for (let key of __getOwnPropNames(from))
30
+ if (!__hasOwnProp.call(to, key) && key !== except)
31
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
32
+ }
33
+ return to;
34
+ };
35
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
+ var __async = (__this, __arguments, generator) => {
37
+ return new Promise((resolve, reject) => {
38
+ var fulfilled = (value) => {
39
+ try {
40
+ step(generator.next(value));
41
+ } catch (e) {
42
+ reject(e);
43
+ }
44
+ };
45
+ var rejected = (value) => {
46
+ try {
47
+ step(generator.throw(value));
48
+ } catch (e) {
49
+ reject(e);
50
+ }
51
+ };
52
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
53
+ step((generator = generator.apply(__this, __arguments)).next());
54
+ });
55
+ };
56
+
57
+ // src/index.ts
58
+ var index_exports = {};
59
+ __export(index_exports, {
60
+ FieldDefinitionSchema: () => FieldDefinitionSchema,
61
+ FieldTypeSchema: () => FieldTypeSchema,
62
+ IndexDefinitionSchema: () => IndexDefinitionSchema,
63
+ MigrationPlanSchema: () => MigrationPlanSchema,
64
+ MixinDefinitionSchema: () => MixinDefinitionSchema,
65
+ ModelDefinitionSchema: () => ModelDefinitionSchema,
66
+ ModelSchema: () => ModelSchema,
67
+ OntologyService: () => OntologyService,
68
+ RelationshipDefinitionSchema: () => RelationshipDefinitionSchema,
69
+ RelationshipTypeSchema: () => RelationshipTypeSchema,
70
+ RuleDefinitionSchema: () => RuleDefinitionSchema,
71
+ SemanticMetadataSchema: () => SemanticMetadataSchema,
72
+ SubstrateRoutingSchema: () => SubstrateRoutingSchema,
73
+ createOntologyClient: () => createOntologyClient,
74
+ ontology: () => ontology
75
+ });
76
+ module.exports = __toCommonJS(index_exports);
77
+ var import_core3 = require("@frontal-labs/core");
78
+
79
+ // src/service.ts
80
+ var import_core2 = require("@frontal-labs/core");
81
+
82
+ // src/schemas.ts
83
+ var import_core = require("@frontal-labs/core");
84
+ var import_zod = require("zod");
85
+ var FieldTypeSchema = import_zod.z.enum([
86
+ "string",
87
+ "integer",
88
+ "float",
89
+ "boolean",
90
+ "uuid",
91
+ "timestamp",
92
+ "currency",
93
+ "json",
94
+ "array",
95
+ "enum",
96
+ "vector",
97
+ "text"
98
+ ]);
99
+ var RelationshipTypeSchema = import_zod.z.enum([
100
+ "hasOne",
101
+ "hasMany",
102
+ "belongsTo",
103
+ "manyToMany"
104
+ ]);
105
+ var FieldDefinitionSchema = import_zod.z.object({
106
+ type: FieldTypeSchema,
107
+ required: import_zod.z.boolean().default(false),
108
+ primary: import_zod.z.boolean().default(false),
109
+ unique: import_zod.z.boolean().default(false),
110
+ default: import_zod.z.unknown().optional(),
111
+ substrate: import_zod.z.string().optional(),
112
+ computed: import_zod.z.boolean().optional(),
113
+ derivedBy: import_zod.z.string().optional(),
114
+ cache: import_zod.z.object({
115
+ ttl: import_zod.z.string()
116
+ }).optional(),
117
+ auto: import_zod.z.boolean().optional(),
118
+ enum: import_zod.z.array(import_zod.z.string()).optional(),
119
+ dimensions: import_zod.z.number().int().optional(),
120
+ items: import_zod.z.string().optional(),
121
+ description: import_zod.z.string().optional()
122
+ }).passthrough();
123
+ var RelationshipDefinitionSchema = import_zod.z.object({
124
+ name: import_zod.z.string().optional(),
125
+ type: RelationshipTypeSchema,
126
+ targetEntity: import_zod.z.string(),
127
+ foreignKey: import_zod.z.string().optional(),
128
+ substrate: import_zod.z.string().optional(),
129
+ cascade: import_zod.z.object({
130
+ delete: import_zod.z.enum(["hard", "soft", "restrict", "nullify"]),
131
+ update: import_zod.z.enum(["cascade", "restrict"])
132
+ }).optional(),
133
+ computed: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional(),
134
+ description: import_zod.z.string().optional()
135
+ }).passthrough();
136
+ var SubstrateRoutingSchema = import_zod.z.object({
137
+ operational: import_zod.z.string().optional(),
138
+ analytical: import_zod.z.string().optional(),
139
+ semantic: import_zod.z.string().optional(),
140
+ cache: import_zod.z.string().optional()
141
+ }).passthrough();
142
+ var SemanticMetadataSchema = import_zod.z.object({
143
+ description: import_zod.z.string().optional(),
144
+ lifecycle: import_zod.z.array(import_zod.z.string()).optional(),
145
+ criticalFields: import_zod.z.array(import_zod.z.string()).optional(),
146
+ significantEvents: import_zod.z.array(import_zod.z.string()).optional(),
147
+ tags: import_zod.z.array(import_zod.z.string()).optional()
148
+ }).passthrough();
149
+ var IndexDefinitionSchema = import_zod.z.object({
150
+ name: import_zod.z.string().optional(),
151
+ fields: import_zod.z.array(import_zod.z.string()).min(1),
152
+ substrate: import_zod.z.string().optional(),
153
+ unique: import_zod.z.boolean().default(false),
154
+ type: import_zod.z.enum(["btree", "hash", "gin", "gist", "brin"]).default("btree")
155
+ }).passthrough();
156
+ var ModelDefinitionSchema = import_zod.z.object({
157
+ name: import_zod.z.string(),
158
+ displayName: import_zod.z.string().optional(),
159
+ description: import_zod.z.string().optional(),
160
+ extends: import_zod.z.string().optional(),
161
+ mixins: import_zod.z.array(import_zod.z.string()).optional(),
162
+ fields: import_zod.z.record(import_zod.z.string(), FieldDefinitionSchema),
163
+ relationships: import_zod.z.record(import_zod.z.string(), RelationshipDefinitionSchema).optional(),
164
+ substrates: SubstrateRoutingSchema.optional(),
165
+ semantics: SemanticMetadataSchema.optional(),
166
+ indexes: import_zod.z.array(IndexDefinitionSchema).optional(),
167
+ status: import_zod.z.enum(["draft", "active", "deprecated"]).default("draft")
168
+ }).strict();
169
+ var ModelSchema = ModelDefinitionSchema.extend({
170
+ id: import_zod.z.string(),
171
+ version: import_zod.z.number().int(),
172
+ createdAt: import_core.timestampSchema,
173
+ updatedAt: import_core.timestampSchema,
174
+ entityCount: import_zod.z.number().int().optional()
175
+ }).passthrough();
176
+ var MigrationPlanSchema = import_zod.z.object({
177
+ id: import_zod.z.string(),
178
+ modelId: import_zod.z.string(),
179
+ fromVersion: import_zod.z.number().int(),
180
+ toVersion: import_zod.z.number().int(),
181
+ changes: import_zod.z.array(
182
+ import_zod.z.object({
183
+ type: import_zod.z.enum([
184
+ "add-field",
185
+ "remove-field",
186
+ "modify-field",
187
+ "add-relationship",
188
+ "remove-relationship"
189
+ ]),
190
+ description: import_zod.z.string(),
191
+ impact: import_zod.z.enum(["breaking", "non-breaking", "data-loss"]),
192
+ sql: import_zod.z.string().optional()
193
+ })
194
+ ),
195
+ riskLevel: import_zod.z.enum(["low", "medium", "high", "critical"]),
196
+ estimatedDowntime: import_zod.z.string().optional(),
197
+ rolloutStrategy: import_zod.z.enum([
198
+ "zero-downtime",
199
+ "maintenance-window",
200
+ "immediate"
201
+ ]),
202
+ createdAt: import_core.timestampSchema
203
+ }).passthrough();
204
+ var RuleDefinitionSchema = import_zod.z.object({
205
+ name: import_zod.z.string(),
206
+ description: import_zod.z.string().optional(),
207
+ entityTypes: import_zod.z.array(import_zod.z.string()).min(1),
208
+ condition: import_zod.z.string(),
209
+ action: import_zod.z.enum(["validate", "transform", "notify"]),
210
+ severity: import_zod.z.enum(["error", "warning", "info"]),
211
+ enabled: import_zod.z.boolean().default(true)
212
+ }).strict();
213
+ var MixinDefinitionSchema = import_zod.z.object({
214
+ name: import_zod.z.string(),
215
+ description: import_zod.z.string().optional(),
216
+ fields: import_zod.z.record(import_zod.z.string(), FieldDefinitionSchema),
217
+ relationships: import_zod.z.record(import_zod.z.string(), RelationshipDefinitionSchema).optional(),
218
+ appliesTo: import_zod.z.array(import_zod.z.string()).optional()
219
+ }).strict();
220
+
221
+ // src/service.ts
222
+ var asPagePayload = (raw) => raw;
223
+ var OntologyService = class {
224
+ constructor(http) {
225
+ this.http = http;
226
+ this.migrations = new MigrationsNamespace(this.http);
227
+ this.rules = new RulesNamespace(this.http);
228
+ this.mixins = new MixinsNamespace(this.http);
229
+ this.generation = new GenerationNamespace(this.http);
230
+ }
231
+ use(name) {
232
+ return new ModelAccessor(name, this.http);
233
+ }
234
+ list() {
235
+ return __async(this, arguments, function* (opts = {}) {
236
+ const raw = yield this.http.get("/ontology/engine/runs", opts);
237
+ return (0, import_core2.createPageResult)(
238
+ asPagePayload(raw),
239
+ (cursor) => this.list(__spreadProps(__spreadValues({}, opts), { cursor }))
240
+ );
241
+ });
242
+ }
243
+ create(definition) {
244
+ return __async(this, null, function* () {
245
+ const body = ModelDefinitionSchema.parse(definition);
246
+ return this.http.post("/ontology/engine/runs", body);
247
+ });
248
+ }
249
+ validate(definition) {
250
+ return __async(this, null, function* () {
251
+ const body = ModelDefinitionSchema.parse(definition);
252
+ return this.http.post("/ontology/engine/ontologies/validate", body);
253
+ });
254
+ }
255
+ checkIntegrity() {
256
+ return __async(this, null, function* () {
257
+ return this.http.get("/ontology/engine/health");
258
+ });
259
+ }
260
+ };
261
+ var ModelAccessor = class {
262
+ constructor(_name, http) {
263
+ this._name = _name;
264
+ this.http = http;
265
+ }
266
+ get(version) {
267
+ return __async(this, null, function* () {
268
+ const params = version ? { version } : void 0;
269
+ return this.http.get("/ontology/engine/runs", params);
270
+ });
271
+ }
272
+ update(definition) {
273
+ return __async(this, null, function* () {
274
+ return this.http.post("/ontology/engine/runs", definition);
275
+ });
276
+ }
277
+ delete(force = false) {
278
+ return __async(this, null, function* () {
279
+ return this.http.post("/ontology/engine/runs", {
280
+ action: "delete-model",
281
+ force
282
+ });
283
+ });
284
+ }
285
+ relationships() {
286
+ return __async(this, null, function* () {
287
+ return this.http.get("/ontology/engine/runs");
288
+ });
289
+ }
290
+ addRelationship(definition) {
291
+ return __async(this, null, function* () {
292
+ const body = RelationshipDefinitionSchema.parse(definition);
293
+ return this.http.post("/ontology/engine/runs", body);
294
+ });
295
+ }
296
+ removeRelationship(relationshipId) {
297
+ return __async(this, null, function* () {
298
+ return this.http.post("/ontology/engine/runs", {
299
+ action: "delete-relationship",
300
+ relationshipId
301
+ });
302
+ });
303
+ }
304
+ validateData() {
305
+ return __async(this, null, function* () {
306
+ return this.http.post("/ontology/engine/ontologies/validate");
307
+ });
308
+ }
309
+ versions() {
310
+ return __async(this, null, function* () {
311
+ return this.http.get("/ontology/engine/runs");
312
+ });
313
+ }
314
+ };
315
+ var MigrationsNamespace = class {
316
+ constructor(http) {
317
+ this.http = http;
318
+ }
319
+ plan(request) {
320
+ return __async(this, null, function* () {
321
+ return this.http.post(
322
+ "/ontology/engine/ontologies/compare-versions",
323
+ request
324
+ );
325
+ });
326
+ }
327
+ apply(planId, strategy = "zero-downtime") {
328
+ return __async(this, null, function* () {
329
+ return this.http.post("/ontology/engine/runs", { planId, strategy });
330
+ });
331
+ }
332
+ rollback(_migrationId) {
333
+ return __async(this, null, function* () {
334
+ return this.http.post("/ontology/engine/runs");
335
+ });
336
+ }
337
+ history() {
338
+ return __async(this, arguments, function* (opts = {}) {
339
+ const raw = yield this.http.get("/ontology/engine/runs", opts);
340
+ return (0, import_core2.createPageResult)(
341
+ asPagePayload(raw),
342
+ (cursor) => this.history(__spreadProps(__spreadValues({}, opts), { cursor }))
343
+ );
344
+ });
345
+ }
346
+ };
347
+ var RulesNamespace = class {
348
+ constructor(http) {
349
+ this.http = http;
350
+ }
351
+ list() {
352
+ return __async(this, null, function* () {
353
+ return this.http.get("/ontology/engine/runs");
354
+ });
355
+ }
356
+ create(definition) {
357
+ return __async(this, null, function* () {
358
+ const body = RuleDefinitionSchema.parse(definition);
359
+ return this.http.post("/ontology/engine/runs", body);
360
+ });
361
+ }
362
+ update(_ruleId, definition) {
363
+ return __async(this, null, function* () {
364
+ return this.http.post("/ontology/engine/runs", definition);
365
+ });
366
+ }
367
+ delete(ruleId) {
368
+ return __async(this, null, function* () {
369
+ return this.http.post("/ontology/engine/runs", {
370
+ action: "delete-rule",
371
+ ruleId
372
+ });
373
+ });
374
+ }
375
+ evaluate(opts) {
376
+ return __async(this, null, function* () {
377
+ return this.http.post("/ontology/engine/ontologies/validate", opts);
378
+ });
379
+ }
380
+ };
381
+ var MixinsNamespace = class {
382
+ constructor(http) {
383
+ this.http = http;
384
+ }
385
+ list() {
386
+ return __async(this, null, function* () {
387
+ return this.http.get("/ontology/engine/runs");
388
+ });
389
+ }
390
+ create(definition) {
391
+ return __async(this, null, function* () {
392
+ const body = MixinDefinitionSchema.parse(definition);
393
+ return this.http.post("/ontology/engine/runs", body);
394
+ });
395
+ }
396
+ };
397
+ var GenerationNamespace = class {
398
+ constructor(http) {
399
+ this.http = http;
400
+ }
401
+ generate(description, opts) {
402
+ return __async(this, null, function* () {
403
+ return this.http.post("/ontology/engine/ontologies/generate", __spreadValues({
404
+ description
405
+ }, opts));
406
+ });
407
+ }
408
+ infer(opts) {
409
+ return __async(this, null, function* () {
410
+ return this.http.post("/ontology/engine/ontologies/infer-classes", opts);
411
+ });
412
+ }
413
+ suggestions() {
414
+ return __async(this, arguments, function* (opts = {}) {
415
+ return this.http.get("/ontology/engine/runs", opts);
416
+ });
417
+ }
418
+ acceptSuggestion(_suggestionId) {
419
+ return __async(this, null, function* () {
420
+ return this.http.post("/ontology/engine/runs");
421
+ });
422
+ }
423
+ rejectSuggestion(_suggestionId, reason) {
424
+ return __async(this, null, function* () {
425
+ return this.http.post("/ontology/engine/runs", {
426
+ reason
427
+ });
428
+ });
429
+ }
430
+ };
431
+
432
+ // src/index.ts
433
+ function createOntologyClient(clientOrConfig) {
434
+ var _a, _b, _c, _d, _e;
435
+ if (clientOrConfig instanceof import_core3.FrontalClient) {
436
+ return new OntologyService(clientOrConfig._http);
437
+ }
438
+ const http = new import_core3.HttpClient({
439
+ apiKey: clientOrConfig.apiKey,
440
+ 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",
441
+ timeout: (_d = clientOrConfig.timeout) != null ? _d : 3e4,
442
+ maxRetries: (_e = clientOrConfig.maxRetries) != null ? _e : 3,
443
+ retryDelay: 1e3,
444
+ headers: {},
445
+ environment: "production",
446
+ debug: false
447
+ });
448
+ return new OntologyService(http);
449
+ }
450
+ var ontology = new OntologyService((0, import_core3.getDefaultClient)()._http);
451
+ // Annotate the CommonJS export names for ESM import in node:
452
+ 0 && (module.exports = {
453
+ FieldDefinitionSchema,
454
+ FieldTypeSchema,
455
+ IndexDefinitionSchema,
456
+ MigrationPlanSchema,
457
+ MixinDefinitionSchema,
458
+ ModelDefinitionSchema,
459
+ ModelSchema,
460
+ OntologyService,
461
+ RelationshipDefinitionSchema,
462
+ RelationshipTypeSchema,
463
+ RuleDefinitionSchema,
464
+ SemanticMetadataSchema,
465
+ SubstrateRoutingSchema,
466
+ createOntologyClient,
467
+ ontology
468
+ });