Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/base/codemirror-editor.gts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { scheduleOnce } from '@ember/runloop';
import { eq } from '@cardstack/boxel-ui/helpers';

import {
cardIdToURL,
resolveCardReference,
trimJsonExtension,
maybeRelativeURL,
Expand Down Expand Up @@ -100,7 +101,11 @@ function makeCardRef(
): string {
if (!baseUrl) return cardUrl;
try {
return maybeRelativeURL(new URL(cardUrl), new URL(baseUrl), undefined);
return maybeRelativeURL(
cardIdToURL(cardUrl),
cardIdToURL(baseUrl),
undefined,
);
} catch {
return cardUrl;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/base/components/card-list.gts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { LoadingIndicator } from '@cardstack/boxel-ui/components';
import { cn, eq } from '@cardstack/boxel-ui/helpers';

import {
cardIdToURL,
removeFileExtension,
CardCrudFunctionsContextName,
type Query,
Expand Down Expand Up @@ -43,7 +44,7 @@ export default class CardList extends Component<Signature> {
handleCardClick(cardUrl: string, event?: Event) {
if (this.cardCrudFunctions?.viewCard) {
event?.preventDefault();
this.cardCrudFunctions.viewCard(new URL(cardUrl));
this.cardCrudFunctions.viewCard(cardIdToURL(cardUrl));
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/base/file-menu-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import CopyFileToRealmCommand from '@cardstack/boxel-host/commands/copy-file-to-
import OpenInInteractModeCommand from '@cardstack/boxel-host/commands/open-in-interact-mode';
import ShowFileCommand from '@cardstack/boxel-host/commands/show-file';
import SwitchSubmodeCommand from '@cardstack/boxel-host/commands/switch-submode';
import { cardIdToURL } from '@cardstack/runtime-common';

import type { FileDef } from './card-api';
import type { GetMenuItemParams } from './menu-items';
Expand Down Expand Up @@ -81,7 +82,7 @@ export function getDefaultFileMenuItems(
await new SwitchSubmodeCommand(params.commandContext).execute({
submode: 'code',
codePath: fileDefInstanceId
? new URL(fileDefInstanceId).href
? cardIdToURL(fileDefInstanceId).href
: undefined,
});
},
Expand Down
3 changes: 2 additions & 1 deletion packages/base/menu-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
ResolvedCodeRef,
} from '@cardstack/runtime-common';
import {
cardIdToURL,
cardTypeIcon,
identifyCard,
isRealmIndexCard,
Expand Down Expand Up @@ -148,7 +149,7 @@ export function getDefaultCardMenuItems(
action: async () => {
await new SwitchSubmodeCommand(params.commandContext).execute({
submode: 'code',
codePath: cardId ? new URL(cardId).href : undefined,
codePath: cardId ? cardIdToURL(cardId).href : undefined,
});
},
icon: CodeIcon,
Expand Down
3 changes: 2 additions & 1 deletion packages/base/skill-set.gts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import EditIcon from '@cardstack/boxel-icons/edit';
import FileTextIcon from '@cardstack/boxel-icons/file-text';

import { gt } from '@cardstack/boxel-ui/helpers';
import { cardIdToURL } from '@cardstack/runtime-common';

import {
SkillPlus,
Expand Down Expand Up @@ -444,7 +445,7 @@ export class SkillSet extends SkillPlus {
if (this.args.viewCard) {
event.preventDefault();
event.stopPropagation();
this.args.viewCard(new URL(cardUrl), 'isolated');
this.args.viewCard(cardIdToURL(cardUrl), 'isolated');
}
};

Expand Down
4 changes: 2 additions & 2 deletions packages/base/system-card.gts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import BooleanField from './boolean';
import StringField from './string';
import enumField from './enum';
import { getMenuItems } from '@cardstack/runtime-common';
import { cardIdToURL, getMenuItems } from '@cardstack/runtime-common';
import { type GetMenuItemParams } from './menu-items';
import { type MenuItemOptions, MenuItem } from '@cardstack/boxel-ui/helpers';
import SetUserSystemCardCommand from '@cardstack/boxel-host/commands/set-user-system-card';
Expand Down Expand Up @@ -214,7 +214,7 @@ class SystemCardIsolated extends Component<typeof SystemCard> {

navigateToActive = async () => {
if (this.activeSystemCardId && this.args.viewCard) {
await this.args.viewCard(new URL(this.activeSystemCardId), 'isolated');
await this.args.viewCard(cardIdToURL(this.activeSystemCardId), 'isolated');
}
};

Expand Down
11 changes: 6 additions & 5 deletions packages/host/app/commands/add-field-to-card-definition.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { service } from '@ember/service';

import { cardIdToURL } from '@cardstack/runtime-common';
import { ModuleSyntax } from '@cardstack/runtime-common/module-syntax';

import type { FieldType } from 'https://cardstack.com/base/card-api';
Expand Down Expand Up @@ -36,13 +37,13 @@ export default class AddFieldToCardDefinitionCommand extends HostBaseCommand<
): Promise<undefined> {
let moduleSource = (
await this.cardService.getSource(
new URL(input.cardDefinitionToModify.module),
cardIdToURL(input.cardDefinitionToModify.module),
)
).content;

let moduleSyntax = new ModuleSyntax(
moduleSource,
new URL(input.cardDefinitionToModify.module),
cardIdToURL(input.cardDefinitionToModify.module),
);

moduleSyntax.addField({
Expand All @@ -52,13 +53,13 @@ export default class AddFieldToCardDefinitionCommand extends HostBaseCommand<
fieldType: input.fieldType as FieldType,
fieldDefinitionType: input.fieldDefinitionType as 'field' | 'card',
incomingRelativeTo: input.incomingRelativeTo
? new URL(input.incomingRelativeTo)
? cardIdToURL(input.incomingRelativeTo)
: undefined,
outgoingRelativeTo: input.outgoingRelativeTo
? new URL(input.outgoingRelativeTo)
? cardIdToURL(input.outgoingRelativeTo)
: undefined,
outgoingRealmURL: input.outgoingRealmURL
? new URL(input.outgoingRealmURL)
? cardIdToURL(input.outgoingRealmURL)
: undefined,
addFieldAtIndex: input.addFieldAtIndex,
computedFieldFunctionSourceCode: input.computedFieldFunctionSourceCode,
Expand Down
9 changes: 5 additions & 4 deletions packages/host/app/commands/check-correctness.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { service } from '@ember/service';

import {
cardIdToURL,
isCardDocumentString,
isCardErrorJSONAPI,
type CardErrorJSONAPI,
Expand Down Expand Up @@ -192,14 +193,14 @@ export default class CheckCorrectnessCommand extends HostBaseCommand<
targetRef: string,
): { moduleURL: URL; realmURL: URL; fileURL: URL } | undefined {
try {
let fileURL = new URL(targetRef);
let fileURL = cardIdToURL(targetRef);
let realmURL = this.realm.realmOfURL(fileURL);
if (!realmURL) {
return undefined;
}

let moduleHref = fileURL.href.replace(/\.gts$/, '');
let moduleURL = new URL(moduleHref);
let moduleURL = cardIdToURL(moduleHref);
return { moduleURL, realmURL, fileURL };
} catch {
return undefined;
Expand Down Expand Up @@ -263,7 +264,7 @@ export default class CheckCorrectnessCommand extends HostBaseCommand<

private async isEmptyFileContent(targetRef: string): Promise<boolean> {
try {
let fileUrl = new URL(targetRef);
let fileUrl = cardIdToURL(targetRef);
let { status, content } = await this.cardService.getSource(fileUrl);
return status === 200 && content.trim() === '';
} catch {
Expand All @@ -289,7 +290,7 @@ export default class CheckCorrectnessCommand extends HostBaseCommand<
): Promise<string | undefined> {
try {
let { status, content } = await this.cardService.getSource(
new URL(fileUrl),
cardIdToURL(fileUrl),
);
if (status !== 200) {
return undefined;
Expand Down
10 changes: 7 additions & 3 deletions packages/host/app/commands/copy-file-to-realm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { service } from '@ember/service';

import { cardIdToURL } from '@cardstack/runtime-common';

import type * as BaseCommandModule from 'https://cardstack.com/base/command';

import HostBaseCommand from '../lib/host-base-command';
Expand Down Expand Up @@ -39,12 +41,12 @@ export default class CopyFileToRealmCommand extends HostBaseCommand<
throw new Error(`Do not have write permissions to ${targetRealm}`);
}

let sourceUrl = new URL(input.sourceFileUrl);
let sourceUrl = cardIdToURL(input.sourceFileUrl);
let filename = decodeURIComponent(
sourceUrl.pathname.split('/').pop() ?? sourceUrl.pathname,
);

let destinationUrl = new URL(filename, targetRealm);
let destinationUrl = new URL(filename, cardIdToURL(targetRealm));

let existing = await this.cardService.getSource(destinationUrl);
if (existing.status === 200 || existing.status === 406) {
Expand Down Expand Up @@ -72,7 +74,9 @@ export default class CopyFileToRealmCommand extends HostBaseCommand<
}

private async fileExists(fileUrl: string): Promise<boolean> {
let getSourceResult = await this.cardService.getSource(new URL(fileUrl));
let getSourceResult = await this.cardService.getSource(
cardIdToURL(fileUrl),
);
return getSourceResult.status !== 404;
}
}
6 changes: 4 additions & 2 deletions packages/host/app/commands/copy-source.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { service } from '@ember/service';

import { cardIdToURL } from '@cardstack/runtime-common';

import type * as BaseCommandModule from 'https://cardstack.com/base/command';

import HostBaseCommand from '../lib/host-base-command';
Expand All @@ -25,8 +27,8 @@ export default class CopySourceCommand extends HostBaseCommand<
protected async run(
input: BaseCommandModule.CopySourceInput,
): Promise<BaseCommandModule.CopySourceResult> {
const originSourceUrl = new URL(input.originSourceUrl);
const destinationSourceUrl = new URL(input.destinationSourceUrl);
const originSourceUrl = cardIdToURL(input.originSourceUrl);
const destinationSourceUrl = cardIdToURL(input.destinationSourceUrl);
let r = await this.cardService.copySource(
originSourceUrl,
destinationSourceUrl,
Expand Down
5 changes: 3 additions & 2 deletions packages/host/app/commands/create-specs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { service } from '@ember/service';

import {
cardIdToURL,
loadCardDef,
specRef,
type ResolvedCodeRef,
Expand Down Expand Up @@ -259,7 +260,7 @@ export default class CreateSpecCommand extends HostBaseCommand<

let url: string;
if (codeRef) {
let relativeTo = new URL(targetRealm);
let relativeTo = cardIdToURL(targetRealm);
let maybeAbsoluteRef = codeRefWithAbsoluteURL(codeRef, relativeTo);
if (isResolvedCodeRef(maybeAbsoluteRef)) {
codeRef = maybeAbsoluteRef;
Expand Down Expand Up @@ -382,7 +383,7 @@ async function getSpecClassFromDeclaration(
};
const loadedSpec = await loadCardDef(specCodeRef, {
loader,
relativeTo: new URL(targetRealm),
relativeTo: cardIdToURL(targetRealm),
});

if (
Expand Down
4 changes: 2 additions & 2 deletions packages/host/app/commands/create-submission-workflow.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { service } from '@ember/service';

import { isCardInstance } from '@cardstack/runtime-common';
import { cardIdToURL, isCardInstance } from '@cardstack/runtime-common';
import type { LooseSingleCardDocument } from '@cardstack/runtime-common';

import type * as BaseCommandModule from 'https://cardstack.com/base/command';
Expand Down Expand Up @@ -60,7 +60,7 @@ export default class CreateSubmissionWorkflowCommand extends HostBaseCommand<

// Save the workflow card in the user's realm (where the listing lives)
let workflowRealm =
this.realm.realmOfURL(new URL(listingId))?.href ?? realm;
this.realm.realmOfURL(cardIdToURL(listingId))?.href ?? realm;

// Step 1: Create the SubmissionWorkflowCard with listing linked
let catalogRealm = this.catalogRealm;
Expand Down
4 changes: 4 additions & 0 deletions packages/host/app/commands/evaluate-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* Used by the software-factory's EvalValidationStep via `_run-command`.
*/

import { cardIdToURL } from '@cardstack/runtime-common';

import type * as BaseCommandModule from 'https://cardstack.com/base/command';

import HostBaseCommand from '../lib/host-base-command';
Expand Down Expand Up @@ -70,6 +72,8 @@ export default class EvaluateModuleCommand extends HostBaseCommand<
* Throws if validation fails.
*/
private validateModuleUrl(moduleUrl: string, realmUrl: string): void {
moduleUrl = cardIdToURL(moduleUrl).href;
realmUrl = cardIdToURL(realmUrl).href;
this.assertHttpOrHttpsUrl(moduleUrl, 'moduleUrl');
this.assertHttpOrHttpsUrl(realmUrl, 'realmUrl');

Expand Down
3 changes: 2 additions & 1 deletion packages/host/app/commands/generate-example-cards.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { service } from '@ember/service';

import {
cardIdToURL,
isCardInstance,
type LooseSingleCardDocument,
} from '@cardstack/runtime-common';
Expand Down Expand Up @@ -284,7 +285,7 @@ function resolveExampleCodeRef(
return codeRef;
}
try {
const relativeTo = realm ? new URL(realm) : undefined;
const relativeTo = realm ? cardIdToURL(realm) : undefined;
const resolved = codeRefWithAbsoluteURL(
codeRef,
relativeTo,
Expand Down
6 changes: 5 additions & 1 deletion packages/host/app/commands/instantiate-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import { service } from '@ember/service';

import { cardIdToURL } from '@cardstack/runtime-common';

import type * as BaseCommandModule from 'https://cardstack.com/base/command';

import HostBaseCommand from '../lib/host-base-command';
Expand Down Expand Up @@ -110,7 +112,7 @@ export default class InstantiateCardCommand extends HostBaseCommand<
await this.store.__dangerousCreateFromSerialized(
doc.data,
doc,
resolveFrom ? new URL(resolveFrom) : undefined,
resolveFrom ? cardIdToURL(resolveFrom) : undefined,
);

return new commandModule.InstantiateCardResult({ passed: true });
Expand All @@ -135,6 +137,8 @@ export default class InstantiateCardCommand extends HostBaseCommand<
* Throws if validation fails.
*/
private validateModuleUrl(moduleUrl: string, realmUrl: string): void {
moduleUrl = cardIdToURL(moduleUrl).href;
realmUrl = cardIdToURL(realmUrl).href;
this.assertHttpOrHttpsUrl(moduleUrl, 'moduleUrl');
this.assertHttpOrHttpsUrl(realmUrl, 'realmUrl');

Expand Down
Loading
Loading