@alepha/protobuf 0.7.5 → 0.7.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.
- package/dist/index.cjs +132 -120
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +65 -0
- package/dist/index.d.ts +59 -97
- package/dist/index.js +110 -119
- package/dist/index.js.map +1 -0
- package/package.json +7 -4
package/dist/index.cjs
CHANGED
|
@@ -1,124 +1,136 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
2
22
|
|
|
3
|
-
|
|
4
|
-
|
|
23
|
+
//#endregion
|
|
24
|
+
const __alepha_core = __toESM(require("@alepha/core"));
|
|
25
|
+
const protobufjs = __toESM(require("protobufjs"));
|
|
5
26
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
* @param schema
|
|
113
|
-
* @protected
|
|
114
|
-
*/
|
|
115
|
-
convertType(schema) {
|
|
116
|
-
if (core.TypeGuard.IsInteger(schema)) return "int32";
|
|
117
|
-
if (core.TypeGuard.IsNumber(schema)) return "double";
|
|
118
|
-
if (core.TypeGuard.IsString(schema)) return "string";
|
|
119
|
-
if (core.TypeGuard.IsBoolean(schema)) return "bool";
|
|
120
|
-
throw new Error(`Unsupported type: ${JSON.stringify(schema)}`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
27
|
+
//#region src/providers/ProtobufProvider.ts
|
|
28
|
+
var ProtobufProvider = class {
|
|
29
|
+
alepha = (0, __alepha_core.$inject)(__alepha_core.Alepha);
|
|
30
|
+
schemas = new Map();
|
|
31
|
+
protobuf = protobufjs.default;
|
|
32
|
+
/**
|
|
33
|
+
* Encode an object to a Uint8Array.
|
|
34
|
+
*
|
|
35
|
+
* @param schema - TypeBox schema used to generate the Protobuf schema.
|
|
36
|
+
* @param data - Object to encode. Can be any object or string.
|
|
37
|
+
*/
|
|
38
|
+
encode(schema, data) {
|
|
39
|
+
return this.parse(schema).encode(this.alepha.parse(schema, data)).finish();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Decode a Uint8Array to an object.
|
|
43
|
+
*
|
|
44
|
+
* @param schema
|
|
45
|
+
* @param data
|
|
46
|
+
*/
|
|
47
|
+
decode(schema, data) {
|
|
48
|
+
return this.alepha.parse(schema, this.parse(schema).decode(data));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Parse a TypeBox schema to a Protobuf Type schema ready for encoding/decoding.
|
|
52
|
+
*
|
|
53
|
+
* @param schema
|
|
54
|
+
* @param typeName
|
|
55
|
+
*/
|
|
56
|
+
parse(schema, typeName = "root.Target") {
|
|
57
|
+
const exists = this.schemas.get(schema);
|
|
58
|
+
if (exists) return exists;
|
|
59
|
+
const pbSchema = typeof schema === "string" ? schema : this.createProtobufSchema(schema);
|
|
60
|
+
const result = this.protobuf.parse(pbSchema);
|
|
61
|
+
const type = result.root.lookupType(typeName);
|
|
62
|
+
this.schemas.set(schema, type);
|
|
63
|
+
return type;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Convert a TypeBox schema to a Protobuf schema as a string.
|
|
67
|
+
*
|
|
68
|
+
* @param schema
|
|
69
|
+
* @param options
|
|
70
|
+
*/
|
|
71
|
+
createProtobufSchema(schema, options = {}) {
|
|
72
|
+
const { rootName = "root", mainMessageName = "Target" } = options;
|
|
73
|
+
const context = {
|
|
74
|
+
proto: `package ${rootName};\nsyntax = "proto3";\n\n`,
|
|
75
|
+
fieldIndex: 1
|
|
76
|
+
};
|
|
77
|
+
if (__alepha_core.TypeGuard.IsObject(schema)) {
|
|
78
|
+
const proto = this.parseObject(schema, mainMessageName, context);
|
|
79
|
+
context.proto += proto;
|
|
80
|
+
}
|
|
81
|
+
return context.proto;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Parse an object schema to a Protobuf message.
|
|
85
|
+
*
|
|
86
|
+
* @param obj
|
|
87
|
+
* @param parentName
|
|
88
|
+
* @param context
|
|
89
|
+
* @protected
|
|
90
|
+
*/
|
|
91
|
+
parseObject(obj, parentName, context) {
|
|
92
|
+
if (!__alepha_core.TypeGuard.IsObject(obj)) return "";
|
|
93
|
+
const fields = [];
|
|
94
|
+
for (const [key, value] of Object.entries(obj.properties)) {
|
|
95
|
+
if (__alepha_core.TypeGuard.IsArray(value)) {
|
|
96
|
+
if (__alepha_core.TypeGuard.IsObject(value.items)) {
|
|
97
|
+
const subMessageName = value.items.title ?? `${parentName}_${key}`;
|
|
98
|
+
context.proto += this.parseObject(value.items, subMessageName, {
|
|
99
|
+
...context,
|
|
100
|
+
fieldIndex: 1
|
|
101
|
+
});
|
|
102
|
+
fields.push(` repeated ${subMessageName} ${key} = ${context.fieldIndex++};`);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const itemType = this.convertType(value.items);
|
|
106
|
+
fields.push(` repeated ${itemType} ${key} = ${context.fieldIndex++};`);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (__alepha_core.TypeGuard.IsObject(value)) {
|
|
110
|
+
const subMessageName = `${parentName}_${key}`;
|
|
111
|
+
context.proto += this.parseObject(value, subMessageName, context);
|
|
112
|
+
fields.push(` ${subMessageName} ${key} = ${context.fieldIndex++};`);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
fields.push(` ${this.convertType(value)} ${key} = ${context.fieldIndex++};`);
|
|
116
|
+
}
|
|
117
|
+
return `message ${parentName} {\n${fields.join("\n")}\n}\n`;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Convert a primitive TypeBox schema type to a Protobuf spec type.
|
|
121
|
+
*
|
|
122
|
+
* @param schema
|
|
123
|
+
* @protected
|
|
124
|
+
*/
|
|
125
|
+
convertType(schema) {
|
|
126
|
+
if (__alepha_core.TypeGuard.IsInteger(schema)) return "int32";
|
|
127
|
+
if (__alepha_core.TypeGuard.IsNumber(schema)) return "double";
|
|
128
|
+
if (__alepha_core.TypeGuard.IsString(schema)) return "string";
|
|
129
|
+
if (__alepha_core.TypeGuard.IsBoolean(schema)) return "bool";
|
|
130
|
+
throw new Error(`Unsupported type: ${JSON.stringify(schema)}`);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
123
133
|
|
|
134
|
+
//#endregion
|
|
124
135
|
exports.ProtobufProvider = ProtobufProvider;
|
|
136
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["Alepha","schema: TObject","data: any","schema: T","data: Uint8Array","schema: ProtobufSchema | TObject","schema: TSchema","options: CreateProtobufSchemaOptions","obj: TSchema","parentName: string","context: { proto: string; fieldIndex: number }","fields: string[]"],"sources":["../src/providers/ProtobufProvider.ts"],"sourcesContent":["import type { Static, TObject, TSchema } from \"@alepha/core\";\nimport { $inject, Alepha, TypeGuard } from \"@alepha/core\";\nimport type { Type } from \"protobufjs\";\nimport protobufjs from \"protobufjs\";\n\nexport class ProtobufProvider {\n\tprotected readonly alepha = $inject(Alepha);\n\tprotected readonly schemas = new Map<TObject | string, Type>();\n\tprotected readonly protobuf = protobufjs;\n\n\t/**\n\t * Encode an object to a Uint8Array.\n\t *\n\t * @param schema - TypeBox schema used to generate the Protobuf schema.\n\t * @param data - Object to encode. Can be any object or string.\n\t */\n\tpublic encode(schema: TObject, data: any): Uint8Array {\n\t\treturn this.parse(schema).encode(this.alepha.parse(schema, data)).finish();\n\t}\n\n\t/**\n\t * Decode a Uint8Array to an object.\n\t *\n\t * @param schema\n\t * @param data\n\t */\n\tpublic decode<T extends TObject>(schema: T, data: Uint8Array): Static<T> {\n\t\treturn this.alepha.parse(schema, this.parse(schema).decode(data));\n\t}\n\n\t/**\n\t * Parse a TypeBox schema to a Protobuf Type schema ready for encoding/decoding.\n\t *\n\t * @param schema\n\t * @param typeName\n\t */\n\tpublic parse(\n\t\tschema: ProtobufSchema | TObject,\n\t\ttypeName = \"root.Target\",\n\t): Type {\n\t\tconst exists = this.schemas.get(schema);\n\t\tif (exists) return exists;\n\n\t\tconst pbSchema =\n\t\t\ttypeof schema === \"string\" ? schema : this.createProtobufSchema(schema);\n\t\tconst result = this.protobuf.parse(pbSchema);\n\t\tconst type = result.root.lookupType(typeName);\n\t\tthis.schemas.set(schema, type);\n\t\treturn type;\n\t}\n\n\t/**\n\t * Convert a TypeBox schema to a Protobuf schema as a string.\n\t *\n\t * @param schema\n\t * @param options\n\t */\n\tpublic createProtobufSchema(\n\t\tschema: TSchema,\n\t\toptions: CreateProtobufSchemaOptions = {},\n\t): string {\n\t\tconst { rootName = \"root\", mainMessageName = \"Target\" } = options;\n\t\tconst context = {\n\t\t\tproto: `package ${rootName};\\nsyntax = \"proto3\";\\n\\n`,\n\t\t\tfieldIndex: 1,\n\t\t};\n\n\t\tif (TypeGuard.IsObject(schema)) {\n\t\t\tconst proto = this.parseObject(schema, mainMessageName, context);\n\t\t\tcontext.proto += proto;\n\t\t}\n\n\t\treturn context.proto;\n\t}\n\n\t/**\n\t * Parse an object schema to a Protobuf message.\n\t *\n\t * @param obj\n\t * @param parentName\n\t * @param context\n\t * @protected\n\t */\n\tprotected parseObject(\n\t\tobj: TSchema,\n\t\tparentName: string,\n\t\tcontext: { proto: string; fieldIndex: number },\n\t): string {\n\t\tif (!TypeGuard.IsObject(obj)) {\n\t\t\treturn \"\";\n\t\t}\n\n\t\tconst fields: string[] = [];\n\n\t\tfor (const [key, value] of Object.entries(obj.properties)) {\n\t\t\tif (TypeGuard.IsArray(value)) {\n\t\t\t\tif (TypeGuard.IsObject(value.items)) {\n\t\t\t\t\tconst subMessageName = value.items.title ?? `${parentName}_${key}`;\n\t\t\t\t\tcontext.proto += this.parseObject(value.items, subMessageName, {\n\t\t\t\t\t\t...context,\n\t\t\t\t\t\tfieldIndex: 1,\n\t\t\t\t\t});\n\t\t\t\t\tfields.push(\n\t\t\t\t\t\t` repeated ${subMessageName} ${key} = ${context.fieldIndex++};`,\n\t\t\t\t\t);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst itemType = this.convertType(value.items);\n\t\t\t\tfields.push(` repeated ${itemType} ${key} = ${context.fieldIndex++};`);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (TypeGuard.IsObject(value)) {\n\t\t\t\tconst subMessageName = `${parentName}_${key}`;\n\t\t\t\tcontext.proto += this.parseObject(value, subMessageName, context);\n\t\t\t\tfields.push(` ${subMessageName} ${key} = ${context.fieldIndex++};`);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfields.push(\n\t\t\t\t` ${this.convertType(value)} ${key} = ${context.fieldIndex++};`,\n\t\t\t);\n\t\t}\n\n\t\treturn `message ${parentName} {\\n${fields.join(\"\\n\")}\\n}\\n`;\n\t}\n\n\t/**\n\t * Convert a primitive TypeBox schema type to a Protobuf spec type.\n\t *\n\t * @param schema\n\t * @protected\n\t */\n\tprotected convertType(schema: TSchema): string {\n\t\tif (TypeGuard.IsInteger(schema)) return \"int32\";\n\t\tif (TypeGuard.IsNumber(schema)) return \"double\";\n\t\tif (TypeGuard.IsString(schema)) return \"string\";\n\t\tif (TypeGuard.IsBoolean(schema)) return \"bool\";\n\n\t\tthrow new Error(`Unsupported type: ${JSON.stringify(schema)}`);\n\t}\n}\n\nexport type ProtobufSchema = string;\n\nexport interface CreateProtobufSchemaOptions {\n\trootName?: string;\n\tmainMessageName?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,IAAa,mBAAb,MAA8B;CAC7B,AAAmB,SAAS,2BAAQA,qBAAO;CAC3C,AAAmB,UAAU,IAAI;CACjC,AAAmB,WAAW;;;;;;;CAQ9B,AAAO,OAAOC,QAAiBC,MAAuB;AACrD,SAAO,KAAK,MAAM,OAAO,CAAC,OAAO,KAAK,OAAO,MAAM,QAAQ,KAAK,CAAC,CAAC,QAAQ;CAC1E;;;;;;;CAQD,AAAO,OAA0BC,QAAWC,MAA6B;AACxE,SAAO,KAAK,OAAO,MAAM,QAAQ,KAAK,MAAM,OAAO,CAAC,OAAO,KAAK,CAAC;CACjE;;;;;;;CAQD,AAAO,MACNC,QACA,WAAW,eACJ;EACP,MAAM,SAAS,KAAK,QAAQ,IAAI,OAAO;AACvC,MAAI,OAAQ,QAAO;EAEnB,MAAM,kBACE,WAAW,WAAW,SAAS,KAAK,qBAAqB,OAAO;EACxE,MAAM,SAAS,KAAK,SAAS,MAAM,SAAS;EAC5C,MAAM,OAAO,OAAO,KAAK,WAAW,SAAS;AAC7C,OAAK,QAAQ,IAAI,QAAQ,KAAK;AAC9B,SAAO;CACP;;;;;;;CAQD,AAAO,qBACNC,QACAC,UAAuC,CAAE,GAChC;EACT,MAAM,EAAE,WAAW,QAAQ,kBAAkB,UAAU,GAAG;EAC1D,MAAM,UAAU;GACf,QAAQ,UAAU,SAAS;GAC3B,YAAY;EACZ;AAED,MAAI,wBAAU,SAAS,OAAO,EAAE;GAC/B,MAAM,QAAQ,KAAK,YAAY,QAAQ,iBAAiB,QAAQ;AAChE,WAAQ,SAAS;EACjB;AAED,SAAO,QAAQ;CACf;;;;;;;;;CAUD,AAAU,YACTC,KACAC,YACAC,SACS;AACT,OAAK,wBAAU,SAAS,IAAI,CAC3B,QAAO;EAGR,MAAMC,SAAmB,CAAE;AAE3B,OAAK,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,QAAQ,IAAI,WAAW,EAAE;AAC1D,OAAI,wBAAU,QAAQ,MAAM,EAAE;AAC7B,QAAI,wBAAU,SAAS,MAAM,MAAM,EAAE;KACpC,MAAM,iBAAiB,MAAM,MAAM,UAAU,EAAE,WAAW,GAAG,IAAI;AACjE,aAAQ,SAAS,KAAK,YAAY,MAAM,OAAO,gBAAgB;MAC9D,GAAG;MACH,YAAY;KACZ,EAAC;AACF,YAAO,MACL,aAAa,eAAe,GAAG,IAAI,KAAK,QAAQ,aAAa,GAC9D;AACD;IACA;IAED,MAAM,WAAW,KAAK,YAAY,MAAM,MAAM;AAC9C,WAAO,MAAM,aAAa,SAAS,GAAG,IAAI,KAAK,QAAQ,aAAa,GAAG;AACvE;GACA;AAED,OAAI,wBAAU,SAAS,MAAM,EAAE;IAC9B,MAAM,kBAAkB,EAAE,WAAW,GAAG,IAAI;AAC5C,YAAQ,SAAS,KAAK,YAAY,OAAO,gBAAgB,QAAQ;AACjE,WAAO,MAAM,IAAI,eAAe,GAAG,IAAI,KAAK,QAAQ,aAAa,GAAG;AACpE;GACA;AAED,UAAO,MACL,IAAI,KAAK,YAAY,MAAM,CAAC,GAAG,IAAI,KAAK,QAAQ,aAAa,GAC9D;EACD;AAED,UAAQ,UAAU,WAAW,MAAM,OAAO,KAAK,KAAK,CAAC;CACrD;;;;;;;CAQD,AAAU,YAAYL,QAAyB;AAC9C,MAAI,wBAAU,UAAU,OAAO,CAAE,QAAO;AACxC,MAAI,wBAAU,SAAS,OAAO,CAAE,QAAO;AACvC,MAAI,wBAAU,SAAS,OAAO,CAAE,QAAO;AACvC,MAAI,wBAAU,UAAU,OAAO,CAAE,QAAO;AAExC,QAAM,IAAI,OAAO,oBAAoB,KAAK,UAAU,OAAO,CAAC;CAC5D;AACD"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as _sinclair_typebox0 from "@sinclair/typebox";
|
|
2
|
+
import { Alepha, Static, TObject, TSchema } from "@alepha/core";
|
|
3
|
+
import protobufjs, { Type } from "protobufjs";
|
|
4
|
+
|
|
5
|
+
//#region src/providers/ProtobufProvider.d.ts
|
|
6
|
+
declare class ProtobufProvider {
|
|
7
|
+
protected readonly alepha: Alepha;
|
|
8
|
+
protected readonly schemas: Map<string | TObject<_sinclair_typebox0.TProperties>, Type>;
|
|
9
|
+
protected readonly protobuf: typeof protobufjs;
|
|
10
|
+
/**
|
|
11
|
+
* Encode an object to a Uint8Array.
|
|
12
|
+
*
|
|
13
|
+
* @param schema - TypeBox schema used to generate the Protobuf schema.
|
|
14
|
+
* @param data - Object to encode. Can be any object or string.
|
|
15
|
+
*/
|
|
16
|
+
encode(schema: TObject, data: any): Uint8Array;
|
|
17
|
+
/**
|
|
18
|
+
* Decode a Uint8Array to an object.
|
|
19
|
+
*
|
|
20
|
+
* @param schema
|
|
21
|
+
* @param data
|
|
22
|
+
*/
|
|
23
|
+
decode<T extends TObject>(schema: T, data: Uint8Array): Static<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Parse a TypeBox schema to a Protobuf Type schema ready for encoding/decoding.
|
|
26
|
+
*
|
|
27
|
+
* @param schema
|
|
28
|
+
* @param typeName
|
|
29
|
+
*/
|
|
30
|
+
parse(schema: ProtobufSchema | TObject, typeName?: string): Type;
|
|
31
|
+
/**
|
|
32
|
+
* Convert a TypeBox schema to a Protobuf schema as a string.
|
|
33
|
+
*
|
|
34
|
+
* @param schema
|
|
35
|
+
* @param options
|
|
36
|
+
*/
|
|
37
|
+
createProtobufSchema(schema: TSchema, options?: CreateProtobufSchemaOptions): string;
|
|
38
|
+
/**
|
|
39
|
+
* Parse an object schema to a Protobuf message.
|
|
40
|
+
*
|
|
41
|
+
* @param obj
|
|
42
|
+
* @param parentName
|
|
43
|
+
* @param context
|
|
44
|
+
* @protected
|
|
45
|
+
*/
|
|
46
|
+
protected parseObject(obj: TSchema, parentName: string, context: {
|
|
47
|
+
proto: string;
|
|
48
|
+
fieldIndex: number;
|
|
49
|
+
}): string;
|
|
50
|
+
/**
|
|
51
|
+
* Convert a primitive TypeBox schema type to a Protobuf spec type.
|
|
52
|
+
*
|
|
53
|
+
* @param schema
|
|
54
|
+
* @protected
|
|
55
|
+
*/
|
|
56
|
+
protected convertType(schema: TSchema): string;
|
|
57
|
+
}
|
|
58
|
+
type ProtobufSchema = string;
|
|
59
|
+
interface CreateProtobufSchemaOptions {
|
|
60
|
+
rootName?: string;
|
|
61
|
+
mainMessageName?: string;
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { CreateProtobufSchemaOptions, ProtobufProvider, ProtobufSchema };
|
|
65
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,103 +1,65 @@
|
|
|
1
|
-
import { Alepha,
|
|
2
|
-
import protobufjs, { Type } from
|
|
3
|
-
|
|
4
|
-
/** Symbol key applied to readonly types */
|
|
5
|
-
declare const ReadonlyKind: unique symbol;
|
|
6
|
-
/** Symbol key applied to optional types */
|
|
7
|
-
declare const OptionalKind: unique symbol;
|
|
8
|
-
/** Symbol key applied to types */
|
|
9
|
-
declare const Hint: unique symbol;
|
|
10
|
-
/** Symbol key applied to types */
|
|
11
|
-
declare const Kind: unique symbol;
|
|
12
|
-
|
|
13
|
-
type TPropertyKey = string | number;
|
|
14
|
-
type TProperties = Record<TPropertyKey, TSchema>;
|
|
15
|
-
|
|
16
|
-
interface SchemaOptions {
|
|
17
|
-
$schema?: string;
|
|
18
|
-
/** Id for this schema */
|
|
19
|
-
$id?: string;
|
|
20
|
-
/** Title of this schema */
|
|
21
|
-
title?: string;
|
|
22
|
-
/** Description of this schema */
|
|
23
|
-
description?: string;
|
|
24
|
-
/** Default value for this schema */
|
|
25
|
-
default?: any;
|
|
26
|
-
/** Example values matching this schema */
|
|
27
|
-
examples?: any;
|
|
28
|
-
/** Optional annotation for readOnly */
|
|
29
|
-
readOnly?: boolean;
|
|
30
|
-
/** Optional annotation for writeOnly */
|
|
31
|
-
writeOnly?: boolean;
|
|
32
|
-
[prop: string]: any;
|
|
33
|
-
}
|
|
34
|
-
interface TKind {
|
|
35
|
-
[Kind]: string;
|
|
36
|
-
}
|
|
37
|
-
interface TSchema extends TKind, SchemaOptions {
|
|
38
|
-
[ReadonlyKind]?: string;
|
|
39
|
-
[OptionalKind]?: string;
|
|
40
|
-
[Hint]?: string;
|
|
41
|
-
params: unknown[];
|
|
42
|
-
static: unknown;
|
|
43
|
-
}
|
|
1
|
+
import { Alepha, Static, TObject, TSchema } from "@alepha/core";
|
|
2
|
+
import protobufjs, { Type } from "protobufjs";
|
|
3
|
+
import * as _sinclair_typebox0 from "@sinclair/typebox";
|
|
44
4
|
|
|
5
|
+
//#region src/providers/ProtobufProvider.d.ts
|
|
45
6
|
declare class ProtobufProvider {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
7
|
+
protected readonly alepha: Alepha;
|
|
8
|
+
protected readonly schemas: Map<string | TObject<_sinclair_typebox0.TProperties>, Type>;
|
|
9
|
+
protected readonly protobuf: typeof protobufjs;
|
|
10
|
+
/**
|
|
11
|
+
* Encode an object to a Uint8Array.
|
|
12
|
+
*
|
|
13
|
+
* @param schema - TypeBox schema used to generate the Protobuf schema.
|
|
14
|
+
* @param data - Object to encode. Can be any object or string.
|
|
15
|
+
*/
|
|
16
|
+
encode(schema: TObject, data: any): Uint8Array;
|
|
17
|
+
/**
|
|
18
|
+
* Decode a Uint8Array to an object.
|
|
19
|
+
*
|
|
20
|
+
* @param schema
|
|
21
|
+
* @param data
|
|
22
|
+
*/
|
|
23
|
+
decode<T extends TObject>(schema: T, data: Uint8Array): Static<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Parse a TypeBox schema to a Protobuf Type schema ready for encoding/decoding.
|
|
26
|
+
*
|
|
27
|
+
* @param schema
|
|
28
|
+
* @param typeName
|
|
29
|
+
*/
|
|
30
|
+
parse(schema: ProtobufSchema | TObject, typeName?: string): Type;
|
|
31
|
+
/**
|
|
32
|
+
* Convert a TypeBox schema to a Protobuf schema as a string.
|
|
33
|
+
*
|
|
34
|
+
* @param schema
|
|
35
|
+
* @param options
|
|
36
|
+
*/
|
|
37
|
+
createProtobufSchema(schema: TSchema, options?: CreateProtobufSchemaOptions): string;
|
|
38
|
+
/**
|
|
39
|
+
* Parse an object schema to a Protobuf message.
|
|
40
|
+
*
|
|
41
|
+
* @param obj
|
|
42
|
+
* @param parentName
|
|
43
|
+
* @param context
|
|
44
|
+
* @protected
|
|
45
|
+
*/
|
|
46
|
+
protected parseObject(obj: TSchema, parentName: string, context: {
|
|
47
|
+
proto: string;
|
|
48
|
+
fieldIndex: number;
|
|
49
|
+
}): string;
|
|
50
|
+
/**
|
|
51
|
+
* Convert a primitive TypeBox schema type to a Protobuf spec type.
|
|
52
|
+
*
|
|
53
|
+
* @param schema
|
|
54
|
+
* @protected
|
|
55
|
+
*/
|
|
56
|
+
protected convertType(schema: TSchema): string;
|
|
96
57
|
}
|
|
97
58
|
type ProtobufSchema = string;
|
|
98
59
|
interface CreateProtobufSchemaOptions {
|
|
99
|
-
|
|
100
|
-
|
|
60
|
+
rootName?: string;
|
|
61
|
+
mainMessageName?: string;
|
|
101
62
|
}
|
|
102
|
-
|
|
103
|
-
export {
|
|
63
|
+
//#endregion
|
|
64
|
+
export { CreateProtobufSchemaOptions, ProtobufProvider, ProtobufSchema };
|
|
65
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,122 +1,113 @@
|
|
|
1
|
-
import { $inject, Alepha, TypeGuard } from
|
|
2
|
-
import protobufjs from
|
|
1
|
+
import { $inject, Alepha, TypeGuard } from "@alepha/core";
|
|
2
|
+
import protobufjs from "protobufjs";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
* @param schema
|
|
111
|
-
* @protected
|
|
112
|
-
*/
|
|
113
|
-
convertType(schema) {
|
|
114
|
-
if (TypeGuard.IsInteger(schema)) return "int32";
|
|
115
|
-
if (TypeGuard.IsNumber(schema)) return "double";
|
|
116
|
-
if (TypeGuard.IsString(schema)) return "string";
|
|
117
|
-
if (TypeGuard.IsBoolean(schema)) return "bool";
|
|
118
|
-
throw new Error(`Unsupported type: ${JSON.stringify(schema)}`);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
4
|
+
//#region src/providers/ProtobufProvider.ts
|
|
5
|
+
var ProtobufProvider = class {
|
|
6
|
+
alepha = $inject(Alepha);
|
|
7
|
+
schemas = new Map();
|
|
8
|
+
protobuf = protobufjs;
|
|
9
|
+
/**
|
|
10
|
+
* Encode an object to a Uint8Array.
|
|
11
|
+
*
|
|
12
|
+
* @param schema - TypeBox schema used to generate the Protobuf schema.
|
|
13
|
+
* @param data - Object to encode. Can be any object or string.
|
|
14
|
+
*/
|
|
15
|
+
encode(schema, data) {
|
|
16
|
+
return this.parse(schema).encode(this.alepha.parse(schema, data)).finish();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Decode a Uint8Array to an object.
|
|
20
|
+
*
|
|
21
|
+
* @param schema
|
|
22
|
+
* @param data
|
|
23
|
+
*/
|
|
24
|
+
decode(schema, data) {
|
|
25
|
+
return this.alepha.parse(schema, this.parse(schema).decode(data));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Parse a TypeBox schema to a Protobuf Type schema ready for encoding/decoding.
|
|
29
|
+
*
|
|
30
|
+
* @param schema
|
|
31
|
+
* @param typeName
|
|
32
|
+
*/
|
|
33
|
+
parse(schema, typeName = "root.Target") {
|
|
34
|
+
const exists = this.schemas.get(schema);
|
|
35
|
+
if (exists) return exists;
|
|
36
|
+
const pbSchema = typeof schema === "string" ? schema : this.createProtobufSchema(schema);
|
|
37
|
+
const result = this.protobuf.parse(pbSchema);
|
|
38
|
+
const type = result.root.lookupType(typeName);
|
|
39
|
+
this.schemas.set(schema, type);
|
|
40
|
+
return type;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Convert a TypeBox schema to a Protobuf schema as a string.
|
|
44
|
+
*
|
|
45
|
+
* @param schema
|
|
46
|
+
* @param options
|
|
47
|
+
*/
|
|
48
|
+
createProtobufSchema(schema, options = {}) {
|
|
49
|
+
const { rootName = "root", mainMessageName = "Target" } = options;
|
|
50
|
+
const context = {
|
|
51
|
+
proto: `package ${rootName};\nsyntax = "proto3";\n\n`,
|
|
52
|
+
fieldIndex: 1
|
|
53
|
+
};
|
|
54
|
+
if (TypeGuard.IsObject(schema)) {
|
|
55
|
+
const proto = this.parseObject(schema, mainMessageName, context);
|
|
56
|
+
context.proto += proto;
|
|
57
|
+
}
|
|
58
|
+
return context.proto;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Parse an object schema to a Protobuf message.
|
|
62
|
+
*
|
|
63
|
+
* @param obj
|
|
64
|
+
* @param parentName
|
|
65
|
+
* @param context
|
|
66
|
+
* @protected
|
|
67
|
+
*/
|
|
68
|
+
parseObject(obj, parentName, context) {
|
|
69
|
+
if (!TypeGuard.IsObject(obj)) return "";
|
|
70
|
+
const fields = [];
|
|
71
|
+
for (const [key, value] of Object.entries(obj.properties)) {
|
|
72
|
+
if (TypeGuard.IsArray(value)) {
|
|
73
|
+
if (TypeGuard.IsObject(value.items)) {
|
|
74
|
+
const subMessageName = value.items.title ?? `${parentName}_${key}`;
|
|
75
|
+
context.proto += this.parseObject(value.items, subMessageName, {
|
|
76
|
+
...context,
|
|
77
|
+
fieldIndex: 1
|
|
78
|
+
});
|
|
79
|
+
fields.push(` repeated ${subMessageName} ${key} = ${context.fieldIndex++};`);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const itemType = this.convertType(value.items);
|
|
83
|
+
fields.push(` repeated ${itemType} ${key} = ${context.fieldIndex++};`);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (TypeGuard.IsObject(value)) {
|
|
87
|
+
const subMessageName = `${parentName}_${key}`;
|
|
88
|
+
context.proto += this.parseObject(value, subMessageName, context);
|
|
89
|
+
fields.push(` ${subMessageName} ${key} = ${context.fieldIndex++};`);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
fields.push(` ${this.convertType(value)} ${key} = ${context.fieldIndex++};`);
|
|
93
|
+
}
|
|
94
|
+
return `message ${parentName} {\n${fields.join("\n")}\n}\n`;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Convert a primitive TypeBox schema type to a Protobuf spec type.
|
|
98
|
+
*
|
|
99
|
+
* @param schema
|
|
100
|
+
* @protected
|
|
101
|
+
*/
|
|
102
|
+
convertType(schema) {
|
|
103
|
+
if (TypeGuard.IsInteger(schema)) return "int32";
|
|
104
|
+
if (TypeGuard.IsNumber(schema)) return "double";
|
|
105
|
+
if (TypeGuard.IsString(schema)) return "string";
|
|
106
|
+
if (TypeGuard.IsBoolean(schema)) return "bool";
|
|
107
|
+
throw new Error(`Unsupported type: ${JSON.stringify(schema)}`);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
121
110
|
|
|
111
|
+
//#endregion
|
|
122
112
|
export { ProtobufProvider };
|
|
113
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["schema: TObject","data: any","schema: T","data: Uint8Array","schema: ProtobufSchema | TObject","schema: TSchema","options: CreateProtobufSchemaOptions","obj: TSchema","parentName: string","context: { proto: string; fieldIndex: number }","fields: string[]"],"sources":["../src/providers/ProtobufProvider.ts"],"sourcesContent":["import type { Static, TObject, TSchema } from \"@alepha/core\";\nimport { $inject, Alepha, TypeGuard } from \"@alepha/core\";\nimport type { Type } from \"protobufjs\";\nimport protobufjs from \"protobufjs\";\n\nexport class ProtobufProvider {\n\tprotected readonly alepha = $inject(Alepha);\n\tprotected readonly schemas = new Map<TObject | string, Type>();\n\tprotected readonly protobuf = protobufjs;\n\n\t/**\n\t * Encode an object to a Uint8Array.\n\t *\n\t * @param schema - TypeBox schema used to generate the Protobuf schema.\n\t * @param data - Object to encode. Can be any object or string.\n\t */\n\tpublic encode(schema: TObject, data: any): Uint8Array {\n\t\treturn this.parse(schema).encode(this.alepha.parse(schema, data)).finish();\n\t}\n\n\t/**\n\t * Decode a Uint8Array to an object.\n\t *\n\t * @param schema\n\t * @param data\n\t */\n\tpublic decode<T extends TObject>(schema: T, data: Uint8Array): Static<T> {\n\t\treturn this.alepha.parse(schema, this.parse(schema).decode(data));\n\t}\n\n\t/**\n\t * Parse a TypeBox schema to a Protobuf Type schema ready for encoding/decoding.\n\t *\n\t * @param schema\n\t * @param typeName\n\t */\n\tpublic parse(\n\t\tschema: ProtobufSchema | TObject,\n\t\ttypeName = \"root.Target\",\n\t): Type {\n\t\tconst exists = this.schemas.get(schema);\n\t\tif (exists) return exists;\n\n\t\tconst pbSchema =\n\t\t\ttypeof schema === \"string\" ? schema : this.createProtobufSchema(schema);\n\t\tconst result = this.protobuf.parse(pbSchema);\n\t\tconst type = result.root.lookupType(typeName);\n\t\tthis.schemas.set(schema, type);\n\t\treturn type;\n\t}\n\n\t/**\n\t * Convert a TypeBox schema to a Protobuf schema as a string.\n\t *\n\t * @param schema\n\t * @param options\n\t */\n\tpublic createProtobufSchema(\n\t\tschema: TSchema,\n\t\toptions: CreateProtobufSchemaOptions = {},\n\t): string {\n\t\tconst { rootName = \"root\", mainMessageName = \"Target\" } = options;\n\t\tconst context = {\n\t\t\tproto: `package ${rootName};\\nsyntax = \"proto3\";\\n\\n`,\n\t\t\tfieldIndex: 1,\n\t\t};\n\n\t\tif (TypeGuard.IsObject(schema)) {\n\t\t\tconst proto = this.parseObject(schema, mainMessageName, context);\n\t\t\tcontext.proto += proto;\n\t\t}\n\n\t\treturn context.proto;\n\t}\n\n\t/**\n\t * Parse an object schema to a Protobuf message.\n\t *\n\t * @param obj\n\t * @param parentName\n\t * @param context\n\t * @protected\n\t */\n\tprotected parseObject(\n\t\tobj: TSchema,\n\t\tparentName: string,\n\t\tcontext: { proto: string; fieldIndex: number },\n\t): string {\n\t\tif (!TypeGuard.IsObject(obj)) {\n\t\t\treturn \"\";\n\t\t}\n\n\t\tconst fields: string[] = [];\n\n\t\tfor (const [key, value] of Object.entries(obj.properties)) {\n\t\t\tif (TypeGuard.IsArray(value)) {\n\t\t\t\tif (TypeGuard.IsObject(value.items)) {\n\t\t\t\t\tconst subMessageName = value.items.title ?? `${parentName}_${key}`;\n\t\t\t\t\tcontext.proto += this.parseObject(value.items, subMessageName, {\n\t\t\t\t\t\t...context,\n\t\t\t\t\t\tfieldIndex: 1,\n\t\t\t\t\t});\n\t\t\t\t\tfields.push(\n\t\t\t\t\t\t` repeated ${subMessageName} ${key} = ${context.fieldIndex++};`,\n\t\t\t\t\t);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst itemType = this.convertType(value.items);\n\t\t\t\tfields.push(` repeated ${itemType} ${key} = ${context.fieldIndex++};`);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (TypeGuard.IsObject(value)) {\n\t\t\t\tconst subMessageName = `${parentName}_${key}`;\n\t\t\t\tcontext.proto += this.parseObject(value, subMessageName, context);\n\t\t\t\tfields.push(` ${subMessageName} ${key} = ${context.fieldIndex++};`);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfields.push(\n\t\t\t\t` ${this.convertType(value)} ${key} = ${context.fieldIndex++};`,\n\t\t\t);\n\t\t}\n\n\t\treturn `message ${parentName} {\\n${fields.join(\"\\n\")}\\n}\\n`;\n\t}\n\n\t/**\n\t * Convert a primitive TypeBox schema type to a Protobuf spec type.\n\t *\n\t * @param schema\n\t * @protected\n\t */\n\tprotected convertType(schema: TSchema): string {\n\t\tif (TypeGuard.IsInteger(schema)) return \"int32\";\n\t\tif (TypeGuard.IsNumber(schema)) return \"double\";\n\t\tif (TypeGuard.IsString(schema)) return \"string\";\n\t\tif (TypeGuard.IsBoolean(schema)) return \"bool\";\n\n\t\tthrow new Error(`Unsupported type: ${JSON.stringify(schema)}`);\n\t}\n}\n\nexport type ProtobufSchema = string;\n\nexport interface CreateProtobufSchemaOptions {\n\trootName?: string;\n\tmainMessageName?: string;\n}\n"],"mappings":";;;;AAKA,IAAa,mBAAb,MAA8B;CAC7B,AAAmB,SAAS,QAAQ,OAAO;CAC3C,AAAmB,UAAU,IAAI;CACjC,AAAmB,WAAW;;;;;;;CAQ9B,AAAO,OAAOA,QAAiBC,MAAuB;AACrD,SAAO,KAAK,MAAM,OAAO,CAAC,OAAO,KAAK,OAAO,MAAM,QAAQ,KAAK,CAAC,CAAC,QAAQ;CAC1E;;;;;;;CAQD,AAAO,OAA0BC,QAAWC,MAA6B;AACxE,SAAO,KAAK,OAAO,MAAM,QAAQ,KAAK,MAAM,OAAO,CAAC,OAAO,KAAK,CAAC;CACjE;;;;;;;CAQD,AAAO,MACNC,QACA,WAAW,eACJ;EACP,MAAM,SAAS,KAAK,QAAQ,IAAI,OAAO;AACvC,MAAI,OAAQ,QAAO;EAEnB,MAAM,kBACE,WAAW,WAAW,SAAS,KAAK,qBAAqB,OAAO;EACxE,MAAM,SAAS,KAAK,SAAS,MAAM,SAAS;EAC5C,MAAM,OAAO,OAAO,KAAK,WAAW,SAAS;AAC7C,OAAK,QAAQ,IAAI,QAAQ,KAAK;AAC9B,SAAO;CACP;;;;;;;CAQD,AAAO,qBACNC,QACAC,UAAuC,CAAE,GAChC;EACT,MAAM,EAAE,WAAW,QAAQ,kBAAkB,UAAU,GAAG;EAC1D,MAAM,UAAU;GACf,QAAQ,UAAU,SAAS;GAC3B,YAAY;EACZ;AAED,MAAI,UAAU,SAAS,OAAO,EAAE;GAC/B,MAAM,QAAQ,KAAK,YAAY,QAAQ,iBAAiB,QAAQ;AAChE,WAAQ,SAAS;EACjB;AAED,SAAO,QAAQ;CACf;;;;;;;;;CAUD,AAAU,YACTC,KACAC,YACAC,SACS;AACT,OAAK,UAAU,SAAS,IAAI,CAC3B,QAAO;EAGR,MAAMC,SAAmB,CAAE;AAE3B,OAAK,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,QAAQ,IAAI,WAAW,EAAE;AAC1D,OAAI,UAAU,QAAQ,MAAM,EAAE;AAC7B,QAAI,UAAU,SAAS,MAAM,MAAM,EAAE;KACpC,MAAM,iBAAiB,MAAM,MAAM,UAAU,EAAE,WAAW,GAAG,IAAI;AACjE,aAAQ,SAAS,KAAK,YAAY,MAAM,OAAO,gBAAgB;MAC9D,GAAG;MACH,YAAY;KACZ,EAAC;AACF,YAAO,MACL,aAAa,eAAe,GAAG,IAAI,KAAK,QAAQ,aAAa,GAC9D;AACD;IACA;IAED,MAAM,WAAW,KAAK,YAAY,MAAM,MAAM;AAC9C,WAAO,MAAM,aAAa,SAAS,GAAG,IAAI,KAAK,QAAQ,aAAa,GAAG;AACvE;GACA;AAED,OAAI,UAAU,SAAS,MAAM,EAAE;IAC9B,MAAM,kBAAkB,EAAE,WAAW,GAAG,IAAI;AAC5C,YAAQ,SAAS,KAAK,YAAY,OAAO,gBAAgB,QAAQ;AACjE,WAAO,MAAM,IAAI,eAAe,GAAG,IAAI,KAAK,QAAQ,aAAa,GAAG;AACpE;GACA;AAED,UAAO,MACL,IAAI,KAAK,YAAY,MAAM,CAAC,GAAG,IAAI,KAAK,QAAQ,aAAa,GAC9D;EACD;AAED,UAAQ,UAAU,WAAW,MAAM,OAAO,KAAK,KAAK,CAAC;CACrD;;;;;;;CAQD,AAAU,YAAYL,QAAyB;AAC9C,MAAI,UAAU,UAAU,OAAO,CAAE,QAAO;AACxC,MAAI,UAAU,SAAS,OAAO,CAAE,QAAO;AACvC,MAAI,UAAU,SAAS,OAAO,CAAE,QAAO;AACvC,MAAI,UAAU,UAAU,OAAO,CAAE,QAAO;AAExC,QAAM,IAAI,OAAO,oBAAoB,KAAK,UAAU,OAAO,CAAC;CAC5D;AACD"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alepha/protobuf",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.6",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=22.0.0"
|
|
7
|
+
},
|
|
5
8
|
"license": "MIT",
|
|
6
9
|
"main": "./dist/index.js",
|
|
7
10
|
"types": "./dist/index.d.ts",
|
|
@@ -10,16 +13,16 @@
|
|
|
10
13
|
"src"
|
|
11
14
|
],
|
|
12
15
|
"dependencies": {
|
|
13
|
-
"@alepha/core": "0.7.
|
|
16
|
+
"@alepha/core": "0.7.6",
|
|
14
17
|
"protobufjs": "^7.5.3"
|
|
15
18
|
},
|
|
16
19
|
"devDependencies": {
|
|
17
|
-
"
|
|
20
|
+
"tsdown": "^0.12.9",
|
|
18
21
|
"vitest": "^3.2.4"
|
|
19
22
|
},
|
|
20
23
|
"scripts": {
|
|
21
24
|
"test": "vitest run",
|
|
22
|
-
"build": "
|
|
25
|
+
"build": "tsdown -c ../../tsdown.config.ts"
|
|
23
26
|
},
|
|
24
27
|
"homepage": "https://github.com/feunard/alepha",
|
|
25
28
|
"repository": {
|