@alepha/protobuf 0.10.0 → 0.10.2
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/package.json +5 -6
- package/dist/index.cjs +0 -165
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -44
- package/dist/index.d.cts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alepha/protobuf",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.0.0"
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"src"
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@alepha/core": "0.10.
|
|
16
|
+
"@alepha/core": "0.10.2",
|
|
17
17
|
"protobufjs": "^7.5.4"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@biomejs/biome": "^2.2.4",
|
|
21
|
-
"tsdown": "^0.15.
|
|
22
|
-
"typescript": "^5.9.
|
|
21
|
+
"tsdown": "^0.15.6",
|
|
22
|
+
"typescript": "^5.9.3",
|
|
23
23
|
"vitest": "^3.2.4"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
@@ -42,8 +42,7 @@
|
|
|
42
42
|
"exports": {
|
|
43
43
|
".": {
|
|
44
44
|
"types": "./dist/index.d.ts",
|
|
45
|
-
"import": "./dist/index.js"
|
|
46
|
-
"require": "./dist/index.cjs"
|
|
45
|
+
"import": "./dist/index.js"
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
48
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
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));
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
const __alepha_core = __toESM(require("@alepha/core"));
|
|
25
|
-
const protobufjs = __toESM(require("protobufjs"));
|
|
26
|
-
|
|
27
|
-
//#region src/providers/ProtobufProvider.ts
|
|
28
|
-
var ProtobufProvider = class {
|
|
29
|
-
alepha = (0, __alepha_core.$inject)(__alepha_core.Alepha);
|
|
30
|
-
schemas = /* @__PURE__ */ new Map();
|
|
31
|
-
protobuf = protobufjs.default;
|
|
32
|
-
/**
|
|
33
|
-
* Encode an object to a Uint8Array.
|
|
34
|
-
*/
|
|
35
|
-
encode(schema, data) {
|
|
36
|
-
return this.parse(schema).encode(this.alepha.parse(schema, data)).finish();
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Decode a Uint8Array to an object.
|
|
40
|
-
*/
|
|
41
|
-
decode(schema, data) {
|
|
42
|
-
return this.alepha.parse(schema, this.parse(schema).decode(data));
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Parse a TypeBox schema to a Protobuf Type schema ready for encoding/decoding.
|
|
46
|
-
*/
|
|
47
|
-
parse(schema, typeName = "root.Target") {
|
|
48
|
-
const exists = this.schemas.get(schema);
|
|
49
|
-
if (exists) return exists;
|
|
50
|
-
const pbSchema = typeof schema === "string" ? schema : this.createProtobufSchema(schema);
|
|
51
|
-
const result = this.protobuf.parse(pbSchema);
|
|
52
|
-
const type = result.root.lookupType(typeName);
|
|
53
|
-
this.schemas.set(schema, type);
|
|
54
|
-
return type;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Convert a TypeBox schema to a Protobuf schema as a string.
|
|
58
|
-
*/
|
|
59
|
-
createProtobufSchema(schema, options = {}) {
|
|
60
|
-
const { rootName = "root", mainMessageName = "Target" } = options;
|
|
61
|
-
const context = {
|
|
62
|
-
proto: `package ${rootName};\nsyntax = "proto3";\n\n`,
|
|
63
|
-
fieldIndex: 1
|
|
64
|
-
};
|
|
65
|
-
if (__alepha_core.t.schema.isObject(schema)) {
|
|
66
|
-
const { message, subMessages } = this.parseObjectWithDependencies(schema, mainMessageName);
|
|
67
|
-
context.proto += subMessages.join("");
|
|
68
|
-
context.proto += message;
|
|
69
|
-
}
|
|
70
|
-
return context.proto;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Parse an object schema with dependencies (sub-messages).
|
|
74
|
-
*/
|
|
75
|
-
parseObjectWithDependencies(obj, parentName) {
|
|
76
|
-
if (!__alepha_core.t.schema.isObject(obj)) return {
|
|
77
|
-
message: "",
|
|
78
|
-
subMessages: []
|
|
79
|
-
};
|
|
80
|
-
const fields = [];
|
|
81
|
-
const subMessages = [];
|
|
82
|
-
let fieldIndex = 1;
|
|
83
|
-
for (const [key, value] of Object.entries(obj.properties)) {
|
|
84
|
-
if (__alepha_core.t.schema.isArray(value)) {
|
|
85
|
-
if (__alepha_core.t.schema.isObject(value.items)) {
|
|
86
|
-
const subMessageName = "title" in value.items && typeof value.items.title === "string" ? value.items.title : `${parentName}_${key}`;
|
|
87
|
-
const { message: subMessage, subMessages: nestedSubMessages } = this.parseObjectWithDependencies(value.items, subMessageName);
|
|
88
|
-
subMessages.push(...nestedSubMessages);
|
|
89
|
-
subMessages.push(subMessage);
|
|
90
|
-
fields.push(` repeated ${subMessageName} ${key} = ${fieldIndex++};`);
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
const itemType = this.convertType(value.items);
|
|
94
|
-
fields.push(` repeated ${itemType} ${key} = ${fieldIndex++};`);
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
if (__alepha_core.t.schema.isObject(value)) {
|
|
98
|
-
const subMessageName = "title" in value && typeof value.title === "string" ? value.title : `${parentName}_${key}`;
|
|
99
|
-
const { message: subMessage, subMessages: nestedSubMessages } = this.parseObjectWithDependencies(value, subMessageName);
|
|
100
|
-
subMessages.push(...nestedSubMessages);
|
|
101
|
-
subMessages.push(subMessage);
|
|
102
|
-
fields.push(` ${subMessageName} ${key} = ${fieldIndex++};`);
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
if (__alepha_core.t.schema.isUnion(value)) {
|
|
106
|
-
const nonNullType = value.anyOf.find((type) => !__alepha_core.t.schema.isNull(type));
|
|
107
|
-
if (nonNullType) {
|
|
108
|
-
if (__alepha_core.t.schema.isObject(nonNullType)) {
|
|
109
|
-
const subMessageName = "title" in nonNullType && typeof nonNullType.title === "string" ? nonNullType.title : `${parentName}_${key}`;
|
|
110
|
-
const { message: subMessage, subMessages: nestedSubMessages } = this.parseObjectWithDependencies(nonNullType, subMessageName);
|
|
111
|
-
subMessages.push(...nestedSubMessages);
|
|
112
|
-
subMessages.push(subMessage);
|
|
113
|
-
fields.push(` ${subMessageName} ${key} = ${fieldIndex++};`);
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
const fieldType$1 = this.convertType(nonNullType);
|
|
117
|
-
fields.push(` ${fieldType$1} ${key} = ${fieldIndex++};`);
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (__alepha_core.t.schema.isRecord(value)) {
|
|
122
|
-
let valueSchema;
|
|
123
|
-
if ("additionalProperties" in value && value.additionalProperties && typeof value.additionalProperties === "object") valueSchema = value.additionalProperties;
|
|
124
|
-
else if (value.patternProperties && typeof value.patternProperties === "object") {
|
|
125
|
-
const patterns = Object.values(value.patternProperties);
|
|
126
|
-
if (patterns.length > 0 && typeof patterns[0] === "object") valueSchema = patterns[0];
|
|
127
|
-
}
|
|
128
|
-
if (valueSchema) {
|
|
129
|
-
const valueType = this.convertType(valueSchema);
|
|
130
|
-
fields.push(` map<string, ${valueType}> ${key} = ${fieldIndex++};`);
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
const fieldType = this.convertType(value);
|
|
135
|
-
fields.push(` ${fieldType} ${key} = ${fieldIndex++};`);
|
|
136
|
-
}
|
|
137
|
-
const message = `message ${parentName} {\n${fields.join("\n")}\n}\n`;
|
|
138
|
-
return {
|
|
139
|
-
message,
|
|
140
|
-
subMessages
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Convert a primitive TypeBox schema type to a Protobuf spec type.
|
|
145
|
-
*/
|
|
146
|
-
convertType(schema) {
|
|
147
|
-
if (__alepha_core.t.schema.isBoolean(schema)) return "bool";
|
|
148
|
-
if (__alepha_core.t.schema.isNumber(schema) && schema.format === "int64") return "int64";
|
|
149
|
-
if (__alepha_core.t.schema.isNumber(schema)) return "double";
|
|
150
|
-
if (__alepha_core.t.schema.isInteger(schema)) return "int32";
|
|
151
|
-
if (__alepha_core.t.schema.isBigInt(schema)) return "int64";
|
|
152
|
-
if (__alepha_core.t.schema.isString(schema)) return "string";
|
|
153
|
-
if (__alepha_core.t.schema.isUnion(schema)) {
|
|
154
|
-
const nonNullType = schema.anyOf.find((type) => !__alepha_core.t.schema.isNull(type));
|
|
155
|
-
if (nonNullType) return this.convertType(nonNullType);
|
|
156
|
-
}
|
|
157
|
-
if (__alepha_core.t.schema.isOptional(schema)) return this.convertType(schema);
|
|
158
|
-
if (__alepha_core.t.schema.isUnsafe(schema)) return "string";
|
|
159
|
-
throw new Error(`Unsupported type: ${JSON.stringify(schema)}`);
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
//#endregion
|
|
164
|
-
exports.ProtobufProvider = ProtobufProvider;
|
|
165
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["Alepha","t","fields: string[]","subMessages: string[]","fieldType","valueSchema: TSchema | undefined"],"sources":["../src/providers/ProtobufProvider.ts"],"sourcesContent":["import {\n\t$inject,\n\tAlepha,\n\ttype Static,\n\ttype TObject,\n\ttype TSchema,\n\tt,\n} 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: Map<string | TObject, Type> = new Map();\n\tprotected readonly protobuf: typeof protobufjs = protobufjs;\n\n\t/**\n\t * Encode an object to a Uint8Array.\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\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\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\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 (t.schema.isObject(schema)) {\n\t\t\tconst { message, subMessages } = this.parseObjectWithDependencies(\n\t\t\t\tschema,\n\t\t\t\tmainMessageName,\n\t\t\t);\n\t\t\t// Add all sub-messages first\n\t\t\tcontext.proto += subMessages.join(\"\");\n\t\t\t// Then add the main message\n\t\t\tcontext.proto += message;\n\t\t}\n\n\t\treturn context.proto;\n\t}\n\n\t/**\n\t * Parse an object schema with dependencies (sub-messages).\n\t */\n\tprotected parseObjectWithDependencies(\n\t\tobj: TSchema,\n\t\tparentName: string,\n\t): { message: string; subMessages: string[] } {\n\t\tif (!t.schema.isObject(obj)) {\n\t\t\treturn { message: \"\", subMessages: [] };\n\t\t}\n\n\t\tconst fields: string[] = [];\n\t\tconst subMessages: string[] = [];\n\t\tlet fieldIndex = 1;\n\n\t\tfor (const [key, value] of Object.entries(obj.properties)) {\n\t\t\t// Handle arrays\n\t\t\tif (t.schema.isArray(value)) {\n\t\t\t\tif (t.schema.isObject(value.items)) {\n\t\t\t\t\tconst subMessageName =\n\t\t\t\t\t\t\"title\" in value.items && typeof value.items.title === \"string\"\n\t\t\t\t\t\t\t? value.items.title\n\t\t\t\t\t\t\t: `${parentName}_${key}`;\n\t\t\t\t\tconst { message: subMessage, subMessages: nestedSubMessages } =\n\t\t\t\t\t\tthis.parseObjectWithDependencies(value.items, subMessageName);\n\t\t\t\t\tsubMessages.push(...nestedSubMessages);\n\t\t\t\t\tsubMessages.push(subMessage);\n\t\t\t\t\tfields.push(` repeated ${subMessageName} ${key} = ${fieldIndex++};`);\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} = ${fieldIndex++};`);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Handle nested objects\n\t\t\tif (t.schema.isObject(value)) {\n\t\t\t\tconst subMessageName =\n\t\t\t\t\t\"title\" in value && typeof value.title === \"string\"\n\t\t\t\t\t\t? value.title\n\t\t\t\t\t\t: `${parentName}_${key}`;\n\t\t\t\tconst { message: subMessage, subMessages: nestedSubMessages } =\n\t\t\t\t\tthis.parseObjectWithDependencies(value, subMessageName);\n\t\t\t\tsubMessages.push(...nestedSubMessages);\n\t\t\t\tsubMessages.push(subMessage);\n\t\t\t\tfields.push(` ${subMessageName} ${key} = ${fieldIndex++};`);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Handle union types (nullable fields)\n\t\t\tif (t.schema.isUnion(value)) {\n\t\t\t\tconst nonNullType = value.anyOf.find(\n\t\t\t\t\t(type: TSchema) => !t.schema.isNull(type),\n\t\t\t\t);\n\t\t\t\tif (nonNullType) {\n\t\t\t\t\tif (t.schema.isObject(nonNullType)) {\n\t\t\t\t\t\tconst subMessageName =\n\t\t\t\t\t\t\t\"title\" in nonNullType && typeof nonNullType.title === \"string\"\n\t\t\t\t\t\t\t\t? nonNullType.title\n\t\t\t\t\t\t\t\t: `${parentName}_${key}`;\n\t\t\t\t\t\tconst { message: subMessage, subMessages: nestedSubMessages } =\n\t\t\t\t\t\t\tthis.parseObjectWithDependencies(nonNullType, subMessageName);\n\t\t\t\t\t\tsubMessages.push(...nestedSubMessages);\n\t\t\t\t\t\tsubMessages.push(subMessage);\n\t\t\t\t\t\tfields.push(` ${subMessageName} ${key} = ${fieldIndex++};`);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst fieldType = this.convertType(nonNullType);\n\t\t\t\t\tfields.push(` ${fieldType} ${key} = ${fieldIndex++};`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Handle records (maps)\n\t\t\tif (t.schema.isRecord(value)) {\n\t\t\t\t// TypeBox records use additionalProperties or patternProperties for the value type\n\t\t\t\tlet valueSchema: TSchema | undefined;\n\t\t\t\tif (\n\t\t\t\t\t\"additionalProperties\" in value &&\n\t\t\t\t\tvalue.additionalProperties &&\n\t\t\t\t\ttypeof value.additionalProperties === \"object\"\n\t\t\t\t) {\n\t\t\t\t\tvalueSchema = value.additionalProperties;\n\t\t\t\t} else if (\n\t\t\t\t\tvalue.patternProperties &&\n\t\t\t\t\ttypeof value.patternProperties === \"object\"\n\t\t\t\t) {\n\t\t\t\t\t// Get the first pattern property (usually \"^(.*)$\" or similar)\n\t\t\t\t\tconst patterns = Object.values(value.patternProperties);\n\t\t\t\t\tif (patterns.length > 0 && typeof patterns[0] === \"object\") {\n\t\t\t\t\t\tvalueSchema = patterns[0] as TSchema;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (valueSchema) {\n\t\t\t\t\tconst valueType = this.convertType(valueSchema);\n\t\t\t\t\tfields.push(` map<string, ${valueType}> ${key} = ${fieldIndex++};`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Handle regular fields\n\t\t\tconst fieldType = this.convertType(value);\n\t\t\tfields.push(` ${fieldType} ${key} = ${fieldIndex++};`);\n\t\t}\n\n\t\tconst message = `message ${parentName} {\\n${fields.join(\"\\n\")}\\n}\\n`;\n\t\treturn { message, subMessages };\n\t}\n\n\t/**\n\t * Convert a primitive TypeBox schema type to a Protobuf spec type.\n\t */\n\tprotected convertType(schema: TSchema): string {\n\t\tif (t.schema.isBoolean(schema)) return \"bool\";\n\t\tif (t.schema.isNumber(schema) && schema.format === \"int64\") return \"int64\";\n\t\tif (t.schema.isNumber(schema)) return \"double\";\n\t\tif (t.schema.isInteger(schema)) return \"int32\";\n\t\tif (t.schema.isBigInt(schema)) return \"int64\";\n\t\tif (t.schema.isString(schema)) return \"string\";\n\n\t\t// Handle union types (nullable)\n\t\tif (t.schema.isUnion(schema)) {\n\t\t\t// Find the non-null type in the union\n\t\t\tconst nonNullType = schema.anyOf.find(\n\t\t\t\t(type: TSchema) => !t.schema.isNull(type),\n\t\t\t);\n\t\t\tif (nonNullType) {\n\t\t\t\treturn this.convertType(nonNullType);\n\t\t\t}\n\t\t}\n\n\t\t// Handle optional types\n\t\tif (t.schema.isOptional(schema)) {\n\t\t\treturn this.convertType(schema);\n\t\t}\n\n\t\t// Handle unsafe types (like enums)\n\t\tif (t.schema.isUnsafe(schema)) {\n\t\t\t// if it's an enum or other unsafe types, default to string\n\t\t\treturn \"string\";\n\t\t}\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,IAAa,mBAAb,MAA8B;CAC7B,AAAmB,oCAAiBA;CACpC,AAAmB,0BAAuC,IAAI;CAC9D,AAAmB,WAA8B;;;;CAKjD,AAAO,OAAO,QAAiB,MAAuB;AACrD,SAAO,KAAK,MAAM,QAAQ,OAAO,KAAK,OAAO,MAAM,QAAQ,OAAO;CAClE;;;;CAKD,AAAO,OAA0B,QAAW,MAA6B;AACxE,SAAO,KAAK,OAAO,MAAM,QAAQ,KAAK,MAAM,QAAQ,OAAO;CAC3D;;;;CAKD,AAAO,MACN,QACA,WAAW,eACJ;EACP,MAAM,SAAS,KAAK,QAAQ,IAAI;AAChC,MAAI,OAAQ,QAAO;EAEnB,MAAM,WACL,OAAO,WAAW,WAAW,SAAS,KAAK,qBAAqB;EACjE,MAAM,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UAAO,KAAK,KAAK,UAAU,GAAG,IAAI,KAAK,aAAa;EACpD;EAED,MAAM,UAAU,WAAW,WAAW,MAAM,OAAO,KAAK,MAAM;AAC9D,SAAO;GAAE;GAAS;GAAa;CAC/B;;;;CAKD,AAAU,YAAY,QAAyB;AAC9C,MAAIJ,gBAAE,OAAO,UAAU,QAAS,QAAO;AACvC,MAAIA,gBAAE,OAAO,SAAS,WAAW,OAAO,WAAW,QAAS,QAAO;AACnE,MAAIA,gBAAE,OAAO,SAAS,QAAS,QAAO;AACtC,MAAIA,gBAAE,OAAO,UAAU,QAAS,QAAO;AACvC,MAAIA,gBAAE,OAAO,SAAS,QAAS,QAAO;AACtC,MAAIA,gBAAE,OAAO,SAAS,QAAS,QAAO;AAGtC,MAAIA,gBAAE,OAAO,QAAQ,SAAS;GAE7B,MAAM,cAAc,OAAO,MAAM,MAC/B,SAAkB,CAACA,gBAAE,OAAO,OAAO;AAErC,OAAI,YACH,QAAO,KAAK,YAAY;EAEzB;AAGD,MAAIA,gBAAE,OAAO,WAAW,QACvB,QAAO,KAAK,YAAY;AAIzB,MAAIA,gBAAE,OAAO,SAAS,QAErB,QAAO;AAGR,QAAM,IAAI,MAAM,qBAAqB,KAAK,UAAU;CACpD;AACD"}
|
package/dist/index.d.cts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Alepha, Static, TObject, TSchema } from "@alepha/core";
|
|
2
|
-
import protobufjs, { Type } from "protobufjs";
|
|
3
|
-
|
|
4
|
-
//#region src/providers/ProtobufProvider.d.ts
|
|
5
|
-
declare class ProtobufProvider {
|
|
6
|
-
protected readonly alepha: Alepha;
|
|
7
|
-
protected readonly schemas: Map<string | TObject, Type>;
|
|
8
|
-
protected readonly protobuf: typeof protobufjs;
|
|
9
|
-
/**
|
|
10
|
-
* Encode an object to a Uint8Array.
|
|
11
|
-
*/
|
|
12
|
-
encode(schema: TObject, data: any): Uint8Array;
|
|
13
|
-
/**
|
|
14
|
-
* Decode a Uint8Array to an object.
|
|
15
|
-
*/
|
|
16
|
-
decode<T extends TObject>(schema: T, data: Uint8Array): Static<T>;
|
|
17
|
-
/**
|
|
18
|
-
* Parse a TypeBox schema to a Protobuf Type schema ready for encoding/decoding.
|
|
19
|
-
*/
|
|
20
|
-
parse(schema: ProtobufSchema | TObject, typeName?: string): Type;
|
|
21
|
-
/**
|
|
22
|
-
* Convert a TypeBox schema to a Protobuf schema as a string.
|
|
23
|
-
*/
|
|
24
|
-
createProtobufSchema(schema: TSchema, options?: CreateProtobufSchemaOptions): string;
|
|
25
|
-
/**
|
|
26
|
-
* Parse an object schema with dependencies (sub-messages).
|
|
27
|
-
*/
|
|
28
|
-
protected parseObjectWithDependencies(obj: TSchema, parentName: string): {
|
|
29
|
-
message: string;
|
|
30
|
-
subMessages: string[];
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Convert a primitive TypeBox schema type to a Protobuf spec type.
|
|
34
|
-
*/
|
|
35
|
-
protected convertType(schema: TSchema): string;
|
|
36
|
-
}
|
|
37
|
-
type ProtobufSchema = string;
|
|
38
|
-
interface CreateProtobufSchemaOptions {
|
|
39
|
-
rootName?: string;
|
|
40
|
-
mainMessageName?: string;
|
|
41
|
-
}
|
|
42
|
-
//#endregion
|
|
43
|
-
export { CreateProtobufSchemaOptions, ProtobufProvider, ProtobufSchema };
|
|
44
|
-
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/providers/ProtobufProvider.ts"],"sourcesContent":[],"mappings":";;;;cAWa,gBAAA;EAAA,mBAAgB,MAAA,EACH,MADG;EAAA,mBAAA,OAAA,EAEA,GAFA,CAAA,MAAA,GAEa,OAFb,EAEsB,IAFtB,CAAA;qBACH,QAAA,EAAA,OAEW,UAFX;;;;QAEW,CAAA,MAAA,EAKd,OALc,EAAA,IAAA,EAAA,GAAA,CAAA,EAKO,UALP;;;;QAYK,CAAA,UAAjB,OAAiB,CAAA,CAAA,MAAA,EAAA,CAAA,EAAA,IAAA,EAAS,UAAT,CAAA,EAAsB,MAAtB,CAA6B,CAA7B,CAAA;;;;OAQhC,CAAA,MAAA,EAAA,cAAA,GAAiB,OAAjB,EAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAEN,IAFM;;;;sBAmBC,CAAA,MAAA,EADD,OACC,EAAA,OAAA,CAAA,EAAA,2BAAA,CAAA,EAAA,MAAA;;;;EA0KC,UAAA,2BAAc,CAAA,GAAA,EAhJnB,OAgJmB,EAAA,UAAA,EAAA,MAAA,CAAA,EAAA;IAET,OAAA,EAAA,MAAA;;;;;;gCApCc;;KAkCnB,cAAA;UAEK,2BAAA"}
|