Browse Source

Split packages

Use monorepo structure for app, core, and plugin projects.
feature/transactions
TheoryOfNekomata 4 years ago
parent
commit
f765207a20
63 changed files with 135 additions and 44 deletions
  1. +6
    -6
      .gitignore
  2. +0
    -0
      packages/app/.babelrc
  3. +0
    -0
      packages/app/.sequelizerc
  4. +0
    -0
      packages/app/README.md
  5. +0
    -0
      packages/app/config/config.js
  6. +0
    -0
      packages/app/migrate.ts
  7. +0
    -0
      packages/app/next-env.d.ts
  8. +0
    -0
      packages/app/next.config.js
  9. +1
    -1
      packages/app/package.json
  10. +0
    -0
      packages/app/public/favicon.ico
  11. +0
    -0
      packages/app/public/vercel.svg
  12. +0
    -0
      packages/app/src/assets/global.css
  13. +0
    -0
      packages/app/src/assets/mobiledoc.css
  14. +0
    -0
      packages/app/src/assets/theme.css
  15. +0
    -0
      packages/app/src/components/Editor/Editor.tsx
  16. +0
    -0
      packages/app/src/components/Icon/Icon.tsx
  17. +0
    -0
      packages/app/src/components/Navbar/Navbar.tsx
  18. +0
    -0
      packages/app/src/components/PrimaryNavItem/PrimaryNavItem.tsx
  19. +0
    -0
      packages/app/src/components/SecondaryNavItem/SecondaryNavItem.tsx
  20. +0
    -0
      packages/app/src/controllers/Folder.ts
  21. +0
    -0
      packages/app/src/controllers/Note.ts
  22. +0
    -0
      packages/app/src/models.ts
  23. +0
    -0
      packages/app/src/models/Folder.ts
  24. +0
    -0
      packages/app/src/models/Note.ts
  25. +0
    -0
      packages/app/src/models/Operation.ts
  26. +0
    -0
      packages/app/src/models/Tag.ts
  27. +0
    -0
      packages/app/src/models/Transaction.ts
  28. +0
    -0
      packages/app/src/pages/_app.tsx
  29. +0
    -0
      packages/app/src/pages/_document.tsx
  30. +0
    -0
      packages/app/src/pages/api/folders.ts
  31. +0
    -0
      packages/app/src/pages/api/folders/[id].ts
  32. +0
    -0
      packages/app/src/pages/api/notes.ts
  33. +0
    -0
      packages/app/src/pages/api/notes/[id].ts
  34. +0
    -0
      packages/app/src/pages/notes.tsx
  35. +0
    -0
      packages/app/src/pages/notes/[id].tsx
  36. +0
    -0
      packages/app/src/seeds.ts
  37. +0
    -0
      packages/app/src/services/LocalStorage.ts
  38. +0
    -0
      packages/app/src/services/Operation.ts
  39. +0
    -0
      packages/app/src/services/Storage.ts
  40. +0
    -0
      packages/app/src/services/entities/Folder.ts
  41. +0
    -0
      packages/app/src/services/entities/Note.ts
  42. +0
    -0
      packages/app/src/utilities/ColumnTypes.ts
  43. +0
    -0
      packages/app/src/utilities/Date.ts
  44. +0
    -0
      packages/app/src/utilities/Id.ts
  45. +0
    -0
      packages/app/src/utilities/ORM.ts
  46. +0
    -0
      packages/app/src/utilities/Response.ts
  47. +0
    -0
      packages/app/src/utilities/Serialization.ts
  48. +0
    -0
      packages/app/tsconfig.json
  49. +0
    -0
      packages/app/yarn.lock
  50. +2
    -2
      packages/app/zeichen.config.ts
  51. +5
    -0
      packages/core/plugin.ts
  52. +1
    -1
      packages/core/storage.ts
  53. +0
    -0
      packages/plugin-local-storage/Engine.ts
  54. +5
    -5
      packages/plugin-local-storage/Storage.ts
  55. +13
    -0
      packages/plugin-local-storage/index.ts
  56. +12
    -0
      packages/plugin-local-storage/package.json
  57. +35
    -0
      packages/plugin-local-storage/tsconfig.json
  58. +1
    -1
      packages/plugin-remote-storage/Engine.ts
  59. +3
    -3
      packages/plugin-remote-storage/Storage.ts
  60. +4
    -7
      packages/plugin-remote-storage/index.ts
  61. +12
    -0
      packages/plugin-remote-storage/package.json
  62. +35
    -0
      packages/plugin-remote-storage/tsconfig.json
  63. +0
    -18
      src/plugins/local-storage/index.ts

+ 6
- 6
.gitignore View File

@@ -1,19 +1,19 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
node_modules/
.pnp/
.pnp.js

# testing
/coverage
coverage/

# next.js
/.next/
/out/
.next/
out/

# production
/build
build/

# misc
.DS_Store


.babelrc → packages/app/.babelrc View File


.sequelizerc → packages/app/.sequelizerc View File


README.md → packages/app/README.md View File


config/config.js → packages/app/config/config.js View File


migrate.ts → packages/app/migrate.ts View File


next-env.d.ts → packages/app/next-env.d.ts View File


next.config.js → packages/app/next.config.js View File


package.json → packages/app/package.json View File

@@ -1,5 +1,5 @@
{
"name": "note.modal.sh",
"name": "zeichen-app",
"version": "0.1.0",
"private": true,
"scripts": {

public/favicon.ico → packages/app/public/favicon.ico View File


public/vercel.svg → packages/app/public/vercel.svg View File


src/assets/global.css → packages/app/src/assets/global.css View File


src/assets/mobiledoc.css → packages/app/src/assets/mobiledoc.css View File


src/assets/theme.css → packages/app/src/assets/theme.css View File


src/components/Editor/Editor.tsx → packages/app/src/components/Editor/Editor.tsx View File


src/components/Icon/Icon.tsx → packages/app/src/components/Icon/Icon.tsx View File


src/components/Navbar/Navbar.tsx → packages/app/src/components/Navbar/Navbar.tsx View File


src/components/PrimaryNavItem/PrimaryNavItem.tsx → packages/app/src/components/PrimaryNavItem/PrimaryNavItem.tsx View File


src/components/SecondaryNavItem/SecondaryNavItem.tsx → packages/app/src/components/SecondaryNavItem/SecondaryNavItem.tsx View File


src/controllers/Folder.ts → packages/app/src/controllers/Folder.ts View File


src/controllers/Note.ts → packages/app/src/controllers/Note.ts View File


src/models.ts → packages/app/src/models.ts View File


src/models/Folder.ts → packages/app/src/models/Folder.ts View File


src/models/Note.ts → packages/app/src/models/Note.ts View File


src/models/Operation.ts → packages/app/src/models/Operation.ts View File


src/models/Tag.ts → packages/app/src/models/Tag.ts View File


src/models/Transaction.ts → packages/app/src/models/Transaction.ts View File


src/pages/_app.tsx → packages/app/src/pages/_app.tsx View File


src/pages/_document.tsx → packages/app/src/pages/_document.tsx View File


src/pages/api/folders.ts → packages/app/src/pages/api/folders.ts View File


src/pages/api/folders/[id].ts → packages/app/src/pages/api/folders/[id].ts View File


src/pages/api/notes.ts → packages/app/src/pages/api/notes.ts View File


src/pages/api/notes/[id].ts → packages/app/src/pages/api/notes/[id].ts View File


src/pages/notes.tsx → packages/app/src/pages/notes.tsx View File


src/pages/notes/[id].tsx → packages/app/src/pages/notes/[id].tsx View File


src/seeds.ts → packages/app/src/seeds.ts View File


src/services/LocalStorage.ts → packages/app/src/services/LocalStorage.ts View File


src/services/Operation.ts → packages/app/src/services/Operation.ts View File


src/services/Storage.ts → packages/app/src/services/Storage.ts View File


src/services/entities/Folder.ts → packages/app/src/services/entities/Folder.ts View File


src/services/entities/Note.ts → packages/app/src/services/entities/Note.ts View File


src/utilities/ColumnTypes.ts → packages/app/src/utilities/ColumnTypes.ts View File


src/utilities/Date.ts → packages/app/src/utilities/Date.ts View File


src/utilities/Id.ts → packages/app/src/utilities/Id.ts View File


src/utilities/ORM.ts → packages/app/src/utilities/ORM.ts View File


src/utilities/Response.ts → packages/app/src/utilities/Response.ts View File


src/utilities/Serialization.ts → packages/app/src/utilities/Serialization.ts View File


tsconfig.json → packages/app/tsconfig.json View File


yarn.lock → packages/app/yarn.lock View File


zeichen.config.ts → packages/app/zeichen.config.ts View File

@@ -1,5 +1,5 @@
import LocalStorage from './src/plugins/local-storage'
import RemoteStorage from './src/plugins/remote-storage'
import LocalStorage from '../plugin-local-storage'
import RemoteStorage from '../plugin-remote-storage'

export default {
plugins: [

+ 5
- 0
packages/core/plugin.ts View File

@@ -0,0 +1,5 @@
export type State = {
currentUserId: string,
}

export type Plugin<T = {}> = (config: T) => (state: State) => void

src/services/storages/Storage.ts → packages/core/storage.ts View File

@@ -4,7 +4,7 @@ export default interface Storage<T> {
deleteItem(item: T): Promise<boolean>
}

export interface StorageMeta<T> {
export interface Collection<T> {
items: T[],
lastModifiedBy: string,
lastModifiedAt: Date,

src/plugins/local-storage/Engine.ts → packages/plugin-local-storage/Engine.ts View File


src/plugins/local-storage/Storage.ts → packages/plugin-local-storage/Storage.ts View File

@@ -1,15 +1,15 @@
import Storage, { StorageMeta, OutOfSyncError } from '../../services/storages/Storage'
import Storage, { Collection, OutOfSyncError } from '../core/storage'
import Engine from './Engine'

export default class LocalStorage<T> implements Storage<T> {
private readonly engine: Engine<StorageMeta<T>>
private readonly engine: Engine<Collection<T>>

constructor(
private readonly ownerId: string,
private readonly storageId: string,
private readonly getItemId = item => item['id'],
) {
this.engine = new Engine<StorageMeta<T>>(window.localStorage)
this.engine = new Engine<Collection<T>>(window.localStorage)
}

private getMeta() {
@@ -31,7 +31,7 @@ export default class LocalStorage<T> implements Storage<T> {
async saveItem(newItem: T) {
const oldMeta = this.getMeta()
const isExistingItem = oldMeta.items.some(this.existenceCheck(newItem))
const newMeta: StorageMeta<T> = {
const newMeta: Collection<T> = {
items: isExistingItem
? oldMeta.items.map(oldItem => this.existenceCheck(newItem)(oldItem) ? newItem : oldItem)
: [...oldMeta.items, newItem],
@@ -44,7 +44,7 @@ export default class LocalStorage<T> implements Storage<T> {
async deleteItem(newItem: T) {
const oldMeta = this.getMeta()
const newItems = oldMeta.items.filter(oldItem => !this.existenceCheck(newItem)(oldItem))
const newMeta: StorageMeta<T> = {
const newMeta: Collection<T> = {
items: newItems,
lastModifiedBy: this.ownerId,
lastModifiedAt: new Date(),

+ 13
- 0
packages/plugin-local-storage/index.ts View File

@@ -0,0 +1,13 @@
import { Plugin } from '../core/plugin'
import Storage from './Storage'

type PluginConfig = {}

const LocalStoragePlugin: Plugin<PluginConfig> = config => ({
currentUserId,
}) => {
new Storage(currentUserId, 'notes')
new Storage(currentUserId, 'folders')
}

export default LocalStoragePlugin

+ 12
- 0
packages/plugin-local-storage/package.json View File

@@ -0,0 +1,12 @@
{
"name": "zeichen-plugin-local-storage",
"author": "TheoryOfNekomata <allan.crisostomo@outlook.com>",
"version": "0.1.0",
"description": "Save and load notes using the browser's local storage.",
"keywords": [
"zeichen",
"plugin",
"storage",
"local"
]
}

+ 35
- 0
packages/plugin-local-storage/tsconfig.json View File

@@ -0,0 +1,35 @@
{
"compilerOptions": {
"target": "es6",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"declaration": true,
"declarationDir": "./dist",
"sourceMap": true,
"strict": false
},
"exclude": [
"node_modules",
"**/*.test.ts",
"**/*.test.tsx"
],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
]
}

src/plugins/remote-storage/Engine.ts → packages/plugin-remote-storage/Engine.ts View File

@@ -1,4 +1,4 @@
import { Deserializer, Serializer } from '../../services/storages/Storage'
import { Deserializer, Serializer } from '../core/storage'

const CREATED = 201
const NO_CONTENT = 204

src/plugins/remote-storage/Storage.ts → packages/plugin-remote-storage/Storage.ts View File

@@ -1,8 +1,8 @@
import Storage, { StorageMeta } from '../../services/storages/Storage'
import Storage, { Collection } from '../core/storage'
import Engine from './Engine'

export default class RemoteStorage<T> implements Storage<T> {
private readonly engine: Engine<T, StorageMeta<T>>
private readonly engine: Engine<T, Collection<T>>

constructor(
private ownerId: string,
@@ -17,7 +17,7 @@ export default class RemoteStorage<T> implements Storage<T> {
}

async queryItems() {
const response = await this.engine.getCollection(this.collectionId) as StorageMeta<T>;
const response = await this.engine.getCollection(this.collectionId) as Collection<T>;
return response.items;
}


src/plugins/remote-storage/index.ts → packages/plugin-remote-storage/index.ts View File

@@ -1,18 +1,15 @@
import { Plugin } from '../core/plugin'
import Storage from './Storage'

type PluginConfig = {
baseUrl: string,
}

type State = {
currentUserId: string,
}

type Plugin = (config: PluginConfig) => (state: State) => void

const RemoteStoragePlugin: Plugin = config => ({
const RemoteStoragePlugin: Plugin<PluginConfig> = config => ({
currentUserId,
}) => {
new Storage(currentUserId, config.baseUrl, 'notes')
new Storage(currentUserId, config.baseUrl, 'folders')
}

export default RemoteStoragePlugin

+ 12
- 0
packages/plugin-remote-storage/package.json View File

@@ -0,0 +1,12 @@
{
"name": "zeichen-plugin-remote-storage",
"author": "TheoryOfNekomata <allan.crisostomo@outlook.com>",
"version": "0.1.0",
"description": "Save and load notes using an external API.",
"keywords": [
"zeichen",
"plugin",
"storage",
"API"
]
}

+ 35
- 0
packages/plugin-remote-storage/tsconfig.json View File

@@ -0,0 +1,35 @@
{
"compilerOptions": {
"target": "es6",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"declaration": true,
"declarationDir": "./dist",
"sourceMap": true,
"strict": false
},
"exclude": [
"node_modules",
"**/*.test.ts",
"**/*.test.tsx"
],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
]
}

+ 0
- 18
src/plugins/local-storage/index.ts View File

@@ -1,18 +0,0 @@
import Storage from './Storage'

type PluginConfig = {

}

type State = {
currentUserId: string,
}

type Plugin = (config: PluginConfig) => (state: State) => void

const LocalStoragePlugin: Plugin = config => ({
currentUserId,
}) => {
new Storage(currentUserId, 'notes')
new Storage(currentUserId, 'folders')
}

Loading…
Cancel
Save