@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
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import {merge} from 'lodash-es';
|
|
2
|
+
import type { default as TeraClient } from './terafy.client.ts';
|
|
3
|
+
|
|
4
|
+
// Define interface for deferred methods
|
|
5
|
+
interface DeferredMethod {
|
|
6
|
+
method: string;
|
|
7
|
+
args: any[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type TeraClientConstructor = typeof TeraClient
|
|
11
|
+
|
|
2
12
|
|
|
3
13
|
/**
|
|
4
14
|
* Tera-Fy Bootstrapper Client
|
|
@@ -7,7 +17,7 @@ import {merge} from 'lodash-es';
|
|
|
7
17
|
* @class TeraFy
|
|
8
18
|
*/
|
|
9
19
|
export default class TeraFy {
|
|
10
|
-
settings = {
|
|
20
|
+
settings: Record<string, any> = { // Added index signature for merge compatibility
|
|
11
21
|
client: 'tera-fy', // Client name within https://tera-tools.com/api/tera-fy/<NAME>.js to load
|
|
12
22
|
clientType: 'esm',
|
|
13
23
|
};
|
|
@@ -19,9 +29,9 @@ export default class TeraFy {
|
|
|
19
29
|
* @param {Object} [options] Additional options to merge into `settings` via `set`
|
|
20
30
|
* @returns {Promise<TeraFy>} An eventual promise which will resovle with this terafy instance
|
|
21
31
|
*/
|
|
22
|
-
init(options) {
|
|
32
|
+
init(options?: any): Promise<this> {
|
|
23
33
|
// FIXME: Note this needs to point at the live site
|
|
24
|
-
let getUrl = client => `https://dev.tera-tools.com/api/tera-fy/${client}.js`;
|
|
34
|
+
let getUrl = (client: string) => `https://dev.tera-tools.com/api/tera-fy/${client}.js`;
|
|
25
35
|
|
|
26
36
|
return Promise.resolve()
|
|
27
37
|
.then(()=>
|
|
@@ -30,34 +40,40 @@ export default class TeraFy {
|
|
|
30
40
|
.then(exported => typeof exported == 'function' ? exported : Promise.reject("Tera-fy import didn't return a class"))
|
|
31
41
|
: Promise.reject(`Unsupported TERA-fy clientType "${this.settings.clientType}"`)
|
|
32
42
|
)
|
|
33
|
-
.then(TeraClient => {
|
|
43
|
+
.then((TeraClient: TeraClientConstructor) => {
|
|
34
44
|
let tc = new TeraClient();
|
|
35
45
|
if (!tc.mixin) throw new Error('TERA-fy client doesnt expose a mixin() method');
|
|
36
46
|
|
|
37
47
|
tc.mixin(this, tc);
|
|
38
48
|
|
|
39
49
|
// Merge settings object
|
|
40
|
-
merge(this.settings, tc.settings,
|
|
50
|
+
merge(this.settings, tc.settings, options || {}); // Use options passed to init here
|
|
41
51
|
})
|
|
42
52
|
.then(()=> { // Sanity checks
|
|
43
53
|
console.log('IAM', this);
|
|
44
|
-
if (!this.init || typeof this.init != 'function') throw new Error('Newly mixed-in TERA-fy client doesnt expose a init() method');
|
|
45
|
-
if (!this.detectMode || typeof this.detectMode != 'function') throw new Error('Newly mixed-in TERA-fy client doesnt expose a detectMode() method');
|
|
54
|
+
if (!(this as any).init || typeof (this as any).init != 'function') throw new Error('Newly mixed-in TERA-fy client doesnt expose a init() method');
|
|
55
|
+
if (!(this as any).detectMode || typeof (this as any).detectMode != 'function') throw new Error('Newly mixed-in TERA-fy client doesnt expose a detectMode() method');
|
|
46
56
|
})
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
// Run all deferred methods as an sequencial promise chain
|
|
58
|
+
.then(() => this.bootstrapperDeferredMethods.reduce((chain: Promise<any>, dm: DeferredMethod) => {
|
|
59
|
+
return chain.then(() => {
|
|
60
|
+
if (dm.method == 'use' && typeof dm.args[0] == 'string') { // Wrap `use(pluginClient:String,options:Object)` method to fetch plugin from remote
|
|
61
|
+
console.log('TERA-FY DEFERRED-USE', dm.args[0]);
|
|
62
|
+
return this.bootstrapperImport(getUrl(dm.args[0]))
|
|
63
|
+
.then(exported => typeof exported == 'function' ? exported : Promise.reject("Tera-fy plugin import didn't return a class"))
|
|
64
|
+
.then(mod => (this as any).use(mod, ...dm.args.slice(1)));
|
|
65
|
+
} else {
|
|
66
|
+
console.log('TERA-FY DEFERRED-METHOD', dm);
|
|
67
|
+
// Assuming the deferred method might return a promise or a value
|
|
68
|
+
return Promise.resolve((this as any)[dm.method].apply(this, dm.args));
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}, Promise.resolve<any>(undefined))) // Initialize reduce chain correctly
|
|
72
|
+
.then(()=> { delete (this as any).bootstrapperDeferredMethods; }) // Use type assertion for delete
|
|
59
73
|
.then(()=> console.log('TYBS', 'Init'))
|
|
60
|
-
|
|
74
|
+
// Call the *actual* init method mixed in from the client
|
|
75
|
+
.then((): Promise<any> => (this as any).init.call(this, options))
|
|
76
|
+
.then(() => this); // Ensure the promise chain resolves with `this`
|
|
61
77
|
}
|
|
62
78
|
|
|
63
79
|
|
|
@@ -67,7 +83,7 @@ export default class TeraFy {
|
|
|
67
83
|
*
|
|
68
84
|
* @type {Array<Object>}
|
|
69
85
|
*/
|
|
70
|
-
bootstrapperDeferredMethods = [];
|
|
86
|
+
bootstrapperDeferredMethods: DeferredMethod[] = [];
|
|
71
87
|
|
|
72
88
|
|
|
73
89
|
/**
|
|
@@ -77,7 +93,7 @@ export default class TeraFy {
|
|
|
77
93
|
* @param {String} url The URL to import
|
|
78
94
|
* @returns {*} The default, single export of the module
|
|
79
95
|
*/
|
|
80
|
-
bootstrapperImport(url) {
|
|
96
|
+
bootstrapperImport(url: string): Promise<any> {
|
|
81
97
|
return new Promise((resolve, reject) => {
|
|
82
98
|
// Create a unique module ID
|
|
83
99
|
const moduleId = `installTFyBS${Math.random().toString(36).slice(2)}`;
|
|
@@ -92,13 +108,15 @@ export default class TeraFy {
|
|
|
92
108
|
|
|
93
109
|
// Create cleanup function
|
|
94
110
|
let cleanup = () => {
|
|
95
|
-
|
|
96
|
-
delete window[moduleId];
|
|
97
|
-
|
|
111
|
+
// console.warn('CLEANUP', moduleId); // Keep console.warn commented out unless needed
|
|
112
|
+
delete (window as any)[`installMod${moduleId}`]; // Use type assertion for delete
|
|
113
|
+
if (script.parentNode) { // Check if script is still in DOM
|
|
114
|
+
script.parentNode.removeChild(script);
|
|
115
|
+
}
|
|
98
116
|
}
|
|
99
117
|
|
|
100
118
|
// Create stub function to accept payload + quit
|
|
101
|
-
window[`installMod${moduleId}`] = payload => {
|
|
119
|
+
(window as any)[`installMod${moduleId}`] = (payload: any) => {
|
|
102
120
|
console.log('Accept module from', url, '=', payload);
|
|
103
121
|
resolve(payload);
|
|
104
122
|
cleanup();
|
|
@@ -106,8 +124,8 @@ export default class TeraFy {
|
|
|
106
124
|
|
|
107
125
|
|
|
108
126
|
// FIXME: Not sure if this is actually detecting errors? addEventListener instead maybe?
|
|
109
|
-
script.onerror = (error) => {
|
|
110
|
-
reject(new Error(`Failed to load module from ${url} - ${error.toString()}`));
|
|
127
|
+
script.onerror = (event: Event | string, source?: string, lineno?: number, colno?: number, error?: Error) => {
|
|
128
|
+
reject(new Error(`Failed to load module from ${url} - ${error ? error.toString() : event}`));
|
|
111
129
|
cleanup();
|
|
112
130
|
};
|
|
113
131
|
|
|
@@ -122,16 +140,16 @@ export default class TeraFy {
|
|
|
122
140
|
*
|
|
123
141
|
* @param {String} [options] Optional settings to merge
|
|
124
142
|
*/
|
|
125
|
-
constructor(options) {
|
|
143
|
+
constructor(options?: any) {
|
|
126
144
|
// Merge options if provided
|
|
127
145
|
if (options) merge(this.settings, options);
|
|
128
146
|
|
|
129
147
|
// Map various methods to a deferred process so we execute these after init() has grabbed the actual TeraFyClient
|
|
130
148
|
['set', 'setIfDev', 'use'].forEach(m => {
|
|
131
|
-
this[m] = (...args) => {
|
|
149
|
+
(this as any)[m] = (...args: any[]) => {
|
|
132
150
|
this.bootstrapperDeferredMethods.push({method: m, args});
|
|
133
151
|
return this;
|
|
134
152
|
}
|
|
135
153
|
});
|
|
136
154
|
}
|
|
137
|
-
}
|
|
155
|
+
}
|