@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 @@
1
+ {"version":3,"file":"mixin.js","sourceRoot":"","sources":["../../utils/mixin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;EASE;AACF,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,QAAa,EAAE,WAAgB;IAC5D,IAAI,MAAM,GAAG,MAAM,CAAC,MAAM,CACzB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,EAC9C,QAAQ,EACR,WAAW,CACX,CAAC;IACF,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Returns a defer object which represents a promise object which can resolve in the future - but without enclosing a function
3
+ * The defer object has the keys {promise, resolve(), reject()}
4
+ * @returns {Defer} A defered promise
5
+ */
6
+ interface Defer {
7
+ promise: Promise<unknown>;
8
+ resolve: (value?: unknown | PromiseLike<unknown>) => void;
9
+ reject: (reason?: any) => void;
10
+ }
11
+ export default function (): Defer;
12
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Returns a defer object which represents a promise object which can resolve in the future - but without enclosing a function
3
+ * The defer object has the keys {promise, resolve(), reject()}
4
+ * @returns {Defer} A defered promise
5
+ */
6
+ export default function () {
7
+ var deferred = {};
8
+ deferred.promise = new Promise((resolve, reject) => {
9
+ deferred.resolve = resolve;
10
+ deferred.reject = reject;
11
+ });
12
+ return deferred;
13
+ }
14
+ //# sourceMappingURL=pDefer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pDefer.js","sourceRoot":"","sources":["../../utils/pDefer.ts"],"names":[],"mappings":"AAAA;;;;EAIE;AAQF,MAAM,CAAC,OAAO;IACb,IAAI,QAAQ,GAAG,EAAW,CAAC;IAE3B,QAAQ,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAClD,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC;QAC3B,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AACjB,CAAC"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * General path setters / getters for project state
3
+ * These are _MAINLY_ wrappers for Lodash functionality such as Lodash.set() / Lodash.get(), any deviations are documented inline
4
+ *
5
+ * In each case these functions work with either dotted or array notation against a target master-object
6
+ * - Dotted notation - e.g. `foo.bar.1.baz`
7
+ * - Array path segments e.g. `['foo', 'bar', 1, 'baz']`
8
+ */
9
+ /**
10
+ * Internal recursive path setter
11
+ *
12
+ * Conflict strategies (copied from utils/pathTools @ `set()`)
13
+ * - 'set' / 'overwrite' - Just overwrite any existing value
14
+ * - 'merge' - Merge existing values using Lodash.merge()
15
+ * - 'defaults' - Merge existing values using Lodash.defaultsDeep()
16
+ *
17
+ * @param {Object} target The target to operate on
18
+ * @param {String|Array} path The path within the target to set, in dotted or array notation
19
+ * @param {*} value The value to set
20
+ * @param {Object} [options] Additional options to mutate behaviour
21
+ * @param {'set'|'overwrite'|'merge'|'defaults'} [options.strategy='set'] How to handle an existing value, if any
22
+ *
23
+ * @returns {*} The set value
24
+ */
25
+ export declare function set(target: any, path: string | (string | number)[], value: any, options?: any): any;
26
+ /**
27
+ * Internal recursive path fetcher
28
+ *
29
+ * @param {Object} target The target to examine
30
+ * @param {String|Array} path The path within the target to fetch, in dotted or array notation
31
+ * @param {*} [fallback] Optional fallback to return if the end point does not exist
32
+ * @returns {*} The fetched value
33
+ */
34
+ export declare function get(target: any, path: string | (string | number)[], fallback?: any): any;
35
+ /**
36
+ * Internal recursive path checker
37
+ *
38
+ * @param {Object} target The target to examine
39
+ * @param {String|Array} path The path within the target, to fetch in dotted or array notation
40
+ * @returns {Boolean} True if the given path already exists within the subject
41
+ */
42
+ export declare function has(target: any, path: string | (string | number)[]): boolean;
43
+ /**
44
+ * Internal recursive path merger
45
+ *
46
+ * @param {Object} target The target to operate on, this is likly to be mutated
47
+ * @param {String|Array} path The path within the target to merge, in dotted or array notation
48
+ * @param {*} value The value to merge
49
+ *
50
+ * @returns {*} The merged value
51
+ */
52
+ export declare function merge(target: any, path: string | (string | number)[], value: any): any;
53
+ /**
54
+ * Internal recursive path defaulter
55
+ *
56
+ * @param {Object} target The target to operate on, this is likly to be mutated
57
+ * @param {String|Array} [path] The path within the target to merge, in dotted or array notation
58
+ * @param {*} value The value to merge
59
+ *
60
+ * @returns {*} The resulting object with defaults applied
61
+ */
62
+ export declare function defaults(target: any, path: string | (string | number)[] | any, value?: any): any;
63
+ declare const _default: {
64
+ set: typeof set;
65
+ get: typeof get;
66
+ has: typeof has;
67
+ merge: typeof merge;
68
+ defaults: typeof defaults;
69
+ };
70
+ export default _default;
@@ -0,0 +1,120 @@
1
+ import { defaultsDeep as _defaults, get as _get, has as _has, merge as _merge, set as _set, } from 'lodash-es';
2
+ /**
3
+ * General path setters / getters for project state
4
+ * These are _MAINLY_ wrappers for Lodash functionality such as Lodash.set() / Lodash.get(), any deviations are documented inline
5
+ *
6
+ * In each case these functions work with either dotted or array notation against a target master-object
7
+ * - Dotted notation - e.g. `foo.bar.1.baz`
8
+ * - Array path segments e.g. `['foo', 'bar', 1, 'baz']`
9
+ */
10
+ /**
11
+ * Internal recursive path setter
12
+ *
13
+ * Conflict strategies (copied from utils/pathTools @ `set()`)
14
+ * - 'set' / 'overwrite' - Just overwrite any existing value
15
+ * - 'merge' - Merge existing values using Lodash.merge()
16
+ * - 'defaults' - Merge existing values using Lodash.defaultsDeep()
17
+ *
18
+ * @param {Object} target The target to operate on
19
+ * @param {String|Array} path The path within the target to set, in dotted or array notation
20
+ * @param {*} value The value to set
21
+ * @param {Object} [options] Additional options to mutate behaviour
22
+ * @param {'set'|'overwrite'|'merge'|'defaults'} [options.strategy='set'] How to handle an existing value, if any
23
+ *
24
+ * @returns {*} The set value
25
+ */
26
+ export function set(target, path, value, options) {
27
+ let settings = {
28
+ strategy: 'overwrite',
29
+ ...options,
30
+ };
31
+ // Fetch the existing value if the strategy calls for it
32
+ let hasExistingValue = ['merge', 'defaults'].includes(settings.strategy)
33
+ ? has(target, path)
34
+ : undefined;
35
+ switch (settings.strategy) {
36
+ case 'set':
37
+ case 'overwrite':
38
+ _set(target, path, value);
39
+ break;
40
+ case 'merge':
41
+ if (hasExistingValue) {
42
+ merge(target, path, value);
43
+ }
44
+ else {
45
+ _set(target, path, value);
46
+ }
47
+ break;
48
+ case 'defaults':
49
+ defaults(target, path, value);
50
+ break;
51
+ default:
52
+ throw new Error(`Unknown conflict resolution strategy "${settings.strategy}"`);
53
+ }
54
+ return value;
55
+ }
56
+ /**
57
+ * Internal recursive path fetcher
58
+ *
59
+ * @param {Object} target The target to examine
60
+ * @param {String|Array} path The path within the target to fetch, in dotted or array notation
61
+ * @param {*} [fallback] Optional fallback to return if the end point does not exist
62
+ * @returns {*} The fetched value
63
+ */
64
+ export function get(target, path, fallback) {
65
+ return _get(target, path, fallback);
66
+ }
67
+ /**
68
+ * Internal recursive path checker
69
+ *
70
+ * @param {Object} target The target to examine
71
+ * @param {String|Array} path The path within the target, to fetch in dotted or array notation
72
+ * @returns {Boolean} True if the given path already exists within the subject
73
+ */
74
+ export function has(target, path) {
75
+ return _has(target, path);
76
+ }
77
+ /**
78
+ * Internal recursive path merger
79
+ *
80
+ * @param {Object} target The target to operate on, this is likly to be mutated
81
+ * @param {String|Array} path The path within the target to merge, in dotted or array notation
82
+ * @param {*} value The value to merge
83
+ *
84
+ * @returns {*} The merged value
85
+ */
86
+ export function merge(target, path, value) {
87
+ _merge(get(target, path), value);
88
+ return value;
89
+ }
90
+ /**
91
+ * Internal recursive path defaulter
92
+ *
93
+ * @param {Object} target The target to operate on, this is likly to be mutated
94
+ * @param {String|Array} [path] The path within the target to merge, in dotted or array notation
95
+ * @param {*} value The value to merge
96
+ *
97
+ * @returns {*} The resulting object with defaults applied
98
+ */
99
+ export function defaults(target, path, value) {
100
+ if (typeof path == 'string' || Array.isArray(path)) { // Called as (target, path, value)
101
+ if (!has(target, path)) { // Target path doesn't exist at all
102
+ return set(target, path, value);
103
+ }
104
+ else { // Target path exists - apply Lodash defaults
105
+ return _defaults(get(target, path), value);
106
+ }
107
+ }
108
+ else { // Called as (target, value)
109
+ return _defaults(target, path);
110
+ }
111
+ }
112
+ // Export all functions as a lookup object
113
+ export default {
114
+ set,
115
+ get,
116
+ has,
117
+ merge,
118
+ defaults,
119
+ };
120
+ //# sourceMappingURL=pathTools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pathTools.js","sourceRoot":"","sources":["../../utils/pathTools.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,IAAI,SAAS,EACzB,GAAG,IAAI,IAAI,EACX,GAAG,IAAI,IAAI,EACX,KAAK,IAAI,MAAM,EACf,GAAG,IAAI,IAAI,GACX,MAAM,WAAW,CAAC;AAGnB;;;;;;;EAOE;AAGF;;;;;;;;;;;;;;;EAeE;AACF,MAAM,UAAU,GAAG,CAAC,MAAW,EAAE,IAAkC,EAAE,KAAU,EAAE,OAAa;IAC7F,IAAI,QAAQ,GAAG;QACd,QAAQ,EAAE,WAAW;QACrB,GAAG,OAAO;KACV,CAAC;IAEF,wDAAwD;IACxD,IAAI,gBAAgB,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACvE,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC;QACnB,CAAC,CAAC,SAAS,CAAC;IAEb,QAAQ,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAC3B,KAAK,KAAK,CAAC;QACX,KAAK,WAAW;YACf,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;YAC1B,MAAM;QACP,KAAK,OAAO;YACX,IAAI,gBAAgB,EAAE,CAAC;gBACtB,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;YAC5B,CAAC;iBAAM,CAAC;gBACP,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;YAC3B,CAAC;YACD,MAAM;QACP,KAAK,UAAU;YACd,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;YAC9B,MAAM;QACP;YACC,MAAM,IAAI,KAAK,CAAC,yCAAyC,QAAQ,CAAC,QAAQ,GAAG,CAAC,CAAC;IACjF,CAAC;IAGD,OAAO,KAAK,CAAC;AACd,CAAC;AAGD;;;;;;;EAOE;AACF,MAAM,UAAU,GAAG,CAAC,MAAW,EAAE,IAAkC,EAAE,QAAc;IAClF,OAAO,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC;AAKD;;;;;;EAME;AACF,MAAM,UAAU,GAAG,CAAC,MAAW,EAAE,IAAkC;IAClE,OAAO,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAC3B,CAAC;AAGD;;;;;;;;EAQE;AACF,MAAM,UAAU,KAAK,CAAC,MAAW,EAAE,IAAkC,EAAE,KAAU;IAChF,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;IACjC,OAAO,KAAK,CAAC;AACd,CAAC;AAGD;;;;;;;;EAQE;AACF,MAAM,UAAU,QAAQ,CAAC,MAAW,EAAE,IAAwC,EAAE,KAAW;IAC1F,IAAI,OAAO,IAAI,IAAI,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,kCAAkC;QACvF,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,mCAAmC;YAC5D,OAAO,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC,CAAC,6CAA6C;YACrD,OAAO,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;QAC5C,CAAC;IACF,CAAC;SAAM,CAAC,CAAC,4BAA4B;QACpC,OAAO,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC;AACF,CAAC;AAGD,0CAA0C;AAC1C,eAAe;IACd,GAAG;IACH,GAAG;IACH,GAAG;IACH,KAAK;IACL,QAAQ;CACR,CAAC"}
package/eslint.config.js CHANGED
@@ -1,14 +1,50 @@
1
- import RulesMFDC from '@momsfriendlydevco/eslint-config';
1
+ import RulesMFDC, {JSCommon} from '@momsfriendlydevco/eslint-config';
2
+ import tseslint from 'typescript-eslint';
2
3
 
3
- export default [
4
+ export default tseslint.config(
4
5
  {
5
- // Global ignore rules - Do not add any other keys to this object or eslint doesn't treat this as global
6
6
  ignores: [
7
- '.*',
8
- 'docs/',
9
- 'dist/',
10
- 'node_modules/',
7
+ '.*', // Ignore dotfiles/folders
8
+ 'docs/', // Ignore documentation output
9
+ 'dist/', // Ignore build output
10
+ 'node_modules/', // Ignore dependencies
11
+ 'api.md', // Ignore generated markdown API file
11
12
  ],
12
13
  },
14
+
15
+ // Include the base configuration from MFDC
13
16
  ...RulesMFDC,
14
- ]
17
+
18
+ // Add TypeScript specific configurations
19
+ {
20
+ // Apply these settings ONLY to .ts files
21
+ files: ['**/*.ts'],
22
+ // Use recommended TypeScript rules (includes parser/plugin setup)
23
+ // Using recommendedTypeChecked enables rules that require type information
24
+ extends: [
25
+ ...tseslint.configs.recommendedTypeChecked,
26
+ ],
27
+ // Configure the parser to find your tsconfig.json for type-aware linting
28
+ languageOptions: {
29
+ parserOptions: {
30
+ project: true, // Tells TS ESLint to find and use tsconfig.json
31
+ tsconfigRootDir: import.meta.dirname, // Helps ESLint find tsconfig.json relative to eslint.config.js
32
+ },
33
+ },
34
+ rules: {
35
+ // Add any TypeScript specific rule overrides here if needed
36
+ // For example:
37
+ // '@typescript-eslint/no-explicit-any': 'warn',
38
+ // '@typescript-eslint/no-unused-vars': ['warn', { 'argsIgnorePattern': '^_' }],
39
+ ...JSCommon,
40
+ },
41
+ },
42
+
43
+ // Your existing global override - this will apply to both JS and TS files
44
+ // If you only want this for JS, you could add `files: ['**/*.js']` here.
45
+ {
46
+ rules: {
47
+ 'unicorn/prefer-global-this': 'off', // Keep your specific override
48
+ },
49
+ },
50
+ );
@@ -1,5 +1,16 @@
1
- import {filesize} from 'filesize';
2
- import {pick} from 'lodash-es';
1
+ import { filesize } from 'filesize';
2
+ import { pick } from 'lodash-es';
3
+ import type TeraFy from './terafy.client.ts';
4
+
5
+ // TODO: Refactor terafy.client.ts so that we don't need to extend the class with injected functions
6
+ interface TeraClient extends TeraFy {
7
+ getProjectFileContents: (id: any, options?: any) => any
8
+ setProjectFileContents: (id: any, contents: any, options?: any) => any
9
+ getProjectLibrary: (id: any, options?: any) => any
10
+ setProjectLibrary: (id: any, refs:any, options?: any) => any
11
+ };
12
+ type SupabaseFile = any;
13
+ type RefLibRef = any;
3
14
 
4
15
  /**
5
16
  * A project file fetched from TERA
@@ -12,7 +23,7 @@ export default class ProjectFile {
12
23
  * @type {TeraClient}
13
24
  * @private
14
25
  */
15
- _tera;
26
+ _tera!: TeraClient;
16
27
 
17
28
 
18
29
  /**
@@ -20,28 +31,28 @@ export default class ProjectFile {
20
31
  * NOTE: This is computed each time from the Base64 of the file path
21
32
  * @type {String}
22
33
  */
23
- id;
34
+ id!: string;
24
35
 
25
36
 
26
37
  /**
27
38
  * The raw Supabase UUID of the file
28
39
  * @type {String}
29
40
  */
30
- sbId;
41
+ sbId!: string;
31
42
 
32
43
 
33
44
  /**
34
45
  * Relative name path (can contain prefix directories) for the human readable file name
35
46
  * @type {String}
36
47
  */
37
- name;
48
+ name!: string;
38
49
 
39
50
 
40
51
  /**
41
52
  * CSS class to use as the file icon
42
53
  * @type {String}
43
54
  */
44
- icon;
55
+ icon!: string;
45
56
 
46
57
 
47
58
  /**
@@ -49,7 +60,7 @@ export default class ProjectFile {
49
60
  * This is also used as the unique identifier within the project
50
61
  * @type {String}
51
62
  */
52
- path;
63
+ path!: string;
53
64
 
54
65
 
55
66
  /**
@@ -57,7 +68,7 @@ export default class ProjectFile {
57
68
  * This will usually open an edit UI within the TERA site
58
69
  * @type {String}
59
70
  */
60
- url;
71
+ url!: string;
61
72
 
62
73
 
63
74
  /**
@@ -65,7 +76,7 @@ export default class ProjectFile {
65
76
  * This is used to direct to the edit/view/download UI when the files project is active and is usually used in place of URL for TERA related operations
66
77
  * @type {String}
67
78
  */
68
- teraUrl;
79
+ teraUrl!: string;
69
80
 
70
81
 
71
82
  /**
@@ -76,77 +87,83 @@ export default class ProjectFile {
76
87
  * @property {String} ext The extension portion of the name (always lower case)
77
88
  * @property {String} dirName The directory path portion of the name
78
89
  */
79
- parsedName;
90
+ // Using 'any' for simplicity, define an interface for better type safety if desired
91
+ parsedName: any;
80
92
 
81
93
 
82
94
  /**
83
95
  * A date representing when the file was created
84
96
  * @type {Date}
85
97
  */
86
- created;
98
+ // Using Date | undefined because constructor checks if it exists
99
+ created: Date | undefined;
87
100
 
88
101
 
89
102
  /**
90
103
  * A human readable, formatted version of "created"
91
104
  * @type {String}
92
105
  */
93
- createdFormatted;
106
+ createdFormatted!: string;
94
107
 
95
108
 
96
109
  /**
97
110
  * A date representing when the file was created
98
111
  * @type {Date}
99
112
  */
100
- modified;
113
+ // Using Date | undefined because constructor checks if it exists
114
+ modified: Date | undefined;
101
115
 
102
116
 
103
117
  /**
104
118
  * A human readable, formatted version of "modified"
105
119
  * @type {String}
106
120
  */
107
- modifiedFormatted;
121
+ modifiedFormatted!: string;
108
122
 
109
123
 
110
124
  /**
111
125
  * A date representing when the file was last accessed
112
126
  * @type {Date}
113
127
  */
114
- accessed;
128
+ // Using Date | undefined because constructor checks if it exists
129
+ accessed: Date | undefined;
115
130
 
116
131
 
117
132
  /**
118
133
  * A human readable, formatted version of "accessed"
119
134
  * @type {String}
120
135
  */
121
- accessedFormatted;
136
+ accessedFormatted!: string;
122
137
 
123
138
 
124
139
  /**
125
140
  * Size, in bytes, of the file
126
141
  * @type {Number}
127
142
  */
128
- size;
143
+ // Using number | undefined because constructor uses `|| 0`
144
+ size: number | undefined;
129
145
 
130
146
 
131
147
  /**
132
148
  * A human readable, formatted version of the file size
133
149
  * @type {String}
134
150
  */
135
- sizeFormatted;
151
+ sizeFormatted!: string;
136
152
 
137
153
 
138
154
  /**
139
155
  * The associated mime type for the file
140
156
  * @type {String}
141
157
  */
142
- mime;
158
+ mime!: string;
143
159
 
144
160
 
145
161
  /**
146
162
  * Additional meta information for the file
147
163
  * @type {Object}
148
164
  */
149
- meta = {};
165
+ // Using Record<string, any> for a generic object, adjust if meta has a known structure
166
+ meta: Record<string, any> = {};
150
167
 
151
168
 
152
169
  /**
@@ -155,12 +172,14 @@ export default class ProjectFile {
155
172
  * @param {SupabaseFile} baseFile The basic Supabase file to extend
156
173
  * @param {TeraFyClient} baseFile.tera The associated TeraFyClient instance to use for some file methods
157
174
  */
158
- constructor(baseFile) {
175
+
176
+ constructor(baseFile: SupabaseFile) {
177
+ // Note: baseFile.tera is assumed to exist based on the check below and the SupabaseFile type definition above
159
178
  if (!baseFile.tera) throw new Error('Basic file requires a `tera` key to access the Tera instance');
160
179
  Object.assign(this, baseFile);
161
180
 
162
181
  // Translate baseFile.tera -> this._tera (non-enumerable, non-configurable)
163
- const tera = this.tera;
182
+ const tera = (this as any).tera;
164
183
  Object.defineProperty(this, '_tera', {
165
184
  enumerable: false,
166
185
  configurable: false,
@@ -169,13 +188,15 @@ export default class ProjectFile {
169
188
  return tera;
170
189
  },
171
190
  });
172
- delete this.tera; // Remove original ref we merged above
191
+
192
+ delete (this as any).tera; // Remove original ref we merged above
173
193
 
174
194
  // Calculate `teraUrl` from URL
195
+ // Assuming this.url is always defined after Object.assign
175
196
  this.teraUrl = this.url.replace(/^https?:\/\/(?:.+?)\/projects\/(?:.+?)\/project\/(.+)$/, '/project/$1');
176
197
 
177
198
  // Set all `*Formatted` fields
178
- this.sizeFormatted = filesize(this.size || 0, {spacer: ''});
199
+ this.sizeFormatted = filesize(this.size || 0, { spacer: '' });
179
200
  this.createdFormatted = this.created ? this.created.toLocaleDateString() : 'Unknown created date';
180
201
  this.modifiedFormatted = this.modified ? this.modified.toLocaleDateString() : 'Unknown modified date';
181
202
  this.accessedFormatted = this.accessed ? this.accessed.toLocaleDateString() : 'Unknown access date';
@@ -187,11 +208,13 @@ export default class ProjectFile {
187
208
  *
188
209
  * @param {Object} [options] Additioanl options to mutate behaviour
189
210
  *
190
- * @returns {Blob} The eventual raw file contents as a Blob
211
+ * @returns {Promise<Blob>} The eventual raw file contents as a Blob
191
212
  *
192
213
  * @see getProjectFile()
193
214
  */
194
- getContents(options) {
215
+
216
+ getContents(options?: any): Promise<Blob> {
217
+ // Assuming _tera has this method and it returns Promise<Blob>
195
218
  return this._tera.getProjectFileContents(this.id, options);
196
219
  }
197
220
 
@@ -201,11 +224,13 @@ export default class ProjectFile {
201
224
  *
202
225
  * @param {File|Blob|FormData|Object|Array} contents The new file contents
203
226
  *
204
- * @returns {Promise} A promise which resolves when the operation has completed
227
+ * @returns {Promise<void>} A promise which resolves when the operation has completed
205
228
  *
206
229
  * @see setProjectFileContents()
207
230
  */
208
- setContents(contents) {
231
+
232
+ setContents(contents: File | Blob | FormData | object | any[]): Promise<void> {
233
+ // Assuming _tera has this method and it returns Promise<void> or similar
209
234
  return this._tera.setProjectFileContents(this.id, contents, {});
210
235
  }
211
236
 
@@ -213,11 +238,13 @@ export default class ProjectFile {
213
238
  /**
214
239
  * Fetch the file contents as an array of Reflib refs
215
240
  *
216
- * @returns {Promise<Array<Ref>>} An eventual array of RefLib references
241
+ * @returns {Promise<Array<RefLibRef>>} An eventual array of RefLib references
217
242
  *
218
243
  * @see getProjectLibrary()
219
244
  */
220
- getRefs() {
245
+
246
+ getRefs(): Promise<Array<RefLibRef>> {
247
+ // Assuming _tera has this method and it returns Promise<Array<RefLibRef>>
221
248
  return this._tera.getProjectLibrary(this.id);
222
249
  }
223
250
 
@@ -227,11 +254,13 @@ export default class ProjectFile {
227
254
  *
228
255
  * @param {Array<RefLibRef>} refs Collection of references for the selected library
229
256
  *
230
- * @returns {Promise} A promise which resolves when the operation has completed
257
+ * @returns {Promise<void>} A promise which resolves when the operation has completed
231
258
  *
232
259
  * @see setProjectLibrary()
233
260
  */
234
- setRefs(refs) {
261
+
262
+ setRefs(refs: Array<RefLibRef>): Promise<void> {
263
+ // Assuming _tera has this method and it returns Promise<void> or similar
235
264
  return this._tera.setProjectLibrary(this.id, refs);
236
265
  }
237
266
 
@@ -243,7 +272,8 @@ export default class ProjectFile {
243
272
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
244
273
  * @returns {Object} A Structured Clone compatible representation of this ProjectFile instance
245
274
  */
246
- serialize() {
275
+
276
+ serialize(): Partial<ProjectFile> { // Using Partial<ProjectFile> as it returns a subset
247
277
  return pick(this, [
248
278
  'id',
249
279
  'sbId',
@@ -265,13 +295,25 @@ export default class ProjectFile {
265
295
 
266
296
  /**
267
297
  * Restore an entity created with serialize
298
+ * NOTE: This requires the 'tera' instance to be manually added to the 'data' object before calling deserialize,
299
+ * as it's not included in the serialized output.
268
300
  *
269
- * @param {Object} data An input object created via `ProjectFiles.serialize()`
301
+ * @param {Object} data An input object created via `ProjectFiles.serialize()` (MUST include a 'tera' property added manually)
270
302
  * @returns {ProjectFile} A ProjectFile instance setup against the deserializzed data
271
303
  */
272
- static deserialize(data) {
273
- return new ProjectFile(pick(data, [
274
- 'tera',
304
+
305
+ static deserialize(data: any): ProjectFile {
306
+ // TODO: Check the below
307
+ // WARNING: The original 'serialize' method does NOT include 'tera'.
308
+ // The caller of 'deserialize' MUST add the correct 'tera' instance to the 'data' object
309
+ // before passing it here, otherwise the constructor will fail.
310
+ // e.g., const serializedData = file.serialize();
311
+ // serializedData.tera = myTeraClientInstance;
312
+ // const restoredFile = ProjectFile.deserialize(serializedData);
313
+
314
+ // This pick includes 'tera', assuming it was added to 'data' externally.
315
+ const constructorArg = pick(data, [
316
+ 'tera', // Assumes 'tera' exists on the input 'data' object
275
317
  'id',
276
318
  'sbId',
277
319
  'name',
@@ -285,6 +327,7 @@ export default class ProjectFile {
285
327
  'size',
286
328
  'mime',
287
329
  'meta',
288
- ]));
330
+ ]);
331
+ return new ProjectFile(constructorArg);
289
332
  }
290
- }
333
+ }