From 544188a8d439f5493576ff8e97a4bc9ae2d9d337 Mon Sep 17 00:00:00 2001 From: streamich Date: Wed, 7 Aug 2024 15:28:23 +0200 Subject: [PATCH 1/5] =?UTF-8?q?feat(json-type):=20=F0=9F=8E=B8=20improve?= =?UTF-8?q?=20type=20builder=20import=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/json-type/type/TypeBuilder.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/json-type/type/TypeBuilder.ts b/src/json-type/type/TypeBuilder.ts index c8857f6bbc..1e37a4d524 100644 --- a/src/json-type/type/TypeBuilder.ts +++ b/src/json-type/type/TypeBuilder.ts @@ -178,6 +178,8 @@ export class TypeBuilder { return this.Binary(this.import(node.type), node); case 'arr': return this.Array(this.import(node.type), node); + case 'tup': + return this.Tuple(...node.types.map((t: schema.Schema) => this.import(t))).options(node); case 'obj': { return this.Object( ...node.fields.map((f: any) => @@ -195,6 +197,10 @@ export class TypeBuilder { return this.Or(...node.types.map((t) => this.import(t as schema.Schema))).options(node); case 'ref': return this.Ref(node.ref).options(node); + case 'fn': + return this.Function(this.import(node.req as schema.Schema), this.import(node.res as schema.Schema)).options(node); + case 'fn$': + return this.Function$(this.import(node.req as schema.Schema), this.import(node.res as schema.Schema)).options(node); } throw new Error(`UNKNOWN_NODE [${node.kind}]`); } From 9826eb54d9255904d141e85a06a01f689b98ab6c Mon Sep 17 00:00:00 2001 From: streamich Date: Wed, 7 Aug 2024 17:43:46 +0200 Subject: [PATCH 2/5] =?UTF-8?q?test(json-type-value):=20=F0=9F=92=8D=20rep?= =?UTF-8?q?licate=20test=20scenario?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/json-type-value/__tests__/data.json | 1 + src/json-type-value/__tests__/fix.spec.ts | 28 +++++++++++++++++++++++ src/json-type/system/TypeSystem.ts | 16 ++++++------- src/json-type/type/types.ts | 2 +- 4 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 src/json-type-value/__tests__/data.json create mode 100644 src/json-type-value/__tests__/fix.spec.ts diff --git a/src/json-type-value/__tests__/data.json b/src/json-type-value/__tests__/data.json new file mode 100644 index 0000000000..e32c0b2698 --- /dev/null +++ b/src/json-type-value/__tests__/data.json @@ -0,0 +1 @@ +{"batch":{"seq":112,"ts":1723037983405},"pull":{"batches":[{"seq":12,"ts":1723037983082,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBB/3AgALUYGv5bnYmNmmCGNudW0f"}]},{"seq":13,"ts":1723037983086,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBCH3AgAMUYGv5bnYmNmmCGNudW0h"}]},{"seq":14,"ts":1723037983089,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBCP3AgANUYGv5bnYmNmmCGNudW0j"}]},{"seq":15,"ts":1723037983092,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBCX3AgAOUYGv5bnYmNmmCGNudW0l"}]},{"seq":16,"ts":1723037983095,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBCf3AgAPUYGv5bnYmNmmCGNudW0n"}]},{"seq":17,"ts":1723037983098,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBCn3AgAQUYGv5bnYmNmmCGNudW0p"}]},{"seq":18,"ts":1723037983101,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBCv3AgARUYGv5bnYmNmmCGNudW0r"}]},{"seq":19,"ts":1723037983105,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBC33AgASUYGv5bnYmNmmCGNudW0t"}]},{"seq":20,"ts":1723037983108,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBC/3AgATUYGv5bnYmNmmCGNudW0v"}]},{"seq":21,"ts":1723037983111,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBDH3AgAUUYGv5bnYmNmmCGNudW0x"}]},{"seq":22,"ts":1723037983114,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBDP3AgAVUYGv5bnYmNmmCGNudW0z"}]},{"seq":23,"ts":1723037983117,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBDX3AgAWUYGv5bnYmNmmCGNudW01"}]},{"seq":24,"ts":1723037983121,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBDf3AgAXUYGv5bnYmNmmCGNudW03"}]},{"seq":25,"ts":1723037983124,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBDn3AgAYGFGBr+W52JjZpghjbnVtOQ=="}]},{"seq":26,"ts":1723037983128,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBDv3AgAYGVGBr+W52JjZpghjbnVtOw=="}]},{"seq":27,"ts":1723037983131,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBD33AgAYGlGBr+W52JjZpghjbnVtPQ=="}]},{"seq":28,"ts":1723037983134,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBD/3AgAYG1GBr+W52JjZpghjbnVtPw=="}]},{"seq":29,"ts":1723037983138,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBEH3AgAYHFGBr+W52JjZpghjbnVtQQE="}]},{"seq":30,"ts":1723037983141,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBEP3AgAYHVGBr+W52JjZpghjbnVtQwE="}]},{"seq":31,"ts":1723037983143,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBEX3AgAYHlGBr+W52JjZpghjbnVtRQE="}]},{"seq":32,"ts":1723037983147,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBEf3AgAYH1GBr+W52JjZpghjbnVtRwE="}]},{"seq":33,"ts":1723037983149,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBEn3AgAYIFGBr+W52JjZpghjbnVtSQE="}]},{"seq":34,"ts":1723037983152,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBEv3AgAYIVGBr+W52JjZpghjbnVtSwE="}]},{"seq":35,"ts":1723037983155,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBE33AgAYIlGBr+W52JjZpghjbnVtTQE="}]},{"seq":36,"ts":1723037983158,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBE/3AgAYI1GBr+W52JjZpghjbnVtTwE="}]},{"seq":37,"ts":1723037983160,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBFH3AgAYJFGBr+W52JjZpghjbnVtUQE="}]},{"seq":38,"ts":1723037983163,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBFP3AgAYJVGBr+W52JjZpghjbnVtUwE="}]},{"seq":39,"ts":1723037983165,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBFX3AgAYJlGBr+W52JjZpghjbnVtVQE="}]},{"seq":40,"ts":1723037983169,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBFf3AgAYJ1GBr+W52JjZpghjbnVtVwE="}]},{"seq":41,"ts":1723037983172,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBFn3AgAYKFGBr+W52JjZpghjbnVtWQE="}]},{"seq":42,"ts":1723037983175,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBFv3AgAYKVGBr+W52JjZpghjbnVtWwE="}]},{"seq":43,"ts":1723037983178,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBF33AgAYKlGBr+W52JjZpghjbnVtXQE="}]},{"seq":44,"ts":1723037983181,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBF/3AgAYK1GBr+W52JjZpghjbnVtXwE="}]},{"seq":45,"ts":1723037983184,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBGH3AgAYLFGBr+W52JjZpghjbnVtYQE="}]},{"seq":46,"ts":1723037983187,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBGP3AgAYLVGBr+W52JjZpghjbnVtYwE="}]},{"seq":47,"ts":1723037983190,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBGX3AgAYLlGBr+W52JjZpghjbnVtZQE="}]},{"seq":48,"ts":1723037983192,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBGf3AgAYL1GBr+W52JjZpghjbnVtZwE="}]},{"seq":49,"ts":1723037983195,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBGn3AgAYMFGBr+W52JjZpghjbnVtaQE="}]},{"seq":50,"ts":1723037983198,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBGv3AgAYMVGBr+W52JjZpghjbnVtawE="}]},{"seq":51,"ts":1723037983200,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBG33AgAYMlGBr+W52JjZpghjbnVtbQE="}]},{"seq":52,"ts":1723037983213,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBG/3AgAYM1GBr+W52JjZpghjbnVtbwE="}]},{"seq":53,"ts":1723037983236,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBHH3AgAYNFGBr+W52JjZpghjbnVtcQE="}]},{"seq":54,"ts":1723037983240,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBHP3AgAYNVGBr+W52JjZpghjbnVtcwE="}]},{"seq":55,"ts":1723037983244,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBHX3AgAYNlGBr+W52JjZpghjbnVtdQE="}]},{"seq":56,"ts":1723037983249,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBHf3AgAYN1GBr+W52JjZpghjbnVtdwE="}]},{"seq":57,"ts":1723037983254,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBHn3AgAYOFGBr+W52JjZpghjbnVteQE="}]},{"seq":58,"ts":1723037983257,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBHv3AgAYOVGBr+W52JjZpghjbnVtewE="}]},{"seq":59,"ts":1723037983260,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBH33AgAYOlGBr+W52JjZpghjbnVtfQE="}]},{"seq":60,"ts":1723037983263,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBH/3AgAYO1GBr+W52JjZpghjbnVtfwE="}]},{"seq":61,"ts":1723037983265,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBIEB9wIAGDxRga/ludiY2aYIY251bUEC"}]},{"seq":62,"ts":1723037983268,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBIMB9wIAGD1Rga/ludiY2aYIY251bUMC"}]},{"seq":63,"ts":1723037983271,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBIUB9wIAGD5Rga/ludiY2aYIY251bUUC"}]},{"seq":64,"ts":1723037983274,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBIcB9wIAGD9Rga/ludiY2aYIY251bUcC"}]},{"seq":65,"ts":1723037983276,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBIkB9wIAGEBRga/ludiY2aYIY251bUkC"}]},{"seq":66,"ts":1723037983278,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBIsB9wIAGEFRga/ludiY2aYIY251bUsC"}]},{"seq":67,"ts":1723037983281,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBI0B9wIAGEJRga/ludiY2aYIY251bU0C"}]},{"seq":68,"ts":1723037983284,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBI8B9wIAGENRga/ludiY2aYIY251bU8C"}]},{"seq":69,"ts":1723037983288,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBJEB9wIAGERRga/ludiY2aYIY251bVEC"}]},{"seq":70,"ts":1723037983290,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBJMB9wIAGEVRga/ludiY2aYIY251bVMC"}]},{"seq":71,"ts":1723037983293,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBJUB9wIAGEZRga/ludiY2aYIY251bVUC"}]},{"seq":72,"ts":1723037983296,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBJcB9wIAGEdRga/ludiY2aYIY251bVcC"}]},{"seq":73,"ts":1723037983299,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBJkB9wIAGEhRga/ludiY2aYIY251bVkC"}]},{"seq":74,"ts":1723037983302,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBJsB9wIAGElRga/ludiY2aYIY251bVsC"}]},{"seq":75,"ts":1723037983305,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBJ0B9wIAGEpRga/ludiY2aYIY251bV0C"}]},{"seq":76,"ts":1723037983307,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBJ8B9wIAGEtRga/ludiY2aYIY251bV8C"}]},{"seq":77,"ts":1723037983310,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBKEB9wIAGExRga/ludiY2aYIY251bWEC"}]},{"seq":78,"ts":1723037983313,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBKMB9wIAGE1Rga/ludiY2aYIY251bWMC"}]},{"seq":79,"ts":1723037983316,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBKUB9wIAGE5Rga/ludiY2aYIY251bWUC"}]},{"seq":80,"ts":1723037983319,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBKcB9wIAGE9Rga/ludiY2aYIY251bWcC"}]},{"seq":81,"ts":1723037983322,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBKkB9wIAGFBRga/ludiY2aYIY251bWkC"}]},{"seq":82,"ts":1723037983325,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBKsB9wIAGFFRga/ludiY2aYIY251bWsC"}]},{"seq":83,"ts":1723037983328,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBK0B9wIAGFJRga/ludiY2aYIY251bW0C"}]},{"seq":84,"ts":1723037983330,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBK8B9wIAGFNRga/ludiY2aYIY251bW8C"}]},{"seq":85,"ts":1723037983333,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBLEB9wIAGFRRga/ludiY2aYIY251bXEC"}]},{"seq":86,"ts":1723037983335,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBLMB9wIAGFVRga/ludiY2aYIY251bXMC"}]},{"seq":87,"ts":1723037983338,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBLUB9wIAGFZRga/ludiY2aYIY251bXUC"}]},{"seq":88,"ts":1723037983340,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBLcB9wIAGFdRga/ludiY2aYIY251bXcC"}]},{"seq":89,"ts":1723037983343,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBLkB9wIAGFhRga/ludiY2aYIY251bXkC"}]},{"seq":90,"ts":1723037983346,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBLsB9wIAGFlRga/ludiY2aYIY251bXsC"}]},{"seq":91,"ts":1723037983349,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBL0B9wIAGFpRga/ludiY2aYIY251bX0C"}]},{"seq":92,"ts":1723037983351,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBL8B9wIAGFtRga/ludiY2aYIY251bX8C"}]},{"seq":93,"ts":1723037983354,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBMEB9wIAGFxRga/ludiY2aYIY251bUED"}]},{"seq":94,"ts":1723037983356,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBMMB9wIAGF1Rga/ludiY2aYIY251bUMD"}]},{"seq":95,"ts":1723037983358,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBMUB9wIAGF5Rga/ludiY2aYIY251bUUD"}]},{"seq":96,"ts":1723037983361,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBMcB9wIAGF9Rga/ludiY2aYIY251bUcD"}]},{"seq":97,"ts":1723037983363,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBMkB9wIAGGBRga/ludiY2aYIY251bUkD"}]},{"seq":98,"ts":1723037983365,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBMsB9wIAGGFRga/ludiY2aYIY251bUsD"}]},{"seq":99,"ts":1723037983369,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBM0B9wIAGGJRga/ludiY2aYIY251bU0D"}]},{"seq":100,"ts":1723037983371,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBM8B9wIAGGNRga/ludiY2aYIY251bU8D"}]},{"seq":101,"ts":1723037983374,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBNEB9wIAGGRRga/ludiY2aYIY251bVED"}]},{"seq":102,"ts":1723037983377,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBNMB9wIAGGVRga/ludiY2aYIY251bVMD"}]},{"seq":103,"ts":1723037983379,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBNUB9wIAGGZRga/ludiY2aYIY251bVUD"}]},{"seq":104,"ts":1723037983382,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBNcB9wIAGGdRga/ludiY2aYIY251bVcD"}]},{"seq":105,"ts":1723037983385,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBNkB9wIAGGhRga/ludiY2aYIY251bVkD"}]},{"seq":106,"ts":1723037983388,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBNsB9wIAGGlRga/ludiY2aYIY251bVsD"}]},{"seq":107,"ts":1723037983391,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBN0B9wIAGGpRga/ludiY2aYIY251bV0D"}]},{"seq":108,"ts":1723037983393,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBN8B9wIAGGtRga/ludiY2aYIY251bV8D"}]},{"seq":109,"ts":1723037983396,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBOEB9wIAGGxRga/ludiY2aYIY251bWED"}]},{"seq":110,"ts":1723037983399,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBOMB9wIAGG1Rga/ludiY2aYIY251bWMD"}]},{"seq":111,"ts":1723037983402,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBOUB9wIAGG5Rga/ludiY2aYIY251bWUD"}]}],"snapshot":{"id":"u2oz5qote6o-lzjwbsjg-8-fierznrkg6f","seq":11,"ts":1723037983079,"blob":"data:application/octet-stream;base64,AAAAFidCZHRleHQmgSVkSGVsbGNudW0xAAoDAh6v5bnYmNmmCAiAreIEHg=="}}} \ No newline at end of file diff --git a/src/json-type-value/__tests__/fix.spec.ts b/src/json-type-value/__tests__/fix.spec.ts new file mode 100644 index 0000000000..d595e75172 --- /dev/null +++ b/src/json-type-value/__tests__/fix.spec.ts @@ -0,0 +1,28 @@ +import {TypeSystem} from '../../json-type/system'; +import {FunctionType, t} from '../../json-type/type'; +import {Value} from '../Value'; +import {JsonDecoder} from '@jsonjoy.com/json-pack/lib/json'; +import {CborJsonValueCodec} from '@jsonjoy.com/json-pack/lib/codecs/cbor'; +import * as fs from 'fs'; +import {Writer} from '@jsonjoy.com/util/lib/buffers/Writer'; + +const decoder = new JsonDecoder(); +const systemSchema = {"BlockId":{"kind":"str","title":"Block ID","min":6,"max":256},"BlockCur":{"kind":"num","title":"Block Sequence Number","gte":-1,"format":"i32"},"BlockBatchSeq":{"kind":"num","title":"Batch Sequence Number","gte":0,"format":"u32"},"Block":{"kind":"obj","fields":[{"kind":"field","key":"id","type":{"kind":"ref","ref":"BlockId"}},{"kind":"field","key":"ts","type":{"kind":"num","format":"u"}},{"kind":"field","key":"uts","type":{"kind":"num","format":"u"}},{"kind":"field","key":"snapshot","type":{"kind":"ref","ref":"BlockSnapshot"}},{"kind":"field","key":"tip","type":{"kind":"arr","type":{"kind":"ref","ref":"BlockBatch"}}}]},"BlockSnapshotReturn":{"kind":"obj","fields":[{"kind":"field","key":"id","type":{"kind":"ref","ref":"BlockId"},"title":"Block ID","description":"The ID of the block."},{"kind":"field","key":"seq","type":{"kind":"ref","ref":"BlockCur"},"title":"Snapshot Cursor","description":"The cursor of the snapshot, representing the position in the history."},{"kind":"field","key":"ts","type":{"kind":"num","format":"u"},"title":"Snapshot Creation Time","description":"The time when the snapshot was created, in milliseconds since the Unix epoch."}],"title":"Block Snapshot Return","description":"Partial snapshot returned on creation, doesn't include the blob."},"BlockSnapshot":{"kind":"obj","fields":[{"kind":"field","key":"id","type":{"kind":"ref","ref":"BlockId"},"title":"Block ID","description":"The ID of the block."},{"kind":"field","key":"seq","type":{"kind":"ref","ref":"BlockCur"},"title":"Snapshot Cursor","description":"The cursor of the snapshot, representing the position in the history."},{"kind":"field","key":"ts","type":{"kind":"num","format":"u"},"title":"Snapshot Creation Time","description":"The time when the snapshot was created, in milliseconds since the Unix epoch."},{"kind":"field","key":"blob","type":{"kind":"bin","type":{"kind":"any"}},"title":"Snapshot Blob","description":"A serialized JSON CRDT model."}],"title":"Block Snapshot","description":"A snapshot of the block's state at a certain point in time."},"NewBlockSnapshotResponse":{"kind":"obj","fields":[{"kind":"field","key":"id","type":{"kind":"ref","ref":"BlockId"},"title":"Block ID","description":"The ID of the block."},{"kind":"field","key":"seq","type":{"kind":"ref","ref":"BlockCur"},"title":"Snapshot Cursor","description":"The cursor of the snapshot, representing the position in the history."},{"kind":"field","key":"ts","type":{"kind":"num","format":"u"},"title":"Snapshot Creation Time","description":"The time when the snapshot was created, in milliseconds since the Unix epoch."}]},"BlockPatch":{"kind":"obj","fields":[{"kind":"field","key":"blob","type":{"kind":"bin","type":{"kind":"any"}},"title":"Patch Blob","description":"The binary data of the patch. The format of the data is defined by the patch type."},{"kind":"field","key":"ts","type":{"kind":"num","format":"u"},"title":"Patch Creation Time","description":"The time when the patch was created, in milliseconds since the Unix epoch.\n\nThis time is set by the server when the patch received and stored on the server. If you want to also store the time when the patch was created by the user, you can include this information in the patch blob itself."}]},"BlockPatchPartial":{"kind":"obj","fields":[{"kind":"field","key":"blob","type":{"kind":"bin","type":{"kind":"any"}},"title":"Patch Blob","description":"The binary data of the patch. The format of the data is defined by the patch type."}]},"BlockPatchPartialReturn":{"kind":"obj","fields":[{"kind":"field","key":"ts","type":{"kind":"num","format":"u"},"title":"Patch Creation Time","description":"The time when the patch was created, in milliseconds since the Unix epoch.\n\nThis time is set by the server when the patch received and stored on the server. If you want to also store the time when the patch was created by the user, you can include this information in the patch blob itself."}]},"BlockBatch":{"kind":"obj","fields":[{"kind":"field","key":"patches","type":{"kind":"arr","type":{"kind":"ref","ref":"BlockPatchPartial"}}},{"kind":"field","key":"cts","type":{"kind":"num","format":"u","title":"Batch Creation Time","description":"The time when the batch was created, in milliseconds since the Unix epoch."},"optional":true},{"kind":"field","key":"seq","type":{"kind":"num","format":"u"},"title":"Batch Sequence Number","description":"The sequence number of the batch, representing the position in the history."},{"kind":"field","key":"ts","type":{"kind":"num","format":"u"},"title":"Batch Creation Time","description":"The time when the batch was created, in milliseconds since the Unix epoch.\n\nThis time is set by the server when the batch was received and stored on the server."}]},"BlockBatchPartial":{"kind":"obj","fields":[{"kind":"field","key":"patches","type":{"kind":"arr","type":{"kind":"ref","ref":"BlockPatchPartial"}}},{"kind":"field","key":"cts","type":{"kind":"num","format":"u","title":"Batch Creation Time","description":"The time when the batch was created, in milliseconds since the Unix epoch."},"optional":true}]},"BlockBatchPartialReturn":{"kind":"obj","fields":[{"kind":"field","key":"seq","type":{"kind":"num","format":"u"},"title":"Batch Sequence Number","description":"The sequence number of the batch, representing the position in the history."},{"kind":"field","key":"ts","type":{"kind":"num","format":"u"},"title":"Batch Creation Time","description":"The time when the batch was created, in milliseconds since the Unix epoch.\n\nThis time is set by the server when the batch was received and stored on the server."}]},"BlockEvent":{"kind":"or","types":[{"kind":"tup","types":[{"kind":"const","value":"new","title":"Event Type"}],"title":"Creation Event"},{"kind":"tup","types":[{"kind":"const","value":"upd","title":"Event Type"},{"kind":"obj","fields":[{"kind":"field","key":"batch","type":{"kind":"ref","ref":"BlockBatch"},"title":"Latest Patches","description":"Patches that have been applied to the block."}],"title":"Event Data"}],"title":"Update Event"},{"kind":"tup","types":[{"kind":"const","value":"del","title":"Event Type"}],"title":"Delete Event"}],"discriminator":["?",["==","del",["$","/0"]],2,["?",["==","upd",["$","/0"]],1,0]],"title":"Block Event","description":"A collection of possible events that can happen to a block."},"PresenceEntry":{"kind":"obj","fields":[{"kind":"field","key":"id","type":{"kind":"str"}},{"kind":"field","key":"lastSeen","type":{"kind":"num"}},{"kind":"field","key":"validUntil","type":{"kind":"num"}},{"kind":"field","key":"data","type":{"kind":"obj","fields":[],"encodeUnknownFields":true}}]}}; +const methodSchema = {"kind":"fn","req":{"kind":"obj","fields":[{"kind":"field","key":"id","type":{"kind":"ref","ref":"BlockId"},"title":"Document ID","description":"The ID of the document to apply the patch to."},{"kind":"field","key":"batch","type":{"kind":"ref","ref":"BlockBatchPartial"},"title":"Batch","description":"The batch of changes to apply to the document."},{"kind":"field","key":"create","type":{"kind":"bool"},"optional":true,"title":"Create, if not Exists","description":"If true, creates a new document if it does not exist."},{"kind":"field","key":"seq","type":{"kind":"ref","ref":"BlockBatchSeq"},"optional":true,"title":"Sequence Number","description":"The last client known sequence number. The server will return history starting from this sequence number."}]},"res":{"kind":"obj","fields":[{"kind":"field","key":"batch","type":{"kind":"ref","ref":"BlockBatchPartialReturn"},"title":"Committed Batch Parts","description":"Parts of committed batch which were generated on the server."},{"kind":"field","key":"pull","type":{"kind":"obj","fields":[{"kind":"field","key":"batches","type":{"kind":"arr","type":{"kind":"ref","ref":"BlockBatch"}},"title":"Batches","description":"The list of batches that happened after the given sequence number."},{"kind":"field","key":"snapshot","type":{"kind":"arr","type":{"kind":"ref","ref":"BlockSnapshot"}},"optional":true,"title":"Snapshot","description":"The snapshot of the block, to which the batches can be applied to get the current state of the block."}]},"optional":true}]},"title":"Edit Block","intro":"Applies patches to an existing block.","description":"Applies patches to an existing document and returns the latest concurrent changes."}; +const data = decoder.decode(fs.readFileSync(__dirname + '/data.json')); + +test('...', () => { + const system = new TypeSystem(); + system.importTypes(systemSchema as any); + const method = system.t.import(methodSchema as any) as FunctionType; + const res = method.res; + const value = new Value(res, data); + const codec = new CborJsonValueCodec(new Writer(16 * 1024) as any); + console.log(value.encode(codec)) + + console.log(system + ''); + console.log(method + ''); + console.log(res + ''); + console.log(data); + console.log(value + ''); +}); diff --git a/src/json-type/system/TypeSystem.ts b/src/json-type/system/TypeSystem.ts index bf3b9ae239..faf59317d1 100644 --- a/src/json-type/system/TypeSystem.ts +++ b/src/json-type/system/TypeSystem.ts @@ -23,14 +23,6 @@ export class TypeSystem implements Printable { return alias; }; - public importTypes( - types: A, - ): {readonly [K in keyof A]: TypeAlias} { - const result = {} as any; - for (const id in types) result[id] = this.alias(id, types[id]); - return result; - } - public readonly unalias = (id: K): TypeAlias => { const alias = this.aliases.get(id); if (!alias) throw new Error(`Alias [id = ${id}] not found.`); @@ -66,6 +58,14 @@ export class TypeSystem implements Printable { return result; } + public importTypes( + types: A, + ): {readonly [K in keyof A]: TypeAlias} { + const result = {} as any; + for (const id in types) result[id] = this.alias(id, this.t.import(types[id])); + return result; + } + public toString(tab: string = '') { const nl = () => ''; return ( diff --git a/src/json-type/type/types.ts b/src/json-type/type/types.ts index 77a71f364d..d92c32a70f 100644 --- a/src/json-type/type/types.ts +++ b/src/json-type/type/types.ts @@ -35,7 +35,7 @@ export type SchemaOfObjectFieldType = export type SchemaOfObjectFields = {[K in keyof F]: SchemaOfObjectFieldType}; -export type TypeMap = {[name: string]: Type}; +export type TypeMap = {[name: string]: schema.Schema}; export type FilterFunctions = { [K in keyof T as T[K] extends classes.FunctionType From 24d5adb96622b3f146a05a597cd2a61fd84c8ed9 Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 8 Aug 2024 10:44:37 +0200 Subject: [PATCH 3/5] =?UTF-8?q?fix(json-type-value):=20=F0=9F=90=9B=20show?= =?UTF-8?q?=20value=20encoding=20problemsn=20in=20development=20mode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/json-type-value/Value.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/json-type-value/Value.ts b/src/json-type-value/Value.ts index 7e18ae229d..a34e7958af 100644 --- a/src/json-type-value/Value.ts +++ b/src/json-type-value/Value.ts @@ -6,7 +6,7 @@ export class Value { public type: T, public data: ResolveType, ) {} - + public encode(codec: JsonValueCodec): void { const value = this.data; const type = this.type; @@ -16,3 +16,24 @@ export class Value { else type.encoder(codec.format)(value, encoder); } } + +if (process.env.NODE_ENV !== 'production') { + const encode = Value.prototype.encode; + Value.prototype.encode = function (codec: JsonValueCodec): void { + try { + encode.call(this, codec); + } catch (error) { + try { + // tslint:disable-next-line no-console + console.error(error); + const type = this.type; + if (type) { + const err = type.validator('object')(this.data); + // tslint:disable-next-line no-console + console.error(err); + } + } catch {} + throw error; + } + }; +} From 8f78465d3c5c11ff6e16480dfb7954994ec81c9b Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 8 Aug 2024 11:36:47 +0200 Subject: [PATCH 4/5] =?UTF-8?q?chore(json-type-value):=20=F0=9F=A4=96=20re?= =?UTF-8?q?move=20fixture=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/json-type-value/__tests__/data.json | 1 - src/json-type-value/__tests__/fix.spec.ts | 28 ----------------------- 2 files changed, 29 deletions(-) delete mode 100644 src/json-type-value/__tests__/data.json delete mode 100644 src/json-type-value/__tests__/fix.spec.ts diff --git a/src/json-type-value/__tests__/data.json b/src/json-type-value/__tests__/data.json deleted file mode 100644 index e32c0b2698..0000000000 --- a/src/json-type-value/__tests__/data.json +++ /dev/null @@ -1 +0,0 @@ -{"batch":{"seq":112,"ts":1723037983405},"pull":{"batches":[{"seq":12,"ts":1723037983082,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBB/3AgALUYGv5bnYmNmmCGNudW0f"}]},{"seq":13,"ts":1723037983086,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBCH3AgAMUYGv5bnYmNmmCGNudW0h"}]},{"seq":14,"ts":1723037983089,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBCP3AgANUYGv5bnYmNmmCGNudW0j"}]},{"seq":15,"ts":1723037983092,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBCX3AgAOUYGv5bnYmNmmCGNudW0l"}]},{"seq":16,"ts":1723037983095,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBCf3AgAPUYGv5bnYmNmmCGNudW0n"}]},{"seq":17,"ts":1723037983098,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBCn3AgAQUYGv5bnYmNmmCGNudW0p"}]},{"seq":18,"ts":1723037983101,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBCv3AgARUYGv5bnYmNmmCGNudW0r"}]},{"seq":19,"ts":1723037983105,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBC33AgASUYGv5bnYmNmmCGNudW0t"}]},{"seq":20,"ts":1723037983108,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBC/3AgATUYGv5bnYmNmmCGNudW0v"}]},{"seq":21,"ts":1723037983111,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBDH3AgAUUYGv5bnYmNmmCGNudW0x"}]},{"seq":22,"ts":1723037983114,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBDP3AgAVUYGv5bnYmNmmCGNudW0z"}]},{"seq":23,"ts":1723037983117,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBDX3AgAWUYGv5bnYmNmmCGNudW01"}]},{"seq":24,"ts":1723037983121,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBDf3AgAXUYGv5bnYmNmmCGNudW03"}]},{"seq":25,"ts":1723037983124,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBDn3AgAYGFGBr+W52JjZpghjbnVtOQ=="}]},{"seq":26,"ts":1723037983128,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBDv3AgAYGVGBr+W52JjZpghjbnVtOw=="}]},{"seq":27,"ts":1723037983131,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBD33AgAYGlGBr+W52JjZpghjbnVtPQ=="}]},{"seq":28,"ts":1723037983134,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBD/3AgAYG1GBr+W52JjZpghjbnVtPw=="}]},{"seq":29,"ts":1723037983138,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBEH3AgAYHFGBr+W52JjZpghjbnVtQQE="}]},{"seq":30,"ts":1723037983141,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBEP3AgAYHVGBr+W52JjZpghjbnVtQwE="}]},{"seq":31,"ts":1723037983143,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBEX3AgAYHlGBr+W52JjZpghjbnVtRQE="}]},{"seq":32,"ts":1723037983147,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBEf3AgAYH1GBr+W52JjZpghjbnVtRwE="}]},{"seq":33,"ts":1723037983149,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBEn3AgAYIFGBr+W52JjZpghjbnVtSQE="}]},{"seq":34,"ts":1723037983152,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBEv3AgAYIVGBr+W52JjZpghjbnVtSwE="}]},{"seq":35,"ts":1723037983155,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBE33AgAYIlGBr+W52JjZpghjbnVtTQE="}]},{"seq":36,"ts":1723037983158,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBE/3AgAYI1GBr+W52JjZpghjbnVtTwE="}]},{"seq":37,"ts":1723037983160,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBFH3AgAYJFGBr+W52JjZpghjbnVtUQE="}]},{"seq":38,"ts":1723037983163,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBFP3AgAYJVGBr+W52JjZpghjbnVtUwE="}]},{"seq":39,"ts":1723037983165,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBFX3AgAYJlGBr+W52JjZpghjbnVtVQE="}]},{"seq":40,"ts":1723037983169,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBFf3AgAYJ1GBr+W52JjZpghjbnVtVwE="}]},{"seq":41,"ts":1723037983172,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBFn3AgAYKFGBr+W52JjZpghjbnVtWQE="}]},{"seq":42,"ts":1723037983175,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBFv3AgAYKVGBr+W52JjZpghjbnVtWwE="}]},{"seq":43,"ts":1723037983178,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBF33AgAYKlGBr+W52JjZpghjbnVtXQE="}]},{"seq":44,"ts":1723037983181,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBF/3AgAYK1GBr+W52JjZpghjbnVtXwE="}]},{"seq":45,"ts":1723037983184,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBGH3AgAYLFGBr+W52JjZpghjbnVtYQE="}]},{"seq":46,"ts":1723037983187,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBGP3AgAYLVGBr+W52JjZpghjbnVtYwE="}]},{"seq":47,"ts":1723037983190,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBGX3AgAYLlGBr+W52JjZpghjbnVtZQE="}]},{"seq":48,"ts":1723037983192,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBGf3AgAYL1GBr+W52JjZpghjbnVtZwE="}]},{"seq":49,"ts":1723037983195,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBGn3AgAYMFGBr+W52JjZpghjbnVtaQE="}]},{"seq":50,"ts":1723037983198,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBGv3AgAYMVGBr+W52JjZpghjbnVtawE="}]},{"seq":51,"ts":1723037983200,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBG33AgAYMlGBr+W52JjZpghjbnVtbQE="}]},{"seq":52,"ts":1723037983213,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBG/3AgAYM1GBr+W52JjZpghjbnVtbwE="}]},{"seq":53,"ts":1723037983236,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBHH3AgAYNFGBr+W52JjZpghjbnVtcQE="}]},{"seq":54,"ts":1723037983240,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBHP3AgAYNVGBr+W52JjZpghjbnVtcwE="}]},{"seq":55,"ts":1723037983244,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBHX3AgAYNlGBr+W52JjZpghjbnVtdQE="}]},{"seq":56,"ts":1723037983249,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBHf3AgAYN1GBr+W52JjZpghjbnVtdwE="}]},{"seq":57,"ts":1723037983254,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBHn3AgAYOFGBr+W52JjZpghjbnVteQE="}]},{"seq":58,"ts":1723037983257,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBHv3AgAYOVGBr+W52JjZpghjbnVtewE="}]},{"seq":59,"ts":1723037983260,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBH33AgAYOlGBr+W52JjZpghjbnVtfQE="}]},{"seq":60,"ts":1723037983263,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBH/3AgAYO1GBr+W52JjZpghjbnVtfwE="}]},{"seq":61,"ts":1723037983265,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBIEB9wIAGDxRga/ludiY2aYIY251bUEC"}]},{"seq":62,"ts":1723037983268,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBIMB9wIAGD1Rga/ludiY2aYIY251bUMC"}]},{"seq":63,"ts":1723037983271,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBIUB9wIAGD5Rga/ludiY2aYIY251bUUC"}]},{"seq":64,"ts":1723037983274,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBIcB9wIAGD9Rga/ludiY2aYIY251bUcC"}]},{"seq":65,"ts":1723037983276,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBIkB9wIAGEBRga/ludiY2aYIY251bUkC"}]},{"seq":66,"ts":1723037983278,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBIsB9wIAGEFRga/ludiY2aYIY251bUsC"}]},{"seq":67,"ts":1723037983281,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBI0B9wIAGEJRga/ludiY2aYIY251bU0C"}]},{"seq":68,"ts":1723037983284,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBI8B9wIAGENRga/ludiY2aYIY251bU8C"}]},{"seq":69,"ts":1723037983288,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBJEB9wIAGERRga/ludiY2aYIY251bVEC"}]},{"seq":70,"ts":1723037983290,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBJMB9wIAGEVRga/ludiY2aYIY251bVMC"}]},{"seq":71,"ts":1723037983293,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBJUB9wIAGEZRga/ludiY2aYIY251bVUC"}]},{"seq":72,"ts":1723037983296,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBJcB9wIAGEdRga/ludiY2aYIY251bVcC"}]},{"seq":73,"ts":1723037983299,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBJkB9wIAGEhRga/ludiY2aYIY251bVkC"}]},{"seq":74,"ts":1723037983302,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBJsB9wIAGElRga/ludiY2aYIY251bVsC"}]},{"seq":75,"ts":1723037983305,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBJ0B9wIAGEpRga/ludiY2aYIY251bV0C"}]},{"seq":76,"ts":1723037983307,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBJ8B9wIAGEtRga/ludiY2aYIY251bV8C"}]},{"seq":77,"ts":1723037983310,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBKEB9wIAGExRga/ludiY2aYIY251bWEC"}]},{"seq":78,"ts":1723037983313,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBKMB9wIAGE1Rga/ludiY2aYIY251bWMC"}]},{"seq":79,"ts":1723037983316,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBKUB9wIAGE5Rga/ludiY2aYIY251bWUC"}]},{"seq":80,"ts":1723037983319,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBKcB9wIAGE9Rga/ludiY2aYIY251bWcC"}]},{"seq":81,"ts":1723037983322,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBKkB9wIAGFBRga/ludiY2aYIY251bWkC"}]},{"seq":82,"ts":1723037983325,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBKsB9wIAGFFRga/ludiY2aYIY251bWsC"}]},{"seq":83,"ts":1723037983328,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBK0B9wIAGFJRga/ludiY2aYIY251bW0C"}]},{"seq":84,"ts":1723037983330,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBK8B9wIAGFNRga/ludiY2aYIY251bW8C"}]},{"seq":85,"ts":1723037983333,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBLEB9wIAGFRRga/ludiY2aYIY251bXEC"}]},{"seq":86,"ts":1723037983335,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBLMB9wIAGFVRga/ludiY2aYIY251bXMC"}]},{"seq":87,"ts":1723037983338,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBLUB9wIAGFZRga/ludiY2aYIY251bXUC"}]},{"seq":88,"ts":1723037983340,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBLcB9wIAGFdRga/ludiY2aYIY251bXcC"}]},{"seq":89,"ts":1723037983343,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBLkB9wIAGFhRga/ludiY2aYIY251bXkC"}]},{"seq":90,"ts":1723037983346,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBLsB9wIAGFlRga/ludiY2aYIY251bXsC"}]},{"seq":91,"ts":1723037983349,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBL0B9wIAGFpRga/ludiY2aYIY251bX0C"}]},{"seq":92,"ts":1723037983351,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBL8B9wIAGFtRga/ludiY2aYIY251bX8C"}]},{"seq":93,"ts":1723037983354,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBMEB9wIAGFxRga/ludiY2aYIY251bUED"}]},{"seq":94,"ts":1723037983356,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBMMB9wIAGF1Rga/ludiY2aYIY251bUMD"}]},{"seq":95,"ts":1723037983358,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBMUB9wIAGF5Rga/ludiY2aYIY251bUUD"}]},{"seq":96,"ts":1723037983361,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBMcB9wIAGF9Rga/ludiY2aYIY251bUcD"}]},{"seq":97,"ts":1723037983363,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBMkB9wIAGGBRga/ludiY2aYIY251bUkD"}]},{"seq":98,"ts":1723037983365,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBMsB9wIAGGFRga/ludiY2aYIY251bUsD"}]},{"seq":99,"ts":1723037983369,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBM0B9wIAGGJRga/ludiY2aYIY251bU0D"}]},{"seq":100,"ts":1723037983371,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBM8B9wIAGGNRga/ludiY2aYIY251bU8D"}]},{"seq":101,"ts":1723037983374,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBNEB9wIAGGRRga/ludiY2aYIY251bVED"}]},{"seq":102,"ts":1723037983377,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBNMB9wIAGGVRga/ludiY2aYIY251bVMD"}]},{"seq":103,"ts":1723037983379,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBNUB9wIAGGZRga/ludiY2aYIY251bVUD"}]},{"seq":104,"ts":1723037983382,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBNcB9wIAGGdRga/ludiY2aYIY251bVcD"}]},{"seq":105,"ts":1723037983385,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBNkB9wIAGGhRga/ludiY2aYIY251bVkD"}]},{"seq":106,"ts":1723037983388,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBNsB9wIAGGlRga/ludiY2aYIY251bVsD"}]},{"seq":107,"ts":1723037983391,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBN0B9wIAGGpRga/ludiY2aYIY251bV0D"}]},{"seq":108,"ts":1723037983393,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBN8B9wIAGGtRga/ludiY2aYIY251bV8D"}]},{"seq":109,"ts":1723037983396,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBOEB9wIAGGxRga/ludiY2aYIY251bWED"}]},{"seq":110,"ts":1723037983399,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBOMB9wIAGG1Rga/ludiY2aYIY251bWMD"}]},{"seq":111,"ts":1723037983402,"cts":"data:application/cbor,base64;9w==","patches":[{"blob":"data:application/octet-stream;base64,gK3iBOUB9wIAGG5Rga/ludiY2aYIY251bWUD"}]}],"snapshot":{"id":"u2oz5qote6o-lzjwbsjg-8-fierznrkg6f","seq":11,"ts":1723037983079,"blob":"data:application/octet-stream;base64,AAAAFidCZHRleHQmgSVkSGVsbGNudW0xAAoDAh6v5bnYmNmmCAiAreIEHg=="}}} \ No newline at end of file diff --git a/src/json-type-value/__tests__/fix.spec.ts b/src/json-type-value/__tests__/fix.spec.ts deleted file mode 100644 index d595e75172..0000000000 --- a/src/json-type-value/__tests__/fix.spec.ts +++ /dev/null @@ -1,28 +0,0 @@ -import {TypeSystem} from '../../json-type/system'; -import {FunctionType, t} from '../../json-type/type'; -import {Value} from '../Value'; -import {JsonDecoder} from '@jsonjoy.com/json-pack/lib/json'; -import {CborJsonValueCodec} from '@jsonjoy.com/json-pack/lib/codecs/cbor'; -import * as fs from 'fs'; -import {Writer} from '@jsonjoy.com/util/lib/buffers/Writer'; - -const decoder = new JsonDecoder(); -const systemSchema = {"BlockId":{"kind":"str","title":"Block ID","min":6,"max":256},"BlockCur":{"kind":"num","title":"Block Sequence Number","gte":-1,"format":"i32"},"BlockBatchSeq":{"kind":"num","title":"Batch Sequence Number","gte":0,"format":"u32"},"Block":{"kind":"obj","fields":[{"kind":"field","key":"id","type":{"kind":"ref","ref":"BlockId"}},{"kind":"field","key":"ts","type":{"kind":"num","format":"u"}},{"kind":"field","key":"uts","type":{"kind":"num","format":"u"}},{"kind":"field","key":"snapshot","type":{"kind":"ref","ref":"BlockSnapshot"}},{"kind":"field","key":"tip","type":{"kind":"arr","type":{"kind":"ref","ref":"BlockBatch"}}}]},"BlockSnapshotReturn":{"kind":"obj","fields":[{"kind":"field","key":"id","type":{"kind":"ref","ref":"BlockId"},"title":"Block ID","description":"The ID of the block."},{"kind":"field","key":"seq","type":{"kind":"ref","ref":"BlockCur"},"title":"Snapshot Cursor","description":"The cursor of the snapshot, representing the position in the history."},{"kind":"field","key":"ts","type":{"kind":"num","format":"u"},"title":"Snapshot Creation Time","description":"The time when the snapshot was created, in milliseconds since the Unix epoch."}],"title":"Block Snapshot Return","description":"Partial snapshot returned on creation, doesn't include the blob."},"BlockSnapshot":{"kind":"obj","fields":[{"kind":"field","key":"id","type":{"kind":"ref","ref":"BlockId"},"title":"Block ID","description":"The ID of the block."},{"kind":"field","key":"seq","type":{"kind":"ref","ref":"BlockCur"},"title":"Snapshot Cursor","description":"The cursor of the snapshot, representing the position in the history."},{"kind":"field","key":"ts","type":{"kind":"num","format":"u"},"title":"Snapshot Creation Time","description":"The time when the snapshot was created, in milliseconds since the Unix epoch."},{"kind":"field","key":"blob","type":{"kind":"bin","type":{"kind":"any"}},"title":"Snapshot Blob","description":"A serialized JSON CRDT model."}],"title":"Block Snapshot","description":"A snapshot of the block's state at a certain point in time."},"NewBlockSnapshotResponse":{"kind":"obj","fields":[{"kind":"field","key":"id","type":{"kind":"ref","ref":"BlockId"},"title":"Block ID","description":"The ID of the block."},{"kind":"field","key":"seq","type":{"kind":"ref","ref":"BlockCur"},"title":"Snapshot Cursor","description":"The cursor of the snapshot, representing the position in the history."},{"kind":"field","key":"ts","type":{"kind":"num","format":"u"},"title":"Snapshot Creation Time","description":"The time when the snapshot was created, in milliseconds since the Unix epoch."}]},"BlockPatch":{"kind":"obj","fields":[{"kind":"field","key":"blob","type":{"kind":"bin","type":{"kind":"any"}},"title":"Patch Blob","description":"The binary data of the patch. The format of the data is defined by the patch type."},{"kind":"field","key":"ts","type":{"kind":"num","format":"u"},"title":"Patch Creation Time","description":"The time when the patch was created, in milliseconds since the Unix epoch.\n\nThis time is set by the server when the patch received and stored on the server. If you want to also store the time when the patch was created by the user, you can include this information in the patch blob itself."}]},"BlockPatchPartial":{"kind":"obj","fields":[{"kind":"field","key":"blob","type":{"kind":"bin","type":{"kind":"any"}},"title":"Patch Blob","description":"The binary data of the patch. The format of the data is defined by the patch type."}]},"BlockPatchPartialReturn":{"kind":"obj","fields":[{"kind":"field","key":"ts","type":{"kind":"num","format":"u"},"title":"Patch Creation Time","description":"The time when the patch was created, in milliseconds since the Unix epoch.\n\nThis time is set by the server when the patch received and stored on the server. If you want to also store the time when the patch was created by the user, you can include this information in the patch blob itself."}]},"BlockBatch":{"kind":"obj","fields":[{"kind":"field","key":"patches","type":{"kind":"arr","type":{"kind":"ref","ref":"BlockPatchPartial"}}},{"kind":"field","key":"cts","type":{"kind":"num","format":"u","title":"Batch Creation Time","description":"The time when the batch was created, in milliseconds since the Unix epoch."},"optional":true},{"kind":"field","key":"seq","type":{"kind":"num","format":"u"},"title":"Batch Sequence Number","description":"The sequence number of the batch, representing the position in the history."},{"kind":"field","key":"ts","type":{"kind":"num","format":"u"},"title":"Batch Creation Time","description":"The time when the batch was created, in milliseconds since the Unix epoch.\n\nThis time is set by the server when the batch was received and stored on the server."}]},"BlockBatchPartial":{"kind":"obj","fields":[{"kind":"field","key":"patches","type":{"kind":"arr","type":{"kind":"ref","ref":"BlockPatchPartial"}}},{"kind":"field","key":"cts","type":{"kind":"num","format":"u","title":"Batch Creation Time","description":"The time when the batch was created, in milliseconds since the Unix epoch."},"optional":true}]},"BlockBatchPartialReturn":{"kind":"obj","fields":[{"kind":"field","key":"seq","type":{"kind":"num","format":"u"},"title":"Batch Sequence Number","description":"The sequence number of the batch, representing the position in the history."},{"kind":"field","key":"ts","type":{"kind":"num","format":"u"},"title":"Batch Creation Time","description":"The time when the batch was created, in milliseconds since the Unix epoch.\n\nThis time is set by the server when the batch was received and stored on the server."}]},"BlockEvent":{"kind":"or","types":[{"kind":"tup","types":[{"kind":"const","value":"new","title":"Event Type"}],"title":"Creation Event"},{"kind":"tup","types":[{"kind":"const","value":"upd","title":"Event Type"},{"kind":"obj","fields":[{"kind":"field","key":"batch","type":{"kind":"ref","ref":"BlockBatch"},"title":"Latest Patches","description":"Patches that have been applied to the block."}],"title":"Event Data"}],"title":"Update Event"},{"kind":"tup","types":[{"kind":"const","value":"del","title":"Event Type"}],"title":"Delete Event"}],"discriminator":["?",["==","del",["$","/0"]],2,["?",["==","upd",["$","/0"]],1,0]],"title":"Block Event","description":"A collection of possible events that can happen to a block."},"PresenceEntry":{"kind":"obj","fields":[{"kind":"field","key":"id","type":{"kind":"str"}},{"kind":"field","key":"lastSeen","type":{"kind":"num"}},{"kind":"field","key":"validUntil","type":{"kind":"num"}},{"kind":"field","key":"data","type":{"kind":"obj","fields":[],"encodeUnknownFields":true}}]}}; -const methodSchema = {"kind":"fn","req":{"kind":"obj","fields":[{"kind":"field","key":"id","type":{"kind":"ref","ref":"BlockId"},"title":"Document ID","description":"The ID of the document to apply the patch to."},{"kind":"field","key":"batch","type":{"kind":"ref","ref":"BlockBatchPartial"},"title":"Batch","description":"The batch of changes to apply to the document."},{"kind":"field","key":"create","type":{"kind":"bool"},"optional":true,"title":"Create, if not Exists","description":"If true, creates a new document if it does not exist."},{"kind":"field","key":"seq","type":{"kind":"ref","ref":"BlockBatchSeq"},"optional":true,"title":"Sequence Number","description":"The last client known sequence number. The server will return history starting from this sequence number."}]},"res":{"kind":"obj","fields":[{"kind":"field","key":"batch","type":{"kind":"ref","ref":"BlockBatchPartialReturn"},"title":"Committed Batch Parts","description":"Parts of committed batch which were generated on the server."},{"kind":"field","key":"pull","type":{"kind":"obj","fields":[{"kind":"field","key":"batches","type":{"kind":"arr","type":{"kind":"ref","ref":"BlockBatch"}},"title":"Batches","description":"The list of batches that happened after the given sequence number."},{"kind":"field","key":"snapshot","type":{"kind":"arr","type":{"kind":"ref","ref":"BlockSnapshot"}},"optional":true,"title":"Snapshot","description":"The snapshot of the block, to which the batches can be applied to get the current state of the block."}]},"optional":true}]},"title":"Edit Block","intro":"Applies patches to an existing block.","description":"Applies patches to an existing document and returns the latest concurrent changes."}; -const data = decoder.decode(fs.readFileSync(__dirname + '/data.json')); - -test('...', () => { - const system = new TypeSystem(); - system.importTypes(systemSchema as any); - const method = system.t.import(methodSchema as any) as FunctionType; - const res = method.res; - const value = new Value(res, data); - const codec = new CborJsonValueCodec(new Writer(16 * 1024) as any); - console.log(value.encode(codec)) - - console.log(system + ''); - console.log(method + ''); - console.log(res + ''); - console.log(data); - console.log(value + ''); -}); From 60aa948c871aca9d98ae9d5ef61cc2e8a647e06c Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 8 Aug 2024 11:38:29 +0200 Subject: [PATCH 5/5] =?UTF-8?q?style:=20=F0=9F=92=84=20run=20Prettier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/json-type-value/Value.ts | 2 +- src/json-type/system/TypeSystem.ts | 7 ++++++- src/json-type/type/TypeBuilder.ts | 8 ++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/json-type-value/Value.ts b/src/json-type-value/Value.ts index a34e7958af..3a66d3e93e 100644 --- a/src/json-type-value/Value.ts +++ b/src/json-type-value/Value.ts @@ -6,7 +6,7 @@ export class Value { public type: T, public data: ResolveType, ) {} - + public encode(codec: JsonValueCodec): void { const value = this.data; const type = this.type; diff --git a/src/json-type/system/TypeSystem.ts b/src/json-type/system/TypeSystem.ts index faf59317d1..8e26786a02 100644 --- a/src/json-type/system/TypeSystem.ts +++ b/src/json-type/system/TypeSystem.ts @@ -60,7 +60,12 @@ export class TypeSystem implements Printable { public importTypes( types: A, - ): {readonly [K in keyof A]: TypeAlias} { + ): { + readonly [K in keyof A]: TypeAlias< + K extends string ? K : never, + /** @todo Replace `any` by inferred type here. */ any + >; + } { const result = {} as any; for (const id in types) result[id] = this.alias(id, this.t.import(types[id])); return result; diff --git a/src/json-type/type/TypeBuilder.ts b/src/json-type/type/TypeBuilder.ts index 1e37a4d524..74885ae4e7 100644 --- a/src/json-type/type/TypeBuilder.ts +++ b/src/json-type/type/TypeBuilder.ts @@ -198,9 +198,13 @@ export class TypeBuilder { case 'ref': return this.Ref(node.ref).options(node); case 'fn': - return this.Function(this.import(node.req as schema.Schema), this.import(node.res as schema.Schema)).options(node); + return this.Function(this.import(node.req as schema.Schema), this.import(node.res as schema.Schema)).options( + node, + ); case 'fn$': - return this.Function$(this.import(node.req as schema.Schema), this.import(node.res as schema.Schema)).options(node); + return this.Function$(this.import(node.req as schema.Schema), this.import(node.res as schema.Schema)).options( + node, + ); } throw new Error(`UNKNOWN_NODE [${node.kind}]`); }