@kubun/protocol 0.3.4 → 0.3.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"cluster.d.ts","sourceRoot":"","sources":["../../src/models/cluster.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAA4C,MAAM,gBAAgB,CAAA;AAC1F,OAAO,EAAE,eAAe,EAAyD,MAAM,WAAW,CAAA;AAClG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEnD,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAElB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EAG1B,MAAM,eAAe,CAAA;AAUtB,MAAM,MAAM,qBAAqB,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAA;AAEtE,MAAM,MAAM,gBAAgB,GAAG,IAAI,CACjC,aAAa,EACb,SAAS,GAAG,UAAU,GAAG,YAAY,GAAG,QAAQ,GAAG,YAAY,CAChE,GAAG;IACF,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,qBAAqB,CAAA;IAChC,YAAY,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IAC5B,UAAU,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IAC1B,MAAM,CAAC,EAAE,UAAU,CAAC,MAAM,CAAA;IAC1B,UAAU,CAAC,EAAE,kBAAkB,CAAA;CAChC,CAAA;AAED,KAAK,gBAAgB,GACjB,UAAU,CAAC,OAAO,GAClB,UAAU,CAAC,OAAO,GAClB,UAAU,CAAC,MAAM,GACjB,UAAU,CAAC,MAAM,CAAA;AACrB,KAAK,eAAe,GAAG,UAAU,CAAC,KAAK,GAAG,UAAU,CAAC,MAAM,CAAA;AAC3D,KAAK,cAAc,GAAG,gBAAgB,GAAG,eAAe,CAAA;AAExD,MAAM,MAAM,0BAA0B,G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2
2
  import { assertType, createValidator } from '@enkaku/schema';
3
- import { DocumentModelID, ScalarModelID, ShapeModelID, digestJSON } from '@kubun/id';
3
+ import { DocumentModelID, digestJSON, ScalarModelID, ShapeModelID } from '@kubun/id';
4
+ import { pascalCase } from 'change-case';
4
5
  import { documentModel, documentModelsCluster } from './document.js';
5
6
  import { binaryStringValue } from './value.js';
6
7
  const JSONObjectSchema = {
@@ -12,9 +13,40 @@ export const REFERENCE_PREFIX = '#/$defs/';
12
13
  function toReference(id) {
13
14
  return `${REFERENCE_PREFIX}${id}`;
14
15
  }
16
+ function resolveReference(root, ref) {
17
+ if (!ref.startsWith('#')) {
18
+ throw new Error(`Invalid reference format: ${ref}`);
19
+ }
20
+ // Handle #/$defs/ references
21
+ if (ref.startsWith(REFERENCE_PREFIX)) {
22
+ const key = ref.slice(REFERENCE_PREFIX.length);
23
+ const resolved = root.$defs?.[key];
24
+ if (resolved == null) {
25
+ throw new Error(`Reference not found: ${ref}`);
26
+ }
27
+ return resolved;
28
+ }
29
+ // Handle other JSON Schema references like #/properties/, #/items/, etc.
30
+ const segments = ref.split('/').slice(1);
31
+ // biome-ignore lint/suspicious/noExplicitAny: mixed type
32
+ let current = root;
33
+ for (const segment of segments){
34
+ if (current == null || typeof current !== 'object') {
35
+ throw new Error(`Invalid reference path: ${ref}`);
36
+ }
37
+ current = current[segment];
38
+ if (current == null) {
39
+ throw new Error(`Reference not found: ${ref}`);
40
+ }
41
+ }
42
+ return current;
43
+ }
15
44
  function addScalar(refs, schema) {
16
45
  const id = ScalarModelID.create(schema);
17
- refs[id.toString()] = schema;
46
+ refs[id.toString()] = schema.title == null ? schema : {
47
+ ...schema,
48
+ title: pascalCase(schema.title)
49
+ };
18
50
  return toReference(id);
19
51
  }
20
52
  function addShape(refs, schema) {
@@ -22,9 +54,10 @@ function addShape(refs, schema) {
22
54
  refs[id.toString()] = schema;
23
55
  return toReference(id);
24
56
  }
25
- function encodeSchema(refs, schema) {
57
+ function encodeSchema(root, refs, schema) {
26
58
  if (schema.$ref != null) {
27
- return schema.$ref;
59
+ const resolvedSchema = resolveReference(root, schema.$ref);
60
+ return encodeSchema(root, refs, resolvedSchema);
28
61
  }
29
62
  const type = schema.type;
30
63
  if (type == null) {
@@ -41,8 +74,9 @@ function encodeSchema(refs, schema) {
41
74
  }
42
75
  return addShape(refs, {
43
76
  ...schema,
77
+ title: pascalCase(schema.title),
44
78
  items: {
45
- $ref: encodeSchema(refs, schema.items)
79
+ $ref: encodeSchema(root, refs, schema.items)
46
80
  }
47
81
  });
48
82
  }
@@ -61,12 +95,12 @@ function encodeSchema(refs, schema) {
61
95
  const properties = {};
62
96
  for (const [key, value] of entries){
63
97
  properties[key] = {
64
- $ref: encodeSchema(refs, value)
98
+ $ref: encodeSchema(root, refs, value)
65
99
  };
66
100
  }
67
101
  return addShape(refs, {
68
102
  type: 'object',
69
- title: schema.title,
103
+ title: pascalCase(schema.title),
70
104
  properties,
71
105
  required: schema.required ?? [],
72
106
  additionalProperties: false
@@ -85,7 +119,7 @@ function normalizeDocumentSchema(schema) {
85
119
  const refs = schema.$defs ?? {};
86
120
  for (const [key, value] of entries){
87
121
  properties[key] = {
88
- $ref: encodeSchema(refs, value)
122
+ $ref: encodeSchema(schema, refs, value)
89
123
  };
90
124
  }
91
125
  return {
@@ -103,7 +137,7 @@ function normalizeFieldsMeta(fields) {
103
137
  const match = field.relationModel?.match(LOCAL_ID_REGEXP);
104
138
  meta[key] = match == null ? field : {
105
139
  ...field,
106
- relationModel: DocumentModelID.local(Number.parseInt(match[1])).toString()
140
+ relationModel: DocumentModelID.local(Number.parseInt(match[1], 10)).toString()
107
141
  };
108
142
  }
109
143
  return meta;
@@ -201,6 +235,7 @@ export class ClusterBuilder {
201
235
  return model;
202
236
  }
203
237
  add(inputModel) {
238
+ const inputSchema = inputModel.schema ?? {};
204
239
  const interfaceIDs = inputModel.interfaces ?? [];
205
240
  const interfaces = new Set();
206
241
  const schemaProperties = {};
@@ -223,10 +258,10 @@ export class ClusterBuilder {
223
258
  for (const interfaceID of interfaceIDs){
224
259
  interfaces.add(interfaceID);
225
260
  }
226
- for (const requiredKey of inputModel.schema?.required ?? []){
261
+ for (const requiredKey of inputSchema.required ?? []){
227
262
  schemaRequired.add(requiredKey);
228
263
  }
229
- Object.assign(schemaProperties, inputModel.schema?.properties ?? {});
264
+ Object.assign(schemaProperties, inputSchema.properties ?? {});
230
265
  Object.assign(fieldsMeta, inputModel.fieldsMeta ?? {});
231
266
  const index = this.#cluster.length;
232
267
  const model = {
@@ -235,11 +270,15 @@ export class ClusterBuilder {
235
270
  ...inputModel,
236
271
  interfaces: Array.from(interfaces),
237
272
  schema: normalizeDocumentSchema({
273
+ ...inputSchema,
238
274
  type: 'object',
239
275
  properties: schemaProperties,
240
276
  required: Array.from(schemaRequired),
241
277
  additionalProperties: false,
242
- $defs: schemaReferences
278
+ $defs: {
279
+ ...inputSchema.$defs,
280
+ ...schemaReferences
281
+ }
243
282
  }),
244
283
  fieldsMeta: normalizeFieldsMeta(fieldsMeta)
245
284
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/protocol",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "license": "see LICENSE.md",
5
5
  "keywords": [],
6
6
  "type": "module",
@@ -16,9 +16,10 @@
16
16
  "sideEffects": false,
17
17
  "dependencies": {
18
18
  "@enkaku/codec": "^0.12.0",
19
- "@enkaku/protocol": "^0.12.0",
20
- "@enkaku/schema": "^0.12.0",
21
- "@kubun/id": "^0.3.0"
19
+ "@enkaku/protocol": "^0.12.1",
20
+ "@enkaku/schema": "^0.12.1",
21
+ "change-case": "^5.4.4",
22
+ "@kubun/id": "^0.3.1"
22
23
  },
23
24
  "devDependencies": {
24
25
  "json-schema-typed": "^8.0.1"