From 0fde5dcb426ce2c923e44ae298fec5c3d1c0874f Mon Sep 17 00:00:00 2001 From: Brandon Kalinowski Date: Fri, 14 Jun 2024 01:50:23 -0400 Subject: [PATCH] refactor for linted items --- deno.json | 3 +- deno.lock | 254 +++++++++++++++++++++- hash-object.ts | 23 +- http-signature/verify.ts | 27 +-- karabiner.ts | 384 +++++++++++++++++---------------- kite/docker/server.ts | 179 +++++++-------- kite/examples/cannot-assign.ts | 27 +++ magic-string.js | 2 + merge.ts | 119 +++++----- quokka-shim.ts | 24 --- resolve-promise-object.ts | 80 +++---- to_aml.js | 35 ++- 12 files changed, 716 insertions(+), 441 deletions(-) create mode 100644 kite/examples/cannot-assign.ts delete mode 100644 quokka-shim.ts diff --git a/deno.json b/deno.json index 39e82be..8ab577d 100644 --- a/deno.json +++ b/deno.json @@ -7,6 +7,7 @@ "exclude": ["kubernetes/gen/"] }, "lint": { - "rules": {"exclude": ["no-explicit-any"]} + "rules": {"exclude": ["no-explicit-any", "no-namespace", "require-await"]}, + "exclude": ["wip", "npm"] } } diff --git a/deno.lock b/deno.lock index d0a1f4a..960a9ea 100644 --- a/deno.lock +++ b/deno.lock @@ -1,14 +1,153 @@ { "version": "3", + "packages": { + "specifiers": { + "npm:http-signature@^1.4.0": "npm:http-signature@1.4.0" + }, + "npm": { + "asn1@0.2.6": { + "integrity": "sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==", + "dependencies": { + "safer-buffer": "safer-buffer@2.1.2" + } + }, + "assert-plus@1.0.0": { + "integrity": "sha512-NfJ4UzBCcQGLDlQq7nHxH+tv3kyZ0hHQqF5BO6J7tNJeP5do1llPr8dZ8zHonfhAu0PHAdMkSo+8o0wxg9lZWw==", + "dependencies": {} + }, + "bcrypt-pbkdf@1.0.2": { + "integrity": "sha512-qeFIXtP4MSoi6NLqO12WfqARWWuCKi2Rn/9hJLEmtB5yTNr9DqFWkJRCf2qShWzPeAMRnOgCrq0sg/KLv5ES9w==", + "dependencies": { + "tweetnacl": "tweetnacl@0.14.5" + } + }, + "core-util-is@1.0.2": { + "integrity": "sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ==", + "dependencies": {} + }, + "dashdash@1.14.1": { + "integrity": "sha512-jRFi8UDGo6j+odZiEpjazZaWqEal3w/basFjQHQEwVtZJGDpxbH1MeYluwCS8Xq5wmLJooDlMgvVarmWfGM44g==", + "dependencies": { + "assert-plus": "assert-plus@1.0.0" + } + }, + "ecc-jsbn@0.1.2": { + "integrity": "sha512-eh9O+hwRHNbG4BLTjEl3nw044CkGm5X6LoaCf7LPp7UU8Qrt47JYNi6nPX8xjW97TKGKm1ouctg0QSpZe9qrnw==", + "dependencies": { + "jsbn": "jsbn@0.1.1", + "safer-buffer": "safer-buffer@2.1.2" + } + }, + "extsprintf@1.3.0": { + "integrity": "sha512-11Ndz7Nv+mvAC1j0ktTa7fAb0vLyGGX+rMHNBYQviQDGU0Hw7lhctJANqbPhu9nV9/izT/IntTgZ7Im/9LJs9g==", + "dependencies": {} + }, + "getpass@0.1.7": { + "integrity": "sha512-0fzj9JxOLfJ+XGLhR8ze3unN0KZCgZwiSSDz168VERjK8Wl8kVSdcu2kspd4s4wtAa1y/qrVRiAA0WclVsu0ng==", + "dependencies": { + "assert-plus": "assert-plus@1.0.0" + } + }, + "http-signature@1.4.0": { + "integrity": "sha512-G5akfn7eKbpDN+8nPS/cb57YeA1jLTVxjpCj7tmm3QKPdyDy7T+qSC40e9ptydSWvkwjSXw1VbkpyEm39ukeAg==", + "dependencies": { + "assert-plus": "assert-plus@1.0.0", + "jsprim": "jsprim@2.0.2", + "sshpk": "sshpk@1.18.0" + } + }, + "jsbn@0.1.1": { + "integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg==", + "dependencies": {} + }, + "json-schema@0.4.0": { + "integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==", + "dependencies": {} + }, + "jsprim@2.0.2": { + "integrity": "sha512-gqXddjPqQ6G40VdnI6T6yObEC+pDNvyP95wdQhkWkg7crHH3km5qP1FsOXEkzEQwnz6gz5qGTn1c2Y52wP3OyQ==", + "dependencies": { + "assert-plus": "assert-plus@1.0.0", + "extsprintf": "extsprintf@1.3.0", + "json-schema": "json-schema@0.4.0", + "verror": "verror@1.10.0" + } + }, + "safer-buffer@2.1.2": { + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "dependencies": {} + }, + "sshpk@1.18.0": { + "integrity": "sha512-2p2KJZTSqQ/I3+HX42EpYOa2l3f8Erv8MWKsy2I9uf4wA7yFIkXRffYdsx86y6z4vHtV8u7g+pPlr8/4ouAxsQ==", + "dependencies": { + "asn1": "asn1@0.2.6", + "assert-plus": "assert-plus@1.0.0", + "bcrypt-pbkdf": "bcrypt-pbkdf@1.0.2", + "dashdash": "dashdash@1.14.1", + "ecc-jsbn": "ecc-jsbn@0.1.2", + "getpass": "getpass@0.1.7", + "jsbn": "jsbn@0.1.1", + "safer-buffer": "safer-buffer@2.1.2", + "tweetnacl": "tweetnacl@0.14.5" + } + }, + "tweetnacl@0.14.5": { + "integrity": "sha512-KXXFFdAbFXY4geFIwoyNK+f5Z1b7swfXABfL7HXCmoIWMKU3dmS26672A4EeQtDzLKy7SXmfBu51JolvEKwtGA==", + "dependencies": {} + }, + "verror@1.10.0": { + "integrity": "sha512-ZZKSmDAEFOijERBLkmYfJ+vmk3w+7hOLYDNkRCuRuMJGEmqYNCNLyBBFwWKVMhfwaEF3WOd0Zlw86U/WC/+nYw==", + "dependencies": { + "assert-plus": "assert-plus@1.0.0", + "core-util-is": "core-util-is@1.0.2", + "extsprintf": "extsprintf@1.3.0" + } + } + } + }, "redirects": { "https://deno.land/x/base64/base64url.ts": "https://deno.land/x/base64@v0.2.1/base64url.ts" }, "remote": { + "https://deno.land/std@0.160.0/hash/sha256.ts": "aa9479c260f41b72c639f36c3e4bc9319940b5d2e52fe793ebe3dc646d12832f", + "https://deno.land/std@0.224.0/assert/_constants.ts": "a271e8ef5a573f1df8e822a6eb9d09df064ad66a4390f21b3e31f820a38e0975", + "https://deno.land/std@0.224.0/assert/assert.ts": "09d30564c09de846855b7b071e62b5974b001bb72a4b797958fe0660e7849834", + "https://deno.land/std@0.224.0/assert/assert_almost_equals.ts": "9e416114322012c9a21fa68e187637ce2d7df25bcbdbfd957cd639e65d3cf293", + "https://deno.land/std@0.224.0/assert/assert_array_includes.ts": "14c5094471bc8e4a7895fc6aa5a184300d8a1879606574cb1cd715ef36a4a3c7", + "https://deno.land/std@0.224.0/assert/assert_equals.ts": "3bbca947d85b9d374a108687b1a8ba3785a7850436b5a8930d81f34a32cb8c74", "https://deno.land/std@0.224.0/assert/assert_exists.ts": "43420cf7f956748ae6ed1230646567b3593cb7a36c5a5327269279c870c5ddfd", + "https://deno.land/std@0.224.0/assert/assert_false.ts": "3e9be8e33275db00d952e9acb0cd29481a44fa0a4af6d37239ff58d79e8edeff", + "https://deno.land/std@0.224.0/assert/assert_greater.ts": "5e57b201fd51b64ced36c828e3dfd773412c1a6120c1a5a99066c9b261974e46", + "https://deno.land/std@0.224.0/assert/assert_greater_or_equal.ts": "9870030f997a08361b6f63400273c2fb1856f5db86c0c3852aab2a002e425c5b", + "https://deno.land/std@0.224.0/assert/assert_instance_of.ts": "e22343c1fdcacfaea8f37784ad782683ec1cf599ae9b1b618954e9c22f376f2c", + "https://deno.land/std@0.224.0/assert/assert_is_error.ts": "f856b3bc978a7aa6a601f3fec6603491ab6255118afa6baa84b04426dd3cc491", + "https://deno.land/std@0.224.0/assert/assert_less.ts": "60b61e13a1982865a72726a5fa86c24fad7eb27c3c08b13883fb68882b307f68", + "https://deno.land/std@0.224.0/assert/assert_less_or_equal.ts": "d2c84e17faba4afe085e6c9123a63395accf4f9e00150db899c46e67420e0ec3", + "https://deno.land/std@0.224.0/assert/assert_match.ts": "ace1710dd3b2811c391946954234b5da910c5665aed817943d086d4d4871a8b7", + "https://deno.land/std@0.224.0/assert/assert_not_equals.ts": "78d45dd46133d76ce624b2c6c09392f6110f0df9b73f911d20208a68dee2ef29", + "https://deno.land/std@0.224.0/assert/assert_not_instance_of.ts": "3434a669b4d20cdcc5359779301a0588f941ffdc2ad68803c31eabdb4890cf7a", + "https://deno.land/std@0.224.0/assert/assert_not_match.ts": "df30417240aa2d35b1ea44df7e541991348a063d9ee823430e0b58079a72242a", + "https://deno.land/std@0.224.0/assert/assert_not_strict_equals.ts": "37f73880bd672709373d6dc2c5f148691119bed161f3020fff3548a0496f71b8", + "https://deno.land/std@0.224.0/assert/assert_object_match.ts": "411450fd194fdaabc0089ae68f916b545a49d7b7e6d0026e84a54c9e7eed2693", + "https://deno.land/std@0.224.0/assert/assert_rejects.ts": "4bee1d6d565a5b623146a14668da8f9eb1f026a4f338bbf92b37e43e0aa53c31", + "https://deno.land/std@0.224.0/assert/assert_strict_equals.ts": "b4f45f0fd2e54d9029171876bd0b42dd9ed0efd8f853ab92a3f50127acfa54f5", + "https://deno.land/std@0.224.0/assert/assert_string_includes.ts": "496b9ecad84deab72c8718735373feb6cdaa071eb91a98206f6f3cb4285e71b8", + "https://deno.land/std@0.224.0/assert/assert_throws.ts": "c6508b2879d465898dab2798009299867e67c570d7d34c90a2d235e4553906eb", "https://deno.land/std@0.224.0/assert/assertion_error.ts": "ba8752bd27ebc51f723702fac2f54d3e94447598f54264a6653d6413738a8917", + "https://deno.land/std@0.224.0/assert/equal.ts": "bddf07bb5fc718e10bb72d5dc2c36c1ce5a8bdd3b647069b6319e07af181ac47", + "https://deno.land/std@0.224.0/assert/fail.ts": "0eba674ffb47dff083f02ced76d5130460bff1a9a68c6514ebe0cdea4abadb68", + "https://deno.land/std@0.224.0/assert/mod.ts": "48b8cb8a619ea0b7958ad7ee9376500fe902284bb36f0e32c598c3dc34cbd6f3", + "https://deno.land/std@0.224.0/assert/unimplemented.ts": "8c55a5793e9147b4f1ef68cd66496b7d5ba7a9e7ca30c6da070c1a58da723d73", + "https://deno.land/std@0.224.0/assert/unreachable.ts": "5ae3dbf63ef988615b93eb08d395dda771c96546565f9e521ed86f6510c29e19", + "https://deno.land/std@0.224.0/async/delay.ts": "f90dd685b97c2f142b8069082993e437b1602b8e2561134827eeb7c12b95c499", "https://deno.land/std@0.224.0/encoding/_util.ts": "beacef316c1255da9bc8e95afb1fa56ed69baef919c88dc06ae6cb7a6103d376", "https://deno.land/std@0.224.0/encoding/base32.ts": "02744a37df78abeaa0b3251e850bfee7c232f26fedc5a62b6c68cb2b99733984", + "https://deno.land/std@0.224.0/encoding/base64.ts": "dd59695391584c8ffc5a296ba82bcdba6dd8a84d41a6a539fbee8e5075286eaf", "https://deno.land/std@0.224.0/flags/mod.ts": "88553267f34519c8982212185339efdb2d2e62c159ec558f47eb50c8952a6be3", + "https://deno.land/std@0.224.0/fmt/colors.ts": "508563c0659dd7198ba4bbf87e97f654af3c34eb56ba790260f252ad8012e1c5", + "https://deno.land/std@0.224.0/internal/diff.ts": "6234a4b493ebe65dc67a18a0eb97ef683626a1166a1906232ce186ae9f65f4e6", + "https://deno.land/std@0.224.0/internal/format.ts": "0a98ee226fd3d43450245b1844b47003419d34d210fa989900861c79820d21c2", + "https://deno.land/std@0.224.0/internal/mod.ts": "534125398c8e7426183e12dc255bb635d94e06d0f93c60a297723abe69d3b22e", "https://deno.land/std@0.224.0/yaml/_dumper/dumper.ts": "08b595b40841a2e1c75303f5096392323b6baf8e9662430a91e3b36fbe175fe9", "https://deno.land/std@0.224.0/yaml/_dumper/dumper_state.ts": "9e29f700ea876ed230b43f11fa006fcb1a62eedc1e27d32baaeaf3210f19f1e7", "https://deno.land/std@0.224.0/yaml/_error.ts": "f38cdebdb69cde16903d9aa2f3b8a3dd9d13e5f7f3570bf662bfaca69fef669e", @@ -45,6 +184,80 @@ "https://deno.land/std@0.224.0/yaml/schema/mod.ts": "0e1558a4823834f106675e48ddc15338e04f6f18469d1a7d6b3f0e1ab06abcb2", "https://deno.land/std@0.224.0/yaml/stringify.ts": "f0ed4e419cb40c807cf79ae4039d6cdf492be9a947121fff4d4b7cd1d4738bae", "https://deno.land/std@0.224.0/yaml/type.ts": "708dde5f20b01cc1096489b7155b6af79a217d585afb841128e78c3c2391eb5c", + "https://deno.land/std@0.92.0/_util/assert.ts": "2f868145a042a11d5ad0a3c748dcf580add8a0dbc0e876eaa0026303a5488f58", + "https://deno.land/std@0.92.0/_util/os.ts": "e282950a0eaa96760c0cf11e7463e66babd15ec9157d4c9ed49cc0925686f6a7", + "https://deno.land/std@0.92.0/async/deferred.ts": "624bef4b755b71394620508a0c234a93cb8020cbd1b04bfcdad41c174392cef6", + "https://deno.land/std@0.92.0/async/delay.ts": "9de1d8d07d1927767ab7f82434b883f3d8294fb19cad819691a2ad81a728cf3d", + "https://deno.land/std@0.92.0/async/mod.ts": "253b41c658d768613eacfb11caa0a9ca7148442f932018a45576f7f27554c853", + "https://deno.land/std@0.92.0/async/mux_async_iterator.ts": "b9091909db04cdb0af6f7807677372f64c1488de6c4bd86004511b064bf230d6", + "https://deno.land/std@0.92.0/async/pool.ts": "876f9e6815366cd017a3b4fbb9e9ae40310b1b6972f1bd541c94358bc11fb7e5", + "https://deno.land/std@0.92.0/bytes/mod.ts": "1ae1ccfe98c4b979f12b015982c7444f81fcb921bea7aa215bf37d84f46e1e13", + "https://deno.land/std@0.92.0/encoding/_yaml/dumper/dumper.ts": "0263c52af22198d72afad43fcf83007b2b586e4ce1cb6516d93c9d190a1add56", + "https://deno.land/std@0.92.0/encoding/_yaml/dumper/dumper_state.ts": "c891f455f5724ec0ead1b970245e757da56e834bafee56ca5caba94d4ee4ecab", + "https://deno.land/std@0.92.0/encoding/_yaml/error.ts": "37127caf2a57a58ed1f4761d1786f341b8169b81cddd8143ee707c5ae8381ed1", + "https://deno.land/std@0.92.0/encoding/_yaml/loader/loader.ts": "3dec6bf72a2e28dc25fbb3a9d4c3fe2fbce5afb8e609f98775240ceb39df2fa0", + "https://deno.land/std@0.92.0/encoding/_yaml/loader/loader_state.ts": "b419c93cd239241a0b0cd15d6f7e641e8e8259f92786e98180c62a37c1f4f2c8", + "https://deno.land/std@0.92.0/encoding/_yaml/mark.ts": "bea6f1b15a2398541a7b98224cedfdad0b5070a6091d2a64f6f1a7f9552f45d9", + "https://deno.land/std@0.92.0/encoding/_yaml/parse.ts": "760d72477e4a9427a44a05cbfdfd36c49e016e03d4d5d5e85291222472d67c26", + "https://deno.land/std@0.92.0/encoding/_yaml/schema.ts": "f455506cfdb6a9b43b1392afebc8bf47f9e07b87f1d892a2bc7aa4bf27b879c4", + "https://deno.land/std@0.92.0/encoding/_yaml/schema/core.ts": "60bc5880ae4bf8a856b7376b4f573688d018207c7095c4e3b7f6f78fb566fb96", + "https://deno.land/std@0.92.0/encoding/_yaml/schema/default.ts": "aa3191b304e78237511b30eccc0c02fe1e6138de08d63ce79243dff57eefaa3a", + "https://deno.land/std@0.92.0/encoding/_yaml/schema/extended.ts": "838bb2f31fcf5364b8c5d58f8d0e421aaa7b5dcc6ead0e7ed45a70026ea18683", + "https://deno.land/std@0.92.0/encoding/_yaml/schema/failsafe.ts": "99b32bbdf1f1d1a9f89412a3047b240df3910348bada9b6addb3d32e45707421", + "https://deno.land/std@0.92.0/encoding/_yaml/schema/json.ts": "46cb110cf78c5eb1ea1cb3a022d9785c16346758c5fd796445625e3eba5e397c", + "https://deno.land/std@0.92.0/encoding/_yaml/schema/mod.ts": "887883e91e15d85687a810dbd2337c91f6bc24cc89fa8d487e5fbb0851fc9d32", + "https://deno.land/std@0.92.0/encoding/_yaml/state.ts": "b4c16a80245ccbf46e5d7e537686216fb178e6e17465edaad52dcc46ca061bc0", + "https://deno.land/std@0.92.0/encoding/_yaml/stringify.ts": "7ffd3226730f8d29efab367e99ac772a254c59277bb6214fc9eb669a99be6b2b", + "https://deno.land/std@0.92.0/encoding/_yaml/type.ts": "c8035db697dcbad50d3d714aab71f932f024067ce443475882ee14e721237f33", + "https://deno.land/std@0.92.0/encoding/_yaml/type/binary.ts": "770b3b1f32ef6e5d39766c449137270aa6da6b75dbe7b1c5fafcaa0c3035df77", + "https://deno.land/std@0.92.0/encoding/_yaml/type/bool.ts": "9d98f676db1004a096f484d3cffc3d6647edc1b1dcb36a6763d4058aa7c8d7ff", + "https://deno.land/std@0.92.0/encoding/_yaml/type/float.ts": "8523e91d7e0e776cd28a7505883b707342d02f167cf2f70cbad907086f8070d1", + "https://deno.land/std@0.92.0/encoding/_yaml/type/function.ts": "ad3155be2625ca307dbee377b00a4d2544f4bdfc70606cd6d9880d20b222e665", + "https://deno.land/std@0.92.0/encoding/_yaml/type/int.ts": "ddd0b4dceaf4004f0d186832430fe622f14c576e8fc1847d8700c9962bd0b224", + "https://deno.land/std@0.92.0/encoding/_yaml/type/map.ts": "1a6adda80abb559d194c2a6c921d77d1663efc528c3436eac30b6c865999cbf2", + "https://deno.land/std@0.92.0/encoding/_yaml/type/merge.ts": "d72e0676455ab82a08ed67bbaec26911730d355600477b339918cc714a9404d2", + "https://deno.land/std@0.92.0/encoding/_yaml/type/mod.ts": "9e93a15efbe9b2d98ec55d782913d8d263d4bfb2c8df89a59b39ac7a46e421de", + "https://deno.land/std@0.92.0/encoding/_yaml/type/nil.ts": "93a6a43ed4cd82aeedf8866a436d050476ed8bf0c92bf77c5b762f146e634578", + "https://deno.land/std@0.92.0/encoding/_yaml/type/omap.ts": "f9059576c95bce96906d9507245d0cb9539b96ec9653981879c4d2d217567e2e", + "https://deno.land/std@0.92.0/encoding/_yaml/type/pairs.ts": "a50dcd677afaaed51a0629c5bde12b1632a7532e03611ef674e034b4140e0940", + "https://deno.land/std@0.92.0/encoding/_yaml/type/regexp.ts": "e571f0888d7cceaa8056293be0914789bdd0eedd4372f4b532da395c6e5db4fa", + "https://deno.land/std@0.92.0/encoding/_yaml/type/seq.ts": "50f1dbf35c2858c6e91b88964bc94836bea50da90a88b4df7814a1319bce921d", + "https://deno.land/std@0.92.0/encoding/_yaml/type/set.ts": "2c9f20b540bd0f3af6264d79c2edf7ffbfc35a4c158fa479361dc579383e5fdf", + "https://deno.land/std@0.92.0/encoding/_yaml/type/str.ts": "c24c0d7eaba943f2a30f827120be280ccf3fe903ebd31d5beb229965afd582b7", + "https://deno.land/std@0.92.0/encoding/_yaml/type/timestamp.ts": "4e7221a8e2eafc818bd5b41ccf0636656044a9ca4892fa5763f45cb1733701fa", + "https://deno.land/std@0.92.0/encoding/_yaml/type/undefined.ts": "bc774444b3a8d9b36cf8c032492584a629597b54cf34b791ed0280de9332296e", + "https://deno.land/std@0.92.0/encoding/_yaml/utils.ts": "2c01dc0321ca969b208e244fa278f29ba7a5fdda2fba73b0f48dea99a4deb91b", + "https://deno.land/std@0.92.0/encoding/yaml.ts": "4989e7fe0be3813f79214a2c0039b71398e8bb61d5667f0d60236e240754ebd3", + "https://deno.land/std@0.92.0/fs/_util.ts": "f2ce811350236ea8c28450ed822a5f42a0892316515b1cd61321dec13569c56b", + "https://deno.land/std@0.92.0/fs/copy.ts": "acc21e2569c92e715be48f40665a299cb995a4dce04145c3dd624791b885114c", + "https://deno.land/std@0.92.0/fs/empty_dir.ts": "2edd70ff6405e1893e781a82aec8c574dfc748a7bb9d9ce8f0abdf002cdbba3f", + "https://deno.land/std@0.92.0/fs/ensure_dir.ts": "f21262e788a707aaa2dd22064da7cd40e3b2f0f067e9b2aed1b288091170cc05", + "https://deno.land/std@0.92.0/fs/ensure_file.ts": "84c7cff81ecedef3969e3fcd2d0c2aecd9bafea246cd18847deba7a54126134f", + "https://deno.land/std@0.92.0/fs/ensure_link.ts": "e48abe5bf639389ee6f42bb8bdd8b7b2a4c93701cd618b12cdcad83ccea44f2e", + "https://deno.land/std@0.92.0/fs/ensure_symlink.ts": "cbb2c908135808c0545c6304046b6ab5c024b0bb1832e69c819b58d9feee66ef", + "https://deno.land/std@0.92.0/fs/eol.ts": "afaebaaac36f48c423b920c836551997715672b80a0fee9aa7667c181a94f2df", + "https://deno.land/std@0.92.0/fs/exists.ts": "b0d2e31654819cc2a8d37df45d6b14686c0cc1d802e9ff09e902a63e98b85a00", + "https://deno.land/std@0.92.0/fs/expand_glob.ts": "b5a8fcadf40eb7b034a1f807349cbace0ddb28c4e5a6b6aaf2d8ca925ba02f9f", + "https://deno.land/std@0.92.0/fs/mod.ts": "26eee4b52a8c516e37d464094b080ff6822883e7f01ff0ba0a72b8dcd54b9927", + "https://deno.land/std@0.92.0/fs/move.ts": "36697916a5cf2ebc7d298089a9a3ccc6b3af1eaecc173e57a9f5eb10f1f04221", + "https://deno.land/std@0.92.0/fs/walk.ts": "8d37f2164a7397668842a7cb5d53b9e7bcd216462623b1b96abe519f76d7f8b9", + "https://deno.land/std@0.92.0/hash/sha256.ts": "2a06afd9c27942b87ffc8a93b3270065b5fe4ea144fe0939e5d050bfb86d40db", + "https://deno.land/std@0.92.0/http/_io.ts": "bf1331dd3be8aace9120614c1fedc2bb2449edc4779e31b74c0181ea9173f702", + "https://deno.land/std@0.92.0/http/http_status.ts": "ebaa9bebfb8adc3d7b20c49e11037e4eefd79629ad80d81383933f4cdc91b3eb", + "https://deno.land/std@0.92.0/http/server.ts": "d4e17c2aa5a5c65a2d19b9f24483be5f6c2a3e03665996fdf973e53c43091b48", + "https://deno.land/std@0.92.0/io/buffer.ts": "2a92f02c1d8daaebaf13e5678ea5969c89f4fab533f687b9e7e86f49f11c3118", + "https://deno.land/std@0.92.0/io/bufio.ts": "4053ea5d978479be68ae4d73424045a59c6b7a6e8f66727e4bfde516baa07126", + "https://deno.land/std@0.92.0/io/util.ts": "03ca10e063afce551c501505c607ec336a40b9cb72363f5508e2a9ac81096bbf", + "https://deno.land/std@0.92.0/path/_constants.ts": "1247fee4a79b70c89f23499691ef169b41b6ccf01887a0abd131009c5581b853", + "https://deno.land/std@0.92.0/path/_interface.ts": "1fa73b02aaa24867e481a48492b44f2598cd9dfa513c7b34001437007d3642e4", + "https://deno.land/std@0.92.0/path/_util.ts": "2e06a3b9e79beaf62687196bd4b60a4c391d862cfa007a20fc3a39f778ba073b", + "https://deno.land/std@0.92.0/path/common.ts": "eaf03d08b569e8a87e674e4e265e099f237472b6fd135b3cbeae5827035ea14a", + "https://deno.land/std@0.92.0/path/glob.ts": "4a524c1c9da3e79a9fdabdc6e850cd9e41bdf31e442856ffa19c5b123268ca95", + "https://deno.land/std@0.92.0/path/mod.ts": "4465dc494f271b02569edbb4a18d727063b5dbd6ed84283ff906260970a15d12", + "https://deno.land/std@0.92.0/path/posix.ts": "f56c3c99feb47f30a40ce9d252ef6f00296fa7c0fcb6dd81211bdb3b8b99ca3b", + "https://deno.land/std@0.92.0/path/separator.ts": "8fdcf289b1b76fd726a508f57d3370ca029ae6976fcde5044007f062e643ff1c", + "https://deno.land/std@0.92.0/path/win32.ts": "77f7b3604e0de40f3a7c698e8a79e7f601dc187035a1c21cb1e596666ce112f8", + "https://deno.land/std@0.92.0/textproto/mod.ts": "1c89b39a079dd158893ab2e9ff79391c66049433d6ca82da7d64b32280570d51", "https://deno.land/x/base64@v0.2.1/base.ts": "47dc8d68f07dc91524bdd6db36eccbe59cf4d935b5fc09f27357a3944bb3ff7b", "https://deno.land/x/base64@v0.2.1/base64url.ts": "18bbf879b31f1f32cca8adaa2b6885ae325c2cec6a66c5817b684ca12c46ad5e", "https://deno.land/x/case@2.2.0/lowerCase.ts": "d75eb55cadfa589f9f2a973924a8a209054477d9574da669410f4d817ab25b41", @@ -94,7 +307,46 @@ "https://raw.githubusercontent.com/brandonkal/runtypes/e4824aae4a3700080048a5e3833e94a2203d1f12/src/util.ts": "cdbe2cffe512e3ec06e21160d0887413bcd6c0cb9e4d9d607e7c4a021b68eebf", "https://x.kite.run/lib/args.ts": "da02e848d0feebda256fb8261bb98b4b6dcc39fea621053d77aea8819cbb1469", "https://x.kite.run/lib/dedent.ts": "0f9f38b0f3b27592edf92e488abcfcb5c27101161873971b5e2ff21d687bad3b", - "https://x.kite.run/lib/kite.ts": "29c5cc077da9438d79b21f6b8570e29a1294f474e21dbe20e36782824b0e1df3", + "https://x.kite.run/lib/http-signature/verify.ts": "237c4d359dd4a361be529cc742be6a42a057b0f74fb470970a70c290b4636200", + "https://x.kite.run/lib/kite.ts": "7ab0d475f46e38d3114721d4b15db74d80d6054cbdfb6d6ec3555b30ba47916c", + "https://x.kite.run/lib/kite/digitalocean/cdn.ts": "bb1bf3600b5555a34d43af9c934bd5091c2fb51b718f8e8ef6e41bc47e69b0db", + "https://x.kite.run/lib/kite/digitalocean/certificate.ts": "eede8c38a89cd1220fed2ef0e59b1d005dac034977c30286b177c601dd3fec8d", + "https://x.kite.run/lib/kite/digitalocean/certificateType.ts": "a2b09a762cae5ad137c839c39a6f1de25c295d20b2a2841a812eceeeb38736ae", + "https://x.kite.run/lib/kite/digitalocean/databaseCluster.ts": "7c819f78de96ed830bde566fcae5f03e113d5028d8684eb01933fdd44b11ae7e", + "https://x.kite.run/lib/kite/digitalocean/databaseConnectionPool.ts": "40e6da25f9ef3f3fed0bfc67f83efec9b1610dde3c7d39c0713f87e177334ca1", + "https://x.kite.run/lib/kite/digitalocean/databaseDb.ts": "ef27f6442ff1c9e9b75333c0949f965c76fa22bd72687549dd1266be247090fd", + "https://x.kite.run/lib/kite/digitalocean/databaseFirewall.ts": "4611b918101662784997fc5bcb824d73e3da59123403655b2e6c0f63a091cb77", + "https://x.kite.run/lib/kite/digitalocean/databaseReplica.ts": "dd3bd286d85a95498af70d865a70272bba5e6b4f56d91e187bc33f624e61a05d", + "https://x.kite.run/lib/kite/digitalocean/databaseSlug.ts": "d7845f5326b20bb26020b6d441f4895baeaa53e9e42b4539a6a4d18b49a71650", + "https://x.kite.run/lib/kite/digitalocean/databaseUser.ts": "e49c6edc77c712abbb469a7ef1af3a4629db66de70fd8367fe8cce8b51615891", + "https://x.kite.run/lib/kite/digitalocean/dnsRecord.ts": "4785aa2db77eebaad83a9cdd7837751f2c81ed2bf7afa87ee9ad45ad946465b1", + "https://x.kite.run/lib/kite/digitalocean/domain.ts": "6125026159dc5c10c6504ca74f6de96dbb48d801ca2b82c370f6baac6ec53886", + "https://x.kite.run/lib/kite/digitalocean/droplet.ts": "d4a2b42d754e2092371375848ea68bb38674b3b339525f1370bac5bad7e26394", + "https://x.kite.run/lib/kite/digitalocean/dropletSlug.ts": "79473b708527aec0715355956e758bdac5b511586faa0afdb67c103364f2806d", + "https://x.kite.run/lib/kite/digitalocean/dropletSnapshot.ts": "662e6f6716b526e273c70ac970d7460fe12707496a215e3bfe9816aaab462c6b", + "https://x.kite.run/lib/kite/digitalocean/filesystemType.ts": "5ad075330608ba13bc4aa5d1c575e9634862fec9fba3c104d2fe0c943f3854ba", + "https://x.kite.run/lib/kite/digitalocean/firewall.ts": "098bc656f31e25ca1eb5c9078e98e47b76e6d4f456540c4cfed146bdf993f94e", + "https://x.kite.run/lib/kite/digitalocean/floatingIp.ts": "6f2b12e15d4681b19dca802efbf4ec07ff9f56d81d7a598157d12711a82a855c", + "https://x.kite.run/lib/kite/digitalocean/floatingIpAssignment.ts": "b303b01d7da4cb4997282a24f39b43fd6120f81cd2bf85eb22f998cc65de5e9b", + "https://x.kite.run/lib/kite/digitalocean/kubernetesCluster.ts": "42b7c2eafdcfd27e2a66c09a3563324e048c59fc771ff2b3615dc5f35de6349f", + "https://x.kite.run/lib/kite/digitalocean/kubernetesNodePool.ts": "d1286e39e1b97579c8c7ab54a24cb6b364e97aaa6272189c48df37d317382534", + "https://x.kite.run/lib/kite/digitalocean/loadBalancer.ts": "8f5881cb8f94b8e718ff1bcf747faff8702d94f73898c6970be07a0a8bd2f611", + "https://x.kite.run/lib/kite/digitalocean/loadbalancerAlgorithm.ts": "1a40512acc4f8b2387141e7b91872bdea1e517a83c09a3f11f92911c059e0bec", + "https://x.kite.run/lib/kite/digitalocean/mod.ts": "473cea1a179e1fbc048807ce8f39f7ba514f6c879ea9ea888543b4c91e55cb30", + "https://x.kite.run/lib/kite/digitalocean/project.ts": "15c7ea5eaa48c665b6571f8f2ed172b43c4287f84757db8ad27a27b99071835d", + "https://x.kite.run/lib/kite/digitalocean/protocol.ts": "1ed91b85dfb4a837cbc4b58146609272d907c6dcc373eae1f6c7b531929e4193", + "https://x.kite.run/lib/kite/digitalocean/provider.ts": "4a40874485ca173ceff3e3d043a142aeca5c381ed21ec1fb6e8aa9f840ca04da", + "https://x.kite.run/lib/kite/digitalocean/recordType.ts": "80bbad1f1c43a7df0a71ef0d306df5366208a74cfa35026e6d8612bca6ec2b0a", + "https://x.kite.run/lib/kite/digitalocean/region.ts": "028d988f0831e12928773f850cf7ed3a640df7c19b1ba0a4ad29b9e431a8cee3", + "https://x.kite.run/lib/kite/digitalocean/spacesBucket.ts": "53b12592669e41a183ae1c6b5571cca3bbd9870cf2c85e655439803c97895794", + "https://x.kite.run/lib/kite/digitalocean/sshKey.ts": "b14d1054ef9aa3e1fd66d3c8ff0a9aca16e78c8f780b74e2532f724d67a47fbe", + "https://x.kite.run/lib/kite/digitalocean/tag.ts": "d2934bd320b922842e380a601ddc9630680f9277603390a2980f6362f0862de1", + "https://x.kite.run/lib/kite/digitalocean/types/input.ts": "14b8f603662357fedb060803b091a9c49707b928bb5fa1e6f095ada423c6671c", + "https://x.kite.run/lib/kite/digitalocean/types/mod.ts": "e9167f700a63c04995a0f918a988bc3783870c306082ba934274e30574d787f5", + "https://x.kite.run/lib/kite/digitalocean/types/output.ts": "b1f9e4dc872b5ce921cdcce3f98b36c8f998994cbc54a0f78e20745eb67fc12b", + "https://x.kite.run/lib/kite/digitalocean/volume.ts": "68681f0b54b2a31ec92b1228e565f352d876047b8e1395d0377455cb064fd16a", + "https://x.kite.run/lib/kite/digitalocean/volumeAttachment.ts": "07473657b6267bf616ebd7ed24981d2ba217f2ac4d0980d9a97ed7a9979bb717", + "https://x.kite.run/lib/kite/digitalocean/volumeSnapshot.ts": "54402535974a39c2117dfa3da062cca3903a9bb81755c83a071a1bede696c6d1", "https://x.kite.run/lib/kite/extended-string.ts": "f32779dceca93430b407c1c1b69a8a4307c1fd6248c722771758fed0925f7142", "https://x.kite.run/lib/merge.ts": "95ae23c79f0a81ae4c76e422864f6832604ed49210617f6fb71ebc011e3563c7", "https://x.kite.run/lib/runtypes.ts": "7d654a239f26e0951d0079350cfc7ad41088181b27cfe06810e39fb32cb7f3ca", diff --git a/hash-object.ts b/hash-object.ts index 60dcd67..1a249f5 100644 --- a/hash-object.ts +++ b/hash-object.ts @@ -2,35 +2,36 @@ * @file hash-object.ts * @author Brandon Kalinowski * @description Take a JavaScript object and compute a sha256 hash of it for comparison. - * @copyright 2020 Brandon Kalinowski + * @copyright 2020-2024 Brandon Kalinowski * @license MIT */ -import { sha256 } from 'https://deno.land/x/sha256@v1.0.2/mod.ts' +import { sha256 } from "https://deno.land/x/sha256@v1.0.2/mod.ts"; /** A JSON replacer that sorts keys recursively and removes type key when required. */ -export const replacer = (key: any, value: any) => { +export const replacer = (_key: any, value: any) => { if (value instanceof Object && !(value instanceof Array)) { return Object.keys(value) .sort() .reduce((sorted, key) => { - ;(sorted as any)[key] = value[key] - return sorted - }, {}) + (sorted as any)[key] = value[key]; + return sorted; + }, {}); } - return value -} + return value; +}; /** print deterministic JSON string specifically for karabiner */ export function orderedJSONString(obj: any) { - return JSON.stringify(obj, replacer).trimEnd() + return JSON.stringify(obj, replacer).trimEnd(); } /** * Takes a JavaScript object and computes a sha256 hash of the deterministic JSON string. * @param obj */ +// deno-lint-ignore require-await export async function hashObject(obj: any): Promise { - const str = orderedJSONString(obj) - return sha256(str, 'utf8', 'hex') as string + const str = orderedJSONString(obj); + return sha256(str, "utf8", "hex") as string; } diff --git a/http-signature/verify.ts b/http-signature/verify.ts index 99b56d0..4ea3c45 100644 --- a/http-signature/verify.ts +++ b/http-signature/verify.ts @@ -7,7 +7,7 @@ * @license MIT */ -import { HmacSha256 } from "https://deno.land/std@0.92.0/hash/sha256.ts"; +import { HmacSha256 } from "https://deno.land/std@0.160.0/hash/sha256.ts"; import { encodeBase64 } from "https://deno.land/std@0.224.0/encoding/base64.ts"; ///// @@ -81,20 +81,20 @@ export function parseRequest( req: ParseRequest, opts: parseOptions = {}, ): ParsedRequest { - let headers = req.headers; - let requiredHeaders = opts.headers || + const headers = req.headers; + const requiredHeaders = opts.headers || [headers["x-date"] ? "x-date" : "date"]; const authz = headers[opts.authzHeader || ""] || headers.authorization || headers.signature; if (!authz) { - let missing = opts.authzHeader + const missing = opts.authzHeader ? opts.authzHeader : "authorization or signature"; throw new Error(`No ${missing} header present in the request`); } opts.clockSkew = opts.clockSkew || 300; - let parsed: ParsedRequest & { params: Record } = { + const parsed: ParsedRequest & { params: Record } = { scheme: authz === headers["signature"] ? "Signature" : ("" as any), params: {} as parsedParams, signingString: "", @@ -104,7 +104,8 @@ export function parseRequest( let tmpName = ""; let tmpValue = ""; for (let i = 0; i < authz.length; i++) { - var c = authz.charAt(i); + const c = authz.charAt(i); + let code: number; switch (Number(state)) { case State.New: @@ -115,7 +116,7 @@ export function parseRequest( case State.Params: switch (Number(substate)) { case ParamsState.Name: - var code = c.charCodeAt(0); + code = c.charCodeAt(0); // restricted name of A-Z / a-z if ( (code >= 0x41 && code <= 0x5a) || // A-Z @@ -207,7 +208,7 @@ export function parseRequest( // Build the signingString for (let i = 0; i < parsed.params.headers.length; i++) { - var h = parsed.params.headers[i].toLowerCase(); + const h = parsed.params.headers[i].toLowerCase(); parsed.params.headers[i] = h; if (h === "request-line") { @@ -221,7 +222,7 @@ export function parseRequest( } else if (h === "(algorithm)") { parsed.signingString += "(algorithm): " + parsed.params.algorithm; } else if (h === "(opaque)") { - var opaque = parsed.params.opaque; + const opaque = parsed.params.opaque; if (opaque === undefined) { throw new Error( "opaque param was not in the " + opts.authzHeader + @@ -230,7 +231,7 @@ export function parseRequest( } parsed.signingString += "(opaque): " + opaque; } else { - var value = headers[h]; + const value = headers[h]; if (value === undefined) { throw new Error(h + " was not in the request"); } @@ -241,15 +242,15 @@ export function parseRequest( } // Check against the constraints - var date; + let date: Date; if (req.headers.date || req.headers["x-date"]) { if (req.headers["x-date"]) { date = new Date(req.headers["x-date"]); } else { date = new Date(req.headers.date); } - var now = new Date(); - var skew = Math.abs(now.getTime() - date.getTime()); + const now = new Date(); + const skew = Math.abs(now.getTime() - date.getTime()); if (skew > opts.clockSkew * 1000) { throw new Error( diff --git a/karabiner.ts b/karabiner.ts index ced7ac2..8786784 100644 --- a/karabiner.ts +++ b/karabiner.ts @@ -6,23 +6,22 @@ * 2. Call out() */ -import * as keys from './karabiner/keys.ts' -export { keys } +import * as keys from "./karabiner/keys.ts"; +export { keys }; -export const nil = undefined +export const nil = undefined; /** stringify for error logs */ function str(x: any) { - return JSON.stringify(x) + return JSON.stringify(x); } /** Represents all possible conditions or VarShorthand */ -export type ConditionOrShorthand = Condition | VarShorthand +export type ConditionOrShorthand = Condition | VarShorthand; /** * Generates a valid manipulator rule given a DSL definition. Can result in a 30x line reduction. * - * * Example: * ```ts * rule([t(VIMIUM, 1), t(G_TAPPED, 0)], ["caps_lock?", "g"], [t(G_TAPPED, 1)]) @@ -38,39 +37,44 @@ export function rule( conditions: ConditionOrShorthand[] | undefined, from: keys.Key[] | [IFromEvent], to: (keys.Key[] | IToEvent | VarShorthand)[], - others?: IManipulatorMod + others?: IManipulatorMod, ): IManipulator { if (!Array.isArray(from) || !from.length) { - throw new Error(`from rule is required for ${str(from)}`) + throw new Error(`from rule is required for ${str(from)}`); } if (!Array.isArray(to) || !to.length) { - throw new Error(`to rule is required for ${str(to)}`) + throw new Error(`to rule is required for ${str(to)}`); } - let outConditions: Condition[] = [] + let outConditions: Condition[] = []; if (conditions) { if (!Array.isArray(conditions)) { - throw new Error(`Conditions must be an array. Got ${str(conditions)}`) + throw new Error( + `Conditions must be an array. Got ${str(conditions)}`, + ); } // All conditions must have a type outConditions = conditions.map((condition) => { if (isVarShorthand(condition)) { return { name: condition[0], - type: 'variable_if', + type: "variable_if", value: condition[1], - } + }; } else if (!condition.type) { throw new Error( - `Condition is invalid. Expected [string, number] or valid type. Got ${str( - condition - )}` - ) + `Condition is invalid. Expected [string, number] or valid type. Got ${ + str( + condition, + ) + }`, + ); } - return condition - }) + return condition; + }); } - const outFrom = - typeof from[0] !== 'string' ? from[0] : genFromEvent(from as keys.Key[]) + const outFrom = typeof from[0] !== "string" + ? from[0] + : genFromEvent(from as keys.Key[]); const outTo = to.map( (key): IToEvent => { if (Array.isArray(key)) { @@ -80,24 +84,26 @@ export function rule( name: key[0], value: key[1], }, - } + }; } else { - return genToEvent(key) + return genToEvent(key); } - } else if (!key || typeof key !== 'object') { - throw new Error(`Invalid key ${str(key)}`) + } else if (!key || typeof key !== "object") { + throw new Error(`Invalid key ${str(key)}`); } - return key - } - ) + return key; + }, + ); return { - conditions: outConditions.length ? outConditions ?? undefined : undefined, + conditions: outConditions.length + ? outConditions ?? undefined + : undefined, from: outFrom, to: outTo.length === 1 ? outTo[0] : outTo, - type: 'basic', + type: "basic", ...others, - } + }; } /** A JSON replacer that sorts keys recursively and removes type key when required. */ @@ -106,21 +112,21 @@ const replacer = (key: any, value: any) => { return Object.keys(value) .sort() .reduce((sorted, key) => { - ;(sorted as any)[key] = value[key] - return sorted - }, {}) + (sorted as any)[key] = value[key]; + return sorted; + }, {}); } if ( Array.isArray(value) && - (key === 'fn_function_keys' || key === 'simple_modifications') + (key === "fn_function_keys" || key === "simple_modifications") ) { return value.map((val) => { - delete val.type - return val - }) + delete val.type; + return val; + }); } - return value -} + return value; +}; /** * Call to output the config object as JSON. @@ -128,7 +134,7 @@ const replacer = (key: any, value: any) => { * @param config The object representing the karabiner.json config */ export function output(config: any) { - console.log(orderedJSONString(config)) + console.log(orderedJSONString(config)); } ///// =================== /////// @@ -137,21 +143,21 @@ export function output(config: any) { /** swap two keys.KeyCodes. Useful for windows keyboards */ export function swap(a: keys.KeyCode, b: keys.KeyCode) { - return [Key.from(a).to(b), Key.from(b).to(a)] + return [Key.from(a).to(b), Key.from(b).to(a)]; } /** repeat creates an array where the item is repeated count times. */ export function repeat(item: A, count: number): A[] { - return Array.from({ length: count }).fill(item) + return Array.from({ length: count }).fill(item); } /** Variable toggle shorthand function. Generates required variable_if or set_variable object. */ export function v(name: string, value: 0 | 1): [string, 0 | 1] { - return [name, value] + return [name, value]; } /** VarShortShand is for creating a variable_if condition or a set_variable object */ -export type VarShorthand = [string, number] +export type VarShorthand = [string, number]; function genFromEvent(keyCodes: keys.Key[]): IFromEvent { if ( @@ -159,104 +165,110 @@ function genFromEvent(keyCodes: keys.Key[]): IFromEvent { !keyCodes.length || keyCodes.some((key) => !keys.isValid(key)) ) { - throw new Error(`Invalid from event ${str(keyCodes)}`) + throw new Error(`Invalid from event ${str(keyCodes)}`); } - let out: IFromEvent = {} - const optionalMods: keys.KeyCode[] = [] - const requiredMods: keys.KeyCode[] = [] - const standardKeys: keys.KeyCode[] = [] + let out: IFromEvent = {}; + const optionalMods: keys.KeyCode[] = []; + const requiredMods: keys.KeyCode[] = []; + const standardKeys: keys.KeyCode[] = []; keyCodes.forEach((key) => { if (keys.isFromModifierKey(key)) { - if (key.endsWith('?')) { - optionalMods.push(key.replace('?', '') as keys.KeyCode) + if (key.endsWith("?")) { + optionalMods.push(key.replace("?", "") as keys.KeyCode); } else { - requiredMods.push(key as keys.KeyCode) + requiredMods.push(key as keys.KeyCode); } } else { - standardKeys.push(key) + standardKeys.push(key); } - }) + }); if (optionalMods.length || requiredMods.length) { - out.modifiers = {} + out.modifiers = {}; if (optionalMods.length) { - out.modifiers.optional = optionalMods + out.modifiers.optional = optionalMods; } if (requiredMods.length) { - out.modifiers.mandatory = requiredMods + out.modifiers.mandatory = requiredMods; } } if (!standardKeys.length) { // pop the last required modifier into key_code if (out.modifiers?.mandatory?.length) { - const stdKey = out.modifiers.mandatory.pop() as keys.KeyCode + const stdKey = out.modifiers.mandatory.pop() as keys.KeyCode; if (!out.modifiers.mandatory.length) { - out.modifiers.mandatory = undefined + out.modifiers.mandatory = undefined; } - out = { ...out, ...keyObject(stdKey) } + out = { ...out, ...keyObject(stdKey) }; } else { throw new Error( - `A from rule requires a non-optional key but got ${str(keyCodes)}` - ) + `A from rule requires a non-optional key but got ${ + str(keyCodes) + }`, + ); } } if (standardKeys.length > 1) { - out.simultaneous = standardKeys.map(keyObject) + out.simultaneous = standardKeys.map(keyObject); } else if (standardKeys.length === 1) { - out = { ...out, ...keyObject(standardKeys[0]) } + out = { ...out, ...keyObject(standardKeys[0]) }; } - return out + return out; } function genToEvent(keyCodes: keys.Key[]): IToEvent { if ( !Array.isArray(keyCodes) || !keyCodes.length || - keyCodes.some((key) => !(key.includes('?') || keys.isValid(key))) + keyCodes.some((key) => !(key.includes("?") || keys.isValid(key))) ) { - throw new Error(`Invalid to event ${str(keyCodes)}`) + throw new Error(`Invalid to event ${str(keyCodes)}`); } - let out: IToEvent = {} - const optionalMods: keys.KeyCode[] = [] - const mods: keys.ToModifier[] = [] - const standardKeys: keys.KeyCode[] = [] + let out: IToEvent = {}; + const optionalMods: keys.KeyCode[] = []; + const mods: keys.ToModifier[] = []; + const standardKeys: keys.KeyCode[] = []; keyCodes.forEach((key) => { if (keys.isToModifierKey(key)) { - mods.push(key) + mods.push(key); } else if (keys.isKeyCode(key)) { - standardKeys.push(key) + standardKeys.push(key); } else { throw new Error( - `Invalid key code for to event. Got ${str(key)} from ${str(keyCodes)}` - ) + `Invalid key code for to event. Got ${str(key)} from ${ + str(keyCodes) + }`, + ); } - }) + }); if (optionalMods.length || mods.length) { if (mods.length) { - out.modifiers = mods + out.modifiers = mods; } } if (!standardKeys.length) { // pop the last required modifier into key_code if (out.modifiers?.length) { - const stdKey = mods.pop() as keys.KeyCode + const stdKey = mods.pop() as keys.KeyCode; if (!out.modifiers.length) { - out.modifiers = undefined + out.modifiers = undefined; } - out = { ...out, ...keyObject(stdKey) } + out = { ...out, ...keyObject(stdKey) }; } else { throw new Error( - `A from rule requires a non-optional key but got ${str(keyCodes)}` - ) + `A from rule requires a non-optional key but got ${ + str(keyCodes) + }`, + ); } } if (standardKeys.length > 1) { throw new Error( - `To events can only have one standard key. Got ${standardKeys}` - ) + `To events can only have one standard key. Got ${standardKeys}`, + ); } else if (standardKeys.length === 1) { - out = { ...out, ...keyObject(standardKeys[0]) } + out = { ...out, ...keyObject(standardKeys[0]) }; } - return out + return out; } /** check if variable_if shorthand or variable_set shorthand */ @@ -264,25 +276,25 @@ export function isVarShorthand(condition: any): condition is VarShorthand { return ( Array.isArray(condition) && condition.length === 2 && - typeof condition[0] === 'string' && - typeof condition[1] === 'number' - ) + typeof condition[0] === "string" && + typeof condition[1] === "number" + ); } /** print deterministic JSON string specifically for karabiner */ function orderedJSONString(obj: any, space = 4) { - return JSON.stringify(obj, replacer, space).trimEnd() + return JSON.stringify(obj, replacer, space).trimEnd(); } function keyObject(code: keys.KeyCode) { if (keys.isConsumerKey(code)) { return { consumer_key_code: code, - } + }; } return { key_code: code, - } + }; } ///// ================== /////// @@ -290,71 +302,71 @@ function keyObject(code: keys.KeyCode) { ///// ================== /////// export interface IRule { - description: string - manipulators: IManipulator[] + description: string; + manipulators: IManipulator[]; } export interface IConditionApplication { - type: 'frontmost_application_if' | 'frontmost_application_unless' + type: "frontmost_application_if" | "frontmost_application_unless"; /** * Bundle identifier regexs. * You can examine application's bundle identifier in EventViewer > Frontmost Application Tab */ - bundle_identifiers?: string + bundle_identifiers?: string; /** * File path regexs. * You can examine application's file path in EventViewer > Frontmost Application Tab */ - file_paths?: string + file_paths?: string; /** condition description for a human */ - description?: string + description?: string; } export interface IConditionDevice { - type: 'device_if' | 'device_unless' + type: "device_if" | "device_unless"; identifiers: { - vendor_id?: number | string - product_id?: number | string - location_id?: number | string - is_keyboard?: boolean - is_pointing_device?: boolean - }[] + vendor_id?: number | string; + product_id?: number | string; + location_id?: number | string; + is_keyboard?: boolean; + is_pointing_device?: boolean; + }[]; /** condition description for a human */ - description?: string + description?: string; } export interface IConditionKeyboardType { - type: 'keyboard_type_if' | 'keyboard_type_unless' - identifiers: ('ansi' | 'iso' | 'jis')[] + type: "keyboard_type_if" | "keyboard_type_unless"; + identifiers: ("ansi" | "iso" | "jis")[]; /** condition description for a human */ - description?: string + description?: string; } export interface IConditionInputSource { - type: 'input_source_if' | 'input_source_unless' + type: "input_source_if" | "input_source_unless"; identifiers: { /** language regex */ - language?: string - input_source_id?: number | string - input_mode_id?: number | string - }[] + language?: string; + input_source_id?: number | string; + input_mode_id?: number | string; + }[]; /** condition description for a human */ - description?: string + description?: string; } export interface IConditionVariable { - type: 'variable_if' | 'variable_unless' - name: string - value: number | string + type: "variable_if" | "variable_unless"; + name: string; + value: number | string; /** condition description for a human */ - description?: string + description?: string; } export interface IConditionEvent { - type: 'event_changed_if' | 'event_changed_unless' - value: boolean + type: "event_changed_if" | "event_changed_unless"; + value: boolean; /** condition description for a human */ - description?: string + description?: string; } /** Represents all possible conditions */ @@ -364,94 +376,94 @@ type Condition = | IConditionEvent | IConditionInputSource | IConditionKeyboardType - | IConditionVariable + | IConditionVariable; export interface IManipulator { - description?: string - type: 'basic' | 'mouse_motion_to_scroll' - from: IFromEvent - to?: IToEvent[] | IToEvent - to_if_alone?: IToEvent[] - to_after_key_up?: IToEvent[] - to_if_held_down?: IToEvent[] - to_delayed_action?: IToEvent[] - conditions?: Condition[] + description?: string; + type: "basic" | "mouse_motion_to_scroll"; + from: IFromEvent; + to?: IToEvent[] | IToEvent; + to_if_alone?: IToEvent[]; + to_after_key_up?: IToEvent[]; + to_if_held_down?: IToEvent[]; + to_delayed_action?: IToEvent[]; + conditions?: Condition[]; /** Override parametes suchs `to_delayed_action_delay_milliseconds` */ - parameters?: any[] + parameters?: any[]; } /** represents a manipulator modification to be used by rule() function. */ export interface IManipulatorMod { - description?: string - type?: 'mouse_motion_to_scroll' - to_if_alone?: IToEvent[] - to_after_key_up?: IToEvent[] - to_if_held_down?: IToEvent[] - to_delayed_action?: IToEvent[] + description?: string; + type?: "mouse_motion_to_scroll"; + to_if_alone?: IToEvent[]; + to_after_key_up?: IToEvent[]; + to_if_held_down?: IToEvent[]; + to_delayed_action?: IToEvent[]; /** Override parametes suchs `to_delayed_action_delay_milliseconds` */ - parameters?: any[] + parameters?: any[]; } export interface IMouseKey { - x?: number - y?: number - vertical_wheel?: number - horizontal_wheel?: number - speed_multiplier?: number + x?: number; + y?: number; + vertical_wheel?: number; + horizontal_wheel?: number; + speed_multiplier?: number; } export interface IModifiers { - mandatory?: keys.KeyCode[] - optional?: keys.KeyCode[] + mandatory?: keys.KeyCode[]; + optional?: keys.KeyCode[]; } export interface ISumultaneousOptions { /** Specify whether key_down detection is interrupted with unrelated events. */ - detect_key_down_uninterruptedly?: boolean + detect_key_down_uninterruptedly?: boolean; /** Restriction of key_down order. */ - key_down_order?: 'insensitive' | 'strict' | 'strict_inverse' + key_down_order?: "insensitive" | "strict" | "strict_inverse"; /** Restriction of key_up order. */ - key_up_order?: 'insensitive' | 'strict' | 'strict_inverse' + key_up_order?: "insensitive" | "strict" | "strict_inverse"; /** When key_up events are posted. */ - key_up_when?: 'any' | 'all' + key_up_when?: "any" | "all"; /** events will be posted when all from events are released. */ - to_after_key_up?: (IFromEvent | IToEvent)[] + to_after_key_up?: (IFromEvent | IToEvent)[]; } export interface IFromEvent { - key_code?: keys.KeyCode - consumer_key_code?: keys.ConsumerKey + key_code?: keys.KeyCode; + consumer_key_code?: keys.ConsumerKey; /** * The name of the mouse button i.e. button1 * Be careful when using "any": "pointing_button" to avoid losing the left click button. */ - pointing_button?: keys.KeyCode + pointing_button?: keys.KeyCode; /** Be careful when using "any": "pointing_button" to avoid losing the left click button. */ - any?: 'key_code' | 'consumer_key_code' | 'pointing_button' - modifiers?: IModifiers + any?: "key_code" | "consumer_key_code" | "pointing_button"; + modifiers?: IModifiers; /** * manipulates keys which are pressed simultaneously in 50 milliseconds by default. * https://pqrs.org/osx/karabiner/json.html#simultaneous */ - simultaneous?: IFromEvent[] - simultaneous_options?: ISumultaneousOptions[] + simultaneous?: IFromEvent[]; + simultaneous_options?: ISumultaneousOptions[]; } export interface IToEvent { - key_code?: keys.KeyCode - consumer_key_code?: keys.ConsumerKey - shell_command?: string - select_input_source?: any + key_code?: keys.KeyCode; + consumer_key_code?: keys.ConsumerKey; + shell_command?: string; + select_input_source?: any; set_variable?: { - name: string - value: number | string - } - mouse_keys?: IMouseKey - modifiers?: keys.ToModifier[] + name: string; + value: number | string; + }; + mouse_keys?: IMouseKey; + modifiers?: keys.ToModifier[]; /** Defaults to false. If true, do not send key_down until another key is pressed */ - lazy?: boolean + lazy?: boolean; /** Defaults true */ - repeat?: boolean + repeat?: boolean; /** * The typical usage of halt is to cancel to_after_key_up if to_if_alone or to_if_held_down is triggered. * If "halt": true exists in `to_if_alone` or `to_if_held_down`, @@ -459,7 +471,7 @@ export interface IToEvent { * * Defaults to true. */ - halt?: boolean + halt?: boolean; /** * An integer value. The default value is 0. * Specify a key press period for when both key down and key up events are posted at the same time (e.g. to_if_alone) @@ -467,7 +479,7 @@ export interface IToEvent { * * Defaults to 0 */ - hold_down_milliseconds?: number + hold_down_milliseconds?: number; } //////////// Key Class ////////////// @@ -476,38 +488,38 @@ export interface IToEvent { * A chainable class generator for shortening key map definitions */ export class Key { - private _from!: keys.KeyCode - private _to!: keys.KeyCode + private _from!: keys.KeyCode; + private _to!: keys.KeyCode; constructor() {} static from(code: keys.KeyCode) { - const that = new Key() - that._from = code - return that + const that = new Key(); + that._from = code; + return that; } to(code: keys.KeyCode) { - this._to = code - return this + this._to = code; + return this; } protected toJSON() { - let out: any = {} + const out: any = {}; if (keys.isConsumerKey(this._from)) { out.from = { consumer_key_code: this._from, - } + }; } else { out.from = { key_code: this._from, - } + }; } if (keys.isConsumerKey(this._to)) { out.to = { consumer_key_code: this._to, - } + }; } else { out.to = { key_code: this._to, - } + }; } - return out + return out; } } diff --git a/kite/docker/server.ts b/kite/docker/server.ts index be8e110..cb5ba4d 100644 --- a/kite/docker/server.ts +++ b/kite/docker/server.ts @@ -1,16 +1,16 @@ -import { serve } from 'https://deno.land/std@0.92.0/http/server.ts' -import * as YAML from 'https://deno.land/std@0.92.0/encoding/yaml.ts' -import { ensureDir } from 'https://deno.land/std@0.92.0/fs/mod.ts' -import * as httpsig from 'https://x.kite.run/lib/http-signature/verify.ts' -import { Sha256 } from 'https://deno.land/std@0.92.0/hash/sha256.ts' +import { serve } from "https://deno.land/std@0.92.0/http/server.ts"; +import * as YAML from "https://deno.land/std@0.92.0/encoding/yaml.ts"; +import { ensureDir } from "https://deno.land/std@0.92.0/fs/mod.ts"; +import * as httpsig from "https://x.kite.run/lib/http-signature/verify.ts"; +import { Sha256 } from "https://deno.land/std@0.92.0/hash/sha256.ts"; -const PORT = 8080 -const EVAL_DIR = '/tmp/deno-eval' -const HMAC_SECRET = Deno.env.get('HMAC_SECRET')! +const PORT = 8080; +const EVAL_DIR = "/tmp/deno-eval"; +const HMAC_SECRET = Deno.env.get("HMAC_SECRET")!; if (!HMAC_SECRET) { - console.error('HMAC_SECRET envar must be specified') - Deno.exit(2) + console.error("HMAC_SECRET envar must be specified"); + Deno.exit(2); } /** @@ -18,13 +18,13 @@ if (!HMAC_SECRET) { */ async function exists(filename: string): Promise { try { - await Deno.stat(filename) - return true + await Deno.stat(filename); + return true; } catch (error) { if (error instanceof Deno.errors.NotFound) { - return false + return false; } else { - throw error + throw error; } } } @@ -35,111 +35,118 @@ async function exists(filename: string): Promise { * Files are stored in the temp directory. */ async function server() { - await ensureDir(EVAL_DIR) - console.log('listening on', PORT, 'caching files at', EVAL_DIR) - for await (const req of serve(`:${PORT}`)) { + await ensureDir(EVAL_DIR); + console.log("listening on", PORT, "caching files at", EVAL_DIR); + Deno.serve({ port: PORT }, async (req) => { try { - const enc = new TextEncoder() - const dec = new TextDecoder() - const headers: Record = {} + const enc = new TextEncoder(); + const dec = new TextDecoder(); + const headers: Record = {}; req.headers.forEach((val, key) => { - headers[key.toLowerCase()] = val - }) + headers[key.toLowerCase()] = val; + }); // HMAC verify first try { const parsed = httpsig.parseRequest({ url: req.url, headers: headers, method: req.method, - }) + }); if (httpsig.verifySignature(parsed, HMAC_SECRET) !== true) { - req.respond({ body: 'invalid or missing signature', status: 400 }) - continue + return new Response("invalid or missing signature", { + status: 400, + }); } - } catch (e) { - req.respond({ body: 'invalid or missing signature error', status: 400 }) - continue + } catch (_e) { + return new Response("invalid or missing signature", { + status: 400, + }); } - console.log(`${req.method} ${req.url}`) - const bodyTxt = dec.decode(await Deno.readAll(req.body)) - const webhook = JSON.parse(bodyTxt) - let cp = webhook.repo.config_path - if (cp.endsWith('.yml')) { - req.respond({ body: 'unchanged', status: 204 }) - continue - } else if (cp.endsWith('.ts') || cp.endsWith('.tsx')) { + console.log(`${req.method} ${req.url}`); + const bodyTxt = dec.decode(await Deno.readAll(req.body)); + const webhook = JSON.parse(bodyTxt); + let cp = webhook.repo.config_path; + if (cp.endsWith(".yml")) { + return new Response("unchanged", { status: 204 }); + } else if (cp.endsWith(".ts") || cp.endsWith(".tsx")) { // execute for output - const ignoreCache = webhook.build.message.includes('[nocache]') - const config = webhook.config.data - const hash = new Sha256().update(config).hex() - const execFile = `${EVAL_DIR}/${hash}.tsx` - const outFile = `${EVAL_DIR}/${hash}-out.yml` - const existing = await exists(outFile) - let output: string - let writingComplete: Promise | undefined + const ignoreCache = webhook.build.message.includes("[nocache]"); + const config = webhook.config.data; + const hash = new Sha256().update(config).hex(); + const execFile = `${EVAL_DIR}/${hash}.tsx`; + const outFile = `${EVAL_DIR}/${hash}-out.yml`; + const existing = await exists(outFile); + let output: string; + let writingComplete: Promise | undefined; if (existing && !ignoreCache) { - output = await Deno.readTextFile(outFile) + output = await Deno.readTextFile(outFile); } else { - await Deno.writeFile(execFile, enc.encode(config)) + await Deno.writeFile(execFile, enc.encode(config)); if (ignoreCache) { const p = Deno.run({ - cmd: ['deno', 'cache', '--unstable', '--reload', execFile], - }) - const s = await p.status() + cmd: [ + "deno", + "cache", + "--unstable", + "--reload", + execFile, + ], + }); + const s = await p.status(); if (!s.success) { - req.respond({ - body: 'failed reload Kite Config program cache', - status: 500, - }) + return new Response( + "failed reload Kite Config program cache", + { status: 500 }, + ); } } const p = Deno.run({ - cmd: ['kite', '-e', execFile], - stdout: 'piped', - }) - const s = await p.status() + cmd: ["kite", "-e", execFile], + stdout: "piped", + }); + const s = await p.status(); if (!s.success) { - req.respond({ - body: 'Kite Config program failed during execution', - status: 500, - }) - continue + return new Response( + "Kite Config program failed during execution", + { status: 500 }, + ); } - const outBinary = await p.output() - output = dec.decode(outBinary) + const outBinary = await p.output(); + output = dec.decode(outBinary); - writingComplete = Deno.writeFile(outFile, outBinary) // await later + writingComplete = Deno.writeFile(outFile, outBinary); // await later } if (!output.length) { - req.respond({ body: 'Kite Config program returned empty output' }) - if (writingComplete) await writingComplete - continue + return new Response( + "Kite Config program returned empty output", + { status: 500 }, + ); + // TODO: Disabled --> if (writingComplete) await writingComplete; } - const files = YAML.parse(output) as any + const files = YAML.parse(output) as any; if ( - typeof files === 'object' && - typeof files['.drone.yml'] === 'string' + typeof files === "object" && + typeof files[".drone.yml"] === "string" ) { - req.respond({ - body: JSON.stringify({ data: files['.drone.yml'] }), - status: 200, - }) + return new Response( + JSON.stringify({ data: files[".drone.yml"] }), + { status: 200 }, + ); } else { - req.respond({ - body: 'Config did not return a .drone.yml value', - status: 500, - }) + return new Response( + "Config did not return a .drone.yml value", + { status: 500 }, + ); } - if (writingComplete) await writingComplete - continue + // TODO: Disabled if (writingComplete) await writingComplete; } - req.respond({ body: 'config unchanged', status: 204 }) + return new Response("unchanged", { status: 204 }); } catch (e) { - console.error(e) - req.respond({ body: 'unexpected error', status: 500 }) + console.error(e); + return new Response("unexpected error", { status: 500 }); } - } + }); } -server() +server(); diff --git a/kite/examples/cannot-assign.ts b/kite/examples/cannot-assign.ts new file mode 100644 index 0000000..561b73a --- /dev/null +++ b/kite/examples/cannot-assign.ts @@ -0,0 +1,27 @@ +class Base { + private __type!: string; + protected readonly __number!: number; + protected readonly __name!: string; + private __cache: any; + constructor(name: string, desc: any) { + this.__type = "Example"; + this.__number = 1; + this.__name = name; + Object.assign(this, desc); + } +} + +class Password extends Base { + public readonly length!: number; + public readonly number!: boolean | undefined; + + constructor( + name: string, + desc: { length: number; number?: boolean | undefined }, + ) { + super(name, desc); + } +} + +const firstPassword = new Password("first", { length: 8 }); +console.log(firstPassword); diff --git a/magic-string.js b/magic-string.js index b678ca5..b671745 100644 --- a/magic-string.js +++ b/magic-string.js @@ -9,6 +9,8 @@ * @version 0.25.6 */ +// deno-lint-ignore-file + import { encode } from './sourcemap-codec.ts' // NOTE: This diff --git a/merge.ts b/merge.ts index 142afdf..099abb3 100644 --- a/merge.ts +++ b/merge.ts @@ -7,25 +7,25 @@ * That original work is Copyright 2020, jk authors. */ -import { isObject } from './utils.ts' +import { isObject } from "./utils.ts"; function mergeFunc(rules: Record, key: string, defaultFunc: any) { - const f = rules && rules[key] + const f = rules && rules[key]; if (f === undefined) { - return defaultFunc + return defaultFunc; } - const t = typeof f - if (t === 'object') { - return deep(f) + const t = typeof f; + if (t === "object") { + return deep(f); } - if (t !== 'function') { + if (t !== "function") { throw new Error( - `merge: expected a function in the rules objects but found a ${t}` - ) + `merge: expected a function in the rules objects but found a ${t}`, + ); } - return f + return f; } /** @@ -35,26 +35,26 @@ function mergeFunc(rules: Record, key: string, defaultFunc: any) { function objectMerge2>( a: A, b: A, - rules: MergeObject + rules: MergeObject, ): A { - const r = {} as Record + const r = {} as Record; - Object.assign(r, a) + Object.assign(r, a); for (const [key, value] of Object.entries(b)) { - r[key] = mergeFunc(rules, key, merge)(a[key], value) + r[key] = mergeFunc(rules, key, merge)(a[key], value); } - return r as A + return r as A; } function assertObject(o: any, prefix: string) { if (!isObject(o)) { - throw new Error(`${prefix}: input value is not an object`) + throw new Error(`${prefix}: input value is not an object`); } } function assertArray(o: unknown, prefix: string) { if (!Array.isArray(o)) { - throw new Error(`${prefix}: input is not an array`) + throw new Error(`${prefix}: input is not an array`); } } @@ -69,12 +69,12 @@ function assertArray(o: unknown, prefix: string) { */ export function deep(rules?: MergeObject) { return (a: T, b: T): T => { - if (a === undefined) a = {} as T - if (b === undefined) b = {} as T - assertObject(a, 'deep') - assertObject(b, 'deep') - return objectMerge2(a, b, rules as any) - } + if (a === undefined) a = {} as T; + if (b === undefined) b = {} as T; + assertObject(a, "deep"); + assertObject(b, "deep"); + return objectMerge2(a, b, rules as any); + }; } /** @@ -114,7 +114,7 @@ export function deep(rules?: MergeObject) { * ``` */ export function first() { - return (a: A, _: any): A => a + return (a: A, _: any): A => a; } /** @@ -155,29 +155,29 @@ export function first() { * ``` */ export function replace() { - return (_: any, b: B): B => b + return (_: any, b: B): B => b; } function arrayMergeWithKey>( a: A, b: A, mergeKey: string, - rules?: MergeObject + rules?: MergeObject, ) { - const r = Array.from(a) - const toAppend: any[] = [] + const r = Array.from(a); + const toAppend: any[] = []; for (const value of b) { - const i = a.findIndex((o) => o[mergeKey] === value[mergeKey]) + const i = a.findIndex((o) => o[mergeKey] === value[mergeKey]); if (i === -1) { // Object doesn't exist in a, save it in the list of objects to append. - toAppend.push(value) - continue + toAppend.push(value); + continue; } - r[i] = objectMerge2(a[i], value, rules as any) + r[i] = objectMerge2(a[i], value, rules as any); } - Array.prototype.push.apply(r, toAppend) - return r + Array.prototype.push.apply(r, toAppend); + return r; } /** @@ -190,7 +190,7 @@ function arrayMergeWithKey>( * **Example**: * * ```js - * importee { merge, deep, deepWithKey } from '@jkcfg/std@0.92.0/merge'; + * importee { merge, deep, deepWithKey } from '@jkcfg/std/merge'; * * const pod = { * spec: { @@ -247,10 +247,10 @@ function arrayMergeWithKey>( */ export function deepWithKey(mergeKey: string, rules?: MergeObject) { return >(a: T, b: T) => { - assertArray(a, 'deepWithKey') - assertArray(b, 'deepWithKey') - return arrayMergeWithKey(a, b, mergeKey, rules) - } + assertArray(a, "deepWithKey"); + assertArray(b, "deepWithKey"); + return arrayMergeWithKey(a, b, mergeKey, rules); + }; } /** @@ -329,7 +329,6 @@ export function deepWithKey(mergeKey: string, rules?: MergeObject) { * third argument of `merge` is an object associating properties with merge * functions. * - * * ```js * // merge a and b, adding the values of the `k0` property. * merge(a, b, { k0: add }); @@ -347,41 +346,39 @@ export function deepWithKey(mergeKey: string, rules?: MergeObject) { export function merge(a: A, b: A, rule?: MergeObject): any { //@ts-ignore if (a === b) { - return a + return a; } - const [typeA, typeB] = [typeof a, typeof b] + const [typeA, typeB] = [typeof a, typeof b]; if (a == null) { - return b + return b; } else if (b === undefined) { - return a + return a; } if (typeA !== typeB) { throw new Error( - `merge cannot combine values of types ${typeA} and ${typeB}` - ) + `merge cannot combine values of types ${typeA} and ${typeB}`, + ); } // Primitive types and arrays default to being replaced. - if (Array.isArray(a) || typeA !== 'object') { - if (typeof rule === 'function') { - return (rule as MergeFunction)(a, b) + if (Array.isArray(a) || typeA !== "object") { + if (typeof rule === "function") { + return (rule as MergeFunction)(a, b); } - return b + return b; } // Objects. We cast as any because we know it to be an object - return objectMerge2(a as any, b, rule as any) + return objectMerge2(a as any, b, rule as any); } /** MergeObject is an object containing merge functions or a MergeFunction */ -export type MergeObject = T extends object - ? Partial< - { - [P in keyof T]: T[P] extends object - ? MergeObject - : MergeFunction - } - > - : MergeFunction +export type MergeObject = T extends object ? Partial< + { + [P in keyof T]: T[P] extends object ? MergeObject + : MergeFunction; + } + > + : MergeFunction; /** MergeFunction is a function that merges two values */ -export type MergeFunction = (a: A, b: A) => A +export type MergeFunction = (a: A, b: A) => A; diff --git a/quokka-shim.ts b/quokka-shim.ts deleted file mode 100644 index 5f4cb64..0000000 --- a/quokka-shim.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * @file quokka-shim.ts - * @copyright 2020 Brandon Kalinowski (@brandonkal) - * @description A shim for test functions when running Deno code. - * Consider using @brandonkal/deno-quokka and babel-plugin-deno npm packages for - * a more robust debugging experience. - * @license MIT - */ - -export function it(name: string, fn: Function) { - console.log(`===${name}===`) - fn() -} -export function assertEquals(left: any, right: any) { - if (left === right) { - console.log('Values Match') - } else { - console.warn('Got') - console.log(right) - console.warn('Expected') - console.log(left) - return new Error('Bad') - } -} diff --git a/resolve-promise-object.ts b/resolve-promise-object.ts index b3ed43c..fcd8655 100644 --- a/resolve-promise-object.ts +++ b/resolve-promise-object.ts @@ -13,17 +13,15 @@ * either be a concrete value or a promise of that value. */ export type MPV = { - [P in keyof T]: T[P] extends (infer U)[] - ? MPV[] - : T[P] extends object - ? MPV - : PromiseLike | T[P] -} + [P in keyof T]: T[P] extends (infer U)[] ? MPV[] + : T[P] extends object ? MPV + : PromiseLike | T[P]; +}; /** * MPVMap is an object where each key is a MPV */ -export type MPVMap = { [P in keyof T]: MPV } +export type MPVMap = { [P in keyof T]: MPV }; /** * deepResolve takes a value and resolves all keys recursively to their promise-resolved values. Call this function to transform an object of promises and values to just their values. @@ -31,106 +29,108 @@ export type MPVMap = { [P in keyof T]: MPV } */ export function deepResolve( object: MPV, - _callback?: Function + // deno-lint-ignore ban-types + _callback?: Function, ): Promise { - if (typeof _callback != 'function') { - _callback = noop + if (typeof _callback != "function") { + _callback = noop; } // If the property is not an object, // it needs no further processing. if (object === null || !isObject(object)) { - return _callback(null, object) + return _callback(null, object); } return new Promise(function (presolve, reject) { - var callback = function (err: any, res: any) { + const callback = function (err: any, res: any) { if (err) { - reject(err) + reject(err); } else { - presolve(res) + presolve(res); } - _callback!(err, res) - } + _callback!(err, res); + }; // If it is a promise, wait for it to resolve. // Run the check again to find nested promises. if (isPromise(object)) { - return (object as any).then(checkAgain.bind(null, null), callback) + return (object as any).then(checkAgain.bind(null, null), callback); } // If it has a toJSON method, assume it can be used directly. if (canJSON(object)) { - object = (object as any).toJSON() + object = (object as any).toJSON(); if (!isObject(object)) { - return callback(null, object) + return callback(null, object); } } // Build a list of promises and promise-like structures to wait for. - let remains: any[] = [] + const remains: any[] = []; Object.keys(object).forEach(function (key) { //@ts-ignore crazy any - var item = object[key] + const item = object[key]; if (isPromise(item) || isObject(item)) { - remains.push(key) + remains.push(key); } - }) + }); // If none were found, we must be done. if (!remains.length) { - return callback(null, object) + return callback(null, object); } // Otherwise, loop through the list. - let pending = remains.length + let pending = remains.length; remains.forEach(function (key) { //@ts-ignore -- crazy any - var item = object[key] + const item = object[key]; // Promises and queries must be checked again upon success // to ensure nested promises are properly processed. if (isPromise(item)) { item.then( doneHandler(key, checkAgain).bind(null, null), - doneHandler(key, callback) - ) + doneHandler(key, callback), + ); } - deepResolve(item, doneHandler(key, callback)) - }) + deepResolve(item, doneHandler(key, callback)); + }); // All the check to be restarted so we // can return promises from promises. function checkAgain(err: any, res: any) { - if (err) return callback(err, undefined) - deepResolve(res, callback) + if (err) return callback(err, undefined); + deepResolve(res, callback); } // Promises need to call the restart the check, // so we use this to allow them to swap out fn. + // deno-lint-ignore ban-types function doneHandler(key: any, fn: Function) { return function (err: any, result: any) { - if (err) return callback(err, undefined) + if (err) return callback(err, undefined); //@ts-ignore crazy any - object[key] = result + object[key] = result; if (--pending === 0) { - fn(null, object) + fn(null, object); } - } + }; } - }) + }); } function canJSON(v: any) { - return typeof v.toJSON === 'function' + return typeof v.toJSON === "function"; } function isObject(v: any) { - return typeof v === 'object' + return typeof v === "object"; } function isPromise(v: any) { - return v && typeof v === 'object' && typeof v.then === 'function' + return v && typeof v === "object" && typeof v.then === "function"; } function noop() {} diff --git a/to_aml.js b/to_aml.js index e40cdaf..3bf5980 100644 --- a/to_aml.js +++ b/to_aml.js @@ -27,7 +27,7 @@ * @param {object} obj */ export function archieml(obj) { - let leafy = toLeaf(obj) + const leafy = toLeaf(obj) return toArchieML(leafy) } @@ -41,8 +41,7 @@ export function archieml(obj) { * accumulator. */ function toLeaf(obj) { - let leafy = [] - let curpath = [] + const leafy = [] to_leaf_1(leafy, [], obj) return leafy @@ -54,7 +53,7 @@ function toLeaf(obj) { to_leaf_1(acc, curpath, obj[i]) } } else if (typeof obj === 'object') { - for (let k in obj) { + for (const k in obj) { curpath.push(path_elem_1(obj, k)) to_leaf_1(acc, curpath, obj[k]) curpath.pop(k) @@ -127,13 +126,13 @@ const rxArray = /^\[(.*)\]$/ * Otherwise enter all the arrays needed and show the remaining value */ function toArchieML(leafy) { - let state = { + const state = { curobject: null, curarrays: [], firstelem: null, moreelems: false, } - let r = [] + const r = [] for (let i = 0; i < leafy.length; i++) { exit_arrays_needed_1(leafy[i], state, r) @@ -158,7 +157,7 @@ function toArchieML(leafy) { * earlier during the `exit_arrays_needed_1` call. */ function enter_arrays_needed_1(leaf, state, r) { - let arrs = leafArraySplit(leaf.path) + const arrs = leafArraySplit(leaf.path) for (let i = state.curarrays.length; i < arrs.length; i++) { if (i == 0) r.push(`[${arrs[i]}]`) else r.push(`[.${arrs[i]}]`) @@ -182,7 +181,7 @@ function toArchieML(leafy) { * to make it look nicer. */ function show_array_elem_1(leaf, state, r) { - let p = array_path_1(leaf.path) + const p = array_path_1(leaf.path) if (!p) { r.push(`* ${leafVal(leaf)}`) } else { @@ -206,7 +205,7 @@ function toArchieML(leafy) { * marker, otherwise it can just be a simple value. */ function leafVal(leaf) { - let v = leaf.value + const v = leaf.value if (v.match(/[\n\r]/)) return `${v}\n:end` else return v } @@ -217,12 +216,12 @@ function toArchieML(leafy) { * exit the current object and then output the leaf path and value. */ function show_obj_1(leaf, state, r) { - let path = as_obj_path_1(leaf.path) + const path = as_obj_path_1(leaf.path) if (!state.curobject) { r.push(`${path}: ${leafVal(leaf)}`) } else { if (path.startsWith(state.curobject)) { - let rem = path.substring(state.curobject.length + 1) + const rem = path.substring(state.curobject.length + 1) r.push(`${rem}: ${leafVal(leaf)}`) } else { r.push('{}') @@ -257,12 +256,12 @@ function toArchieML(leafy) { * object' in our state. */ function resolve_object_path_1(leafy, ndx, state, r) { - let p1 = leafyObjPath(leafy[ndx]) + const p1 = leafyObjPath(leafy[ndx]) if (!p1) return if (p1 == state.curobject) return - let p2 = leafyObjPath(leafy[ndx + 1]) + const p2 = leafyObjPath(leafy[ndx + 1]) if (!p2) return - let p3 = leafyObjPath(leafy[ndx + 2]) + const p3 = leafyObjPath(leafy[ndx + 2]) if (!p3) return if (p2.startsWith(p1) && p3.startsWith(p1)) { @@ -289,7 +288,7 @@ function toArchieML(leafy) { */ function leafyObjPath(leaf) { if (!leaf || !leaf.path || !leaf.path.length) return - let p = [] + const p = [] for (let i = 0; i < leaf.path.length - 1; i++) { if (isPathElemArray(leaf.path[i])) break p.push(leaf.path[i]) @@ -304,7 +303,7 @@ function toArchieML(leafy) { * If we exit the last array, leave a line to make it look better. */ function exit_arrays_needed_1(leaf, state, r) { - let arrs = leafArraySplit(leaf.path) + const arrs = leafArraySplit(leaf.path) let i for (i = 0; i < state.curarrays.length; i++) { if (arrs[i] != state.curarrays[i]) break @@ -329,7 +328,7 @@ function toArchieML(leafy) { * [ "a", "[b]", "c", "[d]" ] ==> [ "a.b", "c.d" ] */ function leafArraySplit(path) { - let arrs = [] + const arrs = [] let start = 0 for (let i = 0; i < path.length; i++) { if (isPathElemArray(path[i])) { @@ -347,7 +346,7 @@ function toArchieML(leafy) { function as_array_path_1(p) { return p .map((e) => { - let m = e.match(rxArray) + const m = e.match(rxArray) if (m) return m[1] else return e })