mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-11 18:24:43 +02:00
Server: Moved database types to separate file
This commit is contained in:
parent
82b157b491
commit
f922e9a239
Binary file not shown.
@ -5,7 +5,7 @@ it('should pass', async function() {
|
||||
// import { afterAllTests, beforeAllDb, beforeEachDb, db } from "./utils/testing/testUtils";
|
||||
// import sqlts from '@rmp135/sql-ts';
|
||||
// import config from "./config";
|
||||
// import { connectDb, DbConnection, disconnectDb, migrateDown, migrateList, migrateUp, nextMigration } from "./db";
|
||||
// import { connectDb, DbConnection, disconnectDb, migrateDown, migrateList, migrateUp, nextMigration } from "./services/database/types";
|
||||
|
||||
// async function dbSchemaSnapshot(db:DbConnection):Promise<any> {
|
||||
// return sqlts.toObject({
|
||||
|
@ -3,6 +3,7 @@ import { DatabaseConfig } from './utils/types';
|
||||
import * as pathUtils from 'path';
|
||||
import time from '@joplin/lib/time';
|
||||
import Logger from '@joplin/lib/Logger';
|
||||
import { databaseSchema } from './services/database/types';
|
||||
|
||||
// Make sure bigInteger values are numbers and not strings
|
||||
//
|
||||
@ -305,401 +306,3 @@ export async function connectionCheck(db: DbConnection): Promise<ConnectionCheck
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export type Uuid = string;
|
||||
|
||||
export enum ItemAddressingType {
|
||||
Id = 1,
|
||||
Path,
|
||||
}
|
||||
|
||||
export enum NotificationLevel {
|
||||
Important = 10,
|
||||
Normal = 20,
|
||||
}
|
||||
|
||||
export enum ItemType {
|
||||
Item = 1,
|
||||
UserItem = 2,
|
||||
User,
|
||||
}
|
||||
|
||||
export enum EmailSender {
|
||||
NoReply = 1,
|
||||
Support = 2,
|
||||
}
|
||||
|
||||
export enum ChangeType {
|
||||
Create = 1,
|
||||
Update = 2,
|
||||
Delete = 3,
|
||||
}
|
||||
|
||||
export enum UserFlagType {
|
||||
FailedPaymentWarning = 1,
|
||||
FailedPaymentFinal = 2,
|
||||
AccountOverLimit = 3,
|
||||
AccountWithoutSubscription = 4,
|
||||
SubscriptionCancelled = 5,
|
||||
ManuallyDisabled = 6,
|
||||
}
|
||||
|
||||
export enum FileContentType {
|
||||
Any = 1,
|
||||
JoplinItem = 2,
|
||||
}
|
||||
|
||||
export function changeTypeToString(t: ChangeType): string {
|
||||
if (t === ChangeType.Create) return 'create';
|
||||
if (t === ChangeType.Update) return 'update';
|
||||
if (t === ChangeType.Delete) return 'delete';
|
||||
throw new Error(`Unkown type: ${t}`);
|
||||
}
|
||||
|
||||
export enum ShareType {
|
||||
Note = 1, // When a note is shared via a public link
|
||||
Folder = 3, // When a complete folder is shared with another Joplin Server user
|
||||
}
|
||||
|
||||
export enum ShareUserStatus {
|
||||
Waiting = 0,
|
||||
Accepted = 1,
|
||||
Rejected = 2,
|
||||
}
|
||||
|
||||
export interface WithDates {
|
||||
updated_time?: number;
|
||||
created_time?: number;
|
||||
}
|
||||
|
||||
export interface WithUuid {
|
||||
id?: Uuid;
|
||||
}
|
||||
|
||||
interface DatabaseTableColumn {
|
||||
type: string;
|
||||
}
|
||||
|
||||
interface DatabaseTable {
|
||||
[key: string]: DatabaseTableColumn;
|
||||
}
|
||||
|
||||
interface DatabaseTables {
|
||||
[key: string]: DatabaseTable;
|
||||
}
|
||||
|
||||
// AUTO-GENERATED-TYPES
|
||||
// Auto-generated using `npm run generate-types`
|
||||
export interface Session extends WithDates, WithUuid {
|
||||
user_id?: Uuid;
|
||||
auth_code?: string;
|
||||
}
|
||||
|
||||
export interface File {
|
||||
id?: Uuid;
|
||||
owner_id?: Uuid;
|
||||
name?: string;
|
||||
content?: any;
|
||||
mime_type?: string;
|
||||
size?: number;
|
||||
is_directory?: number;
|
||||
is_root?: number;
|
||||
parent_id?: Uuid;
|
||||
updated_time?: string;
|
||||
created_time?: string;
|
||||
source_file_id?: Uuid;
|
||||
content_type?: number;
|
||||
content_id?: Uuid;
|
||||
}
|
||||
|
||||
export interface ApiClient extends WithDates, WithUuid {
|
||||
name?: string;
|
||||
secret?: string;
|
||||
}
|
||||
|
||||
export interface Notification extends WithDates, WithUuid {
|
||||
owner_id?: Uuid;
|
||||
level?: NotificationLevel;
|
||||
key?: string;
|
||||
message?: string;
|
||||
read?: number;
|
||||
canBeDismissed?: number;
|
||||
}
|
||||
|
||||
export interface ShareUser extends WithDates, WithUuid {
|
||||
share_id?: Uuid;
|
||||
user_id?: Uuid;
|
||||
status?: ShareUserStatus;
|
||||
}
|
||||
|
||||
export interface Item extends WithDates, WithUuid {
|
||||
name?: string;
|
||||
mime_type?: string;
|
||||
content?: Buffer;
|
||||
content_size?: number;
|
||||
jop_id?: Uuid;
|
||||
jop_parent_id?: Uuid;
|
||||
jop_share_id?: Uuid;
|
||||
jop_type?: number;
|
||||
jop_encryption_applied?: number;
|
||||
jop_updated_time?: number;
|
||||
}
|
||||
|
||||
export interface UserItem extends WithDates {
|
||||
id?: number;
|
||||
user_id?: Uuid;
|
||||
item_id?: Uuid;
|
||||
}
|
||||
|
||||
export interface ItemResource {
|
||||
id?: number;
|
||||
item_id?: Uuid;
|
||||
resource_id?: Uuid;
|
||||
}
|
||||
|
||||
export interface KeyValue {
|
||||
id?: number;
|
||||
key?: string;
|
||||
type?: number;
|
||||
value?: string;
|
||||
}
|
||||
|
||||
export interface Share extends WithDates, WithUuid {
|
||||
owner_id?: Uuid;
|
||||
item_id?: Uuid;
|
||||
type?: ShareType;
|
||||
folder_id?: Uuid;
|
||||
note_id?: Uuid;
|
||||
}
|
||||
|
||||
export interface Change extends WithDates, WithUuid {
|
||||
counter?: number;
|
||||
item_type?: ItemType;
|
||||
item_id?: Uuid;
|
||||
item_name?: string;
|
||||
type?: ChangeType;
|
||||
previous_item?: string;
|
||||
user_id?: Uuid;
|
||||
}
|
||||
|
||||
export interface Email extends WithDates {
|
||||
id?: number;
|
||||
recipient_name?: string;
|
||||
recipient_email?: string;
|
||||
recipient_id?: Uuid;
|
||||
sender_id?: EmailSender;
|
||||
subject?: string;
|
||||
body?: string;
|
||||
sent_time?: number;
|
||||
sent_success?: number;
|
||||
error?: string;
|
||||
key?: string;
|
||||
}
|
||||
|
||||
export interface Token extends WithDates {
|
||||
id?: number;
|
||||
value?: string;
|
||||
user_id?: Uuid;
|
||||
}
|
||||
|
||||
export interface Subscription {
|
||||
id?: number;
|
||||
user_id?: Uuid;
|
||||
stripe_user_id?: Uuid;
|
||||
stripe_subscription_id?: Uuid;
|
||||
last_payment_time?: number;
|
||||
last_payment_failed_time?: number;
|
||||
updated_time?: string;
|
||||
created_time?: string;
|
||||
is_deleted?: number;
|
||||
}
|
||||
|
||||
export interface User extends WithDates, WithUuid {
|
||||
email?: string;
|
||||
password?: string;
|
||||
full_name?: string;
|
||||
is_admin?: number;
|
||||
email_confirmed?: number;
|
||||
must_set_password?: number;
|
||||
account_type?: number;
|
||||
can_upload?: number;
|
||||
max_item_size?: number | null;
|
||||
can_share_folder?: number | null;
|
||||
can_share_note?: number | null;
|
||||
max_total_item_size?: number | null;
|
||||
total_item_size?: number;
|
||||
enabled?: number;
|
||||
}
|
||||
|
||||
export interface UserFlag extends WithDates {
|
||||
id?: number;
|
||||
user_id?: Uuid;
|
||||
type?: UserFlagType;
|
||||
}
|
||||
|
||||
export const databaseSchema: DatabaseTables = {
|
||||
sessions: {
|
||||
id: { type: 'string' },
|
||||
user_id: { type: 'string' },
|
||||
auth_code: { type: 'string' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
},
|
||||
files: {
|
||||
id: { type: 'string' },
|
||||
owner_id: { type: 'string' },
|
||||
name: { type: 'string' },
|
||||
content: { type: 'any' },
|
||||
mime_type: { type: 'string' },
|
||||
size: { type: 'number' },
|
||||
is_directory: { type: 'number' },
|
||||
is_root: { type: 'number' },
|
||||
parent_id: { type: 'string' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
source_file_id: { type: 'string' },
|
||||
content_type: { type: 'number' },
|
||||
content_id: { type: 'string' },
|
||||
},
|
||||
api_clients: {
|
||||
id: { type: 'string' },
|
||||
name: { type: 'string' },
|
||||
secret: { type: 'string' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
},
|
||||
notifications: {
|
||||
id: { type: 'string' },
|
||||
owner_id: { type: 'string' },
|
||||
level: { type: 'number' },
|
||||
key: { type: 'string' },
|
||||
message: { type: 'string' },
|
||||
read: { type: 'number' },
|
||||
canBeDismissed: { type: 'number' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
},
|
||||
share_users: {
|
||||
id: { type: 'string' },
|
||||
share_id: { type: 'string' },
|
||||
user_id: { type: 'string' },
|
||||
status: { type: 'number' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
},
|
||||
items: {
|
||||
id: { type: 'string' },
|
||||
name: { type: 'string' },
|
||||
mime_type: { type: 'string' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
content: { type: 'any' },
|
||||
content_size: { type: 'number' },
|
||||
jop_id: { type: 'string' },
|
||||
jop_parent_id: { type: 'string' },
|
||||
jop_share_id: { type: 'string' },
|
||||
jop_type: { type: 'number' },
|
||||
jop_encryption_applied: { type: 'number' },
|
||||
jop_updated_time: { type: 'string' },
|
||||
},
|
||||
user_items: {
|
||||
id: { type: 'number' },
|
||||
user_id: { type: 'string' },
|
||||
item_id: { type: 'string' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
},
|
||||
item_resources: {
|
||||
id: { type: 'number' },
|
||||
item_id: { type: 'string' },
|
||||
resource_id: { type: 'string' },
|
||||
},
|
||||
key_values: {
|
||||
id: { type: 'number' },
|
||||
key: { type: 'string' },
|
||||
type: { type: 'number' },
|
||||
value: { type: 'string' },
|
||||
},
|
||||
shares: {
|
||||
id: { type: 'string' },
|
||||
owner_id: { type: 'string' },
|
||||
item_id: { type: 'string' },
|
||||
type: { type: 'number' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
folder_id: { type: 'string' },
|
||||
note_id: { type: 'string' },
|
||||
},
|
||||
changes: {
|
||||
counter: { type: 'number' },
|
||||
id: { type: 'string' },
|
||||
item_type: { type: 'number' },
|
||||
item_id: { type: 'string' },
|
||||
item_name: { type: 'string' },
|
||||
type: { type: 'number' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
previous_item: { type: 'string' },
|
||||
user_id: { type: 'string' },
|
||||
},
|
||||
emails: {
|
||||
id: { type: 'number' },
|
||||
recipient_name: { type: 'string' },
|
||||
recipient_email: { type: 'string' },
|
||||
recipient_id: { type: 'string' },
|
||||
sender_id: { type: 'number' },
|
||||
subject: { type: 'string' },
|
||||
body: { type: 'string' },
|
||||
sent_time: { type: 'string' },
|
||||
sent_success: { type: 'number' },
|
||||
error: { type: 'string' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
key: { type: 'string' },
|
||||
},
|
||||
tokens: {
|
||||
id: { type: 'number' },
|
||||
value: { type: 'string' },
|
||||
user_id: { type: 'string' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
},
|
||||
subscriptions: {
|
||||
id: { type: 'number' },
|
||||
user_id: { type: 'string' },
|
||||
stripe_user_id: { type: 'string' },
|
||||
stripe_subscription_id: { type: 'string' },
|
||||
last_payment_time: { type: 'string' },
|
||||
last_payment_failed_time: { type: 'string' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
is_deleted: { type: 'number' },
|
||||
},
|
||||
users: {
|
||||
id: { type: 'string' },
|
||||
email: { type: 'string' },
|
||||
password: { type: 'string' },
|
||||
full_name: { type: 'string' },
|
||||
is_admin: { type: 'number' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
email_confirmed: { type: 'number' },
|
||||
must_set_password: { type: 'number' },
|
||||
account_type: { type: 'number' },
|
||||
can_upload: { type: 'number' },
|
||||
max_item_size: { type: 'number' },
|
||||
can_share_folder: { type: 'number' },
|
||||
can_share_note: { type: 'number' },
|
||||
max_total_item_size: { type: 'string' },
|
||||
total_item_size: { type: 'string' },
|
||||
enabled: { type: 'number' },
|
||||
},
|
||||
user_flags: {
|
||||
id: { type: 'number' },
|
||||
user_id: { type: 'string' },
|
||||
type: { type: 'number' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
},
|
||||
};
|
||||
// AUTO-GENERATED-TYPES
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { createUserAndSession, beforeAllDb, afterAllTests, beforeEachDb, models, koaAppContext, koaNext } from '../utils/testing/testUtils';
|
||||
import { defaultAdminEmail, defaultAdminPassword, Notification } from '../db';
|
||||
import { Notification } from '../services/database/types';
|
||||
import { defaultAdminEmail, defaultAdminPassword } from '../db';
|
||||
import notificationHandler from './notificationHandler';
|
||||
|
||||
describe('notificationHandler', function() {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { AppContext, KoaNext, NotificationView } from '../utils/types';
|
||||
import { isApiRequest } from '../utils/requestUtils';
|
||||
import { defaultAdminEmail, defaultAdminPassword, NotificationLevel } from '../db';
|
||||
import { NotificationLevel } from '../services/database/types';
|
||||
import { defaultAdminEmail, defaultAdminPassword } from '../db';
|
||||
import { _ } from '@joplin/lib/locale';
|
||||
import Logger from '@joplin/lib/Logger';
|
||||
import * as MarkdownIt from 'markdown-it';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { ApiClient } from '../db';
|
||||
import { ApiClient } from '../services/database/types';
|
||||
|
||||
export default class ApiClientModel extends BaseModel<ApiClient> {
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { WithDates, WithUuid, databaseSchema, DbConnection, ItemType, Uuid, User } from '../db';
|
||||
import { WithDates, WithUuid, databaseSchema, ItemType, Uuid, User } from '../services/database/types';
|
||||
import { DbConnection } from '../db';
|
||||
import TransactionHandler from '../utils/TransactionHandler';
|
||||
import uuidgen from '../utils/uuidgen';
|
||||
import { ErrorUnprocessableEntity, ErrorBadRequest } from '../utils/errors';
|
||||
|
@ -1,7 +1,8 @@
|
||||
import { createUserAndSession, beforeAllDb, afterAllTests, beforeEachDb, models, expectThrow, createFolder, createItemTree3, expectNotThrow } from '../utils/testing/testUtils';
|
||||
import { ChangeType, Item, SqliteMaxVariableNum, Uuid } from '../db';
|
||||
import { ChangeType, Item, Uuid } from '../services/database/types';
|
||||
import { msleep } from '../utils/time';
|
||||
import { ChangePagination } from './ChangeModel';
|
||||
import { SqliteMaxVariableNum } from '../db';
|
||||
|
||||
async function makeTestItem(userId: Uuid, num: number): Promise<Item> {
|
||||
return models().item().saveForUser(userId, {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { Knex } from 'knex';
|
||||
import { Change, ChangeType, Item, SqliteMaxVariableNum, Uuid } from '../db';
|
||||
import { SqliteMaxVariableNum } from '../db';
|
||||
import { Change, ChangeType, Item, Uuid } from '../services/database/types';
|
||||
import { md5 } from '../utils/crypto';
|
||||
import { ErrorResyncRequired } from '../utils/errors';
|
||||
import BaseModel, { SaveOptions } from './BaseModel';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { EmailSender } from '../db';
|
||||
import { EmailSender } from '../services/database/types';
|
||||
import { beforeAllDb, afterAllTests, beforeEachDb, models, createUserAndSession } from '../utils/testing/testUtils';
|
||||
import paymentFailedTemplate from '../views/emails/paymentFailedTemplate';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Uuid, Email, EmailSender } from '../db';
|
||||
import { Uuid, Email, EmailSender } from '../services/database/types';
|
||||
import BaseModel from './BaseModel';
|
||||
|
||||
export interface EmailToSend {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import BaseModel, { SaveOptions, LoadOptions, DeleteOptions, ValidateOptions, AclAction } from './BaseModel';
|
||||
import { ItemType, databaseSchema, Uuid, Item, ShareType, Share, ChangeType, User, UserItem } from '../db';
|
||||
import { ItemType, databaseSchema, Uuid, Item, ShareType, Share, ChangeType, User, UserItem } from '../services/database/types';
|
||||
import { defaultPagination, paginateDbQuery, PaginatedResults, Pagination } from './utils/pagination';
|
||||
import { isJoplinItemName, isJoplinResourceBlobPath, linkedResourceIds, serializeJoplinItem, unserializeJoplinItem } from '../utils/joplinUtils';
|
||||
import { ModelType } from '@joplin/lib/BaseModel';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { resourceBlobPath } from '../utils/joplinUtils';
|
||||
import { Item, ItemResource, Uuid } from '../db';
|
||||
import { Item, ItemResource, Uuid } from '../services/database/types';
|
||||
import BaseModel from './BaseModel';
|
||||
|
||||
export default class ItemResourceModel extends BaseModel<ItemResource> {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { KeyValue } from '../db';
|
||||
import { KeyValue } from '../services/database/types';
|
||||
import BaseModel from './BaseModel';
|
||||
|
||||
export enum ValueType {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { createUserAndSession, beforeAllDb, afterAllTests, beforeEachDb, models, expectThrow } from '../utils/testing/testUtils';
|
||||
import { Notification, NotificationLevel } from '../db';
|
||||
import { Notification, NotificationLevel } from '../services/database/types';
|
||||
import { NotificationKey } from './NotificationModel';
|
||||
|
||||
describe('NotificationModel', function() {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Notification, NotificationLevel, Uuid } from '../db';
|
||||
import { Notification, NotificationLevel, Uuid } from '../services/database/types';
|
||||
import { ErrorUnprocessableEntity } from '../utils/errors';
|
||||
import BaseModel, { ValidateOptions } from './BaseModel';
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { User, Session, Uuid } from '../db';
|
||||
import { User, Session, Uuid } from '../services/database/types';
|
||||
import uuidgen from '../utils/uuidgen';
|
||||
import { ErrorForbidden } from '../utils/errors';
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { createUserAndSession, beforeAllDb, afterAllTests, beforeEachDb, models, checkThrowAsync, createItem, createItemTree } from '../utils/testing/testUtils';
|
||||
import { ErrorBadRequest, ErrorNotFound } from '../utils/errors';
|
||||
import { ShareType } from '../db';
|
||||
import { ShareType } from '../services/database/types';
|
||||
import { shareWithUserAndAccept } from '../utils/testing/shareApiUtils';
|
||||
|
||||
describe('ShareModel', function() {
|
||||
|
@ -1,12 +1,13 @@
|
||||
import { ModelType } from '@joplin/lib/BaseModel';
|
||||
import { resourceBlobPath } from '../utils/joplinUtils';
|
||||
import { Change, ChangeType, isUniqueConstraintError, Item, Share, ShareType, ShareUserStatus, User, Uuid } from '../db';
|
||||
import { Change, ChangeType, Item, Share, ShareType, ShareUserStatus, User, Uuid } from '../services/database/types';
|
||||
import { unique } from '../utils/array';
|
||||
import { ErrorBadRequest, ErrorForbidden, ErrorNotFound } from '../utils/errors';
|
||||
import { setQueryParameters } from '../utils/urlUtils';
|
||||
import BaseModel, { AclAction, DeleteOptions, ValidateOptions } from './BaseModel';
|
||||
import { userIdFromUserContentUrl } from '../utils/routeUtils';
|
||||
import { getCanShareFolder } from './utils/user';
|
||||
import { isUniqueConstraintError } from '../db';
|
||||
|
||||
export default class ShareModel extends BaseModel<Share> {
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Item, Share, ShareType, ShareUser, ShareUserStatus, User, Uuid } from '../db';
|
||||
import { Item, Share, ShareType, ShareUser, ShareUserStatus, User, Uuid } from '../services/database/types';
|
||||
import { ErrorForbidden, ErrorNotFound } from '../utils/errors';
|
||||
import BaseModel, { AclAction, DeleteOptions } from './BaseModel';
|
||||
import { getCanShareFolder } from './utils/user';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { EmailSender, Subscription, User, UserFlagType, Uuid } from '../db';
|
||||
import { EmailSender, Subscription, User, UserFlagType, Uuid } from '../services/database/types';
|
||||
import { ErrorNotFound } from '../utils/errors';
|
||||
import { Day } from '../utils/time';
|
||||
import uuidgen from '../utils/uuidgen';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Token, User, Uuid } from '../db';
|
||||
import { Token, User, Uuid } from '../services/database/types';
|
||||
import { ErrorForbidden, ErrorNotFound } from '../utils/errors';
|
||||
import uuidgen from '../utils/uuidgen';
|
||||
import BaseModel from './BaseModel';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { UserFlagType } from '../db';
|
||||
import { UserFlagType } from '../services/database/types';
|
||||
import { beforeAllDb, afterAllTests, beforeEachDb, models, createUserAndSession } from '../utils/testing/testUtils';
|
||||
|
||||
describe('UserFlagModel', function() {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { isUniqueConstraintError, User, UserFlag, UserFlagType, Uuid } from '../db';
|
||||
import { isUniqueConstraintError } from '../db';
|
||||
import { User, UserFlag, UserFlagType, Uuid } from '../services/database/types';
|
||||
import BaseModel from './BaseModel';
|
||||
|
||||
interface AddRemoveOptions {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { ChangeType, ItemType, UserItem, Uuid } from '../db';
|
||||
import { ChangeType, ItemType, UserItem, Uuid } from '../services/database/types';
|
||||
import BaseModel, { DeleteOptions, LoadOptions, SaveOptions } from './BaseModel';
|
||||
import { unique } from '../utils/array';
|
||||
import { ErrorNotFound } from '../utils/errors';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { createUserAndSession, beforeAllDb, afterAllTests, beforeEachDb, models, checkThrowAsync, createItem } from '../utils/testing/testUtils';
|
||||
import { EmailSender, User, UserFlagType } from '../db';
|
||||
import { EmailSender, User, UserFlagType } from '../services/database/types';
|
||||
import { ErrorUnprocessableEntity } from '../utils/errors';
|
||||
import { betaUserDateRange, stripeConfig } from '../utils/stripe';
|
||||
import { AccountType } from './UserModel';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import BaseModel, { AclAction, SaveOptions, ValidateOptions } from './BaseModel';
|
||||
import { EmailSender, Item, User, UserFlagType, Uuid } from '../db';
|
||||
import { EmailSender, Item, User, UserFlagType, Uuid } from '../services/database/types';
|
||||
import * as auth from '../utils/auth';
|
||||
import { ErrorUnprocessableEntity, ErrorForbidden, ErrorPayloadTooLarge, ErrorNotFound } from '../utils/errors';
|
||||
import { ModelType } from '@joplin/lib/BaseModel';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { User } from '../../db';
|
||||
import { User } from '../../services/database/types';
|
||||
import { accountByType } from '../UserModel';
|
||||
|
||||
export function getCanShareFolder(user: User): number {
|
||||
|
@ -2,7 +2,7 @@ import { beforeAllDb, afterAllTests, beforeEachDb, createUserAndSession, models,
|
||||
import { NoteEntity } from '@joplin/lib/services/database/types';
|
||||
import { ModelType } from '@joplin/lib/BaseModel';
|
||||
import { deleteApi, getApi, putApi } from '../../utils/testing/apiUtils';
|
||||
import { Item } from '../../db';
|
||||
import { Item } from '../../services/database/types';
|
||||
import { PaginatedItems, SaveFromRawContentResult } from '../../models/ItemModel';
|
||||
import { shareFolderWithUser } from '../../utils/testing/shareApiUtils';
|
||||
import { resourceBlobPath } from '../../utils/joplinUtils';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Item, Uuid } from '../../db';
|
||||
import { Item, Uuid } from '../../services/database/types';
|
||||
import { formParse } from '../../utils/requestUtils';
|
||||
import { respondWithItemContent, SubPath } from '../../utils/routeUtils';
|
||||
import Router from '../../utils/Router';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Session } from '../../db';
|
||||
import { Session } from '../../services/database/types';
|
||||
import routeHandler from '../../middleware/routeHandler';
|
||||
import { beforeAllDb, afterAllTests, beforeEachDb, koaAppContext, createUserAndSession, models } from '../../utils/testing/testUtils';
|
||||
import { AppContext } from '../../utils/types';
|
||||
|
@ -4,7 +4,7 @@ import { RouteType } from '../../utils/types';
|
||||
import { ErrorForbidden } from '../../utils/errors';
|
||||
import { AppContext } from '../../utils/types';
|
||||
import { bodyFields } from '../../utils/requestUtils';
|
||||
import { User } from '../../db';
|
||||
import { User } from '../../services/database/types';
|
||||
import limiterLoginBruteForce from '../../utils/request/limiterLoginBruteForce';
|
||||
|
||||
const router = new Router(RouteType.Api);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { ShareType, ShareUserStatus } from '../../db';
|
||||
import { ShareType, ShareUserStatus } from '../../services/database/types';
|
||||
import { beforeAllDb, afterAllTests, beforeEachDb, createUserAndSession, models, createItemTree, expectHttpError } from '../../utils/testing/testUtils';
|
||||
import { getApi, patchApi } from '../../utils/testing/apiUtils';
|
||||
import { shareWithUserAndAccept } from '../../utils/testing/shareApiUtils';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { ChangeType, Share, ShareType, ShareUser, ShareUserStatus } from '../../db';
|
||||
import { ChangeType, Share, ShareType, ShareUser, ShareUserStatus } from '../../services/database/types';
|
||||
import { beforeAllDb, afterAllTests, beforeEachDb, createUserAndSession, models, createNote, createFolder, updateItem, createItemTree, makeNoteSerializedBody, updateNote, expectHttpError, createResource } from '../../utils/testing/testUtils';
|
||||
import { postApi, patchApi, getApi, deleteApi } from '../../utils/testing/apiUtils';
|
||||
import { PaginatedDeltaChanges } from '../../models/ChangeModel';
|
||||
|
@ -49,7 +49,7 @@ describe('shares.resource', function() {
|
||||
|
||||
});
|
||||
|
||||
// import { ShareType } from '../../db';
|
||||
// import { ShareType } from '../../services/database/types';
|
||||
// import { beforeAllDb, afterAllTests, beforeEachDb, createUserAndSession, models, createResource, createItemTree2, updateNote, createNote } from '../../utils/testing/testUtils';
|
||||
// import { getApi } from '../../utils/testing/apiUtils';
|
||||
// import { shareWithUserAndAccept } from '../../utils/testing/shareApiUtils';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Share, ShareType, ShareUserStatus } from '../../db';
|
||||
import { Share, ShareType, ShareUserStatus } from '../../services/database/types';
|
||||
import { beforeAllDb, afterAllTests, beforeEachDb, createUserAndSession, models, createItemTree } from '../../utils/testing/testUtils';
|
||||
import { postApi, getApi } from '../../utils/testing/apiUtils';
|
||||
import { shareWithUserAndAccept } from '../../utils/testing/shareApiUtils';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { ErrorBadRequest, ErrorNotFound } from '../../utils/errors';
|
||||
import { Share, ShareType } from '../../db';
|
||||
import { Share, ShareType } from '../../services/database/types';
|
||||
import { bodyFields, ownerRequired } from '../../utils/requestUtils';
|
||||
import { SubPath } from '../../utils/routeUtils';
|
||||
import Router from '../../utils/Router';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { User } from '../../db';
|
||||
import { User } from '../../services/database/types';
|
||||
import { deleteApi, getApi, patchApi, postApi } from '../../utils/testing/apiUtils';
|
||||
import { beforeAllDb, afterAllTests, beforeEachDb, createUserAndSession, models } from '../../utils/testing/testUtils';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { User } from '../../db';
|
||||
import { User } from '../../services/database/types';
|
||||
import { bodyFields } from '../../utils/requestUtils';
|
||||
import { SubPath } from '../../utils/routeUtils';
|
||||
import Router from '../../utils/Router';
|
||||
|
@ -2,7 +2,7 @@ import { SubPath } from '../../utils/routeUtils';
|
||||
import Router from '../../utils/Router';
|
||||
import { RouteType } from '../../utils/types';
|
||||
import { AppContext } from '../../utils/types';
|
||||
import { changeTypeToString } from '../../db';
|
||||
import { changeTypeToString } from '../../services/database/types';
|
||||
import { PaginationOrderDir } from '../../models/utils/pagination';
|
||||
import { formatDateTime } from '../../utils/time';
|
||||
import defaultView from '../../utils/defaultView';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Session } from '../../db';
|
||||
import { Session } from '../../services/database/types';
|
||||
import routeHandler from '../../middleware/routeHandler';
|
||||
import { cookieGet } from '../../utils/cookies';
|
||||
import { beforeAllDb, afterAllTests, beforeEachDb, koaAppContext, models, parseHtml, createUser } from '../../utils/testing/testUtils';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { NotificationLevel } from '../../db';
|
||||
import { NotificationLevel } from '../../services/database/types';
|
||||
import routeHandler from '../../middleware/routeHandler';
|
||||
import { NotificationKey } from '../../models/NotificationModel';
|
||||
import { beforeAllDb, afterAllTests, beforeEachDb, koaAppContext, models, createUserAndSession } from '../../utils/testing/testUtils';
|
||||
|
@ -4,7 +4,7 @@ import { RouteType } from '../../utils/types';
|
||||
import { AppContext } from '../../utils/types';
|
||||
import { bodyFields } from '../../utils/requestUtils';
|
||||
import { ErrorNotFound } from '../../utils/errors';
|
||||
import { Notification } from '../../db';
|
||||
import { Notification } from '../../services/database/types';
|
||||
|
||||
const router = new Router(RouteType.Web);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Share, ShareType } from '../../db';
|
||||
import { Share, ShareType } from '../../services/database/types';
|
||||
import routeHandler from '../../middleware/routeHandler';
|
||||
import { ErrorForbidden } from '../../utils/errors';
|
||||
import { postApi } from '../../utils/testing/apiUtils';
|
||||
|
@ -3,7 +3,7 @@ import Router from '../../utils/Router';
|
||||
import { RouteType } from '../../utils/types';
|
||||
import { AppContext } from '../../utils/types';
|
||||
import { ErrorForbidden, ErrorNotFound } from '../../utils/errors';
|
||||
import { Item, Share } from '../../db';
|
||||
import { Item, Share } from '../../services/database/types';
|
||||
import { ModelType } from '@joplin/lib/BaseModel';
|
||||
import { FileViewerResponse, renderItem as renderJoplinItem } from '../../utils/joplinUtils';
|
||||
import { friendlySafeFilename } from '@joplin/lib/path-utils';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { findPrice, PricePeriod } from '@joplin/lib/utils/joplinCloud';
|
||||
import { UserFlagType } from '../../db';
|
||||
import { UserFlagType } from '../../services/database/types';
|
||||
import { AccountType } from '../../models/UserModel';
|
||||
import { betaUserTrialPeriodDays, isBetaUser, stripeConfig } from '../../utils/stripe';
|
||||
import { beforeAllDb, afterAllTests, beforeEachDb, models, koaAppContext, expectNotThrow } from '../../utils/testing/testUtils';
|
||||
|
@ -10,7 +10,7 @@ import Logger from '@joplin/lib/Logger';
|
||||
import getRawBody = require('raw-body');
|
||||
import { AccountType } from '../../models/UserModel';
|
||||
import { betaUserTrialPeriodDays, cancelSubscription, initStripe, isBetaUser, priceIdToAccountType, stripeConfig } from '../../utils/stripe';
|
||||
import { Subscription, UserFlagType } from '../../db';
|
||||
import { Subscription, UserFlagType } from '../../services/database/types';
|
||||
import { findPrice, PricePeriod } from '@joplin/lib/utils/joplinCloud';
|
||||
|
||||
const logger = Logger.create('/stripe');
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { User } from '../../db';
|
||||
import { User } from '../../services/database/types';
|
||||
import routeHandler from '../../middleware/routeHandler';
|
||||
import { NotificationKey } from '../../models/NotificationModel';
|
||||
import { cookieGet } from '../../utils/cookies';
|
||||
|
@ -4,7 +4,7 @@ import { RouteType } from '../../utils/types';
|
||||
import { AppContext, HttpMethod } from '../../utils/types';
|
||||
import { bodyFields, contextSessionId, formParse } from '../../utils/requestUtils';
|
||||
import { ErrorForbidden, ErrorUnprocessableEntity } from '../../utils/errors';
|
||||
import { User, UserFlagType, Uuid } from '../../db';
|
||||
import { User, UserFlagType, Uuid } from '../../services/database/types';
|
||||
import config from '../../config';
|
||||
import { View } from '../../services/MustacheService';
|
||||
import defaultView from '../../utils/defaultView';
|
||||
|
@ -2,7 +2,7 @@ import Logger from '@joplin/lib/Logger';
|
||||
import BaseService from './BaseService';
|
||||
import Mail = require('nodemailer/lib/mailer');
|
||||
import { createTransport } from 'nodemailer';
|
||||
import { Email, EmailSender } from '../db';
|
||||
import { Email, EmailSender } from '../services/database/types';
|
||||
import { errorToString } from '../utils/errors';
|
||||
import EmailModel from '../models/EmailModel';
|
||||
import { markdownBodyToHtml, markdownBodyToPlainText } from './email/utils';
|
||||
|
@ -3,7 +3,7 @@ import * as fs from 'fs-extra';
|
||||
import config from '../config';
|
||||
import { filename } from '@joplin/lib/path-utils';
|
||||
import { NotificationView } from '../utils/types';
|
||||
import { User } from '../db';
|
||||
import { User } from '../services/database/types';
|
||||
import { makeUrl, UrlType } from '../utils/routeUtils';
|
||||
|
||||
export interface RenderOptions {
|
||||
|
397
packages/server/src/services/database/types.ts
Normal file
397
packages/server/src/services/database/types.ts
Normal file
@ -0,0 +1,397 @@
|
||||
export type Uuid = string;
|
||||
|
||||
export enum ItemAddressingType {
|
||||
Id = 1,
|
||||
Path,
|
||||
}
|
||||
|
||||
export enum NotificationLevel {
|
||||
Important = 10,
|
||||
Normal = 20,
|
||||
}
|
||||
|
||||
export enum ItemType {
|
||||
Item = 1,
|
||||
UserItem = 2,
|
||||
User,
|
||||
}
|
||||
|
||||
export enum EmailSender {
|
||||
NoReply = 1,
|
||||
Support = 2,
|
||||
}
|
||||
|
||||
export enum ChangeType {
|
||||
Create = 1,
|
||||
Update = 2,
|
||||
Delete = 3,
|
||||
}
|
||||
|
||||
export enum UserFlagType {
|
||||
FailedPaymentWarning = 1,
|
||||
FailedPaymentFinal = 2,
|
||||
AccountOverLimit = 3,
|
||||
AccountWithoutSubscription = 4,
|
||||
SubscriptionCancelled = 5,
|
||||
ManuallyDisabled = 6,
|
||||
}
|
||||
|
||||
export enum FileContentType {
|
||||
Any = 1,
|
||||
JoplinItem = 2,
|
||||
}
|
||||
|
||||
export function changeTypeToString(t: ChangeType): string {
|
||||
if (t === ChangeType.Create) return 'create';
|
||||
if (t === ChangeType.Update) return 'update';
|
||||
if (t === ChangeType.Delete) return 'delete';
|
||||
throw new Error(`Unkown type: ${t}`);
|
||||
}
|
||||
|
||||
export enum ShareType {
|
||||
Note = 1, // When a note is shared via a public link
|
||||
Folder = 3, // When a complete folder is shared with another Joplin Server user
|
||||
}
|
||||
|
||||
export enum ShareUserStatus {
|
||||
Waiting = 0,
|
||||
Accepted = 1,
|
||||
Rejected = 2,
|
||||
}
|
||||
|
||||
export interface WithDates {
|
||||
updated_time?: number;
|
||||
created_time?: number;
|
||||
}
|
||||
|
||||
export interface WithUuid {
|
||||
id?: Uuid;
|
||||
}
|
||||
|
||||
interface DatabaseTableColumn {
|
||||
type: string;
|
||||
}
|
||||
|
||||
interface DatabaseTable {
|
||||
[key: string]: DatabaseTableColumn;
|
||||
}
|
||||
|
||||
interface DatabaseTables {
|
||||
[key: string]: DatabaseTable;
|
||||
}
|
||||
|
||||
// AUTO-GENERATED-TYPES
|
||||
// Auto-generated using `npm run generate-types`
|
||||
export interface Session extends WithDates, WithUuid {
|
||||
user_id?: Uuid;
|
||||
auth_code?: string;
|
||||
}
|
||||
|
||||
export interface File {
|
||||
id?: Uuid;
|
||||
owner_id?: Uuid;
|
||||
name?: string;
|
||||
content?: any;
|
||||
mime_type?: string;
|
||||
size?: number;
|
||||
is_directory?: number;
|
||||
is_root?: number;
|
||||
parent_id?: Uuid;
|
||||
updated_time?: string;
|
||||
created_time?: string;
|
||||
source_file_id?: Uuid;
|
||||
content_type?: number;
|
||||
content_id?: Uuid;
|
||||
}
|
||||
|
||||
export interface ApiClient extends WithDates, WithUuid {
|
||||
name?: string;
|
||||
secret?: string;
|
||||
}
|
||||
|
||||
export interface Notification extends WithDates, WithUuid {
|
||||
owner_id?: Uuid;
|
||||
level?: NotificationLevel;
|
||||
key?: string;
|
||||
message?: string;
|
||||
read?: number;
|
||||
canBeDismissed?: number;
|
||||
}
|
||||
|
||||
export interface ShareUser extends WithDates, WithUuid {
|
||||
share_id?: Uuid;
|
||||
user_id?: Uuid;
|
||||
status?: ShareUserStatus;
|
||||
}
|
||||
|
||||
export interface Item extends WithDates, WithUuid {
|
||||
name?: string;
|
||||
mime_type?: string;
|
||||
content?: Buffer;
|
||||
content_size?: number;
|
||||
jop_id?: Uuid;
|
||||
jop_parent_id?: Uuid;
|
||||
jop_share_id?: Uuid;
|
||||
jop_type?: number;
|
||||
jop_encryption_applied?: number;
|
||||
jop_updated_time?: number;
|
||||
}
|
||||
|
||||
export interface UserItem extends WithDates {
|
||||
id?: number;
|
||||
user_id?: Uuid;
|
||||
item_id?: Uuid;
|
||||
}
|
||||
|
||||
export interface ItemResource {
|
||||
id?: number;
|
||||
item_id?: Uuid;
|
||||
resource_id?: Uuid;
|
||||
}
|
||||
|
||||
export interface KeyValue {
|
||||
id?: number;
|
||||
key?: string;
|
||||
type?: number;
|
||||
value?: string;
|
||||
}
|
||||
|
||||
export interface Share extends WithDates, WithUuid {
|
||||
owner_id?: Uuid;
|
||||
item_id?: Uuid;
|
||||
type?: ShareType;
|
||||
folder_id?: Uuid;
|
||||
note_id?: Uuid;
|
||||
}
|
||||
|
||||
export interface Change extends WithDates, WithUuid {
|
||||
counter?: number;
|
||||
item_type?: ItemType;
|
||||
item_id?: Uuid;
|
||||
item_name?: string;
|
||||
type?: ChangeType;
|
||||
previous_item?: string;
|
||||
user_id?: Uuid;
|
||||
}
|
||||
|
||||
export interface Email extends WithDates {
|
||||
id?: number;
|
||||
recipient_name?: string;
|
||||
recipient_email?: string;
|
||||
recipient_id?: Uuid;
|
||||
sender_id?: EmailSender;
|
||||
subject?: string;
|
||||
body?: string;
|
||||
sent_time?: number;
|
||||
sent_success?: number;
|
||||
error?: string;
|
||||
key?: string;
|
||||
}
|
||||
|
||||
export interface Token extends WithDates {
|
||||
id?: number;
|
||||
value?: string;
|
||||
user_id?: Uuid;
|
||||
}
|
||||
|
||||
export interface Subscription {
|
||||
id?: number;
|
||||
user_id?: Uuid;
|
||||
stripe_user_id?: Uuid;
|
||||
stripe_subscription_id?: Uuid;
|
||||
last_payment_time?: number;
|
||||
last_payment_failed_time?: number;
|
||||
updated_time?: string;
|
||||
created_time?: string;
|
||||
is_deleted?: number;
|
||||
}
|
||||
|
||||
export interface User extends WithDates, WithUuid {
|
||||
email?: string;
|
||||
password?: string;
|
||||
full_name?: string;
|
||||
is_admin?: number;
|
||||
email_confirmed?: number;
|
||||
must_set_password?: number;
|
||||
account_type?: number;
|
||||
can_upload?: number;
|
||||
max_item_size?: number | null;
|
||||
can_share_folder?: number | null;
|
||||
can_share_note?: number | null;
|
||||
max_total_item_size?: number | null;
|
||||
total_item_size?: number;
|
||||
enabled?: number;
|
||||
}
|
||||
|
||||
export interface UserFlag extends WithDates {
|
||||
id?: number;
|
||||
user_id?: Uuid;
|
||||
type?: UserFlagType;
|
||||
}
|
||||
|
||||
export const databaseSchema: DatabaseTables = {
|
||||
sessions: {
|
||||
id: { type: 'string' },
|
||||
user_id: { type: 'string' },
|
||||
auth_code: { type: 'string' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
},
|
||||
files: {
|
||||
id: { type: 'string' },
|
||||
owner_id: { type: 'string' },
|
||||
name: { type: 'string' },
|
||||
content: { type: 'any' },
|
||||
mime_type: { type: 'string' },
|
||||
size: { type: 'number' },
|
||||
is_directory: { type: 'number' },
|
||||
is_root: { type: 'number' },
|
||||
parent_id: { type: 'string' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
source_file_id: { type: 'string' },
|
||||
content_type: { type: 'number' },
|
||||
content_id: { type: 'string' },
|
||||
},
|
||||
api_clients: {
|
||||
id: { type: 'string' },
|
||||
name: { type: 'string' },
|
||||
secret: { type: 'string' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
},
|
||||
notifications: {
|
||||
id: { type: 'string' },
|
||||
owner_id: { type: 'string' },
|
||||
level: { type: 'number' },
|
||||
key: { type: 'string' },
|
||||
message: { type: 'string' },
|
||||
read: { type: 'number' },
|
||||
canBeDismissed: { type: 'number' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
},
|
||||
share_users: {
|
||||
id: { type: 'string' },
|
||||
share_id: { type: 'string' },
|
||||
user_id: { type: 'string' },
|
||||
status: { type: 'number' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
},
|
||||
items: {
|
||||
id: { type: 'string' },
|
||||
name: { type: 'string' },
|
||||
mime_type: { type: 'string' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
content: { type: 'any' },
|
||||
content_size: { type: 'number' },
|
||||
jop_id: { type: 'string' },
|
||||
jop_parent_id: { type: 'string' },
|
||||
jop_share_id: { type: 'string' },
|
||||
jop_type: { type: 'number' },
|
||||
jop_encryption_applied: { type: 'number' },
|
||||
jop_updated_time: { type: 'string' },
|
||||
},
|
||||
user_items: {
|
||||
id: { type: 'number' },
|
||||
user_id: { type: 'string' },
|
||||
item_id: { type: 'string' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
},
|
||||
item_resources: {
|
||||
id: { type: 'number' },
|
||||
item_id: { type: 'string' },
|
||||
resource_id: { type: 'string' },
|
||||
},
|
||||
key_values: {
|
||||
id: { type: 'number' },
|
||||
key: { type: 'string' },
|
||||
type: { type: 'number' },
|
||||
value: { type: 'string' },
|
||||
},
|
||||
shares: {
|
||||
id: { type: 'string' },
|
||||
owner_id: { type: 'string' },
|
||||
item_id: { type: 'string' },
|
||||
type: { type: 'number' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
folder_id: { type: 'string' },
|
||||
note_id: { type: 'string' },
|
||||
},
|
||||
changes: {
|
||||
counter: { type: 'number' },
|
||||
id: { type: 'string' },
|
||||
item_type: { type: 'number' },
|
||||
item_id: { type: 'string' },
|
||||
item_name: { type: 'string' },
|
||||
type: { type: 'number' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
previous_item: { type: 'string' },
|
||||
user_id: { type: 'string' },
|
||||
},
|
||||
emails: {
|
||||
id: { type: 'number' },
|
||||
recipient_name: { type: 'string' },
|
||||
recipient_email: { type: 'string' },
|
||||
recipient_id: { type: 'string' },
|
||||
sender_id: { type: 'number' },
|
||||
subject: { type: 'string' },
|
||||
body: { type: 'string' },
|
||||
sent_time: { type: 'string' },
|
||||
sent_success: { type: 'number' },
|
||||
error: { type: 'string' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
key: { type: 'string' },
|
||||
},
|
||||
tokens: {
|
||||
id: { type: 'number' },
|
||||
value: { type: 'string' },
|
||||
user_id: { type: 'string' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
},
|
||||
subscriptions: {
|
||||
id: { type: 'number' },
|
||||
user_id: { type: 'string' },
|
||||
stripe_user_id: { type: 'string' },
|
||||
stripe_subscription_id: { type: 'string' },
|
||||
last_payment_time: { type: 'string' },
|
||||
last_payment_failed_time: { type: 'string' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
is_deleted: { type: 'number' },
|
||||
},
|
||||
users: {
|
||||
id: { type: 'string' },
|
||||
email: { type: 'string' },
|
||||
password: { type: 'string' },
|
||||
full_name: { type: 'string' },
|
||||
is_admin: { type: 'number' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
email_confirmed: { type: 'number' },
|
||||
must_set_password: { type: 'number' },
|
||||
account_type: { type: 'number' },
|
||||
can_upload: { type: 'number' },
|
||||
max_item_size: { type: 'number' },
|
||||
can_share_folder: { type: 'number' },
|
||||
can_share_note: { type: 'number' },
|
||||
max_total_item_size: { type: 'string' },
|
||||
total_item_size: { type: 'string' },
|
||||
enabled: { type: 'number' },
|
||||
},
|
||||
user_flags: {
|
||||
id: { type: 'number' },
|
||||
user_id: { type: 'string' },
|
||||
type: { type: 'number' },
|
||||
updated_time: { type: 'string' },
|
||||
created_time: { type: 'string' },
|
||||
},
|
||||
};
|
||||
// AUTO-GENERATED-TYPES
|
@ -2,7 +2,7 @@ import sqlts from '@rmp135/sql-ts';
|
||||
|
||||
require('source-map-support').install();
|
||||
|
||||
const dbFilePath: string = `${__dirname}/../../src/db.ts`;
|
||||
const dbFilePath: string = `${__dirname}/../../src/services/database/types.ts`;
|
||||
|
||||
const fileReplaceWithinMarker = '// AUTO-GENERATED-TYPES';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { User } from '../db';
|
||||
import { User } from '../services/database/types';
|
||||
import { Models } from '../models/factory';
|
||||
import { ErrorForbidden } from './errors';
|
||||
import { escapeHtml } from './htmlUtils';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Item } from '../db';
|
||||
import { Item } from '../services/database/types';
|
||||
import { itemIsEncrypted } from './joplinUtils';
|
||||
import { expectThrow } from './testing/testUtils';
|
||||
|
||||
|
@ -11,7 +11,7 @@ import MasterKey from '@joplin/lib/models/MasterKey';
|
||||
import Revision from '@joplin/lib/models/Revision';
|
||||
import { Config } from './types';
|
||||
import * as fs from 'fs-extra';
|
||||
import { Item, Share, Uuid } from '../db';
|
||||
import { Item, Share, Uuid } from '../services/database/types';
|
||||
import ItemModel from '../models/ItemModel';
|
||||
import { NoteEntity } from '@joplin/lib/services/database/types';
|
||||
import { formatDateTime } from './time';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { isValidOrigin, parseSubPath, splitItemPath } from './routeUtils';
|
||||
import { ItemAddressingType } from '../db';
|
||||
import { ItemAddressingType } from '../services/database/types';
|
||||
import { RouteType } from './types';
|
||||
|
||||
describe('routeUtils', function() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { baseUrl } from '../config';
|
||||
import { Item, ItemAddressingType, Uuid } from '../db';
|
||||
import { Item, ItemAddressingType, Uuid } from '../services/database/types';
|
||||
import { ErrorBadRequest, ErrorForbidden, ErrorNotFound } from './errors';
|
||||
import Router from './Router';
|
||||
import { AppContext, HttpMethod, RouteType } from './types';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { User } from '../db';
|
||||
import { User } from '../services/database/types';
|
||||
import { getMaxItemSize, getMaxTotalItemSize, totalSizePercent } from '../models/utils/user';
|
||||
import { formatBytes } from './bytes';
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import globalConfig from '../config';
|
||||
import { StripeConfig } from './types';
|
||||
import { Stripe } from 'stripe';
|
||||
import { Subscription, Uuid } from '../db';
|
||||
import { Subscription, Uuid } from '../services/database/types';
|
||||
import { Models } from '../models/factory';
|
||||
import { AccountType } from '../models/UserModel';
|
||||
import { findPrice, PricePeriod } from '@joplin/lib/utils/joplinCloud';
|
||||
|
@ -8,7 +8,7 @@
|
||||
// In that case, it returns the complete Koa context, which can be used in
|
||||
// particular to access the response object and test for errors.
|
||||
|
||||
import { File } from '../../db';
|
||||
import { File } from '../../services/database/types';
|
||||
import routeHandler from '../../middleware/routeHandler';
|
||||
import { PaginatedResults, Pagination, paginationToQueryParams } from '../../models/utils/pagination';
|
||||
import { AppContext } from '../types';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { FolderEntity } from '@joplin/lib/services/database/types';
|
||||
import { linkedResourceIds } from '../joplinUtils';
|
||||
import { Item, Share, ShareType, ShareUser, ShareUserStatus, User, Uuid } from '../../db';
|
||||
import { Item, Share, ShareType, ShareUser, ShareUserStatus, User, Uuid } from '../../services/database/types';
|
||||
import routeHandler from '../../middleware/routeHandler';
|
||||
import { AppContext } from '../types';
|
||||
import { patchApi, postApi } from './apiUtils';
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { User, Session, DbConnection, connectDb, disconnectDb, truncateTables, Item, Uuid } from '../../db';
|
||||
import { DbConnection, connectDb, disconnectDb, truncateTables } from '../../db';
|
||||
import { User, Session, Item, Uuid } from '../../services/database/types';
|
||||
import { createDb, CreateDbOptions } from '../../tools/dbTools';
|
||||
import modelFactory from '../../models/factory';
|
||||
import { AppContext, Env } from '../types';
|
||||
|
@ -1,11 +1,12 @@
|
||||
import { LoggerWrapper } from '@joplin/lib/Logger';
|
||||
import { StripePublicConfig } from '@joplin/lib/utils/joplinCloud';
|
||||
import * as Koa from 'koa';
|
||||
import { DbConnection, User, Uuid } from '../db';
|
||||
import { User, Uuid } from '../services/database/types';
|
||||
import { Models } from '../models/factory';
|
||||
import { Account } from '../models/UserModel';
|
||||
import { Services } from '../services/types';
|
||||
import { Routers } from './routeUtils';
|
||||
import { DbConnection } from '../db';
|
||||
|
||||
export enum Env {
|
||||
Dev = 'dev',
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { URL } from 'url';
|
||||
import config from '../config';
|
||||
import { Uuid } from '../db';
|
||||
import { Uuid } from '../services/database/types';
|
||||
|
||||
export function setQueryParameters(url: string, query: any): string {
|
||||
if (!query) return url;
|
||||
|
Loading…
Reference in New Issue
Block a user