@live-change/db-admin 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/e2e/codecept.conf.js +60 -0
  3. package/e2e/connectEmailCode.test.js +61 -0
  4. package/e2e/connectEmailLink.test.js +60 -0
  5. package/e2e/delete.test.js +44 -0
  6. package/e2e/disconnectEmail.test.js +42 -0
  7. package/e2e/resetPasswordWithEmailCode.test.js +62 -0
  8. package/e2e/resetPasswordWithEmailLink.test.js +62 -0
  9. package/e2e/setPassword.test.js +70 -0
  10. package/e2e/signInEmailCode.test.js +52 -0
  11. package/e2e/signInEmailLink.test.js +52 -0
  12. package/e2e/signInEmailPassword.test.js +47 -0
  13. package/e2e/signOut.test.js +41 -0
  14. package/e2e/signUpEmailCode.test.js +41 -0
  15. package/e2e/signUpEmailLink.test.js +41 -0
  16. package/e2e/steps.d.ts +12 -0
  17. package/e2e/steps_file.js +85 -0
  18. package/front/assets/images/empty-photo.svg +38 -0
  19. package/front/assets/images/empty-user-photo.svg +33 -0
  20. package/front/assets/images/logo.svg +34 -0
  21. package/front/index.html +11 -0
  22. package/front/public/favicon.ico +0 -0
  23. package/front/public/images/empty-photo.svg +38 -0
  24. package/front/public/images/empty-user-photo.svg +33 -0
  25. package/front/public/images/logo.svg +34 -0
  26. package/front/public/images/logo128.png +0 -0
  27. package/front/src/App.vue +93 -0
  28. package/front/src/CodeEditor.vue +92 -0
  29. package/front/src/Data.vue +74 -0
  30. package/front/src/DataRangeView.vue +58 -0
  31. package/front/src/DataView.vue +51 -0
  32. package/front/src/Database.vue +364 -0
  33. package/front/src/DatabaseAdmin.vue +135 -0
  34. package/front/src/Databases.vue +110 -0
  35. package/front/src/NavBar.vue +105 -0
  36. package/front/src/ObjectEditor.vue +143 -0
  37. package/front/src/Page.vue +39 -0
  38. package/front/src/PathEditor.vue +210 -0
  39. package/front/src/dbSugar.js +75 -0
  40. package/front/src/entry-client.js +24 -0
  41. package/front/src/entry-server.js +59 -0
  42. package/front/src/isClientSide.js +3 -0
  43. package/front/src/main.js +61 -0
  44. package/front/src/path.js +68 -0
  45. package/front/src/router.js +42 -0
  46. package/front/src/routes.js +31 -0
  47. package/front/vite.config.js +107 -0
  48. package/package.json +71 -0
  49. package/server/init.js +16 -0
  50. package/server/services.config.js +4 -0
@@ -0,0 +1,24 @@
1
+ import { createApp } from './main'
2
+ import { clientApi } from '@live-change/vue3-ssr/clientApi.js'
3
+
4
+ import {
5
+ createSharedElementDirective,
6
+ SharedElementRouteGuard
7
+ } from 'v-shared-element'
8
+
9
+
10
+ window.api = clientApi({
11
+ use: [ ]
12
+ })
13
+
14
+ const { app, router } = createApp(api)
15
+
16
+ app.use(createSharedElementDirective())
17
+ router.beforeEach(SharedElementRouteGuard)
18
+ window.process = window.process || null
19
+
20
+ // wait until router is ready before mounting to ensure hydration match
21
+ router.isReady().then(() => {
22
+ const instance = app.mount('#app', true)
23
+ app._container._vnode = instance.$.vnode
24
+ })
@@ -0,0 +1,59 @@
1
+ import { renderToString } from 'vue/server-renderer'
2
+ import { renderMetaToString } from 'vue-meta/ssr'
3
+
4
+ import { serverApi } from '@live-change/vue3-ssr/serverApi.js'
5
+
6
+ import { createApp } from './main'
7
+
8
+ function escapeHtml(unsafe) {
9
+ return unsafe
10
+ .replace(/&/g, "&")
11
+ .replace(/</g, "&lt;")
12
+ .replace(/>/g, "&gt;")
13
+ .replace(/"/g, "&quot;")
14
+ .replace(/'/g, "&#039;");
15
+ }
16
+
17
+ export async function render({ url, dao, windowId }) {
18
+ const api = await serverApi(dao, {
19
+ use: [ ]
20
+ })
21
+
22
+ const { app, router } = createApp(api)
23
+
24
+ // set the router to the desired URL before rendering
25
+ router.push(url)
26
+ await router.isReady()
27
+
28
+ // prefetch data
29
+ await api.preFetchRoute(router.currentRoute, router)
30
+
31
+ // passing SSR context object which will be available via useSSRContext()
32
+ // @vitejs/plugin-vue injects code into a component's setup() that registers
33
+ // itself on ctx.modules. After the render, ctx.modules would contain all the
34
+ // components that have been instantiated during this render call.
35
+ const ctx = {}
36
+ const html = await renderToString(app, ctx)
37
+ await renderMetaToString(app, ctx)
38
+
39
+ const data = api.prerenderCache.cacheData()
40
+ console.log("PRERENDER CACHE", Array.from(api.prerenderCache.cache.keys()))
41
+ console.log("PRERENDER CACHE EXTENDED", Array.from(api.prerenderCache.extendedCache.keys()))
42
+
43
+ // the SSR manifest generated by Vite contains module -> chunk/asset mapping
44
+ // which we can then use to determine what files need to be preloaded for this
45
+ // request.
46
+
47
+ const metaManager = app.config.globalProperties.$metaManager
48
+ const activeMeta = metaManager.target.context.active
49
+ console.log("ACTIVE META", activeMeta)
50
+ console.log("TELEPORTS", ctx.teleports)
51
+ ctx.teleports.head = [
52
+ ...(activeMeta.title ? [`<title data-vm-ssr="true">${escapeHtml(activeMeta.title)}</title>`] : []),
53
+ ...((activeMeta.meta || []).map(meta => `<meta ${Object.keys(meta).map(
54
+ key => `${escapeHtml(key)}="${escapeHtml(meta[key])}"`
55
+ ).join(' ')}>`))
56
+ ].join('\n')
57
+
58
+ return { html, data, meta: ctx.teleports, modules: ctx.modules }
59
+ }
@@ -0,0 +1,3 @@
1
+ import { ref } from "vue"
2
+ const isClientSide = ref(false)
3
+ export default isClientSide
@@ -0,0 +1,61 @@
1
+ import { createSSRApp } from 'vue'
2
+ import { createMetaManager } from 'vue-meta'
3
+
4
+ import { registerComponents } from '@live-change/vue3-components'
5
+ import ReactiveDaoVue from '@live-change/dao-vue3'
6
+
7
+ import PrimeVue from 'primevue/config'
8
+ import ConfirmationService from 'primevue/confirmationservice'
9
+ import { PrimeVueConfirmSymbol } from 'primevue/useconfirm'
10
+ import { PrimeVueToastSymbol } from 'primevue/usetoast'
11
+ import ToastService from 'primevue/toastservice'
12
+ import StyleClass from 'primevue/styleclass'
13
+ import Ripple from 'primevue/ripple'
14
+ import BadgeDirective from 'primevue/badgedirective'
15
+
16
+ import App from './App.vue'
17
+ import Page from './Page.vue'
18
+ import { createRouter } from './router'
19
+
20
+ import emailValidator from "@live-change/email-service/clientEmailValidator.js"
21
+ import passwordValidator from "@live-change/password-authentication-service/clientPasswordValidator.js"
22
+
23
+ // SSR requires a fresh app instance per request, therefore we export a function
24
+ // that creates a fresh app instance. If using Vuex, we'd also be creating a
25
+ // fresh store here.
26
+ export function createApp(api) {
27
+ api.validators.email = emailValidator
28
+ api.validators.password = passwordValidator
29
+
30
+ const app = createSSRApp(App)
31
+ app.config.devtools = true
32
+
33
+ api.installInstanceProperties(app.config.globalProperties)
34
+
35
+ registerComponents(app)
36
+ app.use(ReactiveDaoVue, { dao: api })
37
+
38
+ const router = createRouter(app)
39
+ app.use(router)
40
+
41
+ app.use(PrimeVue, {
42
+ ripple: true
43
+ })
44
+
45
+ app.use(ConfirmationService)
46
+ app.provide(PrimeVueConfirmSymbol, app.config.globalProperties.$confirm)
47
+
48
+ app.use(ToastService)
49
+ app.provide(PrimeVueToastSymbol, app.config.globalProperties.$toast)
50
+
51
+ app.directive('styleclass', StyleClass)
52
+ app.directive('ripple', Ripple)
53
+ app.directive('badge', BadgeDirective)
54
+
55
+ const meta = createMetaManager({
56
+ isSSR: import.meta.env.SSR
57
+ })
58
+ app.use(meta)
59
+
60
+ return { app, router }
61
+ }
@@ -0,0 +1,68 @@
1
+ function extractParams(code) {
2
+ return code.match(/(\$\.[a-z]+)/ig)?.map(p => p.slice(2)) ?? []
3
+ }
4
+
5
+ function sortDependencies(params) {
6
+ const allDependencies = new Set()
7
+ const depsMap = new Map(params.map(param => {
8
+ const extracted = extractParams(param[1])
9
+ allDependencies.add(...extracted)
10
+ return [param[0], new Set(extracted)]
11
+ }))
12
+ let foundNewDeps = true
13
+ while(foundNewDeps) {
14
+ foundNewDeps = false
15
+ for(const [ paramName, paramDependencies ] of depsMap.entries()) {
16
+ for(const dependency of paramDependencies) {
17
+ const deps2 = depsMap.get(dependency) || []
18
+ for(const dep2 of Array.from(deps2)) {
19
+ if(dep2 == paramName) throw new Error("recursive dependency " + dependency)
20
+ if(!paramDependencies.has(dep2)) {
21
+ foundNewDeps = true
22
+ paramDependencies.add(dep2)
23
+ allDependencies.add(dep2)
24
+ }
25
+ }
26
+ }
27
+ }
28
+ }
29
+ const sortedParams = Array.from(depsMap.entries()).sort(
30
+ (a, b) => a[1].size - b[1].size
31
+ )
32
+ return {
33
+ paramsOrder: sortedParams.map(p => p[0]),
34
+ dependencies: depsMap
35
+ }
36
+ }
37
+
38
+ function compilePath(path, params, possibleExternal = []) {
39
+ const paramsMap = new Map(params)
40
+ const { paramsOrder, dependencies } = sortDependencies([
41
+ ...params,
42
+ [null, path]
43
+ ])
44
+
45
+ const pathDependencies = dependencies.get(null)
46
+ const filteredParamsOrder = paramsOrder.filter(p => p && pathDependencies.has(p))
47
+
48
+ const externalDependencies = Array.from(pathDependencies).filter(dep => !dependencies.has(dep))
49
+ for(const external of externalDependencies) {
50
+ if(!possibleExternal.includes(external)) {
51
+ throw new Error('External value '+external+' not defined')
52
+ }
53
+ }
54
+
55
+ const lines = [
56
+ `(({ ${externalDependencies.join(', ')} }, db) => {`,
57
+ ` const $ = { ${externalDependencies.join(', ')} };`,
58
+ ...filteredParamsOrder.map(paramName => ` $.${paramName} = ${ paramsMap.get(paramName) };`),
59
+ ` return ${path};`,
60
+ `})`
61
+ ]
62
+ const code = lines.join('\n')
63
+ console.log("CODE", code)
64
+ const result = eval(code)
65
+ return { result, external: externalDependencies }
66
+ }
67
+
68
+ export { extractParams, compilePath }
@@ -0,0 +1,42 @@
1
+ import {
2
+ createMemoryHistory,
3
+ createRouter as _createRouter,
4
+ createWebHistory
5
+ } from 'vue-router'
6
+
7
+ import { routes as dbAdminRoutes } from './routes.js'
8
+
9
+ export function routes(config = {}) {
10
+ const { prefix = '/', route = (r) => r } = config
11
+ return [
12
+
13
+ route({
14
+ path: prefix,
15
+ component: () => import("./DatabaseAdmin.vue"),
16
+ meta: { pageType: 'wide', noNavBar: true },
17
+ children: [
18
+ ...dbAdminRoutes({ ...config, prefix: '' })
19
+ ]
20
+ })
21
+
22
+ ]
23
+ }
24
+
25
+ export async function sitemap(route, api) {
26
+ /// Sitemap not needed
27
+ }
28
+
29
+ import { client as useClient } from '@live-change/vue3-ssr'
30
+
31
+ export function createRouter(app, config) {
32
+ console.log("APP CTX", app._context)
33
+ const client = useClient(app._context)
34
+ const router = _createRouter({
35
+ // use appropriate history implementation for server/client
36
+ // import.meta.env.SSR is injected by Vite.
37
+ history: import.meta.env.SSR ? createMemoryHistory() : createWebHistory(),
38
+ routes: routes(config)
39
+ })
40
+ return router
41
+ }
42
+
@@ -0,0 +1,31 @@
1
+
2
+ export function routes(config = {}) {
3
+ const { prefix = '/', route = (r) => r } = config
4
+
5
+ return [
6
+
7
+ route({
8
+ path: prefix,
9
+ name: 'db:databases',
10
+ component: () => import("./Databases.vue")
11
+ }),
12
+
13
+ route({
14
+ path: prefix+'db/:dbName',
15
+ name: 'db:database',
16
+ component: () => import("./Database.vue"),
17
+ props: true
18
+ }),
19
+
20
+ route({
21
+ path: prefix+'data/:position/:read/:write/:remove/:params*',
22
+ name: 'db:data',
23
+ meta: { pageType: 'wide' },
24
+ component: () => import("./Data.vue"),
25
+ props: true
26
+ }),
27
+
28
+ ]
29
+ }
30
+
31
+ export default routes
@@ -0,0 +1,107 @@
1
+ const path = require('path')
2
+ const vuePlugin = require('@vitejs/plugin-vue')
3
+ import { defineConfig, searchForWorkspaceRoot } from 'vite'
4
+ import findFreePorts from "find-free-ports"
5
+ import { visualizer } from 'rollup-plugin-visualizer'
6
+ import viteImages from 'vite-plugin-vue-images'
7
+ import viteCompression from 'vite-plugin-compression'
8
+
9
+ const ssrTransformCustomDir = () => {
10
+ return {
11
+ props: [],
12
+ needRuntime: true
13
+ }
14
+ }
15
+
16
+ export default defineConfig(async ({ command, mode }) => {
17
+ return {
18
+ define: {
19
+ ENV_BASE_HREF: JSON.stringify(process.env.BASE_HREF || 'http://localhost:8001')
20
+ },
21
+ server: {
22
+ hmr: {
23
+ port: (await findFreePorts())[0]
24
+ },
25
+ fs: {
26
+ allow: [
27
+ searchForWorkspaceRoot(process.cwd()),
28
+ '../../../node_modules'
29
+ ],
30
+ }
31
+ },
32
+ plugins: [
33
+ vuePlugin({
34
+ template: {
35
+ compilerOptions: {
36
+ // whitespace: "preserve",
37
+ directiveTransforms: {
38
+ 'ripple': ssrTransformCustomDir,
39
+ 'styleclass': ssrTransformCustomDir,
40
+ 'badge': ssrTransformCustomDir,
41
+ 'shared-element': ssrTransformCustomDir
42
+ }
43
+ }
44
+ },
45
+ }),
46
+ viteImages({ extensions: ['jpg', 'jpeg', 'png', 'svg', 'webp'] }),
47
+ viteCompression({ algorithm: 'brotliCompress', ext: '.br' }),
48
+ viteCompression({ algorithm: 'gzip', ext: '.gz' }),
49
+ viteCompression({ algorithm: 'deflate', ext: '.zz' }),
50
+ visualizer({
51
+ filename: '../stats.html'
52
+ }),
53
+ ],
54
+ build: {
55
+ minify: false,
56
+ commonjsOptions: {
57
+ transformMixedEsModules: true,
58
+ include: [
59
+ /node_modules/,
60
+ /live-change-framework\/framework\//,
61
+ /live-change-framework\/uid\//,
62
+ /live-change-dao\/dao\//,
63
+ /live-change-dao\/dao-sockjs\//,
64
+ /live-change-dao\/dao-websocket\//,
65
+ ]
66
+ }
67
+ },
68
+ ssr: {
69
+ external: [
70
+ '@live-change/dao',
71
+ '@live-change/uid',
72
+ '@live-change/framework',
73
+ '@live-change/framework/lib/utils/validators.js',
74
+ 'debug',
75
+ 'vite'
76
+ ],
77
+ noExternal: [
78
+ 'vue-meta',
79
+ '@live-change/vue3-components',
80
+ '@live-change/dao-vue3',
81
+ '@live-change/vue3-ssr',
82
+ 'vue3-scroll-border'
83
+ ]
84
+ },
85
+ optimizeDeps: {
86
+ include: [
87
+ '@live-change/vue-api',
88
+ '@live-change/vue-api-session',
89
+ '@live-change/dao',
90
+ '@live-change/dao-sockjs',
91
+ '@live-change/dao-websocket',
92
+ '@live-change/uid',
93
+ '@live-change/framework',
94
+ '@live-change/framework/lib/utils/validators.js',
95
+ 'debug'
96
+ ]
97
+ },
98
+
99
+ resolve: {
100
+ alias: [
101
+ { find: 'debug', replacement: 'debug/src/browser.js' },
102
+ { find: 'universal-websocket-client', replacement: 'universal-websocket-client/browser.js' },
103
+ { find: 'sockjs-client', replacement: 'sockjs-client/dist/sockjs.min.js' }
104
+ ],
105
+ }
106
+ }
107
+ })
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@live-change/db-admin",
3
+ "version": "0.5.6",
4
+ "scripts": {
5
+ "memDev": "lcli memDev --initScript ./init.js --dbAccess",
6
+ "localDevInit": "rm tmp.db; lcli localDev --initScript ./init.js --dbAccess",
7
+ "localDev": "lcli localDev --dbAccess",
8
+ "dev": "lcli dev",
9
+ "ssrDev": "lcli ssrDev --dbAccess",
10
+ "serveAllMem": "cross-env NODE_ENV=production lcli ssrServer --withApi --withServices --updateServices --withDb --dbBackend mem --createDb --dbAccess",
11
+ "serveAll": "cross-env NODE_ENV=production lcli ssrServer --withApi --withServices --updateServices --dbAccess",
12
+ "serve": "cross-env NODE_ENV=production lcli ssrServer --dbAccess",
13
+ "build": "cd front; yarn build:client && yarn build:server",
14
+ "build:client": "cd front; vite build --ssrManifest --outDir dist/client",
15
+ "build:server": "cd front; vite build --ssr src/entry-server.js --outDir dist/server",
16
+ "generate": "vite build --ssrManifest --outDir dist/static && yarn build:server && node prerender",
17
+ "debug": "node --inspect-brk server"
18
+ },
19
+ "dependencies": {
20
+ "@live-change/cli": "0.6.1",
21
+ "@live-change/dao": "0.4.6",
22
+ "@live-change/dao-vue3": "0.4.6",
23
+ "@live-change/dao-websocket": "0.4.6",
24
+ "@live-change/framework": "0.6.1",
25
+ "@live-change/message-authentication-service": "0.2.28",
26
+ "@live-change/secret-code-service": "0.2.28",
27
+ "@live-change/secret-link-service": "0.2.28",
28
+ "@live-change/vue3-components": "0.2.8",
29
+ "@live-change/vue3-ssr": "0.2.7",
30
+ "@vitejs/plugin-vue": "^2.3.1",
31
+ "@vitejs/plugin-vue-jsx": "^1.3.10",
32
+ "@vue/compiler-sfc": "^3.2.33",
33
+ "@vueuse/core": "^8.3.1",
34
+ "codeceptjs-assert": "^0.0.5",
35
+ "compression": "^1.7.4",
36
+ "cross-env": "^7.0.3",
37
+ "get-port-sync": "1.0.1",
38
+ "javascript-stringify": "^2.1.0",
39
+ "primeflex": "^3.1.3",
40
+ "primeicons": "^5.0.0",
41
+ "primevue": "^3.12.5",
42
+ "prism-es6": "^1.2.0",
43
+ "prismjs": "^1.28.0",
44
+ "rollup-plugin-node-builtins": "^2.1.2",
45
+ "rollup-plugin-visualizer": "5.6.0",
46
+ "serialize-javascript": "^6.0.0",
47
+ "serve-static": "^1.15.0",
48
+ "v-shared-element": "3.1.0",
49
+ "vite": "^2.9.5",
50
+ "vite-plugin-compression": "0.5.1",
51
+ "vite-plugin-vue-images": "^0.6.1",
52
+ "vue": "^3.2.33",
53
+ "vue-meta": "^3.0.0-alpha.9",
54
+ "vue-prism-editor": "2.0.0-alpha.2",
55
+ "vue-router": "^4.0.14",
56
+ "vue3-scroll-border": "0.1.2"
57
+ },
58
+ "devDependencies": {
59
+ "@live-change/codeceptjs-helper": "0.6.0",
60
+ "@wdio/selenium-standalone-service": "^7.19.5",
61
+ "codeceptjs": "^3.3.0",
62
+ "generate-password": "1.7.0",
63
+ "playwright": "^1.21.1",
64
+ "random-profile-generator": "^2.3.0",
65
+ "txtgen": "^3.0.1",
66
+ "webdriverio": "^7.19.5"
67
+ },
68
+ "author": "",
69
+ "license": "ISC",
70
+ "description": ""
71
+ }
package/server/init.js ADDED
@@ -0,0 +1,16 @@
1
+ const app = require('@live-change/framework').app()
2
+
3
+ module.exports = async function(services) {
4
+
5
+ await app.dao.request(['database', 'createDatabase', 'testDb'])
6
+ await app.dao.request(['database', 'createTable', 'testDb', 'testTable1'])
7
+ for(let i = 0; i < 100; i++) {
8
+ await app.dao.request(['database', 'put', 'testDb', 'testTable1', {
9
+ id: app.generateUid(),
10
+ number: i,
11
+ text: 'test_'+i,
12
+ created: Date.now()
13
+ }])
14
+ }
15
+
16
+ }
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ services: [
3
+ ]
4
+ }