Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix serializer extractRelationships types, expose adapter properties #295

Merged
merged 4 commits into from
Apr 23, 2024
Merged
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
8 changes: 4 additions & 4 deletions addon/adapters/cloud-firestore-modular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import FirestoreDataManager from 'ember-cloud-firestore-adapter/services/-firest
import buildCollectionName from 'ember-cloud-firestore-adapter/-private/build-collection-name';
import flattenDocSnapshot from 'ember-cloud-firestore-adapter/-private/flatten-doc-snapshot';

interface AdapterOption {
export interface AdapterOption {
isRealtime?: boolean;
queryId?: string;

Expand Down Expand Up @@ -72,11 +72,11 @@ interface HasManyRelationshipMeta {

export default class CloudFirestoreModularAdapter extends Adapter {
@service('-firestore-data-manager')
private declare firestoreDataManager: FirestoreDataManager;
protected declare firestoreDataManager: FirestoreDataManager;

protected referenceKeyName = 'referenceTo';

private get isFastBoot(): boolean {
protected get isFastBoot(): boolean {
const fastboot = getOwner(this).lookup('service:fastboot');

return fastboot && fastboot.isFastBoot;
Expand Down Expand Up @@ -282,7 +282,7 @@ export default class CloudFirestoreModularAdapter extends Adapter {
});
}

private buildCollectionRef(
protected buildCollectionRef(
modelName: keyof ModelRegistry,
adapterOptions?: AdapterOption,
): CollectionReference {
Expand Down
41 changes: 3 additions & 38 deletions addon/serializers/cloud-firestore-modular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { isNone } from '@ember/utils';
import DS from 'ember-data';
import DS, { ModelSchema } from 'ember-data';
import JSONSerializer from '@ember-data/serializer/json';
import Store from '@ember-data/store';

Expand All @@ -33,43 +33,8 @@ interface RelationshipDefinition {
};
}

interface RelationshipSchema {
name: string;
kind: 'belongsTo' | 'hasMany';
type: string;
options: {
async: boolean;
polymorphic?: boolean;
as?: string;
inverse: string | null;
[key: string]: unknown;
};
}

interface AttributeSchema {
name: string;
kind?: 'attribute';
options?: Record<string, unknown>;
type?: string;
}

interface ModelClass {
modelName: string;
fields: Map<string, 'attribute' | 'belongsTo' | 'hasMany'>;
attributes: Map<string, AttributeSchema>;
relationshipsByName: Map<string, RelationshipSchema>;
eachAttribute<T>(
callback: (this: T, key: string, attribute: AttributeSchema) => void,
binding?: T
): void;
eachTransformedAttribute<T>(
callback: (this: T, key: string, relationship: RelationshipSchema) => void,
binding?: T
): void;
type ModelClass = ModelSchema & {
determineRelationshipType(descriptor: { kind: string, type: string }, store: Store): string;
eachRelationship<T>(callback: (this: T, name: string, descriptor: RelationshipSchema) => void,
binding?: T
): void;
}

export default class CloudFirestoreSerializer extends JSONSerializer {
Expand Down Expand Up @@ -105,7 +70,7 @@ export default class CloudFirestoreSerializer extends JSONSerializer {
if (cardinality === 'manyToOne') {
hasManyPath = buildCollectionName(descriptor.type);
} else {
const collectionName = buildCollectionName(modelClass.modelName);
const collectionName = buildCollectionName(modelClass.modelName as string);
const docId = resourceHash.id;

hasManyPath = `${collectionName}/${docId}/${name}`;
Expand Down
Loading