Skip to content

Commit

Permalink
Merge pull request #3460 from quantified-uncertainty/create-pull-requ…
Browse files Browse the repository at this point in the history
…est/patch

Bump versions after 0.10.0 release
  • Loading branch information
berekuk authored Dec 9, 2024
2 parents fada2fa + 5aa1472 commit 586e2f9
Show file tree
Hide file tree
Showing 16 changed files with 347 additions and 45 deletions.
7 changes: 7 additions & 0 deletions .changeset/next-release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@quri/squiggle-lang": patch
"@quri/squiggle-components": patch
"@quri/prettier-plugin-squiggle": patch
"@quri/squiggle-textmate-grammar": patch
"vscode-squiggle": patch
---
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@quri/squiggle-components",
"version": "0.10.0",
"version": "0.10.1-0",
"license": "MIT",
"engines": {
"node": ">=20.x"
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/app/ai/SquigglePlaygroundForWorkflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function SquigglePlaygroundForWorkflow({
<squiggle.components.SquigglePlayground
height={height}
defaultCode={defaultCode}
linker={llmLinker}
linker={llmLinker as any}
renderExtraControls={() => (
<div className="flex h-full items-center justify-end gap-2">
<SquigglePlaygroundVersionPicker
Expand Down
78 changes: 45 additions & 33 deletions packages/hub/src/squiggle/linker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { z } from "zod";

import { SqLinker, SqModule } from "@quri/squiggle-lang";
import {
type GuardedSquigglePackages,
type SquigglePackages,
versionedSquigglePackages,
versionSupportsSqProjectV2,
} from "@quri/versioned-squiggle-components";
Expand Down Expand Up @@ -35,38 +36,40 @@ export function serializeSourceId({ owner, slug }: ParsedSourceId): string {
return `${PREFIX}:${owner}/${slug}`;
}

const linker: SqLinker = {
resolve(name) {
return name;
},
async loadModule(sourceId: string) {
const { owner, slug } = parseSourceId(sourceId);

const data = await fetch(
`/api/get-source?${new URLSearchParams({ owner, slug })}`
).then((res) => res.json());

const parsed = z.object({ code: z.string() }).safeParse(data);
if (!parsed.success) {
throw new Error(`Failed to fetch source for ${sourceId}`);
}
async function fetchSource(sourceId: string) {
const { owner, slug } = parseSourceId(sourceId);

return new SqModule({
name: sourceId,
code: parsed.data.code,
});
},
};
const data = await fetch(
`/api/get-source?${new URLSearchParams({ owner, slug })}`
).then((res) => res.json());
const parsed = z.object({ code: z.string() }).safeParse(data);
if (!parsed.success) {
throw new Error(`Failed to fetch source for ${sourceId}`);
}

const oldLinker: OldSqLinker = {
resolve: (name) => name,
loadSource: async (sourceId: string) => {
return (await linker.loadModule(sourceId)).code;
},
};
return parsed.data.code;
}

// export directly from versioned-components?
type SquigglePackages = Awaited<ReturnType<typeof versionedSquigglePackages>>;
function getModernLinker(
squiggle: GuardedSquigglePackages<typeof versionSupportsSqProjectV2>
) {
const linker: ReturnType<typeof squiggle.lang.makeSelfContainedLinker> = {
resolve(name: string) {
return name;
},
async loadModule(sourceId: string) {
const code = await fetchSource(sourceId);

return new squiggle.lang.SqModule({
name: sourceId,
code,
}) as any;
// Different SqModule types are not compatible, so the union of `SqModule | SqModule` doesn't work.
// But this should be fine if we're careful because we instantiate the SqModule for `squiggle.lang`.
},
};
return linker;
}

// this type extraction is awkward but it works
type OldSqLinker = NonNullable<
Expand All @@ -77,11 +80,18 @@ type OldSqLinker = NonNullable<
>["linker"]
>;

const oldLinker: OldSqLinker = {
resolve: (name: string) => name,
loadSource: async (sourceId: string) => {
return await fetchSource(sourceId);
},
};

export function getHubLinker(
squiggle: Awaited<ReturnType<typeof versionedSquigglePackages>>
) {
if (versionSupportsSqProjectV2.plain(squiggle.version)) {
return linker;
if (versionSupportsSqProjectV2.object(squiggle)) {
return getModernLinker(squiggle);
} else {
return oldLinker;
}
Expand All @@ -91,7 +101,9 @@ export function sqProjectWithHubLinker(
squiggle: Awaited<ReturnType<typeof versionedSquigglePackages>>
) {
if (versionSupportsSqProjectV2.object(squiggle)) {
return new squiggle.lang.SqProject({ linker });
return new squiggle.lang.SqProject({
linker: getModernLinker(squiggle) as any,
});
} else {
return new squiggle.lang.SqProject({ linker: oldLinker });
}
Expand Down
2 changes: 1 addition & 1 deletion packages/prettier-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@quri/prettier-plugin-squiggle",
"version": "0.10.0",
"version": "0.10.1-0",
"license": "MIT",
"homepage": "https://squiggle-language.com",
"author": "Quantified Uncertainty Research Institute",
Expand Down
2 changes: 1 addition & 1 deletion packages/squiggle-lang/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@quri/squiggle-lang",
"version": "0.10.0",
"version": "0.10.1-0",
"license": "MIT",
"homepage": "https://squiggle-language.com",
"author": "Quantified Uncertainty Research Institute",
Expand Down
2 changes: 1 addition & 1 deletion packages/squiggle-lang/src/library/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Value } from "../value/index.js";
import { vString } from "../value/VString.js";

// automatically updated on release by ops/ patch-js utils
const VERSION = "0.10.0";
const VERSION = "0.10.1-0";
export function makeVersionConstant(): ImmutableMap<string, Value> {
return ImmutableMap([["System.version", vString(VERSION)]]);
}
2 changes: 1 addition & 1 deletion packages/textmate-grammar/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@quri/squiggle-textmate-grammar",
"version": "0.10.0",
"version": "0.10.1-0",
"scripts": {
"build": "mkdir -p dist && js-yaml src/squiggle.tmLanguage.yaml >dist/squiggle.tmLanguage.json && js-yaml src/squiggle.js.yaml >dist/squiggle.js.json",
"lint": "prettier --check .",
Expand Down
2 changes: 2 additions & 0 deletions packages/versioned-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
"@tailwindcss/typography": "^0.5.13",
"glob": "^10.3.12",
"lodash": "^4.17.21",
"squiggle-components-0.10.0": "npm:@quri/[email protected]",
"squiggle-components-0.8.5": "npm:@quri/[email protected]",
"squiggle-components-0.8.6": "npm:@quri/[email protected]",
"squiggle-components-0.9.0": "npm:@quri/[email protected]",
"squiggle-components-0.9.2": "npm:@quri/[email protected]",
"squiggle-components-0.9.3": "npm:@quri/[email protected]",
"squiggle-components-0.9.4": "npm:@quri/[email protected]",
"squiggle-components-0.9.5": "npm:@quri/[email protected]",
"squiggle-lang-0.10.0": "npm:@quri/[email protected]",
"squiggle-lang-0.8.5": "npm:@quri/[email protected]",
"squiggle-lang-0.8.6": "npm:@quri/[email protected]",
"squiggle-lang-0.9.0": "npm:@quri/[email protected]",
Expand Down
10 changes: 9 additions & 1 deletion packages/versioned-components/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export { SquigglePlaygroundVersionPicker } from "./SquigglePlaygroundVersionPicker.js";
export { SquiggleVersionShower } from "./SquiggleVersionShower.js";
export { versionedSquigglePackages } from "./versionedSquigglePackages.js";
export {
type SquigglePackages,
versionedSquigglePackages,
} from "./versionedSquigglePackages.js";

export {
checkSquiggleVersion,
Expand All @@ -20,3 +23,8 @@ export {
} from "./predicates.js";

export { useAdjustSquiggleVersion } from "./hooks.js";

export type {
AntiGuardedSquigglePackages,
GuardedSquigglePackages,
} from "./predicates.js";
12 changes: 12 additions & 0 deletions packages/versioned-components/src/predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,15 @@ export const versionSupportsSqProjectV2 = excludeVersions([
"0.9.4",
"0.9.5",
]);

// Useful if you need to write a function that takes `squiggle` object that was previously guarded.
export type GuardedSquigglePackages<
Guard extends CompositeGuard<SquiggleVersion>,
> = SquigglePackages<Guard extends CompositeGuard<infer T> ? T : never>;

// Useful if you need to write a function that takes `squiggle` object that was previously guarded, and the guard check fails.
export type AntiGuardedSquigglePackages<
Guard extends CompositeGuard<SquiggleVersion>,
> = SquigglePackages<
Guard extends CompositeGuard<infer T> ? Exclude<SquiggleVersion, T> : never
>;
16 changes: 13 additions & 3 deletions packages/versioned-components/src/versionedSquiggleComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { FC } from "react";
import { type SqLinker as SqLinkerV1 } from "squiggle-lang-0.9.5";

import { type SqLinker as SqLinkerV2 } from "@quri/squiggle-lang";
import { type SqLinker as SqLinkerDev } from "@quri/squiggle-lang";

import { SquiggleLangPackageTypes } from "./versionedSquiggleLang.js";
import { SquiggleVersion } from "./versions.js";
Expand All @@ -14,22 +14,27 @@ import { SquiggleVersion } from "./versions.js";
* This makes them less type-safe, but matching squiggle-lang object versions with components verisons is almost impossible without this.
*/

type SqLinkerV2 = Omit<SqLinkerDev, "loadModule"> & {
// Relax the type of `loadModule` - various versions of `SqModule` return type
// are not compatible, even if they're identical
// (because of "Types have separate declarations of a private property '_ast'" error.)
loadModule: (sourceId: string, hash?: string) => Promise<unknown>;
};

type AnySqProject = InstanceType<
SquiggleLangPackageTypes[SquiggleVersion]["SqProject"]
>;
type AnySqValuePath = InstanceType<
SquiggleLangPackageTypes[SquiggleVersion]["SqValuePath"]
>;
type AnySqLinker = SqLinkerV1 | SqLinkerV2;

type PatchSqType<Prop> = Prop extends AnySqProject
? AnySqProject
: Prop extends AnySqValuePath
? AnySqValuePath
: Prop extends AnySqLinker
? AnySqLinker
: Prop;

type PatchSqTypesInProps<Props> =
Props extends Record<string, unknown>
? { [k in keyof Props]: PatchSqType<Props[k]> }
Expand All @@ -55,6 +60,7 @@ export type SquiggleComponentsPackageTypes = {
"0.9.3": GetImportType<typeof import("squiggle-components-0.9.3")>;
"0.9.4": GetImportType<typeof import("squiggle-components-0.9.4")>;
"0.9.5": GetImportType<typeof import("squiggle-components-0.9.5")>;
"0.10.0": GetImportType<typeof import("squiggle-components-0.10.0")>;
dev: GetImportType<typeof import("@quri/squiggle-components")>;
};
export async function squiggleComponentsByVersion<T extends SquiggleVersion>(
Expand Down Expand Up @@ -91,6 +97,10 @@ export async function squiggleComponentsByVersion<T extends SquiggleVersion>(
return (await import(
"squiggle-components-0.9.5"
)) as unknown as SquiggleComponentsPackageTypes[T];
case "0.10.0":
return (await import(
"squiggle-components-0.10.0"
)) as unknown as SquiggleComponentsPackageTypes[T];
case "dev":
return (await import(
"@quri/squiggle-components"
Expand Down
5 changes: 5 additions & 0 deletions packages/versioned-components/src/versionedSquiggleLang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type SquiggleLangPackageTypes = {
"0.9.3": GetImportType<typeof import("squiggle-lang-0.9.3")>;
"0.9.4": GetImportType<typeof import("squiggle-lang-0.9.4")>;
"0.9.5": GetImportType<typeof import("squiggle-lang-0.9.5")>;
"0.10.0": GetImportType<typeof import("squiggle-lang-0.10.0")>;
dev: GetImportType<typeof import("@quri/squiggle-lang")>;
};
export async function squiggleLangByVersion<T extends SquiggleVersion>(
Expand Down Expand Up @@ -51,6 +52,10 @@ export async function squiggleLangByVersion<T extends SquiggleVersion>(
return (await import(
"squiggle-lang-0.9.5"
)) as unknown as SquiggleLangPackageTypes[T];
case "0.10.0":
return (await import(
"squiggle-lang-0.10.0"
)) as unknown as SquiggleLangPackageTypes[T];
case "dev":
return (await import(
"@quri/squiggle-lang"
Expand Down
3 changes: 2 additions & 1 deletion packages/versioned-components/src/versions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Auto-generated, don't touch.
export const squiggleVersions = [
"0.10.0",
"0.9.5",
"0.9.4",
"0.9.3",
Expand All @@ -12,7 +13,7 @@ export const squiggleVersions = [
export type SquiggleVersion = (typeof squiggleVersions)[number];

// Auto-generated, don't touch.
export const defaultSquiggleVersion: SquiggleVersion = "0.9.5";
export const defaultSquiggleVersion: SquiggleVersion = "0.10.0";
export function checkSquiggleVersion(
version: string
): version is SquiggleVersion {
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-ext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Squiggle",
"description": "Squiggle language support",
"license": "MIT",
"version": "0.10.0",
"version": "0.10.1-0",
"private": true,
"publisher": "QURI",
"repository": {
Expand Down
Loading

0 comments on commit 586e2f9

Please sign in to comment.