@mapeo/schema
Version:
JSON schema and flow types for Mapeo
143 lines (126 loc) • 4.38 kB
text/typescript
/* eslint-disable */
import _m0 from "protobufjs/minimal.js";
import { Any } from "../google/protobuf/any.js";
export const protobufPackage = "mapeo";
export interface Field_1 {
id: Buffer;
/** keys can be an array of strings or a string */
key?: Any;
type: string;
}
function createBaseField_1(): Field_1 {
return { id: Buffer.alloc(0), key: undefined, type: "" };
}
export const Field_1 = {
encode(message: Field_1, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.id.length !== 0) {
writer.uint32(10).bytes(message.id);
}
if (message.key !== undefined) {
Any.encode(message.key, writer.uint32(18).fork()).ldelim();
}
if (message.type !== "") {
writer.uint32(26).string(message.type);
}
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): Field_1 {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseField_1();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.id = reader.bytes() as Buffer;
break;
case 2:
message.key = Any.decode(reader, reader.uint32());
break;
case 3:
message.type = reader.string();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object: any): Field_1 {
return {
id: isSet(object.id) ? Buffer.from(bytesFromBase64(object.id)) : Buffer.alloc(0),
key: isSet(object.key) ? Any.fromJSON(object.key) : undefined,
type: isSet(object.type) ? String(object.type) : "",
};
},
toJSON(message: Field_1): unknown {
const obj: any = {};
message.id !== undefined && (obj.id = base64FromBytes(message.id !== undefined ? message.id : Buffer.alloc(0)));
message.key !== undefined && (obj.key = message.key ? Any.toJSON(message.key) : undefined);
message.type !== undefined && (obj.type = message.type);
return obj;
},
create<I extends Exact<DeepPartial<Field_1>, I>>(base?: I): Field_1 {
return Field_1.fromPartial(base ?? {});
},
fromPartial<I extends Exact<DeepPartial<Field_1>, I>>(object: I): Field_1 {
const message = createBaseField_1();
message.id = object.id ?? Buffer.alloc(0);
message.key = (object.key !== undefined && object.key !== null) ? Any.fromPartial(object.key) : undefined;
message.type = object.type ?? "";
return message;
},
};
declare var self: any | undefined;
declare var window: any | undefined;
declare var global: any | undefined;
var tsProtoGlobalThis: any = (() => {
if (typeof globalThis !== "undefined") {
return globalThis;
}
if (typeof self !== "undefined") {
return self;
}
if (typeof window !== "undefined") {
return window;
}
if (typeof global !== "undefined") {
return global;
}
throw "Unable to locate global object";
})();
function bytesFromBase64(b64: string): Uint8Array {
if (tsProtoGlobalThis.Buffer) {
return Uint8Array.from(tsProtoGlobalThis.Buffer.from(b64, "base64"));
} else {
const bin = tsProtoGlobalThis.atob(b64);
const arr = new Uint8Array(bin.length);
for (let i = 0; i < bin.length; ++i) {
arr[i] = bin.charCodeAt(i);
}
return arr;
}
}
function base64FromBytes(arr: Uint8Array): string {
if (tsProtoGlobalThis.Buffer) {
return tsProtoGlobalThis.Buffer.from(arr).toString("base64");
} else {
const bin: string[] = [];
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
});
return tsProtoGlobalThis.btoa(bin.join(""));
}
}
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
export type DeepPartial<T> = T extends Builtin ? T
: T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;
type KeysOfUnion<T> = T extends T ? keyof T : never;
export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
function isSet(value: any): boolean {
return value !== null && value !== undefined;
}