Skip to content

Commit

Permalink
Merge branch 'main' into deps/js/openai-4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
CiaranMn authored Dec 16, 2024
2 parents 2968758 + 51d230e commit 971874d
Show file tree
Hide file tree
Showing 64 changed files with 565 additions and 352 deletions.
4 changes: 2 additions & 2 deletions apps/hash-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@
"express": "4.21.2",
"express-handlebars": "7.1.3",
"express-http-proxy": "2.1.1",
"express-rate-limit": "7.4.1",
"express-rate-limit": "7.5.0",
"fractional-indexing": "2.1.0",
"googleapis": "133.0.0",
"graphql": "16.9.0",
"graphql": "16.10.0",
"graphql-parse-resolve-info": "4.13.0",
"graphql-scalars": "1.24.0",
"helmet": "4.6.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/hash-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"graphology-layout-forceatlas2": "0.10.1",
"graphology-shortest-path": "2.1.0",
"graphology-simple-path": "0.2.0",
"graphql": "16.9.0",
"graphql": "16.10.0",
"iframe-resizer": "4.4.5",
"immer": "9.0.21",
"jsonpath": "1.1.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/plugin-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"bowser": "2.11.0",
"date-fns": "4.1.0",
"fractional-indexing": "2.1.0",
"graphql": "16.9.0",
"graphql": "16.10.0",
"lodash.debounce": "4.0.8",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
15 changes: 15 additions & 0 deletions libs/@local/eslint/src/builtIn.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Array as ReadonlyArray, Option, pipe, Predicate } from "effect";
import type { PartialDeep } from "type-fest";
import { baseNoRestrictedSyntaxRules } from "eslint-config-sheriff";

import type { NoRestrictedImportsRule } from "./types.js";
import { defineConfig, type ESConfig } from "./utils.js";
Expand Down Expand Up @@ -89,6 +90,20 @@ export const builtIn =
allowAsStatement: true,
},
],
// remap the `ClassDeclaration` rule to exclude `Error` classes
"no-restricted-syntax": [
"error",
...baseNoRestrictedSyntaxRules.map((rule) =>
rule.selector === "ClassDeclaration"
? {
selector: "ClassDeclaration[id.name!=/Error$/]",
message: rule.message,
}
: rule,
),
],
// exclude forEach from `array-callback-return`, as it only checks by name, not by type and clashes with effect.
"array-callback-return": ["error", { allowImplicit: true }],
},
},
...noRestrictedImports(config, options.noRestrictedImports ?? (() => [])),
Expand Down
4 changes: 4 additions & 0 deletions libs/@local/eslint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { react } from "./react.js";
import { stylistic } from "./stylistic.js";
import type { NoRestrictedImportsRule } from "./types.js";
import { typescript } from "./typescript.js";
import { jsdoc } from "./jsdoc.js";
import { unicorn } from "./unicorn.js";
import { vitest } from "./vitest.js";
import { projectIgnoreFiles, type ESConfig } from "./utils.js";

export type * from "./types.js";
Expand Down Expand Up @@ -60,5 +62,7 @@ export const create = (
react(options ?? {}),
typescript,
stylistic,
jsdoc,
vitest(options ?? {}),
);
};
17 changes: 17 additions & 0 deletions libs/@local/eslint/src/jsdoc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Array } from "effect";

import type { ESConfig } from "./utils.js";

export const jsdoc = (config: readonly ESConfig[]): readonly ESConfig[] =>
Array.appendAll(config, [
{
rules: {
"jsdoc/require-description": [
"error",
{ exemptedBy: ["inheritdoc", "internal"] },
],
// conflicts with tsdoc
"jsdoc/check-tag-names": "off",
},
},
]);
2 changes: 2 additions & 0 deletions libs/@local/eslint/src/unicorn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ export const unicorn = (config: readonly ESConfig[]): readonly ESConfig[] =>
// spread operator. It's also a very common pattern in functional
// programming.
"unicorn/no-array-reduce": "off",
// This doesn't work well with `effect/Data/TaggedError`.
"unicorn/throw-new-error": "off",
},
},
preventAbbreviations(),
Expand Down
27 changes: 27 additions & 0 deletions libs/@local/eslint/src/vitest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { PartialDeep } from "type-fest";
import { Array } from "effect";
import { testsFilePatterns } from "eslint-config-sheriff";

import type { ESConfig } from "./utils.js";

import type { Options } from "./index.js";

export const vitest =
(options: PartialDeep<Options>) =>
(config: readonly ESConfig[]): readonly ESConfig[] => {
if (!options.enabled?.tests) {
return config;
}

return Array.appendAll(config, [
{
files: [...testsFilePatterns],
rules: {
// this rule is too buggy
"vitest/require-hook": "off",
// in tests non-null assertions are fine
"@typescript-eslint/no-non-null-assertion": "off",
},
},
]);
};
20 changes: 10 additions & 10 deletions libs/@local/harpc/client/typescript/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { createBase } from "@local/eslint/deprecated";
import { create } from "@local/eslint";

export default [
...createBase(import.meta.dirname),
...create(import.meta.dirname, {
enabled: {
frontend: false,
playwright: false,
tests: true,
storybook: false,
},
}),
{
rules: {
"@typescript-eslint/no-redeclare": "off",
"unicorn/filename-case": "off",
"func-names": "off",
"canonical/filename-no-index": "off",
"@typescript-eslint/no-empty-object-type": [
"error",
{ allowInterfaces: "with-single-extends" },
],
"fsecond/prefer-destructured-optionals": "off",
},
},
];
33 changes: 22 additions & 11 deletions libs/@local/harpc/client/typescript/src/binary/MutableBytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Match, Option, Pipeable, Predicate } from "effect";
import { createProto } from "../utils.js";

const TypeId: unique symbol = Symbol("@local/harpc-client/binary/Bytes");

export type TypeId = typeof TypeId;

export type GrowthStrategy = "doubling" | "linear" | "exponential";
Expand Down Expand Up @@ -38,13 +39,13 @@ export const make = (options?: {
/**
* The initial capacity of the buffer.
*
* @default 1024
* @defaultValue 1024
*/
readonly initialCapacity?: number;
/**
* The strategy for growing the buffer when more space is needed.
*
* @default "doubling"
* @defaultValue "doubling"
*/
readonly growthStrategy?: GrowthStrategy;
}): MutableBytes =>
Expand Down Expand Up @@ -74,8 +75,10 @@ const allocate = (self: MutableBytes, newCapacity: number) => {
const impl = self as MutableBytesImpl;

const newBuffer = new ArrayBuffer(newCapacity);

new Uint8Array(newBuffer).set(new Uint8Array(impl.inner));
impl.inner = newBuffer;

return self;
};

Expand All @@ -86,19 +89,20 @@ const requiredCapacity = (self: MutableBytes, minimum: number) => {

while (next < minimum) {
next = Match.value(impl.growthStrategy).pipe(
// eslint-disable-next-line no-loop-func
// eslint-disable-next-line @typescript-eslint/no-loop-func
Match.when(Match.is("doubling"), () => next * 2),
Match.when(
Match.is("linear"),
// eslint-disable-next-line no-loop-func

// eslint-disable-next-line @typescript-eslint/no-loop-func
() =>
next +
// if the initialCapacity is 0 we should use the default, otherwise this turns into an infinite loop
(impl.initialCapacity === 0
? DEFAULT_INITIAL_CAPACITY
: impl.initialCapacity),
),
// eslint-disable-next-line no-loop-func
// eslint-disable-next-line @typescript-eslint/no-loop-func
Match.when(Match.is("exponential"), () => next ** 2),
Match.exhaustive,
);
Expand Down Expand Up @@ -133,13 +137,16 @@ export const appendArray = (
return self;
}

const totalLength = bytes.reduce((acc, b) => acc + b.byteLength, 0);
const totalLength = bytes.reduce(
(accumulator, b) => accumulator + b.byteLength,
0,
);

reserve(self, totalLength);

for (const array of bytes) {
new Uint8Array(impl.inner).set(array, impl.length);
impl.length += array.byteLength;
impl.length = impl.length + array.byteLength;
}

return self;
Expand All @@ -160,20 +167,23 @@ export const append = (
return self;
}

const totalLength = other.reduce((acc, b) => acc + length(b), 0);
const totalLength = other.reduce(
(accumulator, b) => accumulator + length(b),
0,
);

reserve(self, totalLength);

for (const array of other) {
new Uint8Array(impl.inner).set(asArray(array), impl.length);
impl.length += length(array);
impl.length = impl.length + length(array);
}

return self;
};

/**
* Split the bytes object, so that bytes object contains `[at,length)` and the rest is returned as a new bytes object
* Split the bytes object, so that bytes object contains `[at,length)` and the rest is returned as a new bytes object.
*/
export const splitTo = (self: MutableBytes, at: number) => {
if (at > length(self)) {
Expand All @@ -186,10 +196,11 @@ export const splitTo = (self: MutableBytes, at: number) => {
initialCapacity: at,
growthStrategy: impl.growthStrategy,
});

appendBuffer(destination, impl.inner.slice(0, at));

impl.inner = impl.inner.slice(at);
impl.length -= at;
impl.length = impl.length - at;

return Option.some(destination);
};
Expand Down
13 changes: 11 additions & 2 deletions libs/@local/harpc/client/typescript/src/codec/Decoder.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import type { ParseResult, Schema, Stream } from "effect";
import { Data, Function, Inspectable, Pipeable } from "effect";
import {
type ParseResult,
type Schema,
type Stream,
Data,
Function,
Inspectable,
Pipeable,
} from "effect";
import { GenericTag } from "effect/Context";

import { createProto } from "../utils.js";

const TypeId: unique symbol = Symbol("@local/harpc-client/codec/Decoder");

export type TypeId = typeof TypeId;

export class DecodingError extends Data.TaggedError("DecodingError")<{
Expand Down Expand Up @@ -67,6 +75,7 @@ const DecoderProto: Omit<DecoderImpl, "decode"> = {
},
};

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- description is defined
export const Decoder = GenericTag<Decoder>(TypeId.description!);

export const make = <E = DecodingError, R = never>(
Expand Down
13 changes: 11 additions & 2 deletions libs/@local/harpc/client/typescript/src/codec/Encoder.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import type { ParseResult, Schema, Stream } from "effect";
import { Data, Function, Inspectable, Pipeable } from "effect";
import {
type ParseResult,
type Schema,
type Stream,
Data,
Function,
Inspectable,
Pipeable,
} from "effect";
import { GenericTag } from "effect/Context";

import { createProto } from "../utils.js";

const TypeId: unique symbol = Symbol("@local/harpc-client/codec/Encoder");

export type TypeId = typeof TypeId;

export class EncodingError extends Data.TaggedError("EncodingError")<{
Expand Down Expand Up @@ -67,6 +75,7 @@ const EncoderProto: Omit<EncoderImpl, "encode"> = {
},
};

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- description is defined
export const Encoder = GenericTag<Encoder>(TypeId.description!);

export const make = <E = EncodingError, R = never>(
Expand Down
Loading

0 comments on commit 971874d

Please sign in to comment.