@alepha/protobuf 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1 +1,35 @@
1
1
  # @alepha/protobuf
2
+
3
+ Alepha Protobuf is a simple protobuf adapter for Alepha.
4
+ It uses TypeBox Schema to define the protobuf schema and serialize/deserialize the data.
5
+
6
+ ## Installation
7
+
8
+ ```bash
9
+ npm install @alepha/protobuf
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```ts
15
+ import { Alepha, t } from "@alepha/core";
16
+ import { ProtobufProvider } from "@alepha/protobuf";
17
+
18
+ const protobuf = Alepha.create().get(ProtobufProvider);
19
+
20
+ const userSchema = t.object({
21
+ username: t.string(),
22
+ createdAt: t.datetime(),
23
+ age: t.int(),
24
+ isActive: t.boolean()
25
+ });
26
+
27
+ const buffer = protobuf.encode(userSchema, {
28
+ username: "John Doe",
29
+ createdAt: new Date().toISOString(),
30
+ age: 30,
31
+ isActive: true
32
+ });
33
+
34
+ const user = protobuf.decode(userSchema, buffer);
35
+ ```
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@alepha/protobuf",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
- "main": "./dist/index.cjs",
7
- "module": "./dist/index.mjs",
8
- "types": "./dist/index.d.cts",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
9
8
  "dependencies": {
10
- "@alepha/core": "0.5.1",
9
+ "@alepha/core": "0.6.0",
11
10
  "protobufjs": "^7.4.0"
12
11
  },
13
12
  "devDependencies": {
@@ -18,13 +17,10 @@
18
17
  "build": "pkgroll --clean-dist"
19
18
  },
20
19
  "exports": {
21
- "require": {
22
- "types": "./dist/index.d.cts",
23
- "default": "./dist/index.cjs"
24
- },
25
- "import": {
26
- "types": "./dist/index.d.mts",
27
- "default": "./dist/index.mjs"
20
+ ".": {
21
+ "import": "./dist/index.js",
22
+ "require": "./dist/index.cjs",
23
+ "types": "./dist/index.d.ts"
28
24
  }
29
25
  }
30
26
  }
package/dist/index.d.mts DELETED
@@ -1,103 +0,0 @@
1
- import { Alepha, TObject, Static, TSchema as TSchema$1 } from '@alepha/core';
2
- import protobufjs, { Type } from 'protobufjs';
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
- }
44
-
45
- declare class ProtobufProvider {
46
- protected readonly alepha: Alepha;
47
- protected readonly schemas: Map<string | TObject<TProperties>, Type>;
48
- protected readonly protobuf: typeof protobufjs;
49
- /**
50
- * Encode an object to a Uint8Array.
51
- *
52
- * @param schema - TypeBox schema used to generate the Protobuf schema.
53
- * @param data - Object to encode. Can be any object or string.
54
- */
55
- encode(schema: TObject, data: any): Uint8Array;
56
- /**
57
- * Decode a Uint8Array to an object.
58
- *
59
- * @param schema
60
- * @param data
61
- */
62
- decode<T extends TObject>(schema: T, data: Uint8Array): Static<T>;
63
- /**
64
- * Parse a TypeBox schema to a Protobuf Type schema ready for encoding/decoding.
65
- *
66
- * @param schema
67
- * @param typeName
68
- */
69
- parse(schema: ProtobufSchema | TObject, typeName?: string): Type;
70
- /**
71
- * Convert a TypeBox schema to a Protobuf schema as a string.
72
- *
73
- * @param schema
74
- * @param options
75
- */
76
- createProtobufSchema(schema: TSchema$1, options?: CreateProtobufSchemaOptions): string;
77
- /**
78
- * Parse an object schema to a Protobuf message.
79
- *
80
- * @param obj
81
- * @param parentName
82
- * @param context
83
- * @protected
84
- */
85
- protected parseObject(obj: TSchema$1, parentName: string, context: {
86
- proto: string;
87
- fieldIndex: number;
88
- }): string;
89
- /**
90
- * Convert a primitive TypeBox schema type to a Protobuf spec type.
91
- *
92
- * @param schema
93
- * @protected
94
- */
95
- protected convertType(schema: TSchema$1): string;
96
- }
97
- type ProtobufSchema = string;
98
- interface CreateProtobufSchemaOptions {
99
- rootName?: string;
100
- mainMessageName?: string;
101
- }
102
-
103
- export { type CreateProtobufSchemaOptions, ProtobufProvider, type ProtobufSchema };
File without changes
File without changes