Skip to content

Commit 8b4a275

Browse files
authored
chore: Apply deno fmt to workspace packages. (commontoolsinc#482)
1 parent 557426f commit 8b4a275

File tree

233 files changed

+5554
-2943
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+5554
-2943
lines changed

typescript/packages/common-builder/src/built-in.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,21 @@ export const navigateTo = createNodeFactory({
6565
// str`Hello, ${name}!`
6666
//
6767
// TODO: This should be a built-in module
68-
export function str(strings: TemplateStringsArray, ...values: any[]): OpaqueRef<string> {
68+
export function str(
69+
strings: TemplateStringsArray,
70+
...values: any[]
71+
): OpaqueRef<string> {
6972
const interpolatedString = ({
7073
strings,
7174
values,
7275
}: {
7376
strings: TemplateStringsArray;
7477
values: any[];
75-
}) => strings.reduce((result, str, i) => result + str + (i < values.length ? values[i] : ""), "");
78+
}) =>
79+
strings.reduce(
80+
(result, str, i) => result + str + (i < values.length ? values[i] : ""),
81+
"",
82+
);
7683

7784
return lift(interpolatedString)({ strings, values });
7885
}

typescript/packages/common-builder/src/index.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
export { opaqueRef as cell, stream } from "./opaque-ref.ts";
22
export { $, event, select, Spell } from "./spell.ts";
3-
export { byRef, compute, createNodeFactory, derive, handler, lift, render } from "./module.ts";
3+
export {
4+
byRef,
5+
compute,
6+
createNodeFactory,
7+
derive,
8+
handler,
9+
lift,
10+
render,
11+
} from "./module.ts";
412
export {
513
getTopFrame,
614
popFrame,
@@ -9,7 +17,14 @@ export {
917
recipe,
1018
recipeFromFrame,
1119
} from "./recipe.ts";
12-
export { fetchData, ifElse, llm, navigateTo, str, streamData } from "./built-in.ts";
20+
export {
21+
fetchData,
22+
ifElse,
23+
llm,
24+
navigateTo,
25+
str,
26+
streamData,
27+
} from "./built-in.ts";
1328
export {
1429
type Alias,
1530
type Frame,
@@ -45,4 +60,9 @@ export {
4560
} from "./types.ts";
4661

4762
// This should be a separate package, but for now it's easier to keep it here.
48-
export { createJsonSchema, deepEqual, getValueAtPath, setValueAtPath } from "./utils.ts";
63+
export {
64+
createJsonSchema,
65+
deepEqual,
66+
getValueAtPath,
67+
setValueAtPath,
68+
} from "./utils.ts";

typescript/packages/common-builder/src/module.ts

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@ import type {
1111
} from "./types.ts";
1212
import { isModule } from "./types.ts";
1313
import { opaqueRef } from "./opaque-ref.ts";
14-
import { connectInputAndOutputs, moduleToJSON, traverseValue } from "./utils.ts";
14+
import {
15+
connectInputAndOutputs,
16+
moduleToJSON,
17+
traverseValue,
18+
} from "./utils.ts";
1519
import { getTopFrame } from "./recipe.ts";
1620
import { z } from "zod";
1721
import { zodToJsonSchema } from "zod-to-json-schema";
1822

19-
export function createNodeFactory<T = any, R = any>(moduleSpec: Module): ModuleFactory<T, R> {
23+
export function createNodeFactory<T = any, R = any>(
24+
moduleSpec: Module,
25+
): ModuleFactory<T, R> {
2026
const module: Module & toJSON = {
2127
...moduleSpec,
2228
toJSON: () => moduleToJSON(module),
@@ -47,9 +53,13 @@ export function lift<T, R>(
4753
export function lift<T extends z.ZodTypeAny, R extends z.ZodTypeAny>(
4854
argumentSchema: T,
4955
resultSchema: R,
50-
implementation: (input: z.infer<typeof argumentSchema>) => z.infer<typeof resultSchema>,
56+
implementation: (
57+
input: z.infer<typeof argumentSchema>,
58+
) => z.infer<typeof resultSchema>,
59+
): ModuleFactory<T, R>;
60+
export function lift<T, R>(
61+
implementation: (input: T) => R,
5162
): ModuleFactory<T, R>;
52-
export function lift<T, R>(implementation: (input: T) => R): ModuleFactory<T, R>;
5363
export function lift<T>(
5464
implementation: (input: T) => any,
5565
): ModuleFactory<T, ReturnType<typeof implementation>>;
@@ -95,11 +105,20 @@ export function handler<E, T>(
95105
export function handler<E extends z.ZodTypeAny, T extends z.ZodTypeAny>(
96106
eventSchema: E,
97107
stateSchema: T,
98-
handler: (event: z.infer<typeof eventSchema>, props: z.infer<typeof stateSchema>) => any,
108+
handler: (
109+
event: z.infer<typeof eventSchema>,
110+
props: z.infer<typeof stateSchema>,
111+
) => any,
112+
): HandlerFactory<T, E>;
113+
export function handler<E, T>(
114+
handler: (event: E, props: T) => any,
99115
): HandlerFactory<T, E>;
100-
export function handler<E, T>(handler: (event: E, props: T) => any): HandlerFactory<T, E>;
101116
export function handler<E, T>(
102-
eventSchema: JSONSchema | z.ZodTypeAny | ((event: E, props: T) => any) | undefined,
117+
eventSchema:
118+
| JSONSchema
119+
| z.ZodTypeAny
120+
| ((event: E, props: T) => any)
121+
| undefined,
103122
stateSchema?: JSONSchema | z.ZodTypeAny,
104123
handler?: (event: E, props: T) => any,
105124
): HandlerFactory<T, E> {
@@ -115,18 +134,19 @@ export function handler<E, T>(
115134
stateSchema = zodToJsonSchema(stateSchema) as JSONSchema;
116135
}
117136

118-
const schema: JSONSchema | undefined =
119-
eventSchema || stateSchema
120-
? {
121-
type: "object",
122-
properties: {
123-
$event: eventSchema ?? {},
124-
...(stateSchema?.properties ?? {}),
125-
},
126-
}
127-
: undefined;
128-
129-
const module: Handler & toJSON & { bind: (inputs: Opaque<T>) => OpaqueRef<E> } = {
137+
const schema: JSONSchema | undefined = eventSchema || stateSchema
138+
? {
139+
type: "object",
140+
properties: {
141+
$event: eventSchema ?? {},
142+
...(stateSchema?.properties ?? {}),
143+
},
144+
}
145+
: undefined;
146+
147+
const module: Handler & toJSON & {
148+
bind: (inputs: Opaque<T>) => OpaqueRef<E>;
149+
} = {
130150
type: "javascript",
131151
implementation: handler,
132152
wrapper: "handler",
@@ -157,11 +177,14 @@ export function handler<E, T>(
157177
return factory;
158178
}
159179

160-
export const derive = <In, Out>(input: Opaque<In>, f: (input: In) => Out): OpaqueRef<Out> =>
161-
lift(f)(input);
180+
export const derive = <In, Out>(
181+
input: Opaque<In>,
182+
f: (input: In) => Out,
183+
): OpaqueRef<Out> => lift(f)(input);
162184

163185
// unsafe closures: like derive, but doesn't need any arguments
164-
export const compute: <T>(fn: () => T) => OpaqueRef<T> = (fn: () => any) => lift(fn)(undefined);
186+
export const compute: <T>(fn: () => T) => OpaqueRef<T> = (fn: () => any) =>
187+
lift(fn)(undefined);
165188

166189
// unsafe closures: like compute, but also convert all functions to handlers
167190
export const render = <T>(fn: () => T): OpaqueRef<T> =>
@@ -170,5 +193,5 @@ export const render = <T>(fn: () => T): OpaqueRef<T> =>
170193
// Modules are functions, so we need to exclude them
171194
if (!isModule(v) && typeof v === "function") return handler(v)({});
172195
else return v;
173-
}),
196+
})
174197
);

typescript/packages/common-builder/src/opaque-ref.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ export function opaqueRef<T>(value?: Opaque<T> | T): OpaqueRef<T> {
4040

4141
let unsafe_binding: { recipe: Recipe; path: PropertyKey[] } | undefined;
4242

43-
function createNestedProxy(path: PropertyKey[], target?: any): OpaqueRef<any> {
43+
function createNestedProxy(
44+
path: PropertyKey[],
45+
target?: any,
46+
): OpaqueRef<any> {
4447
const methods: OpaqueRefMethods<any> = {
4548
get: () => unsafe_materialize(unsafe_binding, path),
4649
set: (newValue: Opaque<any>) => {
@@ -65,8 +68,10 @@ export function opaqueRef<T>(value?: Opaque<T> | T): OpaqueRef<T> {
6568
path,
6669
...store,
6770
}),
68-
unsafe_bindToRecipeAndPath: (recipe: Recipe, path: PropertyKey[]) =>
69-
(unsafe_binding = { recipe, path }),
71+
unsafe_bindToRecipeAndPath: (
72+
recipe: Recipe,
73+
path: PropertyKey[],
74+
) => (unsafe_binding = { recipe, path }),
7075
unsafe_getExternal: () => {
7176
if (!unsafe_binding) return proxy;
7277
const value = unsafe_materialize(unsafe_binding, path);
@@ -89,8 +94,10 @@ export function opaqueRef<T>(value?: Opaque<T> | T): OpaqueRef<T> {
8994
});
9095
return mapFactory({
9196
list: proxy,
92-
op: recipe("mapping function", ({ element, index, array }: Opaque<any>) =>
93-
fn(element, index, array),
97+
op: recipe(
98+
"mapping function",
99+
({ element, index, array }: Opaque<any>) =>
100+
fn(element, index, array),
94101
),
95102
});
96103
},
@@ -106,7 +113,9 @@ export function opaqueRef<T>(value?: Opaque<T> | T): OpaqueRef<T> {
106113
return {
107114
next: () => {
108115
if (index >= 50) {
109-
throw new Error("Can't use iterator over an opaque value in an unlimited loop.");
116+
throw new Error(
117+
"Can't use iterator over an opaque value in an unlimited loop.",
118+
);
110119
}
111120
return {
112121
done: false,
@@ -128,7 +137,10 @@ export function opaqueRef<T>(value?: Opaque<T> | T): OpaqueRef<T> {
128137
if (typeof prop === "symbol") {
129138
return methods[prop as keyof OpaqueRefMethods<any>];
130139
} else if (prop in methods) {
131-
return createNestedProxy([...path, prop], methods[prop as keyof OpaqueRefMethods<any>]);
140+
return createNestedProxy(
141+
[...path, prop],
142+
methods[prop as keyof OpaqueRefMethods<any>],
143+
);
132144
} else return createNestedProxy([...path, prop], store);
133145
},
134146
set(_, prop, value) {

typescript/packages/common-builder/src/recipe.ts

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ export function recipe<T, R>(
9292
const frame = pushFrame();
9393
const inputs = opaqueRef<Required<T>>();
9494
const outputs = fn!(inputs);
95-
const result = factoryFromRecipe<T, R>(argumentSchema, resultSchema, inputs, outputs);
95+
const result = factoryFromRecipe<T, R>(
96+
argumentSchema,
97+
resultSchema,
98+
inputs,
99+
outputs,
100+
);
96101
popFrame(frame);
97102
return result;
98103
}
@@ -123,13 +128,19 @@ function factoryFromRecipe<T, R>(
123128
traverseValue(value, (value) => {
124129
if (canBeOpaqueRef(value)) value = makeOpaqueRef(value);
125130
if (isOpaqueRef(value)) value = value.unsafe_getExternal();
126-
if ((isOpaqueRef(value) || isShadowRef(value)) && !cells.has(value) && !shadows.has(value)) {
131+
if (
132+
(isOpaqueRef(value) || isShadowRef(value)) && !cells.has(value) &&
133+
!shadows.has(value)
134+
) {
127135
if (isOpaqueRef(value) && value.export().frame !== getTopFrame()) {
128136
value = createShadowRef(value.export().value);
129137
}
130138
if (isShadowRef(value)) {
131139
shadows.add(value);
132-
if (isOpaqueRef(value.shadowOf) && value.shadowOf.export().frame === getTopFrame()) {
140+
if (
141+
isOpaqueRef(value.shadowOf) &&
142+
value.shadowOf.export().frame === getTopFrame()
143+
) {
133144
cells.add(value.shadowOf);
134145
}
135146
} else if (isOpaqueRef(value)) {
@@ -154,7 +165,10 @@ function factoryFromRecipe<T, R>(
154165
// First from results
155166
if (typeof outputs === "object" && outputs !== null) {
156167
Object.entries(outputs).forEach(([key, value]) => {
157-
if (isOpaqueRef(value) && !value.export().path.length && !value.export().name) {
168+
if (
169+
isOpaqueRef(value) && !value.export().path.length &&
170+
!value.export().name
171+
) {
158172
value.setName(key);
159173
}
160174
});
@@ -166,7 +180,9 @@ function factoryFromRecipe<T, R>(
166180
cell.export().nodes.forEach((node: NodeRef) => {
167181
if (typeof node.inputs === "object" && node.inputs !== null) {
168182
Object.entries(node.inputs).forEach(([key, input]) => {
169-
if (isOpaqueRef(input) && input.cell === cell && !cell.export().name) {
183+
if (
184+
isOpaqueRef(input) && input.cell === cell && !cell.export().name
185+
) {
170186
cell.setName(key);
171187
}
172188
});
@@ -205,7 +221,11 @@ function factoryFromRecipe<T, R>(
205221
const result = toJSONWithAliases(outputs ?? {}, paths, true)!;
206222

207223
// Collect default values for the inputs
208-
const defaults = toJSONWithAliases(inputs.export().defaultValue ?? {}, paths, true)!;
224+
const defaults = toJSONWithAliases(
225+
inputs.export().defaultValue ?? {},
226+
paths,
227+
true,
228+
)!;
209229

210230
// Set initial values for all cells, add non-inputs defaults
211231
const initial: any = {};
@@ -236,7 +256,11 @@ function factoryFromRecipe<T, R>(
236256

237257
delete argumentSchema.properties?.[UI]; // TODO: This should be a schema for views
238258
if (argumentSchema.properties?.internal?.properties) {
239-
for (const key of Object.keys(argumentSchema.properties.internal.properties as any)) {
259+
for (
260+
const key of Object.keys(
261+
argumentSchema.properties.internal.properties as any,
262+
)
263+
) {
240264
if (key.startsWith("__#")) {
241265
delete (argumentSchema as any).properties.internal.properties[key];
242266
}
@@ -248,10 +272,9 @@ function factoryFromRecipe<T, R>(
248272
argumentSchema = argumentSchemaArg as unknown as JSONSchema;
249273
}
250274

251-
const resultSchema: JSONSchema =
252-
resultSchemaArg instanceof z.ZodType
253-
? (zodToJsonSchema(resultSchemaArg) as JSONSchema)
254-
: (resultSchemaArg ?? ({} as JSONSchema));
275+
const resultSchema: JSONSchema = resultSchemaArg instanceof z.ZodType
276+
? (zodToJsonSchema(resultSchemaArg) as JSONSchema)
277+
: (resultSchemaArg ?? ({} as JSONSchema));
255278

256279
const serializedNodes = Array.from(nodes).map((node) => {
257280
const module = toJSONWithAliases(node.module, paths) as Module;
@@ -294,7 +317,9 @@ function factoryFromRecipe<T, R>(
294317
// TODO: Does OpaqueRef cause issues here?
295318
[...cells]
296319
.filter((cell) => !cell.export().path.length) // Only bind root cells
297-
.forEach((cell) => cell.unsafe_bindToRecipeAndPath(recipeFactory, paths.get(cell)!));
320+
.forEach((cell) =>
321+
cell.unsafe_bindToRecipeAndPath(recipeFactory, paths.get(cell)!)
322+
);
298323

299324
return recipeFactory;
300325
}
@@ -307,7 +332,10 @@ export function pushFrame(frame?: Frame): Frame {
307332
return frame;
308333
}
309334

310-
export function pushFrameFromCause(cause: any, unsafe_binding?: UnsafeBinding): Frame {
335+
export function pushFrameFromCause(
336+
cause: any,
337+
unsafe_binding?: UnsafeBinding,
338+
): Frame {
311339
const frame = {
312340
parent: getTopFrame(),
313341
cause,

0 commit comments

Comments
 (0)