@kubun/protocol 0.1.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/models/document.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAwB,MAAM,gBAAgB,CAAA;AAKtE,eAAO,MAAM,oBAAoB;;;CAA6D,CAAA;AAE9F,eAAO,MAAM,iBAAiB;;;;;;;;;;;;CAMH,CAAA;AAC3B,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAA;AAErE,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;CAGJ,CAAA;AAC3B,MAAM,MAAM,kBAAkB,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAA;AAEtE,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAQL,CAAA;AAC3B,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAExE,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGN,CAAA;AAC3B,MAAM,MAAM,oBAAoB,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAE1E,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAcC,CAAA;AACjC,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAExE,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAaF,CAAA;AACjC,MAAM,MAAM,sBAAsB,GAAG,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAE9E,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGI,CAAA;AACjC,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAElE,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA"}
@@ -0,0 +1,229 @@
1
+ import { baseObjectModel, referencesRecordModel } from './json-schema.js';
2
+ import { binaryStringValue, didStringValue } from './value.js';
3
+ export const documentModelVersion = {
4
+ type: 'string',
5
+ const: '1.0'
6
+ };
7
+ export const documentFieldMeta = {
8
+ type: 'object',
9
+ properties: {
10
+ relationModel: {
11
+ anyOf: [
12
+ {
13
+ type: 'string'
14
+ },
15
+ {
16
+ type: 'null'
17
+ }
18
+ ]
19
+ }
20
+ },
21
+ additionalProperties: false
22
+ };
23
+ export const documentFieldsMeta = {
24
+ type: 'object',
25
+ additionalProperties: documentFieldMeta
26
+ };
27
+ export const documentModelSchema = {
28
+ type: 'object',
29
+ properties: {
30
+ ...baseObjectModel.properties,
31
+ $defs: referencesRecordModel
32
+ },
33
+ required: [
34
+ ...baseObjectModel.required,
35
+ '$defs'
36
+ ],
37
+ additionalProperties: false
38
+ };
39
+ export const documentModelBase = {
40
+ type: 'object',
41
+ properties: {
42
+ name: {
43
+ type: 'string'
44
+ },
45
+ version: documentModelVersion,
46
+ interfaces: {
47
+ type: 'array',
48
+ items: {
49
+ type: 'string'
50
+ }
51
+ },
52
+ schema: documentModelSchema,
53
+ fieldsMeta: documentFieldsMeta
54
+ },
55
+ required: [
56
+ 'name',
57
+ 'version',
58
+ 'interfaces',
59
+ 'schema',
60
+ 'fieldsMeta'
61
+ ],
62
+ additionalProperties: false
63
+ };
64
+ export const documentModelInterface = {
65
+ type: 'object',
66
+ properties: {
67
+ ...documentModelBase.properties,
68
+ behavior: {
69
+ type: 'string',
70
+ const: 'interface'
71
+ }
72
+ },
73
+ required: [
74
+ ...documentModelBase.required,
75
+ 'behavior'
76
+ ],
77
+ additionalProperties: false
78
+ };
79
+ export const documentModelList = {
80
+ type: 'object',
81
+ properties: {
82
+ ...documentModelBase.properties,
83
+ behavior: {
84
+ type: 'string',
85
+ const: 'list'
86
+ }
87
+ },
88
+ required: [
89
+ ...documentModelBase.required,
90
+ 'behavior'
91
+ ],
92
+ additionalProperties: false
93
+ };
94
+ export const documentModelSet = {
95
+ type: 'object',
96
+ properties: {
97
+ ...documentModelBase.properties,
98
+ behavior: {
99
+ type: 'string',
100
+ const: 'set'
101
+ },
102
+ setFields: {
103
+ type: 'array',
104
+ items: {
105
+ type: 'string'
106
+ }
107
+ }
108
+ },
109
+ required: [
110
+ ...documentModelBase.required,
111
+ 'behavior',
112
+ 'setFields'
113
+ ],
114
+ additionalProperties: false
115
+ };
116
+ export const documentModel = {
117
+ $id: 'urn:kubun:protocol:model:document',
118
+ anyOf: [
119
+ documentModelInterface,
120
+ documentModelList,
121
+ documentModelSet
122
+ ]
123
+ };
124
+ export const documentModelsCluster = {
125
+ type: 'array',
126
+ items: documentModel
127
+ };
128
+ export const documentModelsRecord = {
129
+ type: 'object',
130
+ additionalProperties: documentModel
131
+ };
132
+ export const setDocumentMutation = {
133
+ $id: 'urn:kubun:protocol:mutation:set',
134
+ type: 'object',
135
+ properties: {
136
+ typ: {
137
+ type: 'string',
138
+ const: 'set'
139
+ },
140
+ iss: didStringValue,
141
+ aud: didStringValue,
142
+ sub: {
143
+ type: 'string'
144
+ },
145
+ data: {
146
+ anyOf: [
147
+ binaryStringValue,
148
+ {
149
+ type: 'null'
150
+ }
151
+ ]
152
+ },
153
+ unq: binaryStringValue,
154
+ cap: {
155
+ anyOf: [
156
+ {
157
+ type: 'string'
158
+ },
159
+ {
160
+ type: 'array',
161
+ items: {
162
+ type: 'string'
163
+ }
164
+ }
165
+ ]
166
+ }
167
+ },
168
+ required: [
169
+ 'iss',
170
+ 'sub',
171
+ 'typ',
172
+ 'data',
173
+ 'unq'
174
+ ],
175
+ additionalProperties: false
176
+ };
177
+ export const changeDocumentMutation = {
178
+ $id: 'urn:kubun:protocol:mutation:change',
179
+ type: 'object',
180
+ properties: {
181
+ typ: {
182
+ type: 'string',
183
+ const: 'change'
184
+ },
185
+ iss: didStringValue,
186
+ sub: {
187
+ type: 'string'
188
+ },
189
+ data: {
190
+ anyOf: [
191
+ binaryStringValue,
192
+ {
193
+ type: 'null'
194
+ }
195
+ ]
196
+ },
197
+ inc: {
198
+ type: 'boolean'
199
+ },
200
+ cap: {
201
+ anyOf: [
202
+ {
203
+ type: 'string'
204
+ },
205
+ {
206
+ type: 'array',
207
+ items: {
208
+ type: 'string'
209
+ }
210
+ }
211
+ ]
212
+ }
213
+ },
214
+ required: [
215
+ 'iss',
216
+ 'sub',
217
+ 'typ',
218
+ 'data',
219
+ 'inc'
220
+ ],
221
+ additionalProperties: false
222
+ };
223
+ export const documentMutation = {
224
+ $id: 'urn:kubun:protocol:mutation',
225
+ anyOf: [
226
+ setDocumentMutation,
227
+ changeDocumentMutation
228
+ ]
229
+ };
@@ -0,0 +1,23 @@
1
+ import type { DocumentModel, DocumentModelsCluster, DocumentModelsRecord } from './document.js';
2
+ export type FromClustersParams = {
3
+ aliases?: Record<string, string>;
4
+ clusters: Array<DocumentModelsCluster>;
5
+ };
6
+ export type GraphModelParams = {
7
+ aliases?: Record<string, string>;
8
+ record: DocumentModelsRecord;
9
+ };
10
+ export type GraphModelJSON = {
11
+ aliases: Record<string, string>;
12
+ record: DocumentModelsRecord;
13
+ };
14
+ export declare class GraphModel {
15
+ #private;
16
+ static fromClusters(params: FromClustersParams): GraphModel;
17
+ constructor(params: GraphModelParams);
18
+ get aliases(): Record<string, string>;
19
+ get record(): DocumentModelsRecord;
20
+ getModel(aliasOrID: string): DocumentModel | null;
21
+ toJSON(): GraphModelJSON;
22
+ }
23
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/models/graph.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAE/F,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,QAAQ,EAAE,KAAK,CAAC,qBAAqB,CAAC,CAAA;CACvC,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;gBAe/C,MAAM,EAAE,gBAAgB;IAKpC,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"}
@@ -0,0 +1,39 @@
1
+ import { GraphModelID, toDigestBytes } from '@kubun/id';
2
+ export class GraphModel {
3
+ static fromClusters(params) {
4
+ const record = {};
5
+ for (const cluster of params.clusters){
6
+ const digestBytes = toDigestBytes(cluster);
7
+ for (const [index, model] of cluster.entries()){
8
+ const id = new GraphModelID(digestBytes, index);
9
+ record[id.toString()] = model;
10
+ }
11
+ }
12
+ return new GraphModel({
13
+ aliases: params.aliases,
14
+ record
15
+ });
16
+ }
17
+ #aliases;
18
+ #record;
19
+ constructor(params){
20
+ this.#aliases = params.aliases ?? {};
21
+ this.#record = params.record;
22
+ }
23
+ get aliases() {
24
+ return this.#aliases;
25
+ }
26
+ get record() {
27
+ return this.#record;
28
+ }
29
+ getModel(aliasOrID) {
30
+ const id = this.#aliases[aliasOrID] ?? aliasOrID;
31
+ return this.#record[id] ?? null;
32
+ }
33
+ toJSON() {
34
+ return {
35
+ aliases: this.#aliases,
36
+ record: this.#record
37
+ };
38
+ }
39
+ }