@iebh/tera-fy 2.0.21 → 2.2.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.
- package/CHANGELOG.md +38 -0
- package/api.md +68 -66
- package/dist/lib/projectFile.d.ts +182 -0
- package/dist/lib/projectFile.js +157 -0
- package/dist/lib/projectFile.js.map +1 -0
- package/dist/lib/syncro/entities.d.ts +28 -0
- package/dist/lib/syncro/entities.js +203 -0
- package/dist/lib/syncro/entities.js.map +1 -0
- package/dist/lib/syncro/keyed.d.ts +95 -0
- package/dist/lib/syncro/keyed.js +286 -0
- package/dist/lib/syncro/keyed.js.map +1 -0
- package/dist/lib/syncro/syncro.d.ts +328 -0
- package/dist/lib/syncro/syncro.js +633 -0
- package/dist/lib/syncro/syncro.js.map +1 -0
- package/dist/lib/terafy.bootstrapper.d.ts +42 -0
- package/dist/lib/terafy.bootstrapper.js +130 -0
- package/dist/lib/terafy.bootstrapper.js.map +1 -0
- package/dist/lib/terafy.client.d.ts +532 -0
- package/dist/lib/terafy.client.js +1110 -0
- package/dist/lib/terafy.client.js.map +1 -0
- package/dist/lib/terafy.proxy.d.ts +66 -0
- package/dist/lib/terafy.proxy.js +123 -0
- package/dist/lib/terafy.proxy.js.map +1 -0
- package/dist/lib/terafy.server.d.ts +607 -0
- package/dist/lib/terafy.server.js +1774 -0
- package/dist/lib/terafy.server.js.map +1 -0
- package/dist/plugin.vue2.es2019.js +30 -13
- package/dist/plugins/base.d.ts +20 -0
- package/dist/plugins/base.js +21 -0
- package/dist/plugins/base.js.map +1 -0
- package/dist/plugins/firebase.d.ts +62 -0
- package/dist/plugins/firebase.js +111 -0
- package/dist/plugins/firebase.js.map +1 -0
- package/dist/plugins/vite.d.ts +12 -0
- package/dist/plugins/vite.js +22 -0
- package/dist/plugins/vite.js.map +1 -0
- package/dist/plugins/vue2.d.ts +68 -0
- package/dist/plugins/vue2.js +96 -0
- package/dist/plugins/vue2.js.map +1 -0
- package/dist/plugins/vue3.d.ts +64 -0
- package/dist/plugins/vue3.js +96 -0
- package/dist/plugins/vue3.js.map +1 -0
- package/dist/terafy.bootstrapper.es2019.js +2 -2
- package/dist/terafy.bootstrapper.js +2 -2
- package/dist/terafy.es2019.js +2 -2
- package/dist/terafy.js +1 -1
- package/dist/utils/mixin.d.ts +11 -0
- package/dist/utils/mixin.js +15 -0
- package/dist/utils/mixin.js.map +1 -0
- package/dist/utils/pDefer.d.ts +12 -0
- package/dist/utils/pDefer.js +14 -0
- package/dist/utils/pDefer.js.map +1 -0
- package/dist/utils/pathTools.d.ts +70 -0
- package/dist/utils/pathTools.js +120 -0
- package/dist/utils/pathTools.js.map +1 -0
- package/eslint.config.js +44 -8
- package/lib/{projectFile.js → projectFile.ts} +83 -40
- package/lib/syncro/entities.ts +288 -0
- package/lib/syncro/{keyed.js → keyed.ts} +114 -57
- package/lib/syncro/{syncro.js → syncro.ts} +204 -169
- package/lib/{terafy.bootstrapper.js → terafy.bootstrapper.ts} +49 -31
- package/lib/{terafy.client.js → terafy.client.ts} +94 -86
- package/lib/{terafy.proxy.js → terafy.proxy.ts} +43 -16
- package/lib/{terafy.server.js → terafy.server.ts} +364 -223
- package/package.json +65 -26
- package/plugins/{base.js → base.ts} +3 -1
- package/plugins/{firebase.js → firebase.ts} +34 -16
- package/plugins/{vite.js → vite.ts} +3 -3
- package/plugins/{vue2.js → vue2.ts} +17 -10
- package/plugins/{vue3.js → vue3.ts} +11 -9
- package/tsconfig.json +30 -0
- package/utils/{mixin.js → mixin.ts} +1 -1
- package/utils/{pDefer.js → pDefer.ts} +10 -3
- package/utils/{pathTools.js → pathTools.ts} +11 -9
- package/lib/syncro/entities.js +0 -232
package/package.json
CHANGED
|
@@ -1,43 +1,73 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iebh/tera-fy",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "TERA website worker",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"dev": "esbuild --platform=browser --format=esm --bundle lib/terafy.client.
|
|
6
|
+
"dev": "esbuild --platform=browser --format=esm --bundle lib/terafy.client.ts --outfile=dist/terafy.js --minify --serve --servedir=.",
|
|
7
7
|
"build": "concurrently 'npm:build:*'",
|
|
8
|
-
"build:
|
|
9
|
-
"build:client
|
|
10
|
-
"build:
|
|
11
|
-
"build:bootstrapper
|
|
12
|
-
"build:
|
|
13
|
-
"build:
|
|
14
|
-
"build:docs:
|
|
15
|
-
"
|
|
8
|
+
"build:tsc": "tsc --outDir dist",
|
|
9
|
+
"build:client": "esbuild --platform=browser --format=esm --bundle lib/terafy.client.ts --outfile=dist/terafy.js --minify",
|
|
10
|
+
"build:client:es2019": "esbuild --platform=browser --format=esm --target=es2019 --bundle lib/terafy.client.ts --outfile=dist/terafy.es2019.js --minify",
|
|
11
|
+
"build:bootstrapper": "esbuild --platform=browser --format=esm --bundle lib/terafy.bootstrapper.ts --outfile=dist/terafy.bootstrapper.js --minify",
|
|
12
|
+
"build:bootstrapper:es2019": "esbuild --platform=browser --format=esm --target=es2019 --bundle lib/terafy.bootstrapper.ts --outfile=dist/terafy.bootstrapper.es2019.js --minify",
|
|
13
|
+
"build:plugins:vue2:es2019": "esbuild --platform=browser --format=esm --target=es2019 --bundle plugins/vue2.ts --outfile=dist/plugin.vue2.es2019.js --minify",
|
|
14
|
+
"build:docs:api": "documentation build lib/terafy.client.ts lib/projectFile.ts --format html --config documentation.yml --output docs/",
|
|
15
|
+
"build:docs:markdown": "documentation build lib/terafy.client.ts lib/projectFile.ts --format md --markdown-toc --output api.md",
|
|
16
|
+
"lint": "eslint lib plugins utils widgets --ext .ts",
|
|
16
17
|
"release": "release-it",
|
|
17
|
-
"watch": "nodemon --watch lib --watch plugins --exec npm run build"
|
|
18
|
+
"watch": "nodemon --watch lib --watch plugins --exec \"npm run build\""
|
|
18
19
|
},
|
|
19
20
|
"type": "module",
|
|
20
21
|
"imports": {
|
|
21
|
-
"#terafy": "./lib/terafy.client.
|
|
22
|
-
"#utils/*": "./utils/*.
|
|
22
|
+
"#terafy": "./lib/terafy.client.ts",
|
|
23
|
+
"#utils/*": "./utils/*.ts"
|
|
23
24
|
},
|
|
24
25
|
"exports": {
|
|
25
26
|
".": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
27
|
+
"types": "./dist/lib/terafy.client.d.ts",
|
|
28
|
+
"browser": "./dist/lib/terafy.client.js",
|
|
29
|
+
"import": "./dist/lib/terafy.client.js",
|
|
28
30
|
"require": "./dist/terafy.js",
|
|
29
31
|
"default": "./dist/terafy.js"
|
|
30
32
|
},
|
|
31
|
-
"./bootstrap":
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"./
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
"./bootstrap": {
|
|
34
|
+
"types": "./dist/lib/terafy.bootstrapper.d.ts",
|
|
35
|
+
"import": "./dist/lib/terafy.bootstrapper.js",
|
|
36
|
+
"default": "./dist/lib/terafy.bootstrapper.js"
|
|
37
|
+
},
|
|
38
|
+
"./projectFile": {
|
|
39
|
+
"types": "./dist/lib/projectFile.d.ts",
|
|
40
|
+
"import": "./dist/lib/projectFile.js",
|
|
41
|
+
"default": "./dist/lib/projectFile.js"
|
|
42
|
+
},
|
|
43
|
+
"./proxy": {
|
|
44
|
+
"types": "./dist/lib/terafy.proxy.d.ts",
|
|
45
|
+
"import": "./dist/lib/terafy.proxy.js",
|
|
46
|
+
"default": "./dist/lib/terafy.proxy.js"
|
|
47
|
+
},
|
|
48
|
+
"./server": {
|
|
49
|
+
"types": "./dist/lib/terafy.server.d.ts",
|
|
50
|
+
"import": "./dist/lib/terafy.server.js",
|
|
51
|
+
"default": "./dist/lib/terafy.server.js"
|
|
52
|
+
},
|
|
53
|
+
"./syncro": {
|
|
54
|
+
"types": "./dist/lib/syncro/syncro.d.ts",
|
|
55
|
+
"import": "./dist/lib/syncro/syncro.js",
|
|
56
|
+
"default": "./dist/lib/syncro/syncro.js"
|
|
57
|
+
},
|
|
58
|
+
"./syncro/*": {
|
|
59
|
+
"types": "./dist/lib/syncro/*.d.ts",
|
|
60
|
+
"import": "./dist/lib/syncro/*.js",
|
|
61
|
+
"default": "./dist/lib/syncro/*.js"
|
|
62
|
+
},
|
|
63
|
+
"./plugins/*": {
|
|
64
|
+
"types": "./dist/plugins/*.d.ts",
|
|
65
|
+
"import": "./dist/plugins/*.js",
|
|
66
|
+
"default": "./dist/plugins/*.js"
|
|
67
|
+
},
|
|
39
68
|
"./widgets/*": "./widgets/*"
|
|
40
69
|
},
|
|
70
|
+
"types": "./dist/lib/terafy.client.d.ts",
|
|
41
71
|
"repository": {
|
|
42
72
|
"type": "git",
|
|
43
73
|
"url": "git+https://github.com/IEBH/TERA-fy.git"
|
|
@@ -54,7 +84,7 @@
|
|
|
54
84
|
"url": "https://github.com/connorf25"
|
|
55
85
|
},
|
|
56
86
|
{
|
|
57
|
-
"name": "Justin
|
|
87
|
+
"name": "Justin Clark",
|
|
58
88
|
"email": "jclark@bond.edu.au",
|
|
59
89
|
"url": "https://github.com/Justin-Clarc"
|
|
60
90
|
},
|
|
@@ -74,6 +104,7 @@
|
|
|
74
104
|
"node": ">=18"
|
|
75
105
|
},
|
|
76
106
|
"dependencies": {
|
|
107
|
+
"@iebh/supabasey": "^1.1.0",
|
|
77
108
|
"@momsfriendlydevco/marshal": "^2.1.4",
|
|
78
109
|
"detect-port": "^2.1.0",
|
|
79
110
|
"filesize": "^10.1.6",
|
|
@@ -86,13 +117,21 @@
|
|
|
86
117
|
"uuid": "^11.1.0"
|
|
87
118
|
},
|
|
88
119
|
"devDependencies": {
|
|
89
|
-
"@momsfriendlydevco/eslint-config": "^2.1.
|
|
120
|
+
"@momsfriendlydevco/eslint-config": "^2.1.2",
|
|
90
121
|
"@release-it/conventional-changelog": "^10.0.0",
|
|
122
|
+
"@types/detect-port": "^1.3.5",
|
|
123
|
+
"@types/http-proxy": "^1.17.14",
|
|
124
|
+
"@types/lodash-es": "^4.17.12",
|
|
125
|
+
"@types/node": "^18.0.0",
|
|
126
|
+
"@types/uuid": "^10.0.0",
|
|
127
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
128
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
91
129
|
"concurrently": "^9.1.2",
|
|
92
130
|
"documentation": "^14.0.3",
|
|
93
131
|
"esbuild": "^0.25.0",
|
|
94
132
|
"eslint": "^9.21.0",
|
|
95
|
-
"nodemon": "^3.1.9"
|
|
133
|
+
"nodemon": "^3.1.9",
|
|
134
|
+
"typescript": "^5.5.4"
|
|
96
135
|
},
|
|
97
136
|
"peerDependencies": {
|
|
98
137
|
"@iebh/reflib": "^2.5.4",
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type TeraFy from "../lib/terafy.client.ts";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Base TeraFy plugin interface
|
|
3
5
|
* This is included as a documentation exanple only
|
|
@@ -18,6 +20,6 @@ export default class TeraFyPlugin {
|
|
|
18
20
|
* @param {TeraFy} terafy The TeraFy client this plugin is being initalized against
|
|
19
21
|
* @param {Object} [options] Additional options to mutate behaviour
|
|
20
22
|
*/
|
|
21
|
-
constructor(terafy, options) { // eslint-disable-line no-unused-vars
|
|
23
|
+
constructor(terafy: TeraFy, options: Object) { // eslint-disable-line no-unused-vars
|
|
22
24
|
}
|
|
23
25
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {initializeApp as Firebase} from 'firebase/app';
|
|
2
|
-
import {getFirestore as Firestore} from 'firebase/firestore';
|
|
3
|
-
import
|
|
1
|
+
import {initializeApp as Firebase, FirebaseApp} from 'firebase/app';
|
|
2
|
+
import {getFirestore as Firestore, Firestore as FirestoreInstance} from 'firebase/firestore';
|
|
3
|
+
import Supabasey from '@iebh/supabasey';
|
|
4
4
|
import Syncro from '../lib/syncro/syncro.js';
|
|
5
5
|
import TeraFyPluginBase from './base.js';
|
|
6
6
|
|
|
7
|
+
|
|
7
8
|
/**
|
|
8
9
|
* Plugin which adds Firebase / Firestore support for namespace mounts
|
|
9
10
|
*
|
|
@@ -16,7 +17,13 @@ export default class TeraFyPluginFirebase extends TeraFyPluginBase {
|
|
|
16
17
|
*
|
|
17
18
|
* @type {Object<Syncro>}
|
|
18
19
|
*/
|
|
19
|
-
syncros = {};
|
|
20
|
+
syncros: Record<string, Syncro> = {};
|
|
21
|
+
namespaces: Record<string, any> = {}; // Declare namespaces property
|
|
22
|
+
|
|
23
|
+
// Declare properties expected by the class methods or potentially inherited
|
|
24
|
+
getCredentials!: () => Promise<Record<string, any>>;
|
|
25
|
+
requireProject!: () => Promise<{ id: string }>;
|
|
26
|
+
debug!: (...args: any[]) => void;
|
|
20
27
|
|
|
21
28
|
|
|
22
29
|
/**
|
|
@@ -28,6 +35,7 @@ export default class TeraFyPluginFirebase extends TeraFyPluginBase {
|
|
|
28
35
|
* @name getReactive
|
|
29
36
|
* @type {Function} A reactive function as defined in Syncro
|
|
30
37
|
*/
|
|
38
|
+
getReactive?: Function;
|
|
31
39
|
|
|
32
40
|
|
|
33
41
|
/**
|
|
@@ -44,7 +52,7 @@ export default class TeraFyPluginFirebase extends TeraFyPluginBase {
|
|
|
44
52
|
*
|
|
45
53
|
* @returns {Promise} A Promise which will resolve when the init process has completed
|
|
46
54
|
*/
|
|
47
|
-
async init(options) {
|
|
55
|
+
async init(options?: any): Promise<void> { // Add optional '?' and type 'any', keep async Promise<void>
|
|
48
56
|
let settings = {
|
|
49
57
|
firebaseApiKey: null,
|
|
50
58
|
firebaseAuthDomain: null,
|
|
@@ -61,14 +69,19 @@ export default class TeraFyPluginFirebase extends TeraFyPluginBase {
|
|
|
61
69
|
throw new Error('Firebase plugin requires mandatory options: ' + emptyValues.join(', '));
|
|
62
70
|
|
|
63
71
|
Syncro.firebase = Firebase({
|
|
64
|
-
apiKey: settings.firebaseApiKey
|
|
65
|
-
authDomain: settings.firebaseAuthDomain
|
|
66
|
-
projectId: settings.firebaseProjectId
|
|
67
|
-
appId: settings.firebaseAppId
|
|
72
|
+
apiKey: settings.firebaseApiKey!, // Add non-null assertion
|
|
73
|
+
authDomain: settings.firebaseAuthDomain!, // Add non-null assertion
|
|
74
|
+
projectId: settings.firebaseProjectId!, // Add non-null assertion
|
|
75
|
+
appId: settings.firebaseAppId!, // Add non-null assertion
|
|
68
76
|
});
|
|
69
|
-
Syncro.firestore = Firestore(
|
|
77
|
+
Syncro.firestore = Firestore(Syncro.firebase); // Use Syncro.firebase
|
|
70
78
|
|
|
71
|
-
Syncro.
|
|
79
|
+
Syncro.supabasey = await Supabasey.init({
|
|
80
|
+
env: {
|
|
81
|
+
SUPABASE_URL: settings.supabaseUrl!,
|
|
82
|
+
SUPABASE_KEY: settings.supabaseKey!, // Add non-null assertions
|
|
83
|
+
},
|
|
84
|
+
});
|
|
72
85
|
}
|
|
73
86
|
|
|
74
87
|
|
|
@@ -79,8 +92,8 @@ export default class TeraFyPluginFirebase extends TeraFyPluginBase {
|
|
|
79
92
|
*
|
|
80
93
|
* @returns {Promise} A promise which resolves when the operation has completed
|
|
81
94
|
*/
|
|
82
|
-
_mountNamespace(name) {
|
|
83
|
-
let syncro; //
|
|
95
|
+
_mountNamespace(name: string): Promise<void> { // Add type 'string'
|
|
96
|
+
let syncro: Syncro; // Add type Syncro
|
|
84
97
|
|
|
85
98
|
return Promise.resolve()
|
|
86
99
|
.then(()=> this.requireProject())
|
|
@@ -90,7 +103,7 @@ export default class TeraFyPluginFirebase extends TeraFyPluginBase {
|
|
|
90
103
|
: `project_namespaces::${project.id}::${name}`;
|
|
91
104
|
|
|
92
105
|
syncro = this.syncros[name] = new Syncro(path, {
|
|
93
|
-
debug: (...msg) => this.debug(`SYNCRO://${path}`, ...msg),
|
|
106
|
+
debug: (...msg: any[]) => this.debug(`SYNCRO://${path}`, ...msg), // Add type any[]
|
|
94
107
|
getReactive: this.getReactive, // Try to inherit this instances getReactive prop, otherwise Syncro will fall back to its default
|
|
95
108
|
});
|
|
96
109
|
|
|
@@ -110,13 +123,18 @@ export default class TeraFyPluginFirebase extends TeraFyPluginBase {
|
|
|
110
123
|
*
|
|
111
124
|
* @returns {Promise} A promise which resolves when the operation has completed
|
|
112
125
|
*/
|
|
113
|
-
_unmountNamespace(name) {
|
|
126
|
+
_unmountNamespace(name: string): Promise<void | any[]> { // Add type 'string'
|
|
114
127
|
let syncro = this.syncros[name]; // Create local alias for Syncro before we detach it
|
|
115
128
|
|
|
116
129
|
// Detach local state
|
|
117
130
|
delete this.namespaces[name];
|
|
118
131
|
delete this.syncros[name];
|
|
119
132
|
|
|
120
|
-
|
|
133
|
+
// Check if syncro exists before calling destroy
|
|
134
|
+
if (syncro) {
|
|
135
|
+
return syncro.destroy(); // Trigger Syncro distruction
|
|
136
|
+
} else {
|
|
137
|
+
return Promise.resolve(); // Or handle the case where syncro doesn't exist
|
|
138
|
+
}
|
|
121
139
|
}
|
|
122
140
|
}
|
|
@@ -8,12 +8,12 @@ import TeraProxy from '../lib/terafy.proxy.js';
|
|
|
8
8
|
* @param {Object} [options] Options to pass to the Proxy module
|
|
9
9
|
* @returns {VitePlugin}
|
|
10
10
|
*/
|
|
11
|
-
export default function vitePluginTeraFy(options) {
|
|
11
|
+
export default function vitePluginTeraFy(options: any) {
|
|
12
12
|
|
|
13
13
|
// Vite plugin config
|
|
14
14
|
return {
|
|
15
15
|
name: 'tera-fy',
|
|
16
|
-
apply(config, {command}) { // Only run within serve-mode rather than each build
|
|
16
|
+
apply(config: any, { command }: any) { // Only run within serve-mode rather than each build
|
|
17
17
|
|
|
18
18
|
// Don't run when building
|
|
19
19
|
if (command == 'build') return false;
|
|
@@ -21,4 +21,4 @@ export default function vitePluginTeraFy(options) {
|
|
|
21
21
|
TeraProxy(options);
|
|
22
22
|
},
|
|
23
23
|
}
|
|
24
|
-
}
|
|
24
|
+
}
|
|
@@ -31,15 +31,21 @@ export default class TeraFyPluginVue2 extends TeraFyPluginFirebase {
|
|
|
31
31
|
*
|
|
32
32
|
* @type {Vue}
|
|
33
33
|
*/
|
|
34
|
-
Vue;
|
|
34
|
+
Vue: any;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The root Vue app instance
|
|
38
|
+
* @type {any}
|
|
39
|
+
*/
|
|
40
|
+
app: any;
|
|
35
41
|
|
|
36
42
|
|
|
37
43
|
/**
|
|
38
44
|
* The bound, reactive state of the active TERA project
|
|
39
45
|
*
|
|
40
|
-
* @type {Object}
|
|
46
|
+
* @type {Object | null}
|
|
41
47
|
*/
|
|
42
|
-
project = null;
|
|
48
|
+
project: any = null;
|
|
43
49
|
|
|
44
50
|
|
|
45
51
|
/**
|
|
@@ -61,7 +67,7 @@ export default class TeraFyPluginVue2 extends TeraFyPluginFirebase {
|
|
|
61
67
|
*
|
|
62
68
|
* @returns {Promise} A Promise which will resolve when the init process has completed
|
|
63
69
|
*/
|
|
64
|
-
async init(options) {
|
|
70
|
+
async init(options: any) {
|
|
65
71
|
let settings = {
|
|
66
72
|
app: null,
|
|
67
73
|
Vue: null,
|
|
@@ -80,13 +86,14 @@ export default class TeraFyPluginVue2 extends TeraFyPluginFirebase {
|
|
|
80
86
|
this.Vue.prototype[settings.globalName] = this;
|
|
81
87
|
|
|
82
88
|
await super.init(settings); // Initalize parent class Firebase functionality
|
|
83
|
-
|
|
89
|
+
// @ts-ignore
|
|
84
90
|
this.project = await this.mountNamespace('_PROJECT');
|
|
85
91
|
}
|
|
86
92
|
|
|
87
93
|
|
|
88
94
|
/** @override */
|
|
89
|
-
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
getReactive(value: any) {
|
|
90
97
|
let doc = this.Vue.observable(value);
|
|
91
98
|
|
|
92
99
|
let watcherPath = `_teraFy_${this.reactiveId++}`;
|
|
@@ -94,19 +101,19 @@ export default class TeraFyPluginVue2 extends TeraFyPluginFirebase {
|
|
|
94
101
|
|
|
95
102
|
return {
|
|
96
103
|
doc,
|
|
97
|
-
setState(state) {
|
|
104
|
+
setState: (state: any) => {
|
|
98
105
|
// Shallow copy all sub-keys into existing object (keeping the object pointer)
|
|
99
106
|
Object.entries(state || {})
|
|
100
107
|
.filter(([k]) => !isEqual(doc[k], state[k])) // Only accept changed keys
|
|
101
108
|
.forEach(([k, v]) => doc[k] = v)
|
|
102
109
|
},
|
|
103
|
-
getState() {
|
|
110
|
+
getState: () => {
|
|
104
111
|
return cloneDeep(doc);
|
|
105
112
|
},
|
|
106
|
-
watch: cb => {
|
|
113
|
+
watch: (cb: Function) => {
|
|
107
114
|
this.app.$watch(watcherPath, cb, {deep: true});
|
|
108
115
|
},
|
|
109
116
|
};
|
|
110
117
|
}
|
|
111
118
|
|
|
112
|
-
}
|
|
119
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {cloneDeep} from 'lodash-es';
|
|
2
2
|
import TeraFyPluginFirebase from './firebase.js';
|
|
3
|
-
import {reactive as vueReactive, watch as vueWatch} from 'vue';
|
|
3
|
+
import {reactive as vueReactive, watch as vueWatch, App, WatchCallback} from 'vue';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Vue observables plugin
|
|
@@ -33,29 +33,31 @@ export default class TeraFyPluginVue3 extends TeraFyPluginFirebase {
|
|
|
33
33
|
*
|
|
34
34
|
* @type {Object}
|
|
35
35
|
*/
|
|
36
|
-
project = null;
|
|
36
|
+
project: any = null;
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Init the project including create a reactive mount for the active project
|
|
41
41
|
*
|
|
42
42
|
* @param {Object} options Additional options to mutate behaviour
|
|
43
|
-
* @param {
|
|
43
|
+
* @param {*} [options...] see TeraFyPluginFirebase
|
|
44
44
|
*/
|
|
45
|
-
async init(options) {
|
|
45
|
+
async init(options: Record<string, any>) {
|
|
46
46
|
await super.init(options); // Initalize parent class Firebase functionality
|
|
47
47
|
|
|
48
48
|
// Mount the project namespace
|
|
49
|
+
// @ts-ignore
|
|
49
50
|
this.project = await this.mountNamespace('_PROJECT');
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
|
|
53
54
|
/** @override */
|
|
54
|
-
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
getReactive(value: any) {
|
|
55
57
|
let doc = vueReactive(value);
|
|
56
58
|
return {
|
|
57
59
|
doc,
|
|
58
|
-
setState(state) {
|
|
60
|
+
setState(state: any) {
|
|
59
61
|
// Shallow copy all sub-keys into existing object (keeping the object pointer)
|
|
60
62
|
Object.entries(state || {})
|
|
61
63
|
.forEach(([k, v]) => doc[k] = v)
|
|
@@ -63,7 +65,7 @@ export default class TeraFyPluginVue3 extends TeraFyPluginFirebase {
|
|
|
63
65
|
getState() {
|
|
64
66
|
return cloneDeep(doc);
|
|
65
67
|
},
|
|
66
|
-
watch(cb) {
|
|
68
|
+
watch(cb: WatchCallback<any, any>) {
|
|
67
69
|
vueWatch(doc, cb, {deep: true});
|
|
68
70
|
},
|
|
69
71
|
};
|
|
@@ -88,7 +90,7 @@ export default class TeraFyPluginVue3 extends TeraFyPluginFirebase {
|
|
|
88
90
|
* @param {Object} [options] Additional options to mutate behaviour
|
|
89
91
|
* @param {String} [options.globalName='$tera'] Global property to allocate this service as
|
|
90
92
|
*/
|
|
91
|
-
install(app, options) {
|
|
93
|
+
install(app: App, options: Record<string, any>) {
|
|
92
94
|
let settings = {
|
|
93
95
|
globalName: '$tera',
|
|
94
96
|
...options,
|
|
@@ -101,4 +103,4 @@ export default class TeraFyPluginVue3 extends TeraFyPluginFirebase {
|
|
|
101
103
|
};
|
|
102
104
|
}
|
|
103
105
|
|
|
104
|
-
}
|
|
106
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"rootDir": "./",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"paths": {
|
|
16
|
+
"#terafy": ["./lib/terafy.client.ts"],
|
|
17
|
+
"#utils/*": ["./utils/*.ts"]
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"include": [
|
|
21
|
+
"lib/**/*.ts",
|
|
22
|
+
"plugins/**/*.ts",
|
|
23
|
+
"utils/**/*.ts",
|
|
24
|
+
"widgets/**/*.ts"
|
|
25
|
+
],
|
|
26
|
+
"exclude": [
|
|
27
|
+
"node_modules",
|
|
28
|
+
"dist",
|
|
29
|
+
]
|
|
30
|
+
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @param {Object} assignments Additional object properties to mix
|
|
9
9
|
* @returns {Object} A shallow copy of the input instance extended with the assignments
|
|
10
10
|
*/
|
|
11
|
-
export default function mixin(instance, assignments) {
|
|
11
|
+
export default function mixin(instance: any, assignments: any) {
|
|
12
12
|
let output = Object.assign(
|
|
13
13
|
Object.create(Object.getPrototypeOf(instance)),
|
|
14
14
|
instance,
|
|
@@ -3,8 +3,15 @@
|
|
|
3
3
|
* The defer object has the keys {promise, resolve(), reject()}
|
|
4
4
|
* @returns {Defer} A defered promise
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
|
|
7
|
+
interface Defer {
|
|
8
|
+
promise: Promise<unknown>;
|
|
9
|
+
resolve: (value?: unknown | PromiseLike<unknown>) => void;
|
|
10
|
+
reject: (reason?: any) => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default function(): Defer {
|
|
14
|
+
var deferred = {} as Defer;
|
|
8
15
|
|
|
9
16
|
deferred.promise = new Promise((resolve, reject) => {
|
|
10
17
|
deferred.resolve = resolve;
|
|
@@ -12,4 +19,4 @@ export default function() {
|
|
|
12
19
|
});
|
|
13
20
|
|
|
14
21
|
return deferred;
|
|
15
|
-
}
|
|
22
|
+
}
|
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
*
|
|
34
34
|
* @returns {*} The set value
|
|
35
35
|
*/
|
|
36
|
-
export function set(target, path, value, options) {
|
|
36
|
+
export function set(target: any, path: string | (string | number)[], value: any, options?: any): any {
|
|
37
37
|
let settings = {
|
|
38
38
|
strategy: 'overwrite',
|
|
39
39
|
...options,
|
|
@@ -76,7 +76,7 @@ export function set(target, path, value, options) {
|
|
|
76
76
|
* @param {*} [fallback] Optional fallback to return if the end point does not exist
|
|
77
77
|
* @returns {*} The fetched value
|
|
78
78
|
*/
|
|
79
|
-
export function get(target, path, fallback) {
|
|
79
|
+
export function get(target: any, path: string | (string | number)[], fallback?: any): any {
|
|
80
80
|
return _get(target, path, fallback);
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -90,7 +90,7 @@ export function get(target, path, fallback) {
|
|
|
90
90
|
* @param {String|Array} path The path within the target, to fetch in dotted or array notation
|
|
91
91
|
* @returns {Boolean} True if the given path already exists within the subject
|
|
92
92
|
*/
|
|
93
|
-
export function has(target, path) {
|
|
93
|
+
export function has(target: any, path: string | (string | number)[]): boolean {
|
|
94
94
|
return _has(target, path);
|
|
95
95
|
}
|
|
96
96
|
|
|
@@ -104,7 +104,7 @@ export function has(target, path) {
|
|
|
104
104
|
*
|
|
105
105
|
* @returns {*} The merged value
|
|
106
106
|
*/
|
|
107
|
-
export function merge(target, path, value) {
|
|
107
|
+
export function merge(target: any, path: string | (string | number)[], value: any): any {
|
|
108
108
|
_merge(get(target, path), value);
|
|
109
109
|
return value;
|
|
110
110
|
}
|
|
@@ -119,11 +119,13 @@ export function merge(target, path, value) {
|
|
|
119
119
|
*
|
|
120
120
|
* @returns {*} The resulting object with defaults applied
|
|
121
121
|
*/
|
|
122
|
-
export function defaults(target, path, value) {
|
|
122
|
+
export function defaults(target: any, path: string | (string | number)[] | any, value?: any): any {
|
|
123
123
|
if (typeof path == 'string' || Array.isArray(path)) { // Called as (target, path, value)
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
if (!has(target, path)) { // Target path doesn't exist at all
|
|
125
|
+
return set(target, path, value);
|
|
126
|
+
} else { // Target path exists - apply Lodash defaults
|
|
127
|
+
return _defaults(get(target, path), value);
|
|
128
|
+
}
|
|
127
129
|
} else { // Called as (target, value)
|
|
128
130
|
return _defaults(target, path);
|
|
129
131
|
}
|
|
@@ -137,4 +139,4 @@ export default {
|
|
|
137
139
|
has,
|
|
138
140
|
merge,
|
|
139
141
|
defaults,
|
|
140
|
-
};
|
|
142
|
+
};
|