@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.
Files changed (75) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/api.md +68 -66
  3. package/dist/lib/projectFile.d.ts +182 -0
  4. package/dist/lib/projectFile.js +157 -0
  5. package/dist/lib/projectFile.js.map +1 -0
  6. package/dist/lib/syncro/entities.d.ts +28 -0
  7. package/dist/lib/syncro/entities.js +203 -0
  8. package/dist/lib/syncro/entities.js.map +1 -0
  9. package/dist/lib/syncro/keyed.d.ts +95 -0
  10. package/dist/lib/syncro/keyed.js +286 -0
  11. package/dist/lib/syncro/keyed.js.map +1 -0
  12. package/dist/lib/syncro/syncro.d.ts +328 -0
  13. package/dist/lib/syncro/syncro.js +633 -0
  14. package/dist/lib/syncro/syncro.js.map +1 -0
  15. package/dist/lib/terafy.bootstrapper.d.ts +42 -0
  16. package/dist/lib/terafy.bootstrapper.js +130 -0
  17. package/dist/lib/terafy.bootstrapper.js.map +1 -0
  18. package/dist/lib/terafy.client.d.ts +532 -0
  19. package/dist/lib/terafy.client.js +1110 -0
  20. package/dist/lib/terafy.client.js.map +1 -0
  21. package/dist/lib/terafy.proxy.d.ts +66 -0
  22. package/dist/lib/terafy.proxy.js +123 -0
  23. package/dist/lib/terafy.proxy.js.map +1 -0
  24. package/dist/lib/terafy.server.d.ts +607 -0
  25. package/dist/lib/terafy.server.js +1774 -0
  26. package/dist/lib/terafy.server.js.map +1 -0
  27. package/dist/plugin.vue2.es2019.js +30 -13
  28. package/dist/plugins/base.d.ts +20 -0
  29. package/dist/plugins/base.js +21 -0
  30. package/dist/plugins/base.js.map +1 -0
  31. package/dist/plugins/firebase.d.ts +62 -0
  32. package/dist/plugins/firebase.js +111 -0
  33. package/dist/plugins/firebase.js.map +1 -0
  34. package/dist/plugins/vite.d.ts +12 -0
  35. package/dist/plugins/vite.js +22 -0
  36. package/dist/plugins/vite.js.map +1 -0
  37. package/dist/plugins/vue2.d.ts +68 -0
  38. package/dist/plugins/vue2.js +96 -0
  39. package/dist/plugins/vue2.js.map +1 -0
  40. package/dist/plugins/vue3.d.ts +64 -0
  41. package/dist/plugins/vue3.js +96 -0
  42. package/dist/plugins/vue3.js.map +1 -0
  43. package/dist/terafy.bootstrapper.es2019.js +2 -2
  44. package/dist/terafy.bootstrapper.js +2 -2
  45. package/dist/terafy.es2019.js +2 -2
  46. package/dist/terafy.js +1 -1
  47. package/dist/utils/mixin.d.ts +11 -0
  48. package/dist/utils/mixin.js +15 -0
  49. package/dist/utils/mixin.js.map +1 -0
  50. package/dist/utils/pDefer.d.ts +12 -0
  51. package/dist/utils/pDefer.js +14 -0
  52. package/dist/utils/pDefer.js.map +1 -0
  53. package/dist/utils/pathTools.d.ts +70 -0
  54. package/dist/utils/pathTools.js +120 -0
  55. package/dist/utils/pathTools.js.map +1 -0
  56. package/eslint.config.js +44 -8
  57. package/lib/{projectFile.js → projectFile.ts} +83 -40
  58. package/lib/syncro/entities.ts +288 -0
  59. package/lib/syncro/{keyed.js → keyed.ts} +114 -57
  60. package/lib/syncro/{syncro.js → syncro.ts} +204 -169
  61. package/lib/{terafy.bootstrapper.js → terafy.bootstrapper.ts} +49 -31
  62. package/lib/{terafy.client.js → terafy.client.ts} +94 -86
  63. package/lib/{terafy.proxy.js → terafy.proxy.ts} +43 -16
  64. package/lib/{terafy.server.js → terafy.server.ts} +364 -223
  65. package/package.json +65 -26
  66. package/plugins/{base.js → base.ts} +3 -1
  67. package/plugins/{firebase.js → firebase.ts} +34 -16
  68. package/plugins/{vite.js → vite.ts} +3 -3
  69. package/plugins/{vue2.js → vue2.ts} +17 -10
  70. package/plugins/{vue3.js → vue3.ts} +11 -9
  71. package/tsconfig.json +30 -0
  72. package/utils/{mixin.js → mixin.ts} +1 -1
  73. package/utils/{pDefer.js → pDefer.ts} +10 -3
  74. package/utils/{pathTools.js → pathTools.ts} +11 -9
  75. package/lib/syncro/entities.js +0 -232
@@ -0,0 +1,42 @@
1
+ interface DeferredMethod {
2
+ method: string;
3
+ args: any[];
4
+ }
5
+ /**
6
+ * Tera-Fy Bootstrapper Client
7
+ * This class loads the "real" Tera-Fy from remote and mutates into it
8
+ *
9
+ * @class TeraFy
10
+ */
11
+ export default class TeraFy {
12
+ settings: Record<string, any>;
13
+ /**
14
+ * Download the remote TERA-fy client, initalize it and mix it in with this class instance
15
+ *
16
+ * @param {Object} [options] Additional options to merge into `settings` via `set`
17
+ * @returns {Promise<TeraFy>} An eventual promise which will resovle with this terafy instance
18
+ */
19
+ init(options?: any): Promise<this>;
20
+ /**
21
+ * Methods to call post-init when the main TeraFyClient has loaded
22
+ * These are setup during construction
23
+ *
24
+ * @type {Array<Object>}
25
+ */
26
+ bootstrapperDeferredMethods: DeferredMethod[];
27
+ /**
28
+ * Go fetch a remote URL, inject it as a <script> element and resolve to the exported default
29
+ * This is a fix for the fact that regular import() can't accept URLs
30
+ *
31
+ * @param {String} url The URL to import
32
+ * @returns {*} The default, single export of the module
33
+ */
34
+ bootstrapperImport(url: string): Promise<any>;
35
+ /**
36
+ * TeraFyBootstrapper constructor
37
+ *
38
+ * @param {String} [options] Optional settings to merge
39
+ */
40
+ constructor(options?: any);
41
+ }
42
+ export {};
@@ -0,0 +1,130 @@
1
+ import { merge } from 'lodash-es';
2
+ /**
3
+ * Tera-Fy Bootstrapper Client
4
+ * This class loads the "real" Tera-Fy from remote and mutates into it
5
+ *
6
+ * @class TeraFy
7
+ */
8
+ export default class TeraFy {
9
+ /**
10
+ * Download the remote TERA-fy client, initalize it and mix it in with this class instance
11
+ *
12
+ * @param {Object} [options] Additional options to merge into `settings` via `set`
13
+ * @returns {Promise<TeraFy>} An eventual promise which will resovle with this terafy instance
14
+ */
15
+ init(options) {
16
+ // FIXME: Note this needs to point at the live site
17
+ let getUrl = (client) => `https://dev.tera-tools.com/api/tera-fy/${client}.js`;
18
+ return Promise.resolve()
19
+ .then(() => this.settings.clientType == 'esm' ?
20
+ this.bootstrapperImport(getUrl(this.settings.client))
21
+ .then(exported => typeof exported == 'function' ? exported : Promise.reject("Tera-fy import didn't return a class"))
22
+ : Promise.reject(`Unsupported TERA-fy clientType "${this.settings.clientType}"`))
23
+ .then((TeraClient) => {
24
+ let tc = new TeraClient();
25
+ if (!tc.mixin)
26
+ throw new Error('TERA-fy client doesnt expose a mixin() method');
27
+ tc.mixin(this, tc);
28
+ // Merge settings object
29
+ merge(this.settings, tc.settings, options || {}); // Use options passed to init here
30
+ })
31
+ .then(() => {
32
+ console.log('IAM', this);
33
+ if (!this.init || typeof this.init != 'function')
34
+ throw new Error('Newly mixed-in TERA-fy client doesnt expose a init() method');
35
+ if (!this.detectMode || typeof this.detectMode != 'function')
36
+ throw new Error('Newly mixed-in TERA-fy client doesnt expose a detectMode() method');
37
+ })
38
+ // Run all deferred methods as an sequencial promise chain
39
+ .then(() => this.bootstrapperDeferredMethods.reduce((chain, dm) => {
40
+ return chain.then(() => {
41
+ if (dm.method == 'use' && typeof dm.args[0] == 'string') { // Wrap `use(pluginClient:String,options:Object)` method to fetch plugin from remote
42
+ console.log('TERA-FY DEFERRED-USE', dm.args[0]);
43
+ return this.bootstrapperImport(getUrl(dm.args[0]))
44
+ .then(exported => typeof exported == 'function' ? exported : Promise.reject("Tera-fy plugin import didn't return a class"))
45
+ .then(mod => this.use(mod, ...dm.args.slice(1)));
46
+ }
47
+ else {
48
+ console.log('TERA-FY DEFERRED-METHOD', dm);
49
+ // Assuming the deferred method might return a promise or a value
50
+ return Promise.resolve(this[dm.method].apply(this, dm.args));
51
+ }
52
+ });
53
+ }, Promise.resolve(undefined))) // Initialize reduce chain correctly
54
+ .then(() => { delete this.bootstrapperDeferredMethods; }) // Use type assertion for delete
55
+ .then(() => console.log('TYBS', 'Init'))
56
+ // Call the *actual* init method mixed in from the client
57
+ .then(() => this.init.call(this, options))
58
+ .then(() => this); // Ensure the promise chain resolves with `this`
59
+ }
60
+ /**
61
+ * Go fetch a remote URL, inject it as a <script> element and resolve to the exported default
62
+ * This is a fix for the fact that regular import() can't accept URLs
63
+ *
64
+ * @param {String} url The URL to import
65
+ * @returns {*} The default, single export of the module
66
+ */
67
+ bootstrapperImport(url) {
68
+ return new Promise((resolve, reject) => {
69
+ // Create a unique module ID
70
+ const moduleId = `installTFyBS${Math.random().toString(36).slice(2)}`;
71
+ // Add a wrapper module that will expose the class
72
+ const script = document.createElement('script');
73
+ script.type = 'module';
74
+ script.textContent = `
75
+ import mod from '${url}';
76
+ window['installMod${moduleId}'](mod);
77
+ `;
78
+ // Create cleanup function
79
+ let cleanup = () => {
80
+ // console.warn('CLEANUP', moduleId); // Keep console.warn commented out unless needed
81
+ delete window[`installMod${moduleId}`]; // Use type assertion for delete
82
+ if (script.parentNode) { // Check if script is still in DOM
83
+ script.parentNode.removeChild(script);
84
+ }
85
+ };
86
+ // Create stub function to accept payload + quit
87
+ window[`installMod${moduleId}`] = (payload) => {
88
+ console.log('Accept module from', url, '=', payload);
89
+ resolve(payload);
90
+ cleanup();
91
+ };
92
+ // FIXME: Not sure if this is actually detecting errors? addEventListener instead maybe?
93
+ script.onerror = (event, source, lineno, colno, error) => {
94
+ reject(new Error(`Failed to load module from ${url} - ${error ? error.toString() : event}`));
95
+ cleanup();
96
+ };
97
+ // Append stub script element and quit
98
+ document.head.appendChild(script);
99
+ });
100
+ }
101
+ /**
102
+ * TeraFyBootstrapper constructor
103
+ *
104
+ * @param {String} [options] Optional settings to merge
105
+ */
106
+ constructor(options) {
107
+ this.settings = {
108
+ client: 'tera-fy', // Client name within https://tera-tools.com/api/tera-fy/<NAME>.js to load
109
+ clientType: 'esm',
110
+ };
111
+ /**
112
+ * Methods to call post-init when the main TeraFyClient has loaded
113
+ * These are setup during construction
114
+ *
115
+ * @type {Array<Object>}
116
+ */
117
+ this.bootstrapperDeferredMethods = [];
118
+ // Merge options if provided
119
+ if (options)
120
+ merge(this.settings, options);
121
+ // Map various methods to a deferred process so we execute these after init() has grabbed the actual TeraFyClient
122
+ ['set', 'setIfDev', 'use'].forEach(m => {
123
+ this[m] = (...args) => {
124
+ this.bootstrapperDeferredMethods.push({ method: m, args });
125
+ return this;
126
+ };
127
+ });
128
+ }
129
+ }
130
+ //# sourceMappingURL=terafy.bootstrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terafy.bootstrapper.js","sourceRoot":"","sources":["../../lib/terafy.bootstrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,WAAW,CAAC;AAYhC;;;;;EAKE;AACF,MAAM,CAAC,OAAO,OAAO,MAAM;IAO1B;;;;;MAKE;IACF,IAAI,CAAC,OAAa;QACjB,mDAAmD;QACnD,IAAI,MAAM,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,0CAA0C,MAAM,KAAK,CAAC;QAEvF,OAAO,OAAO,CAAC,OAAO,EAAE;aACtB,IAAI,CAAC,GAAE,EAAE,CACT,IAAI,CAAC,QAAQ,CAAC,UAAU,IAAI,KAAK,CAAC,CAAC;YAClC,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;iBACnD,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,QAAQ,IAAI,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,sCAAsC,CAAC,CAAC;YACtH,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,mCAAmC,IAAI,CAAC,QAAQ,CAAC,UAAU,GAAG,CAAC,CAChF;aACA,IAAI,CAAC,CAAC,UAAiC,EAAE,EAAE;YAC3C,IAAI,EAAE,GAAG,IAAI,UAAU,EAAE,CAAC;YAC1B,IAAI,CAAC,EAAE,CAAC,KAAK;gBAAE,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;YAEhF,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAEnB,wBAAwB;Y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