diff --git a/packages/model/src/-private/legacy-relationships-support.ts b/packages/model/src/-private/legacy-relationships-support.ts index 05909013c68..e15030a3ee4 100644 --- a/packages/model/src/-private/legacy-relationships-support.ts +++ b/packages/model/src/-private/legacy-relationships-support.ts @@ -27,6 +27,7 @@ import type { CollectionRelationship } from '@warp-drive/core-types/cache/relati import type { LocalRelationshipOperation } from '@warp-drive/core-types/graph'; import type { CollectionResourceRelationship, SingleResourceRelationship } from '@warp-drive/core-types/spec/raw'; +import type { ManyArray } from '../-private'; import RelatedCollection from './many-array'; import type { MinimalLegacyRecord } from './model-methods'; import type { BelongsToProxyCreateArgs, BelongsToProxyMeta } from './promise-belongs-to'; @@ -298,11 +299,11 @@ export class LegacySupport { assert('hasMany only works with the @ember-data/json-api package'); } - reloadHasMany(key: string, options?: BaseFinderOptions) { + reloadHasMany(key: string, options?: BaseFinderOptions): Promise> | PromiseManyArray { if (HAS_JSON_API_PACKAGE) { const loadingPromise = this._relationshipPromisesCache[key]; if (loadingPromise) { - return loadingPromise; + return loadingPromise as Promise>; } const relationship = this.graph.get(this.identifier, key) as CollectionEdge; const { definition, state } = relationship; @@ -313,10 +314,10 @@ export class LegacySupport { const promise = this.fetchAsyncHasMany(key, relationship, manyArray, options); if (this._relationshipProxyCache[key]) { - return this._updatePromiseProxyFor('hasMany', key, { promise }); + return this._updatePromiseProxyFor('hasMany', key, { promise }) as PromiseManyArray; } - return promise; + return promise as Promise>; } assert(`hasMany only works with the @ember-data/json-api package`); } @@ -388,7 +389,9 @@ export class LegacySupport { return promiseProxy; } - referenceFor(kind: string | null, name: string) { + referenceFor(kind: 'belongsTo', name: string): BelongsToReference; + referenceFor(kind: 'hasMany', name: string): HasManyReference; + referenceFor(kind: 'belongsTo' | 'hasMany', name: string) { let reference = this.references[name]; if (!reference) { diff --git a/packages/model/src/-private/many-array.ts b/packages/model/src/-private/many-array.ts index 0b51dae3f7a..8b12ad27391 100644 --- a/packages/model/src/-private/many-array.ts +++ b/packages/model/src/-private/many-array.ts @@ -390,10 +390,10 @@ export default class RelatedCollection extends RecordArray { /** Reloads all of the records in the manyArray. If the manyArray holds a relationship that was originally fetched using a links url - Ember Data will revisit the original links url to repopulate the + EmberData will revisit the original links url to repopulate the relationship. - If the manyArray holds the result of a `store.query()` reload will + If the ManyArray holds the result of a `store.query()` reload will re-run the original query. Example @@ -409,9 +409,9 @@ export default class RelatedCollection extends RecordArray { @method reload @public */ - reload(options?: BaseFinderOptions) { + reload(options?: BaseFinderOptions): Promise { // TODO this is odd, we don't ask the store for anything else like this? - return this._manager.reloadHasMany(this.key, options); + return this._manager.reloadHasMany(this.key, options) as Promise; } /** diff --git a/packages/model/src/-private/model-methods.ts b/packages/model/src/-private/model-methods.ts index 2f96295c4d2..51bf52127a4 100644 --- a/packages/model/src/-private/model-methods.ts +++ b/packages/model/src/-private/model-methods.ts @@ -13,6 +13,8 @@ import { RecordStore } from '@warp-drive/core-types/symbols'; import type Errors from './errors'; import { lookupLegacySupport } from './legacy-relationships-support'; import type RecordState from './record-state'; +import type BelongsToReference from './references/belongs-to'; +import type HasManyReference from './references/has-many'; export interface MinimalLegacyRecord { errors: Errors; @@ -51,11 +53,11 @@ export function unloadRecord(this: MinimalLegacyRecord) { this[RecordStore].unloadRecord(this); } -export function belongsTo(this: MinimalLegacyRecord, prop: string) { +export function belongsTo(this: MinimalLegacyRecord, prop: string): BelongsToReference { return lookupLegacySupport(this).referenceFor('belongsTo', prop); } -export function hasMany(this: MinimalLegacyRecord, prop: string) { +export function hasMany(this: MinimalLegacyRecord, prop: string): HasManyReference { return lookupLegacySupport(this).referenceFor('hasMany', prop); } diff --git a/packages/model/src/-private/promise-belongs-to.ts b/packages/model/src/-private/promise-belongs-to.ts index edf3361d58a..f8e3e29520d 100644 --- a/packages/model/src/-private/promise-belongs-to.ts +++ b/packages/model/src/-private/promise-belongs-to.ts @@ -10,7 +10,6 @@ import type { TypeFromInstanceOrString } from '@warp-drive/core-types/record'; import type { LegacySupport } from './legacy-relationships-support'; import { PromiseObject } from './promise-proxy-base'; -import type BelongsToReference from './references/belongs-to'; export interface BelongsToProxyMeta { key: string; @@ -51,9 +50,9 @@ class PromiseBelongsTo extends Extended { declare _belongsToState: BelongsToProxyMeta; @cached - get id() { + get id(): string | null { const { key, legacySupport } = this._belongsToState; - const ref = legacySupport.referenceFor('belongsTo', key) as BelongsToReference; + const ref = legacySupport.referenceFor('belongsTo', key); return ref.id(); } diff --git a/packages/model/src/-private/references/has-many.ts b/packages/model/src/-private/references/has-many.ts index be4cf3dae49..87956e8db3e 100644 --- a/packages/model/src/-private/references/has-many.ts +++ b/packages/model/src/-private/references/has-many.ts @@ -743,11 +743,11 @@ export default class HasManyReference< @param {Object} options the options to pass in. @return {Promise} a promise that resolves with the ManyArray in this has-many relationship. */ - reload(options?: BaseFinderOptions) { + reload(options?: BaseFinderOptions): Promise> { const support: LegacySupport = (LEGACY_SUPPORT as Map).get( this.___identifier )!; - return support.reloadHasMany(this.key, options); + return support.reloadHasMany(this.key, options) as Promise>; } } defineSignal(HasManyReference.prototype, '_ref', 0); diff --git a/release/core/publish/steps/generate-tarballs.ts b/release/core/publish/steps/generate-tarballs.ts index d1cf914a141..4ac5cf7f09c 100644 --- a/release/core/publish/steps/generate-tarballs.ts +++ b/release/core/publish/steps/generate-tarballs.ts @@ -4,7 +4,6 @@ import { APPLIED_STRATEGY, Package } from '../../../utils/package'; import path from 'path'; import fs from 'fs'; import { Glob } from 'bun'; -import { getFile } from '../../../utils/json-file'; const PROJECT_ROOT = process.cwd(); const TARBALL_DIR = path.join(PROJECT_ROOT, 'tmp/tarballs'); @@ -176,9 +175,13 @@ async function convertFileToModule(fileData: string, relativePath: string, pkgNa lines[i] = lines[i].replace(/^declare /, '').replaceAll(' declare ', ' '); const line = lines[i]; + if (line.includes(`import(".`) || line.includes(`import('.`)) { + throw new Error(`Unhandled Dynamic Relative Import in ${relativePath}`); + } + if (line.startsWith('import ')) { if (!line.includes(`'`)) { - throw new Error(`Unhandled import in ${relativePath}`); + throw new Error(`Unhandled Import in ${relativePath}`); } if (line.includes(`'.`)) { const importPath = line.match(/'([^']+)'/)![1]; @@ -190,7 +193,7 @@ async function convertFileToModule(fileData: string, relativePath: string, pkgNa // fix re-exports else if (line.startsWith('export {')) { if (!line.includes('}')) { - throw new Error(`Unhandled re-export in ${relativePath}`); + throw new Error(`Unhandled Re-export in ${relativePath}`); } if (line.includes(`'.`)) { const importPath = line.match(/'([^']+)'/)![1]; @@ -202,7 +205,7 @@ async function convertFileToModule(fileData: string, relativePath: string, pkgNa // fix * re-exports else if (line.startsWith('export * from')) { if (!line.includes(`'`)) { - throw new Error(`Unhandled re-export in ${relativePath}`); + throw new Error(`Unhandled Re-export in ${relativePath}`); } if (line.includes(`'.`)) { const importPath = line.match(/'([^']+)'/)![1];