bt-core-app 0.0.0

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 (53) hide show
  1. package/.vscode/extensions.json +3 -0
  2. package/README.md +45 -0
  3. package/index.html +13 -0
  4. package/package.json +39 -0
  5. package/public/vite.svg +1 -0
  6. package/src/assets/vue.svg +1 -0
  7. package/src/components/BT-Btn.vue +40 -0
  8. package/src/components/BT-Col.vue +36 -0
  9. package/src/components/BT-Span.vue +21 -0
  10. package/src/components/Dialog-Confirm.vue +47 -0
  11. package/src/components/Dialog-Select-Date.vue +89 -0
  12. package/src/components/Dialog-Select.vue +140 -0
  13. package/src/components/Dialog-Text.vue +59 -0
  14. package/src/composables/actions-tracker.ts +99 -0
  15. package/src/composables/actions.ts +354 -0
  16. package/src/composables/api.ts +471 -0
  17. package/src/composables/auth.ts +382 -0
  18. package/src/composables/cosmetics.ts +178 -0
  19. package/src/composables/csv.ts +198 -0
  20. package/src/composables/dates.ts +79 -0
  21. package/src/composables/demo.ts +25 -0
  22. package/src/composables/dialogs.ts +115 -0
  23. package/src/composables/document-meta.ts +40 -0
  24. package/src/composables/draggable.ts +189 -0
  25. package/src/composables/filters.ts +256 -0
  26. package/src/composables/forage.ts +49 -0
  27. package/src/composables/helpers.ts +694 -0
  28. package/src/composables/id.ts +20 -0
  29. package/src/composables/list.ts +601 -0
  30. package/src/composables/navigation.ts +214 -0
  31. package/src/composables/presets.ts +20 -0
  32. package/src/composables/pwa.ts +89 -0
  33. package/src/composables/resizable.ts +382 -0
  34. package/src/composables/rules.ts +40 -0
  35. package/src/composables/stores.ts +797 -0
  36. package/src/composables/track.ts +55 -0
  37. package/src/composables/urls.ts +11 -0
  38. package/src/core.ts +92 -0
  39. package/src/index.ts +16 -0
  40. package/src/types.ts +13 -0
  41. package/src/useApi.ts +68 -0
  42. package/src/vite-env.d.ts +1 -0
  43. package/test/api.test.ts +84 -0
  44. package/test/forage.test.ts +31 -0
  45. package/test/helpers.test.ts +231 -0
  46. package/test/navigation.test.ts +99 -0
  47. package/test/stores-last-update.test.ts +138 -0
  48. package/test/stores-session.test.ts +118 -0
  49. package/test/track.test.ts +29 -0
  50. package/test/utils.ts +15 -0
  51. package/tsconfig.json +33 -0
  52. package/tsconfig.node.json +11 -0
  53. package/vite.config.ts +19 -0
@@ -0,0 +1,99 @@
1
+ import { createNavigation } from '../src/composables/navigation'
2
+ import { describe, expect, test } from 'vitest'
3
+
4
+ describe("navigation", () => {
5
+ const nav = createNavigation({
6
+ defaultCacheExpiryHours: 3,
7
+ navItems: [
8
+ {
9
+ name: 'test-nav'
10
+ },
11
+ {
12
+ name: 'navA',
13
+ background: 'b',
14
+ displayName: 'discs',
15
+ hideAppBar: true,
16
+ hideNavigation: true,
17
+ hesitate: true,
18
+ icon: 'mdi-plus',
19
+ path: '/testing/one',
20
+ children: [
21
+ {
22
+ name: 'navB',
23
+ cacheExpiryHours: 4,
24
+ children: [
25
+ {
26
+ archiveName: 'nav-archive',
27
+ aliases: ['nav-alias', 'nav-alia'],
28
+ name: 'navC',
29
+ path: '/test/alias'
30
+ }
31
+ ],
32
+ singleName: 'navone'
33
+ }
34
+ ]
35
+ }
36
+ ]
37
+ })
38
+
39
+ test('find archive name', () => {
40
+ expect(nav.findArchiveName('navC')).toEqual('nav-archive')
41
+ expect(nav.findArchiveName('navB')).toEqual(undefined)
42
+ expect(nav.findArchiveName('navD')).toEqual(undefined)
43
+ })
44
+
45
+ test('find cache length', () => {
46
+ expect(nav.findCacheHours('navC')).toEqual(3)
47
+ expect(nav.findCacheHours('navB')).toEqual(4)
48
+ })
49
+
50
+ test('find display', () => {
51
+ expect(nav.findDisplay('test-nav')).toEqual(undefined)
52
+ expect(nav.findDisplay('navA')).toEqual('discs')
53
+ })
54
+
55
+ test('find icon', () => {
56
+ expect(nav.findIcon('test-nav')).toEqual(undefined)
57
+ expect(nav.findIcon('navA')).toEqual('mdi-plus')
58
+ })
59
+
60
+ test('find item', () => {
61
+ expect(nav.findItem('test-nav')).not.toBeNull()
62
+ expect(nav.findItem('test-navs')).toBeNull()
63
+ expect(nav.findItem('test-nav')?.name).toEqual('test-nav')
64
+ expect(nav.findItem('nav-alias')?.name).toEqual('navC')
65
+ })
66
+
67
+ test('find store name', () => {
68
+ expect(nav.findStoreName('navA')).toEqual('navA')
69
+ expect(nav.findStoreName('navB')).toEqual('navB')
70
+ expect(nav.findStoreName('test-nav')).toEqual('test-nav')
71
+ })
72
+
73
+ test('find path', () => {
74
+ expect(nav.findPath('test-nav')).toEqual('')
75
+ expect(nav.findPath('navA')).toEqual('/testing/one')
76
+ expect(nav.findPath('nav-alias')).toEqual('/test/alias')
77
+ })
78
+
79
+ test('find single display', () => {
80
+ expect(nav.findSingleDisplay('navA')).toEqual('disc')
81
+ expect(nav.findSingleDisplay('navB')).toEqual('navone')
82
+ })
83
+
84
+ test('update nav props', () => {
85
+ nav.updateNavigationProperties('test-nav')
86
+
87
+ expect(nav.showAppBar.value).toEqual(true)
88
+ expect(nav.showAppNavigation.value).toEqual(true)
89
+ expect(nav.backgroundName.value).toEqual(undefined)
90
+ expect(nav.hesitate.value).toEqual(false)
91
+
92
+ nav.updateNavigationProperties('navA')
93
+
94
+ expect(nav.showAppBar.value).toEqual(false)
95
+ expect(nav.showAppNavigation.value).toEqual(false)
96
+ expect(nav.backgroundName.value).toEqual('b')
97
+ expect(nav.hesitate.value).toEqual(true)
98
+ })
99
+ })
@@ -0,0 +1,138 @@
1
+ import { setActivePinia, createPinia } from 'pinia'
2
+ import { createSessionStore, createWholeLastUpdateStore } from '../src/composables/stores'
3
+ import { createApi } from '../src/composables/api'
4
+ import { describe, test, expect, beforeEach, afterAll, afterEach, beforeAll } from 'vitest'
5
+ import { setupServer } from 'msw/node'
6
+ import { http, HttpResponse } from 'msw'
7
+ import { createApp } from 'vue'
8
+ import { withSetup } from './utils'
9
+
10
+ const handlers = [
11
+ http.get('https://api/get/1', () => {
12
+ return HttpResponse.json({
13
+ data: { test: 'g' }
14
+ })
15
+ }),
16
+ http.get('https://api/getAll', () => {
17
+ return HttpResponse.json({
18
+ data: [{ test: 'a', id: '1' }, { test: 'b', id: '2' }],
19
+ count: 2,
20
+ filters: ['test', 'test two']
21
+ })
22
+ }),
23
+ http.post('https://api/post', () => {
24
+ return HttpResponse.json({ data: { test: 'd', id: '11' } })
25
+ }),
26
+ http.patch('https://api/patch', () => {
27
+ return HttpResponse.json({ data: { test: 'e', rowVersion: 2 } })
28
+ })
29
+ ]
30
+
31
+ const server = setupServer(...handlers)
32
+
33
+ beforeAll(() => server.listen({ onUnhandledRequest: 'error' }))
34
+
35
+ afterAll(() => server.close())
36
+
37
+ afterEach(() => {
38
+ server.resetHandlers()
39
+ })
40
+
41
+ describe('use last update store no api no caching', () => {
42
+ const [api, app] = withSetup(() => createApi({
43
+ findPath: () => 'https://api/',
44
+ defaultThrowError: false
45
+ }))
46
+
47
+ const pinia = createPinia()
48
+ app.use(pinia)
49
+
50
+ setActivePinia(pinia)
51
+
52
+ const store = createWholeLastUpdateStore({
53
+ api: null,
54
+ storageMode: 'session',
55
+ storeName: 'whole'
56
+ })()
57
+
58
+ test('all session activity', async () => {
59
+
60
+ await store.post<any>({ data: { id: '1', test: 'a' }})
61
+ await store.post<any>({ data: { id: '2', test: 'b' }})
62
+ await store.post<any>({ data: { id: '3', test: 'c' }})
63
+
64
+ let postRes = await store.get<any>({ id: '1' })
65
+ expect(postRes.data).toEqual({ id: '1', test: 'a' })
66
+
67
+ await store.patch<any>({ data: { id: '1', test: 'd' }})
68
+ postRes = await store.get<any>({ id: '1' })
69
+ expect(postRes.data).toEqual({ id: '1', test: 'd' })
70
+
71
+ let getAll = await store.getAll<any>({})
72
+ expect(getAll.data.length).toEqual(3)
73
+ expect(getAll.count).toEqual(3)
74
+
75
+
76
+ await store.deleteItem({ data: { id: '1' }})
77
+ postRes = await store.get<any>({ id: '1' })
78
+ expect(postRes.data).toEqual(undefined)
79
+
80
+ getAll = await store.getAll<any>({})
81
+ expect(getAll.data.length).toEqual(2)
82
+ expect(getAll.count).toEqual(2)
83
+ })
84
+
85
+ })
86
+
87
+
88
+ describe('use last update store with api no caching', () => {
89
+ const [api, app] = withSetup(() => createApi({
90
+ findPath: () => 'https://api/',
91
+ defaultThrowError: false
92
+ }))
93
+
94
+ const pinia = createPinia()
95
+ app.use(pinia)
96
+ setActivePinia(pinia)
97
+
98
+ const store = createWholeLastUpdateStore({
99
+ storageMode: 'session',
100
+ api: api,
101
+ storeName: 'whole-api'
102
+ })()
103
+
104
+
105
+ test('get', async () => {
106
+ const res = await store.get<any>({ id: '1' })
107
+ expect(res.data).toEqual({ test: 'a', id: '1' })
108
+ let getAll = await store.getAll<any>({})
109
+ expect(getAll.data.length).toEqual(2)
110
+ expect(getAll.count).toEqual(2)
111
+ })
112
+
113
+
114
+ test('get all', async () => {
115
+ const res = await store.getAll<any>({})
116
+ expect(res).toEqual({
117
+ data: [{test: 'a', id: '1' },{test: 'b', id: '2' }],
118
+ count: 2,
119
+ filters: []
120
+ })
121
+ })
122
+
123
+ test('post', async () => {
124
+ const res = await store.post<any>({ data: { test: 'a', id: '11' }})
125
+ expect(res).not.toBeNull()
126
+
127
+ //gets api post return
128
+ let getRes = await store.get<any>({ id: '11' })
129
+ expect(getRes.data).toEqual({ test: 'd', id: '11' })
130
+ })
131
+
132
+ test('patch', async () => {
133
+ const res = await store.patch<any>({ data: { test: 'a', id: '1', rowVersion: 1 }})
134
+ let getRes = await store.get<any>({ id: '1' })
135
+ expect(getRes.data.rowVersion).toEqual(2)
136
+ })
137
+
138
+ })
@@ -0,0 +1,118 @@
1
+ import { setActivePinia, createPinia } from 'pinia'
2
+ import { createSessionStore, createWholeLastUpdateStore } from '../src/composables/stores'
3
+ import { createApi } from '../src/composables/api'
4
+ import { describe, test, expect, beforeEach, afterAll, afterEach, beforeAll } from 'vitest'
5
+ import { setupServer } from 'msw/node'
6
+ import { http, HttpResponse } from 'msw'
7
+ import { createApp } from 'vue'
8
+ import { withSetup } from './utils'
9
+
10
+ const handlers = [
11
+ http.get('https://test-api/get/1', () => {
12
+ return HttpResponse.json({
13
+ data: { test: 'a' }
14
+ })
15
+ }),
16
+ http.get('https://test-api/get/2', () => {
17
+ return new HttpResponse('not found', {
18
+ status: 304
19
+ })
20
+ }),
21
+ http.get('https://test-api/getAll', () => {
22
+ return HttpResponse.json({
23
+ data: [{ test: 'a' }, { test: 'b' }],
24
+ count: 2,
25
+ filters: ['test', 'test two']
26
+ })
27
+ }),
28
+ http.post('https://test-api/post', () => {
29
+ return HttpResponse.json({ data: { test: 'b' } })
30
+ }),
31
+ http.patch('https://test-api/patch', () => {
32
+ return HttpResponse.json({ data: { test: 'c', rowVersion: 2 } })
33
+ })
34
+ ]
35
+
36
+ const server = setupServer(...handlers)
37
+
38
+ beforeAll(() => server.listen({ onUnhandledRequest: 'error' }))
39
+
40
+ afterAll(() => server.close())
41
+
42
+ afterEach(() => {
43
+ server.resetHandlers()
44
+ })
45
+
46
+ describe('use session store with no api no caching', () => {
47
+ const [api, app] = withSetup(() => createApi())
48
+
49
+ const pinia = createPinia()
50
+ app.use(pinia)
51
+ setActivePinia(pinia)
52
+
53
+ const store = createSessionStore({
54
+ storageMode: 'session',
55
+ storeName: 'sesh'
56
+ })()
57
+
58
+ test('all session activity', async () => {
59
+ await store.post<any>({ data: { id: '1', test: 'a' }})
60
+ let postRes = await store.get<any>({ id: '1' })
61
+ expect(postRes.data).toEqual({ id: '1', test: 'a' })
62
+ await store.patch<any>({ nav: 'test', data: { id: '1', test: 'b' }})
63
+ postRes = await store.get<any>({ id: '1' })
64
+ expect(postRes.data).toEqual({ id: '1', test: 'b' })
65
+ await store.deleteItem({ id: '1' })
66
+ postRes = await store.get<any>({ id: '1' })
67
+ expect(postRes).toEqual(undefined)
68
+ })
69
+ })
70
+
71
+ describe('use session store with api no caching', () => {
72
+ const [api, app] = withSetup(() => createApi({
73
+ findPath: () => 'https://test-api/',
74
+ defaultThrowError: false
75
+ }))
76
+
77
+ const pinia = createPinia()
78
+ app.use(pinia)
79
+
80
+ setActivePinia(pinia)
81
+
82
+ const store = createSessionStore({
83
+ storageMode: 'session',
84
+ api: api,
85
+ storeName: 'test'
86
+ })()
87
+
88
+
89
+ test('get', async () => {
90
+ const res = await store.get<any>({ nav: 'test', id: '1' })
91
+ expect(res).toEqual({ data: { test: 'a' }})
92
+ //expect(store.searchMemory['test_no-user-id_1']).toEqual({ data: { test: 'a' }})
93
+ })
94
+
95
+ test('get all', async () => {
96
+ const res = await store.getAll<any>({ nav: 'test' })
97
+ expect(res).toEqual({
98
+ data: [{test: 'a' },{test: 'b'}],
99
+ count: 2,
100
+ filters: ['test', 'test two']
101
+ })
102
+ })
103
+
104
+ test('post', async () => {
105
+ const res = await store.post<any>({ nav: 'test', data: { test: 'a', id: '11' }})
106
+ expect(res).not.toBeNull()
107
+ //gets api post return
108
+ let getRes = await store.get<any>({ nav: 'test', id: '11' })
109
+ expect(getRes.data).toEqual({ test: 'b' })
110
+ })
111
+
112
+ test('patch', async () => {
113
+ const res = await store.patch<any>({ nav: 'test', data: { test: 'a', id: '1', rowVersion: 1 }})
114
+ let getRes = await store.get<any>({ nav: 'test', id: '1' })
115
+ expect(getRes.data.rowVersion).toEqual(2)
116
+ })
117
+
118
+ })
@@ -0,0 +1,29 @@
1
+ import { describe, expect, test } from "vitest"
2
+ import { withSetup } from './utils'
3
+ import { useTracker } from '../src/composables/track'
4
+ import { twiddleThumbs } from "../src/composables/helpers"
5
+
6
+ describe("track", () => {
7
+ test('tracker test', async () => {
8
+
9
+ const item = { test: 'a' }
10
+ const [{ asyncItem, isChanged, restartTracker }] = withSetup(() => useTracker(item))
11
+
12
+
13
+ expect(isChanged.value).toEqual(false)
14
+ asyncItem.value.test = 'b'
15
+ await twiddleThumbs(500)
16
+ expect(isChanged.value).toEqual(true)
17
+ asyncItem.value.test = 'a'
18
+ await twiddleThumbs(500)
19
+ expect(isChanged.value).toEqual(false)
20
+ asyncItem.value.test = 'b'
21
+ await twiddleThumbs(500)
22
+ expect(isChanged.value).toEqual(true)
23
+ restartTracker()
24
+ await twiddleThumbs(500)
25
+ expect(isChanged.value).toEqual(false)
26
+
27
+ })
28
+
29
+ })
package/test/utils.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { createApp } from 'vue'
2
+
3
+ export function withSetup(composable) {
4
+ let result
5
+ const app = createApp({
6
+ setup() {
7
+ result = composable()
8
+ return () => {}
9
+ }
10
+ })
11
+
12
+ app.mount(document.createElement('div'))
13
+
14
+ return [result, app]
15
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "target": "ES2020",
5
+ "useDefineForClassFields": true,
6
+ "module": "ESNext",
7
+ "lib": ["ES2020", "ES2021.String", "DOM", "DOM.Iterable"],
8
+ "skipLibCheck": true,
9
+
10
+ /* Bundler mode */
11
+ "moduleResolution": "bundler",
12
+ "allowImportingTsExtensions": true,
13
+ "resolveJsonModule": true,
14
+ "isolatedModules": true,
15
+ "noEmit": true,
16
+ "jsx": "preserve",
17
+
18
+ /* Linting */
19
+ "strict": true,
20
+ "noUnusedLocals": true,
21
+ "noUnusedParameters": true,
22
+ "noFallthroughCasesInSwitch": true,
23
+ "paths": {
24
+ "@/*": [
25
+ "src/*"
26
+ ]
27
+ },
28
+ "types": ["vitest/globals"]
29
+ },
30
+ "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
31
+ "references": [{ "path": "./tsconfig.node.json" }],
32
+ "exclude": ["node_modules"]
33
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "skipLibCheck": true,
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "allowSyntheticDefaultImports": true,
8
+ "strict": true
9
+ },
10
+ "include": ["vite.config.ts"]
11
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,19 @@
1
+ /// <reference types="vitest" />
2
+ import { defineConfig } from 'vite'
3
+ import path from 'path'
4
+ import vue from '@vitejs/plugin-vue'
5
+
6
+ // https://vitejs.dev/config/
7
+
8
+ export default defineConfig({
9
+ test: {
10
+ globals: true,
11
+ environment: 'happy-dom'
12
+ },
13
+ plugins: [vue()],
14
+ resolve: {
15
+ alias: {
16
+ '@': path.resolve(__dirname, './src')
17
+ }
18
+ }
19
+ })