@kubun/protocol 0.3.10 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/models/cluster.d.ts +134 -300
- package/lib/models/cluster.d.ts.map +1 -1
- package/lib/models/cluster.js +14 -201
- package/lib/models/document.d.ts +890 -148
- package/lib/models/document.d.ts.map +1 -1
- package/lib/models/document.js +300 -2
- package/lib/models/graph.d.ts +1 -0
- package/lib/models/graph.d.ts.map +1 -1
- package/lib/models/graph.js +8 -0
- package/lib/services/graph.d.ts +648 -162
- package/lib/services/graph.d.ts.map +1 -1
- package/package.json +3 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/models/document.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/models/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,UAAU,EAAe,MAAM,gBAAgB,CAAA;AAEtF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAMnD,eAAO,MAAM,oBAAoB;;;CAA6D,CAAA;AAE9F,eAAO,MAAM,wBAAwB;;;;;;;;;;CAOV,CAAA;AAC3B,MAAM,MAAM,wBAAwB,GAAG,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAA;AAElF,eAAO,MAAM,2BAA2B;;;;;;;;;;CAOb,CAAA;AAC3B,MAAM,MAAM,2BAA2B,GAAG,UAAU,CAAC,OAAO,2BAA2B,CAAC,CAAA;AAExF,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;CAQX,CAAA;AAC3B,MAAM,MAAM,yBAAyB,GAAG,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAA;AAEpF,eAAO,MAAM,iBAAiB;;;;;;;;;;;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AAsB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CACtC,CAAA;AAGD,qBAAa,uBAAuB;;gBAYtB,MAAM,EAAE,6BAA6B;IAgNjD,eAAe,IAAI,aAAa;CAUjC"}
|
package/lib/models/document.js
CHANGED
|
@@ -1,13 +1,46 @@
|
|
|
1
|
+
import { asType, createValidator } from '@enkaku/schema';
|
|
2
|
+
import { DocumentModelID, ScalarModelID, ShapeModelID } from '@kubun/id';
|
|
3
|
+
import { pascalCase } from 'change-case';
|
|
1
4
|
import { baseObjectModel, nameString, referencesRecordModel } from './json-schema.js';
|
|
2
5
|
import { binaryStringValue, didStringValue } from './value.js';
|
|
3
6
|
export const documentModelVersion = {
|
|
4
7
|
type: 'string',
|
|
5
8
|
const: '1.0'
|
|
6
9
|
};
|
|
7
|
-
export const
|
|
10
|
+
export const documentFieldMetaAccount = {
|
|
11
|
+
type: 'object',
|
|
12
|
+
properties: {
|
|
13
|
+
type: {
|
|
14
|
+
type: 'string',
|
|
15
|
+
const: 'account'
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
required: [
|
|
19
|
+
'type'
|
|
20
|
+
],
|
|
21
|
+
additionalProperties: false
|
|
22
|
+
};
|
|
23
|
+
export const documentFieldMetaAttachment = {
|
|
8
24
|
type: 'object',
|
|
9
25
|
properties: {
|
|
10
|
-
|
|
26
|
+
type: {
|
|
27
|
+
type: 'string',
|
|
28
|
+
const: 'attachment'
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
required: [
|
|
32
|
+
'type'
|
|
33
|
+
],
|
|
34
|
+
additionalProperties: false
|
|
35
|
+
};
|
|
36
|
+
export const documentFieldMetaDocument = {
|
|
37
|
+
type: 'object',
|
|
38
|
+
properties: {
|
|
39
|
+
type: {
|
|
40
|
+
type: 'string',
|
|
41
|
+
const: 'document'
|
|
42
|
+
},
|
|
43
|
+
model: {
|
|
11
44
|
anyOf: [
|
|
12
45
|
{
|
|
13
46
|
type: 'string'
|
|
@@ -18,8 +51,19 @@ export const documentFieldMeta = {
|
|
|
18
51
|
]
|
|
19
52
|
}
|
|
20
53
|
},
|
|
54
|
+
required: [
|
|
55
|
+
'type',
|
|
56
|
+
'model'
|
|
57
|
+
],
|
|
21
58
|
additionalProperties: false
|
|
22
59
|
};
|
|
60
|
+
export const documentFieldMeta = {
|
|
61
|
+
anyOf: [
|
|
62
|
+
documentFieldMetaAccount,
|
|
63
|
+
documentFieldMetaAttachment,
|
|
64
|
+
documentFieldMetaDocument
|
|
65
|
+
]
|
|
66
|
+
};
|
|
23
67
|
export const documentFieldsMeta = {
|
|
24
68
|
type: 'object',
|
|
25
69
|
additionalProperties: documentFieldMeta
|
|
@@ -225,3 +269,257 @@ export const documentMutation = {
|
|
|
225
269
|
changeDocumentMutation
|
|
226
270
|
]
|
|
227
271
|
};
|
|
272
|
+
// Normalization logic
|
|
273
|
+
export const validateDocumentModel = createValidator(documentModel);
|
|
274
|
+
export const REFERENCE_PREFIX = '#/$defs/';
|
|
275
|
+
function toReference(id) {
|
|
276
|
+
return `${REFERENCE_PREFIX}${id}`;
|
|
277
|
+
}
|
|
278
|
+
const JSONObjectSchema = {
|
|
279
|
+
type: 'object',
|
|
280
|
+
title: 'JSONObject',
|
|
281
|
+
additionalProperties: true
|
|
282
|
+
};
|
|
283
|
+
const LOCAL_ID_REGEXP = /^#([0-9]+)$/;
|
|
284
|
+
// TODO: add fieldsMeta for account and attachment when walking the schema
|
|
285
|
+
export class DocumentModelNormalizer {
|
|
286
|
+
#inputModel;
|
|
287
|
+
#interfaces = new Set();
|
|
288
|
+
#logger;
|
|
289
|
+
#normalizedSchema;
|
|
290
|
+
#refs;
|
|
291
|
+
#root;
|
|
292
|
+
#schemaProperties = {};
|
|
293
|
+
#schemaReferences = {};
|
|
294
|
+
#schemaRequired = new Set();
|
|
295
|
+
#fieldsMeta = {};
|
|
296
|
+
constructor(params){
|
|
297
|
+
this.#inputModel = params.inputModel;
|
|
298
|
+
this.#logger = params.logger;
|
|
299
|
+
const inputSchema = params.inputModel.schema ?? {};
|
|
300
|
+
this.#processInterfaces(params.interfaceModels);
|
|
301
|
+
this.#processMeta(inputSchema, params.normalizedInterfaceIDs);
|
|
302
|
+
this.#refs = inputSchema.$defs ?? {};
|
|
303
|
+
this.#root = {
|
|
304
|
+
...inputSchema,
|
|
305
|
+
type: 'object',
|
|
306
|
+
properties: this.#schemaProperties,
|
|
307
|
+
required: Array.from(this.#schemaRequired),
|
|
308
|
+
additionalProperties: false,
|
|
309
|
+
$defs: {
|
|
310
|
+
...inputSchema.$defs,
|
|
311
|
+
...this.#schemaReferences
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
this.#normalizedSchema = this.#normalizeSchema();
|
|
315
|
+
this.#processFieldsMeta();
|
|
316
|
+
}
|
|
317
|
+
#processInterfaces(interfaceModels) {
|
|
318
|
+
// Add interface fields
|
|
319
|
+
for (const interfaceModel of interfaceModels){
|
|
320
|
+
for (const interfaceID of interfaceModel.interfaces){
|
|
321
|
+
this.#interfaces.add(interfaceID);
|
|
322
|
+
}
|
|
323
|
+
for (const requiredKey of interfaceModel.schema.required){
|
|
324
|
+
this.#schemaRequired.add(requiredKey);
|
|
325
|
+
}
|
|
326
|
+
Object.assign(this.#schemaProperties, interfaceModel.schema.properties);
|
|
327
|
+
Object.assign(this.#schemaReferences, interfaceModel.schema.$defs);
|
|
328
|
+
Object.assign(this.#fieldsMeta, interfaceModel.fieldsMeta ?? {});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
#processMeta(inputSchema, normalizedInterfaceIDs) {
|
|
332
|
+
for (const interfaceID of normalizedInterfaceIDs){
|
|
333
|
+
this.#interfaces.add(interfaceID);
|
|
334
|
+
}
|
|
335
|
+
for (const requiredKey of inputSchema.required ?? []){
|
|
336
|
+
this.#schemaRequired.add(requiredKey);
|
|
337
|
+
}
|
|
338
|
+
Object.assign(this.#schemaProperties, inputSchema.properties ?? {});
|
|
339
|
+
Object.assign(this.#fieldsMeta, this.#inputModel.fieldsMeta ?? {});
|
|
340
|
+
}
|
|
341
|
+
#normalizeSchema() {
|
|
342
|
+
const schema = this.#root;
|
|
343
|
+
const entries = Object.entries(schema.properties ?? {});
|
|
344
|
+
if (entries.length === 0) {
|
|
345
|
+
throw new Error('Document schema must contain at least one property');
|
|
346
|
+
}
|
|
347
|
+
const properties = {};
|
|
348
|
+
for (const [key, value] of entries){
|
|
349
|
+
properties[key] = {
|
|
350
|
+
$ref: this.#encodeSchema(key, value)
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
return {
|
|
354
|
+
type: 'object',
|
|
355
|
+
properties,
|
|
356
|
+
additionalProperties: false,
|
|
357
|
+
required: schema.required ?? [],
|
|
358
|
+
$defs: this.#refs
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
#encodeSchema(fieldKey, schema) {
|
|
362
|
+
if (schema.$ref != null) {
|
|
363
|
+
const resolvedSchema = this.#resolveReference(schema.$ref);
|
|
364
|
+
return this.#encodeSchema(fieldKey, resolvedSchema);
|
|
365
|
+
}
|
|
366
|
+
const type = schema.type;
|
|
367
|
+
if (type == null) {
|
|
368
|
+
throw new Error('Invalid schema: missing type');
|
|
369
|
+
}
|
|
370
|
+
switch(type){
|
|
371
|
+
case 'array':
|
|
372
|
+
{
|
|
373
|
+
if (schema.title == null) {
|
|
374
|
+
throw new Error('Invalid array schema: missing title');
|
|
375
|
+
}
|
|
376
|
+
if (schema.items == null) {
|
|
377
|
+
throw new Error('Invalid array schema: missing items');
|
|
378
|
+
}
|
|
379
|
+
const { default: _, ...rest } = schema;
|
|
380
|
+
return this.#addShape({
|
|
381
|
+
...rest,
|
|
382
|
+
title: pascalCase(schema.title),
|
|
383
|
+
items: {
|
|
384
|
+
$ref: this.#encodeSchema(fieldKey, schema.items)
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
case 'object':
|
|
389
|
+
{
|
|
390
|
+
if (schema.additionalProperties) {
|
|
391
|
+
return this.#addShape(JSONObjectSchema);
|
|
392
|
+
}
|
|
393
|
+
if (schema.title == null) {
|
|
394
|
+
throw new Error('Invalid object schema: missing title');
|
|
395
|
+
}
|
|
396
|
+
const entries = Object.entries(schema.properties ?? {});
|
|
397
|
+
if (entries.length === 0) {
|
|
398
|
+
throw new Error('Invalid object schema: must contain at least one property');
|
|
399
|
+
}
|
|
400
|
+
const properties = {};
|
|
401
|
+
for (const [key, value] of entries){
|
|
402
|
+
properties[key] = {
|
|
403
|
+
$ref: this.#encodeSchema(key, value)
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
return this.#addShape({
|
|
407
|
+
type: 'object',
|
|
408
|
+
title: pascalCase(schema.title),
|
|
409
|
+
properties,
|
|
410
|
+
required: schema.required ?? [],
|
|
411
|
+
additionalProperties: false
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
default:
|
|
415
|
+
return this.#addScalar(fieldKey, schema);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
#resolveReference(ref) {
|
|
419
|
+
if (!ref.startsWith('#')) {
|
|
420
|
+
throw new Error(`Invalid reference format: ${ref}`);
|
|
421
|
+
}
|
|
422
|
+
// Handle #/$defs/ references
|
|
423
|
+
if (ref.startsWith(REFERENCE_PREFIX)) {
|
|
424
|
+
const key = ref.slice(REFERENCE_PREFIX.length);
|
|
425
|
+
const resolved = this.#root.$defs?.[key];
|
|
426
|
+
if (resolved == null) {
|
|
427
|
+
throw new Error(`Reference not found: ${ref}`);
|
|
428
|
+
}
|
|
429
|
+
return resolved;
|
|
430
|
+
}
|
|
431
|
+
// Handle other JSON Schema references like #/properties/, #/items/, etc.
|
|
432
|
+
const segments = ref.split('/').slice(1);
|
|
433
|
+
// biome-ignore lint/suspicious/noExplicitAny: mixed type
|
|
434
|
+
let current = this.#root;
|
|
435
|
+
for (const segment of segments){
|
|
436
|
+
if (current == null || typeof current !== 'object') {
|
|
437
|
+
throw new Error(`Invalid reference path: ${ref}`);
|
|
438
|
+
}
|
|
439
|
+
current = current[segment];
|
|
440
|
+
if (current == null) {
|
|
441
|
+
throw new Error(`Reference not found: ${ref}`);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
return current;
|
|
445
|
+
}
|
|
446
|
+
#addScalar(fieldKey, schema) {
|
|
447
|
+
const id = ScalarModelID.create(schema);
|
|
448
|
+
let normalizedSchema = schema;
|
|
449
|
+
if (schema.type === 'boolean') {
|
|
450
|
+
const { title: _, ...rest } = schema;
|
|
451
|
+
normalizedSchema = rest;
|
|
452
|
+
} else if (schema.title != null) {
|
|
453
|
+
const lowerCaseTitle = schema.title.toLowerCase();
|
|
454
|
+
if (lowerCaseTitle === 'attachmentid') {
|
|
455
|
+
this.#fieldsMeta[fieldKey] = {
|
|
456
|
+
type: 'attachment'
|
|
457
|
+
};
|
|
458
|
+
normalizedSchema = {
|
|
459
|
+
...schema,
|
|
460
|
+
title: 'attachmentid'
|
|
461
|
+
};
|
|
462
|
+
} else if (lowerCaseTitle === 'did') {
|
|
463
|
+
this.#fieldsMeta[fieldKey] = {
|
|
464
|
+
type: 'account'
|
|
465
|
+
};
|
|
466
|
+
normalizedSchema = {
|
|
467
|
+
...schema,
|
|
468
|
+
title: 'did'
|
|
469
|
+
};
|
|
470
|
+
} else if (lowerCaseTitle === 'docid') {
|
|
471
|
+
if (this.#fieldsMeta[fieldKey] == null) {
|
|
472
|
+
this.#logger.warn('Missing fieldMeta entry for document reference {fieldKey} of model {inputModel}', {
|
|
473
|
+
fieldKey,
|
|
474
|
+
inputModel: this.#inputModel
|
|
475
|
+
});
|
|
476
|
+
this.#fieldsMeta[fieldKey] = {
|
|
477
|
+
type: 'document',
|
|
478
|
+
model: null
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
normalizedSchema = {
|
|
482
|
+
...schema,
|
|
483
|
+
title: 'docid'
|
|
484
|
+
};
|
|
485
|
+
} else {
|
|
486
|
+
normalizedSchema = {
|
|
487
|
+
...schema,
|
|
488
|
+
title: pascalCase(schema.title)
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
this.#refs[id.toString()] = normalizedSchema;
|
|
493
|
+
return toReference(id);
|
|
494
|
+
}
|
|
495
|
+
#addShape(schema) {
|
|
496
|
+
const id = ShapeModelID.create(schema);
|
|
497
|
+
this.#refs[id.toString()] = schema;
|
|
498
|
+
return toReference(id);
|
|
499
|
+
}
|
|
500
|
+
#processFieldsMeta() {
|
|
501
|
+
// Convert model relations by index to local IDs
|
|
502
|
+
for (const [key, field] of Object.entries(this.#fieldsMeta)){
|
|
503
|
+
if (field.type !== 'document' || field.model === null) {
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
506
|
+
const match = field.model.match(LOCAL_ID_REGEXP);
|
|
507
|
+
if (match != null) {
|
|
508
|
+
this.#fieldsMeta[key] = {
|
|
509
|
+
...field,
|
|
510
|
+
model: DocumentModelID.local(Number.parseInt(match[1], 10)).toString()
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
toDocumentModel() {
|
|
516
|
+
return asType(validateDocumentModel, {
|
|
517
|
+
version: '1.0',
|
|
518
|
+
behavior: 'default',
|
|
519
|
+
...this.#inputModel,
|
|
520
|
+
interfaces: Array.from(this.#interfaces),
|
|
521
|
+
schema: this.#normalizedSchema,
|
|
522
|
+
fieldsMeta: this.#fieldsMeta
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
}
|
package/lib/models/graph.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare class GraphModel {
|
|
|
18
18
|
constructor(params: GraphModelParams);
|
|
19
19
|
get aliases(): Record<string, string>;
|
|
20
20
|
get record(): DocumentModelsRecord;
|
|
21
|
+
getAlias(modelID: string): string | null;
|
|
21
22
|
getModel(aliasOrID: string): DocumentModel | null;
|
|
22
23
|
toJSON(): GraphModelJSON;
|
|
23
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/models/graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAiB,MAAM,cAAc,CAAA;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAExE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,MAAM,EAAE,oBAAoB,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,MAAM,EAAE,oBAAoB,CAAA;CAC7B,CAAA;AAED,qBAAa,UAAU;;IACrB,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,UAAU;gBAY/C,MAAM,EAAE,gBAAgB;IAoBpC,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEpC;IAED,IAAI,MAAM,IAAI,oBAAoB,CAEjC;IAED,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI;IAKjD,MAAM,IAAI,cAAc;CAGzB"}
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/models/graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAiB,MAAM,cAAc,CAAA;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAExE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,MAAM,EAAE,oBAAoB,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,MAAM,EAAE,oBAAoB,CAAA;CAC7B,CAAA;AAED,qBAAa,UAAU;;IACrB,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,UAAU;gBAY/C,MAAM,EAAE,gBAAgB;IAoBpC,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEpC;IAED,IAAI,MAAM,IAAI,oBAAoB,CAEjC;IAED,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IASxC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI;IAKjD,MAAM,IAAI,cAAc;CAGzB"}
|
package/lib/models/graph.js
CHANGED
|
@@ -31,6 +31,14 @@ export class GraphModel {
|
|
|
31
31
|
get record() {
|
|
32
32
|
return this.#record;
|
|
33
33
|
}
|
|
34
|
+
getAlias(modelID) {
|
|
35
|
+
for (const [alias, id] of Object.entries(this.#aliases)){
|
|
36
|
+
if (id === modelID) {
|
|
37
|
+
return alias;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
34
42
|
getModel(aliasOrID) {
|
|
35
43
|
const id = this.#aliases[aliasOrID] ?? aliasOrID;
|
|
36
44
|
return this.#record[id] ?? null;
|