Skip to content

Commit

Permalink
functions: Fix to use @bouzuya/tsukota-schema
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Jul 17, 2023
1 parent c0c75a2 commit cf6984d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 42 deletions.
1 change: 1 addition & 0 deletions packages/functions/.npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@bouzuya:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
1 change: 1 addition & 0 deletions packages/functions/_env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
BUCKET_NAME=demo-project.appspot.com
GITHUB_TOKEN=ghp_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
PROJECT_ID=demo-project
8 changes: 8 additions & 0 deletions packages/functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"devDependencies": {
"@bouzuya/tsukota-account-events": "^4.0.0",
"@bouzuya/tsukota-schema": "^1.0.1",
"@types/bcryptjs": "^2.4.2",
"@types/jest": "^29.5.2",
"@types/uuid": "^9.0.1",
Expand Down
51 changes: 9 additions & 42 deletions packages/functions/src/schema/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AccountEvent } from "@bouzuya/tsukota-account-events";
import {
DocumentData,
DocumentReference,
Expand All @@ -8,14 +7,9 @@ import {
WithFieldValue,
} from "firebase-admin/firestore";
export { validateStoreAccountEventBody } from "./validate-store-account-event-body";
import * as schema from "@bouzuya/tsukota-schema";

// `/accounts/${account_id}`
export type AccountDocumentForQuery = {
deletedAt: string | null;
id: string;
name: string;
owners: string[];
};
export type AccountDocumentForQuery = schema.AccountDocumentForQuery;

const accountDocumentForQueryConverter: FirestoreDataConverter<AccountDocumentForQuery> =
{
Expand All @@ -42,8 +36,7 @@ export function getAccountDocumentForQueryRef(
.withConverter(accountDocumentForQueryConverter);
}

// `/accounts/${account_id}/events/${event_id}`
export type AccountEventDocumentForQuery = AccountEvent;
export type AccountEventDocumentForQuery = schema.AccountEventDocumentForQuery;

const accountEventDocumentForQueryConverter: FirestoreDataConverter<AccountEventDocumentForQuery> =
{
Expand Down Expand Up @@ -81,14 +74,7 @@ export function getAccountEventDocumentForQueryRef(
);
}

// `/aggregates/account/event_streams/${event_stream_id}`
export type AccountEventStreamDocument = {
id: string;
lastEventId: string;
owners: string[];
protocolVersion: number;
updatedAt: string;
};
export type AccountEventStreamDocument = schema.AccountEventStreamDocument;

const accountEventStreamDocumentConverter: FirestoreDataConverter<AccountEventStreamDocument> =
{
Expand Down Expand Up @@ -117,8 +103,7 @@ export function getAccountEventStreamDocumentRef(
.withConverter(accountEventStreamDocumentConverter);
}

// `/aggregates/account/event_streams/${event_stream_id}/events/${event_id}`
export type AccountEventDocument = AccountEvent;
export type AccountEventDocument = schema.AccountEventDocument;

const accountEventDocumentConverter: FirestoreDataConverter<AccountEventDocument> =
{
Expand Down Expand Up @@ -156,13 +141,7 @@ export function getAccountEventDocumentRef(
);
}

// `/deleted_users/${user_id}`
export type DeletedUserDocument = {
authenticationDeletedAt: string | null;
createdAt: string;
firestoreDeletedAt: string | null;
id: string;
};
export type DeletedUserDocument = schema.DeletedUserDocument;

const deletedUserDocumentConverter: FirestoreDataConverter<DeletedUserDocument> =
{
Expand All @@ -189,12 +168,7 @@ export function getDeletedUserDocumentRef(
.withConverter(deletedUserDocumentConverter);
}

// `/devices/${device_id}`
export type DeviceDocument = {
encryptedSecret: string;
id: string;
uid: string;
};
export type DeviceDocument = schema.DeviceDocument;

const deviceDocumentConverter: FirestoreDataConverter<DeviceDocument> = {
fromFirestore: (snapshot: QueryDocumentSnapshot): DeviceDocument => {
Expand All @@ -215,19 +189,12 @@ export function getDeviceDocumentRef(
.withConverter(deviceDocumentConverter);
}

// `/system/status`
export type SystemStatusDocumentForQuery = {
minAppVersion: string | null;
};
export type SystemStatusDocumentForQuery = schema.SystemStatusDocumentForQuery;

// TODO: Converter
// TODO: Ref Helper

// `/users/${user_id}`
export type UserDocument = {
id: string;
account_ids: string[];
};
export type UserDocument = schema.UserDocument;

const userDocumentConverter: FirestoreDataConverter<UserDocument> = {
fromFirestore: function (
Expand Down

0 comments on commit cf6984d

Please sign in to comment.