Initial commit: New MoreminiMore website with fresh design
This commit is contained in:
13
node_modules/@libsql/hrana-client/lib-esm/encoding/json/decode.d.ts
generated
vendored
Normal file
13
node_modules/@libsql/hrana-client/lib-esm/encoding/json/decode.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
export type Value = Obj | Array<Value> | string | number | true | false | null;
|
||||
export type Obj = {
|
||||
[key: string]: Value | undefined;
|
||||
};
|
||||
export type ObjectFun<T> = (obj: Obj) => T;
|
||||
export declare function string(value: Value | undefined): string;
|
||||
export declare function stringOpt(value: Value | undefined): string | undefined;
|
||||
export declare function number(value: Value | undefined): number;
|
||||
export declare function boolean(value: Value | undefined): boolean;
|
||||
export declare function array(value: Value | undefined): Array<Value>;
|
||||
export declare function object(value: Value | undefined): Obj;
|
||||
export declare function arrayObjectsMap<T>(value: Value | undefined, fun: ObjectFun<T>): Array<T>;
|
||||
export declare function readJsonObject<T>(value: unknown, fun: ObjectFun<T>): T;
|
||||
59
node_modules/@libsql/hrana-client/lib-esm/encoding/json/decode.js
generated
vendored
Normal file
59
node_modules/@libsql/hrana-client/lib-esm/encoding/json/decode.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
import { ProtoError } from "../../errors.js";
|
||||
export function string(value) {
|
||||
if (typeof value === "string") {
|
||||
return value;
|
||||
}
|
||||
throw typeError(value, "string");
|
||||
}
|
||||
export function stringOpt(value) {
|
||||
if (value === null || value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
else if (typeof value === "string") {
|
||||
return value;
|
||||
}
|
||||
throw typeError(value, "string or null");
|
||||
}
|
||||
export function number(value) {
|
||||
if (typeof value === "number") {
|
||||
return value;
|
||||
}
|
||||
throw typeError(value, "number");
|
||||
}
|
||||
export function boolean(value) {
|
||||
if (typeof value === "boolean") {
|
||||
return value;
|
||||
}
|
||||
throw typeError(value, "boolean");
|
||||
}
|
||||
export function array(value) {
|
||||
if (Array.isArray(value)) {
|
||||
return value;
|
||||
}
|
||||
throw typeError(value, "array");
|
||||
}
|
||||
export function object(value) {
|
||||
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
||||
return value;
|
||||
}
|
||||
throw typeError(value, "object");
|
||||
}
|
||||
export function arrayObjectsMap(value, fun) {
|
||||
return array(value).map((elemValue) => fun(object(elemValue)));
|
||||
}
|
||||
function typeError(value, expected) {
|
||||
if (value === undefined) {
|
||||
return new ProtoError(`Expected ${expected}, but the property was missing`);
|
||||
}
|
||||
let received = typeof value;
|
||||
if (value === null) {
|
||||
received = "null";
|
||||
}
|
||||
else if (Array.isArray(value)) {
|
||||
received = "array";
|
||||
}
|
||||
return new ProtoError(`Expected ${expected}, received ${received}`);
|
||||
}
|
||||
export function readJsonObject(value, fun) {
|
||||
return fun(object(value));
|
||||
}
|
||||
14
node_modules/@libsql/hrana-client/lib-esm/encoding/json/encode.d.ts
generated
vendored
Normal file
14
node_modules/@libsql/hrana-client/lib-esm/encoding/json/encode.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
export type ObjectFun<T> = (w: ObjectWriter, value: T) => void;
|
||||
export declare class ObjectWriter {
|
||||
#private;
|
||||
constructor(output: Array<string>);
|
||||
begin(): void;
|
||||
end(): void;
|
||||
string(name: string, value: string): void;
|
||||
stringRaw(name: string, value: string): void;
|
||||
number(name: string, value: number): void;
|
||||
boolean(name: string, value: boolean): void;
|
||||
object<T>(name: string, value: T, valueFun: ObjectFun<T>): void;
|
||||
arrayObjects<T>(name: string, values: Array<T>, valueFun: ObjectFun<T>): void;
|
||||
}
|
||||
export declare function writeJsonObject<T>(value: T, fun: ObjectFun<T>): string;
|
||||
72
node_modules/@libsql/hrana-client/lib-esm/encoding/json/encode.js
generated
vendored
Normal file
72
node_modules/@libsql/hrana-client/lib-esm/encoding/json/encode.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
export class ObjectWriter {
|
||||
#output;
|
||||
#isFirst;
|
||||
constructor(output) {
|
||||
this.#output = output;
|
||||
this.#isFirst = false;
|
||||
}
|
||||
begin() {
|
||||
this.#output.push('{');
|
||||
this.#isFirst = true;
|
||||
}
|
||||
end() {
|
||||
this.#output.push('}');
|
||||
this.#isFirst = false;
|
||||
}
|
||||
#key(name) {
|
||||
if (this.#isFirst) {
|
||||
this.#output.push('"');
|
||||
this.#isFirst = false;
|
||||
}
|
||||
else {
|
||||
this.#output.push(',"');
|
||||
}
|
||||
this.#output.push(name);
|
||||
this.#output.push('":');
|
||||
}
|
||||
string(name, value) {
|
||||
this.#key(name);
|
||||
this.#output.push(JSON.stringify(value));
|
||||
}
|
||||
stringRaw(name, value) {
|
||||
this.#key(name);
|
||||
this.#output.push('"');
|
||||
this.#output.push(value);
|
||||
this.#output.push('"');
|
||||
}
|
||||
number(name, value) {
|
||||
this.#key(name);
|
||||
this.#output.push("" + value);
|
||||
}
|
||||
boolean(name, value) {
|
||||
this.#key(name);
|
||||
this.#output.push(value ? "true" : "false");
|
||||
}
|
||||
object(name, value, valueFun) {
|
||||
this.#key(name);
|
||||
this.begin();
|
||||
valueFun(this, value);
|
||||
this.end();
|
||||
}
|
||||
arrayObjects(name, values, valueFun) {
|
||||
this.#key(name);
|
||||
this.#output.push('[');
|
||||
for (let i = 0; i < values.length; ++i) {
|
||||
if (i !== 0) {
|
||||
this.#output.push(',');
|
||||
}
|
||||
this.begin();
|
||||
valueFun(this, values[i]);
|
||||
this.end();
|
||||
}
|
||||
this.#output.push(']');
|
||||
}
|
||||
}
|
||||
export function writeJsonObject(value, fun) {
|
||||
const output = [];
|
||||
const writer = new ObjectWriter(output);
|
||||
writer.begin();
|
||||
fun(writer, value);
|
||||
writer.end();
|
||||
return output.join("");
|
||||
}
|
||||
Reference in New Issue
Block a user