diff --git a/.editorconfig b/.editorconfig index aafdc4298..28ef180e8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,10 +12,10 @@ insert_final_newline = true indent_style = space indent_size = 2 -[*.ts] +[*.{ts}] quote_type = single -[*.rs] +[*.{rs}] indent_style = space indent_size = 4 @@ -23,6 +23,6 @@ indent_size = 4 indent_style = space indent_size = 4 -[*.xml] +[*.{xml}] # VS Code XML extension removes the final newline insert_final_newline = false diff --git a/crates/bitwarden-napi/src-ts/bitwarden_client/index.ts b/crates/bitwarden-napi/src-ts/bitwarden_client/index.ts index 2e0fa63cc..3a3765a12 100644 --- a/crates/bitwarden-napi/src-ts/bitwarden_client/index.ts +++ b/crates/bitwarden-napi/src-ts/bitwarden_client/index.ts @@ -1,5 +1,5 @@ -import * as rust from '../../binding'; -import { LogLevel } from '../../binding'; +import * as rust from "../../binding"; +import { LogLevel } from "../../binding"; import { Convert, ClientSettings, @@ -11,7 +11,7 @@ import { SecretsDeleteResponse, SecretsResponse, SecretsSyncResponse, -} from './schemas'; +} from "./schemas"; function handleResponse(response: { success: boolean; @@ -19,11 +19,11 @@ function handleResponse(response: { data?: T | null; }): T { if (!response.success) { - throw new Error(response.errorMessage || ''); + throw new Error(response.errorMessage || ""); } if (response.data === null) { - throw new Error(response.errorMessage || 'SDK response data is null'); + throw new Error(response.errorMessage || "SDK response data is null"); } return response.data as T; diff --git a/crates/bitwarden-napi/src-ts/index.ts b/crates/bitwarden-napi/src-ts/index.ts index f0bcb892b..36b0649ed 100644 --- a/crates/bitwarden-napi/src-ts/index.ts +++ b/crates/bitwarden-napi/src-ts/index.ts @@ -1,3 +1,3 @@ -export * from './bitwarden_client/index'; -export * from './bitwarden_client/schemas'; -export { LogLevel } from '../binding'; +export * from "./bitwarden_client/index"; +export * from "./bitwarden_client/schemas"; +export { LogLevel } from "../binding"; diff --git a/support/docs/docs.ts b/support/docs/docs.ts index ca8385dde..067ff0827 100644 --- a/support/docs/docs.ts +++ b/support/docs/docs.ts @@ -2,36 +2,36 @@ // // Do note that this script follows no best practices and will not handle anything many edge cases. -import fs from 'fs'; -import path from 'path'; -import Handlebars from 'handlebars'; +import fs from "fs"; +import path from "path"; +import Handlebars from "handlebars"; -import { Input, InputType } from './rustdoc'; +import { Input, InputType } from "./rustdoc"; -const doc = JSON.parse(fs.readFileSync('./target/doc/bitwarden_uniffi.json', 'utf8')); +const doc = JSON.parse(fs.readFileSync("./target/doc/bitwarden_uniffi.json", "utf8")); const command = JSON.parse( - fs.readFileSync('./support/schemas/bitwarden_uniffi/DocRef.json', 'utf8'), + fs.readFileSync("./support/schemas/bitwarden_uniffi/DocRef.json", "utf8"), ); const template = Handlebars.compile( - fs.readFileSync(path.resolve(__dirname, 'template.hbs'), 'utf8'), + fs.readFileSync(path.resolve(__dirname, "template.hbs"), "utf8"), ); // Modify this to include more root elements const rootElements = [ - 'Client', - 'ClientAuth', - 'ClientAttachments', - 'ClientCiphers', - 'ClientCollections', - 'ClientCrypto', - 'ClientExporters', - 'ClientFolders', - 'ClientGenerators', - 'ClientPasswordHistory', - 'ClientPlatform', - 'ClientSends', - 'ClientVault', + "Client", + "ClientAuth", + "ClientAttachments", + "ClientCiphers", + "ClientCollections", + "ClientCrypto", + "ClientExporters", + "ClientFolders", + "ClientGenerators", + "ClientPasswordHistory", + "ClientPlatform", + "ClientSends", + "ClientVault", ]; const localIndexArray = Object.values(doc.index).filter((entry: any) => entry.crate_id == 0); @@ -66,10 +66,10 @@ const out = rootElements.map((rootElement) => { }); function stripDef(str: string) { - return str.replace(/#\/definitions\//g, ''); + return str.replace(/#\/definitions\//g, ""); } -Handlebars.registerHelper('stripDef', (str: string) => { +Handlebars.registerHelper("stripDef", (str: string) => { return stripDef(str); }); @@ -83,7 +83,7 @@ for (let i = 0; i < usedDefinitions.length; i++) { Object.entries(cmd.properties ?? {}).forEach((prop: any) => { prop[1].allOf?.forEach((e: any) => { - usedDefinitions.push(stripDef(e['$ref'] as string)); + usedDefinitions.push(stripDef(e["$ref"] as string)); }); }); } @@ -112,7 +112,7 @@ function map_type(t: InputType) { const args = t.resolved_path?.args; const name = t.resolved_path?.name; - let out = ''; + let out = ""; if (name) { usedDefinitions.push(name); @@ -125,7 +125,7 @@ function map_type(t: InputType) { } if (args != null && args.angle_bracketed.args.length > 0) { - out += '<'; + out += "<"; out += args.angle_bracketed.args.map((t: any) => { if (t.type.generic) { return t.type.generic; @@ -133,7 +133,7 @@ function map_type(t: InputType) { return t.type.resolved_path.name; } }); - out += '>'; + out += ">"; } return out; } diff --git a/support/scripts/schemas.ts b/support/scripts/schemas.ts index accbf788b..3eaad1903 100644 --- a/support/scripts/schemas.ts +++ b/support/scripts/schemas.ts @@ -4,10 +4,10 @@ import { InputData, JSONSchemaInput, FetchingJSONSchemaStore, -} from 'quicktype-core'; +} from "quicktype-core"; -import fs from 'fs'; -import path from 'path'; +import fs from "fs"; +import path from "path"; async function* walk(dir: string): AsyncIterable { for await (const d of await fs.promises.opendir(dir)) { @@ -25,92 +25,92 @@ async function main() { const inputData = new InputData(); inputData.addInput(schemaInput); inputData.addSource( - 'schema', + "schema", { - name: 'SchemaTypes', - uris: ['support/schemas/schema_types/SchemaTypes.json#/definitions/'], + name: "SchemaTypes", + uris: ["support/schemas/schema_types/SchemaTypes.json#/definitions/"], }, () => new JSONSchemaInput(new FetchingJSONSchemaStore()), ); const ts = await quicktype({ inputData, - lang: 'typescript', + lang: "typescript", rendererOptions: {}, }); - writeToFile('./languages/js/sdk-client/src/schemas.ts', ts.lines); - writeToFile('./crates/bitwarden-napi/src-ts/bitwarden_client/schemas.ts', ts.lines); + writeToFile("./languages/js/sdk-client/src/schemas.ts", ts.lines); + writeToFile("./crates/bitwarden-napi/src-ts/bitwarden_client/schemas.ts", ts.lines); const python = await quicktype({ inputData, - lang: 'python', + lang: "python", rendererOptions: { - 'python-version': '3.7', + "python-version": "3.7", }, }); - writeToFile('./languages/python/bitwarden_sdk/schemas.py', python.lines); + writeToFile("./languages/python/bitwarden_sdk/schemas.py", python.lines); const ruby = await quicktype({ inputData, - lang: 'ruby', + lang: "ruby", rendererOptions: { - 'ruby-version': '3.0', + "ruby-version": "3.0", }, }); - writeToFile('./languages/ruby/bitwarden_sdk_secrets/lib/schemas.rb', ruby.lines); + writeToFile("./languages/ruby/bitwarden_sdk_secrets/lib/schemas.rb", ruby.lines); const csharp = await quicktype({ inputData, - lang: 'csharp', + lang: "csharp", rendererOptions: { - namespace: 'Bitwarden.Sdk', - framework: 'SystemTextJson', - 'csharp-version': '6', + namespace: "Bitwarden.Sdk", + framework: "SystemTextJson", + "csharp-version": "6", }, }); - writeToFile('./languages/csharp/Bitwarden.Sdk/schemas.cs', csharp.lines); + writeToFile("./languages/csharp/Bitwarden.Sdk/schemas.cs", csharp.lines); const cpp = await quicktype({ inputData, - lang: 'cpp', + lang: "cpp", rendererOptions: { - namespace: 'Bitwarden::Sdk', - 'include-location': 'global-include', + namespace: "Bitwarden::Sdk", + "include-location": "global-include", }, }); cpp.lines.forEach((line, idx) => { // Replace DOMAIN for URI_DOMAIN, because DOMAIN is an already defined macro - cpp.lines[idx] = line.replace(/DOMAIN/g, 'URI_DOMAIN'); + cpp.lines[idx] = line.replace(/DOMAIN/g, "URI_DOMAIN"); }); - writeToFile('./languages/cpp/include/schemas.hpp', cpp.lines); + writeToFile("./languages/cpp/include/schemas.hpp", cpp.lines); const go = await quicktype({ inputData, - lang: 'go', + lang: "go", rendererOptions: { - package: 'sdk', - 'omit-empty': true, + package: "sdk", + "omit-empty": true, }, }); - writeToFile('./languages/go/schema.go', go.lines); + writeToFile("./languages/go/schema.go", go.lines); const java = await quicktypeMultiFile({ inputData, - lang: 'java', + lang: "java", rendererOptions: { - package: 'com.bitwarden.sdk.schema', - 'java-version': '8', + package: "com.bitwarden.sdk.schema", + "java-version": "8", }, }); - const javaDir = './languages/java/src/main/java/com/bitwarden/sdk/schema/'; + const javaDir = "./languages/java/src/main/java/com/bitwarden/sdk/schema/"; if (!fs.existsSync(javaDir)) { fs.mkdirSync(javaDir); } @@ -120,23 +120,23 @@ async function main() { const php = await quicktype({ inputData, - lang: 'php', + lang: "php", inferUuids: false, inferDateTimes: false, rendererOptions: { - 'acronym-style': 'camel', - 'with-get': false, + "acronym-style": "camel", + "with-get": false, }, }); - const phpDir = './languages/php/src/Schemas/'; + const phpDir = "./languages/php/src/Schemas/"; if (!fs.existsSync(phpDir)) { fs.mkdirSync(phpDir); } - php.lines.splice(1, 0, 'namespace Bitwarden\\Sdk\\Schemas;', 'use stdClass;', 'use Exception;'); + php.lines.splice(1, 0, "namespace Bitwarden\\Sdk\\Schemas;", "use stdClass;", "use Exception;"); - writeToFile('./languages/php/src/Schemas/Schemas.php', php.lines); + writeToFile("./languages/php/src/Schemas/Schemas.php", php.lines); } main(); @@ -144,7 +144,7 @@ main(); function writeToFile(filename: string, lines: string[]) { const output = fs.createWriteStream(filename); lines.forEach((line) => { - output.write(line + '\n'); + output.write(line + "\n"); }); output.close(); }