Skip to content

Commit 6de35aa

Browse files
committed
Remove vendored compiler lodash dependency
1 parent 4b862ac commit 6de35aa

13 files changed

Lines changed: 145 additions & 20 deletions

File tree

bun.lock

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/sdk/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
"fractional-indexing": "^3.2.0",
7272
"fumadb": "workspace:*",
7373
"js-yaml": "^4.1.1",
74-
"lodash": "^4.18.1",
7574
"oauth4webapi": "^3.8.5"
7675
},
7776
"devDependencies": {
@@ -80,8 +79,6 @@
8079
"@effect/vitest": "catalog:",
8180
"@types/better-sqlite3": "^7.6.13",
8281
"@types/js-yaml": "^4.0.9",
83-
"@types/json-schema": "^7.0.15",
84-
"@types/lodash": "^4.17.24",
8582
"@types/node": "catalog:",
8683
"@types/react": "catalog:",
8784
"better-sqlite3": "^12.9.0",

packages/core/sdk/src/vendor/json-schema-to-typescript/generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { memoize, omit } from "lodash";
1+
import { memoize, omit } from "./lodash";
22
import { DEFAULT_OPTIONS, type Options } from "./index";
33
import { hasComment, hasStandaloneName, T_ANY, T_UNKNOWN } from "./types/AST";
44
import type {

packages/core/sdk/src/vendor/json-schema-to-typescript/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/// <reference types="node" />
22

33
import { readFileSync } from "fs";
4-
import type { JSONSchema4 } from "json-schema";
4+
import type { JSONSchema4 } from "./types/json-schema";
55
import type { ParserOptions as $RefOptions } from "@apidevtools/json-schema-ref-parser";
6-
import { cloneDeep, endsWith, merge } from "lodash";
6+
import { cloneDeep, endsWith, merge } from "./lodash";
77
import { dirname } from "path";
88
import { format } from "./formatter";
99
import { generate } from "./generator";

packages/core/sdk/src/vendor/json-schema-to-typescript/linker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Parent } from "./types/JSONSchema";
22
import type { JSONSchema, LinkedJSONSchema } from "./types/JSONSchema";
3-
import { isPlainObject } from "lodash";
4-
import type { JSONSchema4Type } from "json-schema";
3+
import { isPlainObject } from "./lodash";
4+
import type { JSONSchema4Type } from "./types/json-schema";
55

66
/**
77
* Traverses over the schema, giving each node a reference to its
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
export const isPlainObject = (value: unknown): value is Record<string, unknown> => {
2+
if (value === null || typeof value !== "object") return false;
3+
const prototype = Object.getPrototypeOf(value);
4+
return prototype === Object.prototype || prototype === null;
5+
};
6+
7+
export const cloneDeep = <T>(value: T): T => structuredClone(value);
8+
9+
export const endsWith = (value: string, suffix: string): boolean => value.endsWith(suffix);
10+
11+
export const merge = <T extends Record<string, unknown>>(
12+
target: T,
13+
...sources: ReadonlyArray<Record<string, unknown> | undefined>
14+
): T => {
15+
for (const source of sources) {
16+
if (!source) continue;
17+
for (const [key, value] of Object.entries(source)) {
18+
const current = target[key];
19+
target[key] =
20+
isPlainObject(current) && isPlainObject(value)
21+
? merge({ ...current }, value)
22+
: cloneDeep(value);
23+
}
24+
}
25+
return target;
26+
};
27+
28+
export const findKey = <T>(
29+
object: Record<string, T> | undefined,
30+
predicate: (value: T, key: string) => boolean,
31+
): string | undefined => {
32+
if (!object) return undefined;
33+
for (const [key, value] of Object.entries(object)) {
34+
if (predicate(value, key)) return key;
35+
}
36+
return undefined;
37+
};
38+
39+
export const includes = <T>(array: ReadonlyArray<T>, value: T): boolean => array.includes(value);
40+
41+
export const map = <T, U>(
42+
object: Record<string, T> | undefined,
43+
iteratee: (value: T, key: string) => U,
44+
): U[] => (object ? Object.entries(object).map(([key, value]) => iteratee(value, key)) : []);
45+
46+
export const memoize = <F extends (arg: any, ...rest: any[]) => any>(fn: F): F => {
47+
const cache = new Map<Parameters<F>[0], ReturnType<F>>();
48+
return ((arg: Parameters<F>[0], ...rest: unknown[]) => {
49+
if (cache.has(arg)) return cache.get(arg);
50+
const value = fn(arg, ...rest);
51+
cache.set(arg, value);
52+
return value;
53+
}) as F;
54+
};
55+
56+
export const omit = <T extends object, K extends keyof T>(object: T, ...keys: K[]): Omit<T, K> => {
57+
const omitted = new Set<PropertyKey>(keys);
58+
return Object.fromEntries(
59+
Object.entries(object).filter(([key]) => !omitted.has(key)),
60+
) as Omit<T, K>;
61+
};
62+
63+
export const uniqBy = <T>(items: ReadonlyArray<T>, iteratee: (value: T) => string): T[] => {
64+
const seen = new Set<string>();
65+
const result: T[] = [];
66+
for (const item of items) {
67+
const key = iteratee(item);
68+
if (seen.has(key)) continue;
69+
seen.add(key);
70+
result.push(item);
71+
}
72+
return result;
73+
};
74+
75+
export const deburr = (value: string): string =>
76+
value.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
77+
78+
export const trim = (value: string): string => value.trim();
79+
80+
export const upperFirst = (value: string): string =>
81+
value.length === 0 ? value : value[0]!.toUpperCase() + value.slice(1);

packages/core/sdk/src/vendor/json-schema-to-typescript/optimizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { uniqBy } from "lodash";
1+
import { uniqBy } from "./lodash";
22
import type { Options } from ".";
33
import { generateType } from "./generator";
44
import { T_ANY, T_UNKNOWN } from "./types/AST";

packages/core/sdk/src/vendor/json-schema-to-typescript/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { JSONSchema4Type, JSONSchema4TypeName } from "json-schema";
2-
import { findKey, includes, isPlainObject, map, memoize, omit } from "lodash";
1+
import type { JSONSchema4Type, JSONSchema4TypeName } from "./types/json-schema";
2+
import { findKey, includes, isPlainObject, map, memoize, omit } from "./lodash";
33
import { format } from "util";
44
import type { Options } from "./";
55
import { applySchemaTyping } from "./applySchemaTyping";

packages/core/sdk/src/vendor/json-schema-to-typescript/types/AST.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { JSONSchema4Type } from "json-schema";
1+
import type { JSONSchema4Type } from "./json-schema";
22

33
export type AST_TYPE = AST["type"];
44

packages/core/sdk/src/vendor/json-schema-to-typescript/types/JSONSchema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { JSONSchema4, JSONSchema4Type, JSONSchema4TypeName } from "json-schema";
2-
import { isPlainObject, memoize } from "lodash";
1+
import type { JSONSchema4, JSONSchema4Type, JSONSchema4TypeName } from "./json-schema";
2+
import { isPlainObject, memoize } from "../lodash";
33

44
export type SchemaType =
55
| "ALL_OF"

0 commit comments

Comments
 (0)