@jointhedots/gear 1.2.0 → 1.2.3

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 (115) hide show
  1. package/esm/builder/build-app-bundle.d.ts +29 -0
  2. package/esm/builder/build-app-bundle.js +9 -6
  3. package/esm/builder/build-app-host.d.ts +28 -0
  4. package/esm/builder/build-app-host.js +20 -19
  5. package/esm/builder/build-application.d.ts +51 -0
  6. package/esm/builder/build-application.js +53 -74
  7. package/esm/builder/build-library.d.ts +21 -0
  8. package/esm/builder/build-library.js +13 -10
  9. package/esm/builder/build-target.d.ts +36 -0
  10. package/esm/builder/build-target.js +20 -12
  11. package/esm/builder/helpers/emit-artifact.d.ts +13 -0
  12. package/esm/builder/helpers/emit-artifact.js +40 -0
  13. package/esm/builder/helpers/emit-bundle-manifest.d.ts +19 -0
  14. package/esm/builder/helpers/emit-bundle-manifest.js +38 -16
  15. package/esm/builder/helpers/emit-components-dts.d.ts +9 -0
  16. package/esm/builder/helpers/emit-components-dts.js +1 -2
  17. package/esm/builder/helpers/emit-esmodules.d.ts +61 -0
  18. package/esm/builder/helpers/emit-esmodules.js +22 -23
  19. package/esm/builder/helpers/emit-package-manifest.d.ts +9 -0
  20. package/esm/builder/helpers/emit-package-manifest.js +1 -2
  21. package/esm/builder/helpers/emit-static-assets.d.ts +14 -0
  22. package/esm/builder/helpers/emit-static-assets.js +1 -2
  23. package/esm/builder/helpers/emit-typescript-definition.d.ts +35 -0
  24. package/esm/builder/helpers/emit-typescript-definition.js +7 -8
  25. package/esm/builder/helpers/path-helpers.d.ts +9 -0
  26. package/esm/builder/helpers/path-helpers.js +0 -1
  27. package/esm/builder/helpers/task.d.ts +8 -0
  28. package/esm/builder/helpers/task.js +0 -1
  29. package/esm/cli.d.ts +2 -0
  30. package/esm/cli.js +1 -4
  31. package/esm/commands/init.d.ts +2 -0
  32. package/esm/commands/init.js +0 -1
  33. package/esm/commands/install.d.ts +5 -0
  34. package/esm/commands/install.js +3 -4
  35. package/esm/commands/make.d.ts +17 -0
  36. package/esm/commands/make.js +12 -5
  37. package/esm/commands/run.d.ts +8 -0
  38. package/esm/commands/run.js +6 -7
  39. package/esm/commands/serve.d.ts +9 -0
  40. package/esm/commands/serve.js +11 -13
  41. package/esm/core/commands/interface.d.ts +26 -0
  42. package/esm/core/commands/interface.js +21 -0
  43. package/esm/core/components/components.d.ts +73 -0
  44. package/esm/core/components/components.js +2 -0
  45. package/esm/core/components/helpers.d.ts +7 -0
  46. package/esm/core/components/helpers.js +68 -0
  47. package/esm/core/components/manifold.d.ts +77 -0
  48. package/esm/core/components/manifold.js +442 -0
  49. package/esm/core/components/mod.d.ts +4 -0
  50. package/esm/core/components/mod.js +4 -0
  51. package/esm/core/components/provider.d.ts +42 -0
  52. package/esm/core/components/provider.js +127 -0
  53. package/esm/core/logging/mod.d.ts +53 -0
  54. package/esm/core/logging/mod.js +142 -0
  55. package/esm/core/logging/trace.d.ts +51 -0
  56. package/esm/core/logging/trace.js +17 -0
  57. package/esm/core/mod-browser.d.ts +1 -0
  58. package/esm/core/mod-browser.js +1 -0
  59. package/esm/core/mod-node.d.ts +1 -0
  60. package/esm/core/mod-node.js +1 -0
  61. package/esm/core/mod.d.ts +5 -0
  62. package/esm/core/mod.js +5 -0
  63. package/esm/core/schema/helpers.d.ts +36 -0
  64. package/esm/core/schema/helpers.js +163 -0
  65. package/esm/core/schema/mod.d.ts +3 -0
  66. package/esm/core/schema/mod.js +3 -0
  67. package/esm/core/schema/schema.d.ts +376 -0
  68. package/esm/core/schema/schema.js +234 -0
  69. package/esm/core/schema/zod.d.ts +44 -0
  70. package/esm/core/schema/zod.js +127 -0
  71. package/esm/core/services/mod.d.ts +5 -0
  72. package/esm/core/services/mod.js +5 -0
  73. package/esm/core/services/service-accessor.d.ts +17 -0
  74. package/esm/core/services/service-accessor.js +20 -0
  75. package/esm/core/services/service-definitions.d.ts +37 -0
  76. package/esm/core/services/service-definitions.js +44 -0
  77. package/esm/core/services/service-points.d.ts +40 -0
  78. package/esm/core/services/service-points.js +164 -0
  79. package/esm/core/services/service-specification.d.ts +52 -0
  80. package/esm/core/services/service-specification.js +59 -0
  81. package/esm/core/services/settings.d.ts +29 -0
  82. package/esm/core/services/settings.js +123 -0
  83. package/esm/utils/file.d.ts +39 -0
  84. package/esm/utils/file.js +3 -4
  85. package/esm/utils/graph-ordering.d.ts +21 -0
  86. package/esm/utils/graph-ordering.js +0 -1
  87. package/esm/utils/normalized-name.d.ts +17 -0
  88. package/esm/utils/normalized-name.js +0 -1
  89. package/esm/workspace/component.d.ts +70 -0
  90. package/esm/workspace/component.js +0 -1
  91. package/esm/workspace/helpers/config-loader.d.ts +37 -0
  92. package/esm/workspace/helpers/config-loader.js +4 -5
  93. package/esm/workspace/helpers/create-manifests.d.ts +13 -0
  94. package/esm/workspace/helpers/create-manifests.js +3 -4
  95. package/esm/workspace/helpers/discover-workspace.d.ts +4 -0
  96. package/esm/workspace/helpers/discover-workspace.js +19 -30
  97. package/esm/workspace/helpers/lockfile.d.ts +5 -0
  98. package/esm/workspace/helpers/lockfile.js +13 -14
  99. package/esm/workspace/helpers/logger.d.ts +65 -0
  100. package/esm/workspace/helpers/logger.js +1 -2
  101. package/esm/workspace/helpers/package-npm.d.ts +1 -0
  102. package/esm/workspace/helpers/package-npm.js +0 -1
  103. package/esm/workspace/mod.d.ts +1 -0
  104. package/esm/workspace/mod.js +1 -0
  105. package/esm/workspace/packager.d.ts +5 -0
  106. package/esm/workspace/packager.js +1 -2
  107. package/esm/workspace/packagers/packager-standard.d.ts +7 -0
  108. package/esm/workspace/packagers/packager-standard.js +3 -4
  109. package/esm/workspace/storage.d.ts +59 -0
  110. package/esm/workspace/storage.js +4 -5
  111. package/esm/workspace/workspace.d.ts +165 -0
  112. package/esm/workspace/workspace.js +27 -16
  113. package/package.json +74 -66
  114. package/esm/commands/publish.js +0 -36
  115. package/esm/publish/publish_aws_s3.js +0 -67
@@ -0,0 +1,442 @@
1
+ import { URI, Utils } from "vscode-uri";
2
+ import { ComponentControllerKey } from "./components.js";
3
+ import { Log, queryLogInfos, queryLogObjects } from "../logging/mod.js";
4
+ import { parseResourceEntry } from "./helpers.js";
5
+ import { ComponentProviderHub } from "./provider.js";
6
+ // Component registry entry
7
+ export class ComponentEntry {
8
+ id;
9
+ __instance__ = undefined;
10
+ manifest = undefined;
11
+ constructor(id) {
12
+ this.id = id;
13
+ }
14
+ get title() {
15
+ return this.id;
16
+ }
17
+ get namespace() {
18
+ const sep = this.id.indexOf(":");
19
+ switch (sep) {
20
+ case -1:
21
+ return "std";
22
+ case 0:
23
+ return "";
24
+ default:
25
+ return this.id.slice(0, sep);
26
+ }
27
+ }
28
+ get valid() {
29
+ return this.manifest !== undefined && this.manifest.type !== "<error>";
30
+ }
31
+ get loaded() {
32
+ return this.manifest !== undefined;
33
+ }
34
+ get installed() {
35
+ return this.__instance__ !== undefined;
36
+ }
37
+ get instance() {
38
+ return this.__instance__;
39
+ }
40
+ set instance(value) {
41
+ this.__instance__ = value;
42
+ if (value instanceof Object) {
43
+ ComponentsRegistry.datamap.set(value, this);
44
+ }
45
+ else if (value !== null) {
46
+ this.__instance__ = null;
47
+ throw new Error(`Component instance shall be an object`);
48
+ }
49
+ }
50
+ get() {
51
+ if (this.manifest === undefined) {
52
+ throw new Error(`Cannot get manifest of not loaded module`);
53
+ }
54
+ return this.manifest;
55
+ }
56
+ set(manifest) {
57
+ this.manifest = manifest;
58
+ return this;
59
+ }
60
+ fetch() {
61
+ let loading = ComponentsRegistry.loadings.get(this);
62
+ if (loading)
63
+ return loading;
64
+ if (this.manifest === undefined) {
65
+ loading = ComponentsRegistry.components_provider.get_component_manifest(this.id).then(async (manifest) => {
66
+ if (manifest) {
67
+ if (manifest.type) {
68
+ await acquireComponent(manifest.type).fetch();
69
+ }
70
+ this.manifest = manifest;
71
+ }
72
+ else
73
+ throw new Error(`Component '${this.id}' not found`);
74
+ return this.manifest;
75
+ }).catch((e) => {
76
+ Log.error(e, this);
77
+ this.set({
78
+ $id: this.id,
79
+ type: "<error>",
80
+ message: e.message,
81
+ stack: e.stack,
82
+ });
83
+ this.__instance__ = new Error(e.message);
84
+ return this.manifest;
85
+ });
86
+ }
87
+ else {
88
+ loading = Promise.resolve(this.manifest);
89
+ }
90
+ ComponentsRegistry.loadings.set(this, loading);
91
+ return loading;
92
+ }
93
+ async install() {
94
+ let installing = ComponentsRegistry.installings.get(this);
95
+ if (installing)
96
+ return installing;
97
+ if (this.instance === undefined) {
98
+ this.instance = null;
99
+ installing = new Promise(async (resolve) => {
100
+ try {
101
+ if (this.loaded === false) {
102
+ await this.fetch();
103
+ }
104
+ const type = this.manifest?.type;
105
+ if (type) {
106
+ const entry = acquireComponent(type);
107
+ const controller = await ComponentControllerKey.fetch(entry);
108
+ await controller.createComponent(this, this.manifest);
109
+ }
110
+ }
111
+ catch (e) {
112
+ Log.error(e, this);
113
+ }
114
+ resolve(this);
115
+ });
116
+ }
117
+ else {
118
+ installing = Promise.resolve(this);
119
+ }
120
+ ComponentsRegistry.installings.set(this, installing);
121
+ return installing;
122
+ }
123
+ acquireResource(identifier) {
124
+ const ref = `${this.id}#${identifier}`;
125
+ let rc = ComponentsRegistry.resources.get(ref);
126
+ if (!rc) {
127
+ rc = new ComponentResource(this, identifier);
128
+ ComponentsRegistry.resources.set(ref, rc);
129
+ }
130
+ return rc;
131
+ }
132
+ getResource(identifier) {
133
+ if (this.hasResource(identifier)) {
134
+ return this.acquireResource(identifier);
135
+ }
136
+ return null;
137
+ }
138
+ hasResource(identifier) {
139
+ const { manifest } = this;
140
+ if (manifest?.apis?.[identifier]) {
141
+ return true;
142
+ }
143
+ else if (manifest?.type) {
144
+ const type = acquireComponent(manifest.type);
145
+ if (type) {
146
+ return type?.hasResource(`component.${identifier}`);
147
+ }
148
+ }
149
+ return false;
150
+ }
151
+ async getResourceAsync(identifier) {
152
+ if (this.manifest === undefined)
153
+ await this.fetch();
154
+ return this.getResource(identifier);
155
+ }
156
+ async fetchResource(identifier) {
157
+ if (this.manifest === undefined)
158
+ await this.fetch();
159
+ return this.getResource(identifier)?.fetch();
160
+ }
161
+ getLogStats() {
162
+ return queryLogInfos(this.id);
163
+ }
164
+ getLogs(count) {
165
+ return queryLogObjects(count, this.id);
166
+ }
167
+ }
168
+ // Component resource
169
+ export class ComponentResource {
170
+ component;
171
+ resource;
172
+ entry = undefined;
173
+ identifier = undefined;
174
+ constructor(component, resource) {
175
+ this.component = component;
176
+ this.resource = resource;
177
+ component.fetch();
178
+ }
179
+ get valid() {
180
+ return this.identifier !== undefined && this.component.valid;
181
+ }
182
+ get loaded() {
183
+ return this.identifier !== undefined;
184
+ }
185
+ async fetch() {
186
+ if (this.identifier === undefined) {
187
+ let loading = ComponentsRegistry.loadings.get(this);
188
+ if (loading)
189
+ return loading;
190
+ loading = new Promise(async (resolve) => {
191
+ const { component } = this;
192
+ try {
193
+ // Fetch manifest with resource catalog
194
+ if (component.installed === false) {
195
+ await component.install();
196
+ }
197
+ // Fetch resource data
198
+ const { manifest } = component;
199
+ const entry = parseResourceEntry(manifest.apis?.[this.resource]);
200
+ const type = entry?.type;
201
+ if (type === "module") {
202
+ this.entry = await ComponentsRegistry.resources_loader.load_resource(entry.location);
203
+ this.identifier = entry.identifier;
204
+ }
205
+ /*else if (type === "api.rest") {
206
+ this.entry = __import_RESTService(entry as RESTServiceImport, component)
207
+ this.identifier = null
208
+ }*/
209
+ else if (manifest.type) {
210
+ const controller = acquireComponent(manifest.type);
211
+ const resource = controller.getResource(`component.${this.resource}`);
212
+ if (resource) {
213
+ const getter = await resource.fetch();
214
+ if (getter)
215
+ this.entry = await getter(this.component);
216
+ else
217
+ this.entry = null;
218
+ this.identifier = null;
219
+ }
220
+ else {
221
+ throw new Error(`Cannot provide resource '${this.resource}'`);
222
+ }
223
+ }
224
+ else {
225
+ throw new Error(`Cannot load resource '${this.resource}': ${JSON.stringify(entry)}`);
226
+ }
227
+ const entrypoint = this.get();
228
+ if (entrypoint instanceof Object) {
229
+ ComponentsRegistry.datamap.set(entrypoint, this);
230
+ }
231
+ }
232
+ catch (e) {
233
+ console.error(`Cannot install service api '${this.resource}' of '${component.id}':`, e);
234
+ this.entry = null;
235
+ this.identifier = null;
236
+ }
237
+ resolve(this.get());
238
+ ComponentsRegistry.loadings.set(this, null);
239
+ });
240
+ ComponentsRegistry.loadings.set(this, loading);
241
+ return loading;
242
+ }
243
+ else {
244
+ return this.get();
245
+ }
246
+ }
247
+ get() {
248
+ if (this.entry) {
249
+ if (this.identifier !== null) {
250
+ return this.entry?.[this.identifier];
251
+ }
252
+ else {
253
+ return this.entry;
254
+ }
255
+ }
256
+ return undefined;
257
+ }
258
+ set(data) {
259
+ this.entry = data;
260
+ this.identifier = null;
261
+ }
262
+ get spec() {
263
+ const norm = this.resource.split(".")[0];
264
+ return this.component.manifest?.specs?.[norm];
265
+ }
266
+ get url() {
267
+ const ref = this.component.manifest?.apis?.[this.resource];
268
+ if (typeof ref === "string") {
269
+ const base = URI.parse(window.location.href).with({ fragment: null });
270
+ const uri = Utils.joinPath(base, "..", ref.split("#")[0]);
271
+ return uri.toString();
272
+ }
273
+ return null;
274
+ }
275
+ }
276
+ export class ComponentsManifold {
277
+ components = new Map();
278
+ resources = new Map();
279
+ datamap = new WeakMap();
280
+ loadings = new Map();
281
+ installings = new Map();
282
+ listeners = new Set();
283
+ components_provider = null;
284
+ resources_loader = null;
285
+ content_provider = null;
286
+ constructor() {
287
+ /*
288
+ const componen_provider=new ComponentProviderHub()
289
+ this.content_provider = new StaticContentProvider()
290
+ this.components_provider.add_provider(new StaticComponentProvider(this.content_provider))
291
+ this.components_provider.add_provider(createLocalComponentProvider())
292
+ this.resources_loader = new CommonResourceProvider(this.content_provider)*/
293
+ }
294
+ listen(l) {
295
+ this.listeners.add(l);
296
+ return l;
297
+ }
298
+ unlisten(l) {
299
+ this.listeners.delete(l);
300
+ }
301
+ notifyError(subject, error) {
302
+ }
303
+ }
304
+ export const ComponentsRegistry = new ComponentsManifold();
305
+ acquireComponent("<error>").set({
306
+ $id: "<error>",
307
+ icon: "bi:house",
308
+ title: "Define invalid component",
309
+ });
310
+ export function getDefaultComponent() {
311
+ return acquireComponent("log:application");
312
+ }
313
+ export function getComponentFromData(data, is_static) {
314
+ if (data instanceof Object) {
315
+ const target = ComponentsRegistry.datamap.get(data) || data;
316
+ if (target instanceof ComponentEntry) {
317
+ return target;
318
+ }
319
+ if (target instanceof ComponentResource) {
320
+ return target.component;
321
+ }
322
+ if (!is_static && data["getComponent"] instanceof Function) {
323
+ return getComponentFromData(data["getComponent"](), true);
324
+ }
325
+ }
326
+ return getDefaultComponent();
327
+ }
328
+ export function acquireComponent(id) {
329
+ let obj = ComponentsRegistry.components.get(id);
330
+ if (!obj && typeof id === "string") {
331
+ obj = new ComponentEntry(id);
332
+ ComponentsRegistry.components.set(id, obj);
333
+ }
334
+ return obj;
335
+ }
336
+ export function acquireFutureComponent(manifest) {
337
+ const id = manifest.$id;
338
+ let obj = ComponentsRegistry.components.get(id);
339
+ if (!obj && typeof id === "string") {
340
+ obj = new ComponentEntry(id);
341
+ obj.manifest = manifest;
342
+ obj.instance = null;
343
+ ComponentsRegistry.components.set(id, obj);
344
+ }
345
+ return obj;
346
+ }
347
+ export function acquireResource(ref) {
348
+ const parts = ref.split("#");
349
+ if (parts.length === 2) {
350
+ const entry = acquireComponent(parts[0]);
351
+ return entry?.acquireResource(parts[1]);
352
+ }
353
+ return null;
354
+ }
355
+ export function resolveRelativeComponent(ref, from) {
356
+ if (from && ref.startsWith("/")) {
357
+ return acquireComponent(`${from?.id}${ref}`);
358
+ }
359
+ return null;
360
+ }
361
+ export async function saveComponentManifest(manifest) {
362
+ const component = acquireComponent(manifest.$id);
363
+ ComponentsRegistry.loadings.delete(component);
364
+ component.manifest = manifest;
365
+ return saveComponent(component);
366
+ }
367
+ export async function saveComponent(component) {
368
+ console.log("[Update Component]", component.id);
369
+ const manifest = await component.fetch();
370
+ const provider = ComponentsRegistry.components_provider;
371
+ if (!provider)
372
+ throw new Error(`No component provider`);
373
+ await provider.add_component(manifest);
374
+ if (component.loaded) {
375
+ if (manifest.type && component.installed) {
376
+ const controller = await ComponentControllerKey.fetch(acquireComponent(manifest.type));
377
+ if (controller) {
378
+ if (component.instance) {
379
+ await controller.updateComponent(component, manifest);
380
+ }
381
+ else {
382
+ component["__instance__"] = undefined;
383
+ await controller.createComponent(component, manifest);
384
+ }
385
+ }
386
+ if (component.instance instanceof Object) {
387
+ ComponentsRegistry.datamap.set(component.instance, component);
388
+ }
389
+ ComponentsRegistry.listeners.forEach(l => l(component));
390
+ }
391
+ }
392
+ return component;
393
+ }
394
+ export async function deleteComponent(id) {
395
+ console.log("deleteComponent", id);
396
+ const provider = ComponentsRegistry.components_provider;
397
+ if (!provider)
398
+ throw new Error(`No component provider`);
399
+ if (await provider.delete_component(id)) {
400
+ unregisterComponent(id);
401
+ }
402
+ }
403
+ export function unregisterComponent(id) {
404
+ const component = ComponentsRegistry.components.get(id);
405
+ if (component) {
406
+ component.set({
407
+ $id: component.id,
408
+ type: "<error>",
409
+ message: `Component deleted`,
410
+ });
411
+ ComponentsRegistry.listeners.forEach(l => l(component));
412
+ ComponentsRegistry.components.delete(id);
413
+ }
414
+ }
415
+ export async function searchComponentsPublications(filter) {
416
+ const provider = ComponentsRegistry.components_provider;
417
+ if (!provider)
418
+ throw new Error(`No component provider`);
419
+ return provider.search_component_publications(filter);
420
+ }
421
+ export async function fetchComponentsPublications(components_ids) {
422
+ const results = [];
423
+ const provider = ComponentsRegistry.components_provider;
424
+ if (!provider)
425
+ throw new Error(`No component provider`);
426
+ for (const id of components_ids) {
427
+ const cnx = await provider.get_component_publication(id);
428
+ if (cnx) {
429
+ results.push(cnx);
430
+ }
431
+ else {
432
+ results.push(failedComponentPublication(id));
433
+ }
434
+ }
435
+ return results;
436
+ }
437
+ export function failedComponentPublication(id, title) {
438
+ return {
439
+ id: id,
440
+ title: title ? title : "! Not found: " + id,
441
+ };
442
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./components.ts";
2
+ export * from "./manifold.ts";
3
+ export * from "./provider.ts";
4
+ export * from "./helpers.ts";
@@ -0,0 +1,4 @@
1
+ export * from "./components.js";
2
+ export * from "./manifold.js";
3
+ export * from "./provider.js";
4
+ export * from "./helpers.js";
@@ -0,0 +1,42 @@
1
+ import { type ComponentManifest, type ComponentPublication } from "@jointhedots/gear/core";
2
+ import { URI } from "vscode-uri";
3
+ export type ContentType = string;
4
+ export interface IResourceLoader {
5
+ load_resource(uri: string): Promise<any>;
6
+ }
7
+ export interface IComponentPublisher {
8
+ search_component_publications(filter: ComponentFilter): Promise<ComponentPublication[]>;
9
+ get_component_publication(component_id: string): Promise<ComponentPublication>;
10
+ }
11
+ export interface IComponentProvider extends IComponentPublisher {
12
+ get_component_manifest(component_id: string): Promise<ComponentManifest>;
13
+ set_component_manifest(component_id: string, manifest: ComponentManifest): Promise<boolean>;
14
+ add_component(manifest: ComponentManifest): Promise<ComponentPublication>;
15
+ delete_component(component_id: string): Promise<boolean>;
16
+ }
17
+ export interface IContentProvider {
18
+ check_content(uri: URI): Promise<ContentType>;
19
+ load_content(uri: URI): Promise<Blob>;
20
+ store_content(uri: URI, content: Blob): Promise<boolean>;
21
+ }
22
+ export type ComponentFilter = {
23
+ query: string;
24
+ pattern: RegExp;
25
+ keywords: string[];
26
+ tags: string[];
27
+ types: string[];
28
+ services: string[];
29
+ };
30
+ export declare function createComponentFilter(filter?: Partial<ComponentFilter>): ComponentFilter;
31
+ export declare function matchComponentFilter(pub: ComponentPublication, filter?: Partial<ComponentFilter>): boolean;
32
+ export declare class ComponentProviderHub implements IComponentProvider {
33
+ readonly providers: IComponentProvider[];
34
+ constructor(providers?: IComponentProvider[]);
35
+ add_provider(provider: IComponentProvider): void;
36
+ get_component_publication(id: string): Promise<ComponentPublication>;
37
+ search_component_publications(filter: ComponentFilter): Promise<ComponentPublication[]>;
38
+ get_component_manifest(id: string): Promise<ComponentManifest>;
39
+ set_component_manifest(component_id: string, manifest: ComponentManifest): Promise<boolean>;
40
+ add_component(manifest: ComponentManifest): Promise<ComponentPublication>;
41
+ delete_component(component_id: string): Promise<boolean>;
42
+ }
@@ -0,0 +1,127 @@
1
+ import {} from "@jointhedots/gear/core";
2
+ import { URI } from "vscode-uri";
3
+ export function createComponentFilter(filter) {
4
+ const result = {
5
+ query: filter?.query || "",
6
+ pattern: filter?.pattern || null,
7
+ tags: filter?.tags || [],
8
+ keywords: filter?.keywords || [],
9
+ services: filter?.services || [],
10
+ types: filter?.types || [],
11
+ };
12
+ if (result.query.length > 0) {
13
+ for (const kw of result.query.split(/\s/)) {
14
+ if (kw.length > 0 && !result.keywords.includes(kw)) {
15
+ result.keywords.push(kw);
16
+ }
17
+ }
18
+ }
19
+ if (result.keywords.length > 0) {
20
+ result.pattern = new RegExp(`(${result.keywords.join(").*(")})`);
21
+ }
22
+ return result;
23
+ }
24
+ export function matchComponentFilter(pub, filter) {
25
+ function match_text(text, pattern) {
26
+ if (!pattern) {
27
+ return true;
28
+ }
29
+ if (text) {
30
+ return !pattern || pattern.test(text);
31
+ }
32
+ return false;
33
+ }
34
+ function match_item_in_list(target, expecteds) {
35
+ if (expecteds.length === 0) {
36
+ return true;
37
+ }
38
+ if (target && expecteds.includes(target)) {
39
+ return true;
40
+ }
41
+ return false;
42
+ }
43
+ function match_list_in_list(targets, expecteds) {
44
+ if (expecteds.length === 0) {
45
+ return true;
46
+ }
47
+ if (targets) {
48
+ for (const target of targets) {
49
+ if (expecteds.includes(target))
50
+ return true;
51
+ }
52
+ }
53
+ return false;
54
+ }
55
+ if (!match_text(pub.title || pub.id, filter.pattern) && !match_text(pub.description, filter.pattern))
56
+ return false;
57
+ if (!match_list_in_list(pub.services, filter.services))
58
+ return false;
59
+ if (!match_list_in_list(pub.keywords, filter.keywords))
60
+ return false;
61
+ if (!match_list_in_list(pub.tags, filter.tags))
62
+ return false;
63
+ if (!match_item_in_list(pub.type, filter.types))
64
+ return false;
65
+ return true;
66
+ }
67
+ //-------------------------------------------------------------
68
+ // Component providers hub
69
+ //-------------------------------------------------------------
70
+ export class ComponentProviderHub {
71
+ providers;
72
+ constructor(providers = []) {
73
+ this.providers = providers;
74
+ }
75
+ add_provider(provider) {
76
+ this.providers.push(provider);
77
+ }
78
+ async get_component_publication(id) {
79
+ for (const provider of this.providers) {
80
+ const found = await provider.get_component_publication(id);
81
+ if (found)
82
+ return found;
83
+ }
84
+ return null;
85
+ }
86
+ async search_component_publications(filter) {
87
+ const result = [];
88
+ for (const provider of this.providers) {
89
+ const founds = await provider.search_component_publications(filter);
90
+ if (founds)
91
+ result.push(...founds);
92
+ }
93
+ return result;
94
+ }
95
+ async get_component_manifest(id) {
96
+ for (const provider of this.providers) {
97
+ const founds = await provider.get_component_manifest(id);
98
+ if (founds)
99
+ return founds;
100
+ }
101
+ return null;
102
+ }
103
+ async set_component_manifest(component_id, manifest) {
104
+ for (const provider of this.providers) {
105
+ const done = await provider.set_component_manifest(component_id, manifest);
106
+ if (done)
107
+ return true;
108
+ }
109
+ return false;
110
+ }
111
+ async add_component(manifest) {
112
+ for (const provider of this.providers) {
113
+ const done = await provider.add_component(manifest);
114
+ if (done)
115
+ return done;
116
+ }
117
+ return null;
118
+ }
119
+ async delete_component(component_id) {
120
+ for (const provider of this.providers) {
121
+ const done = await provider.delete_component(component_id);
122
+ if (done)
123
+ return true;
124
+ }
125
+ return false;
126
+ }
127
+ }
@@ -0,0 +1,53 @@
1
+ import type { Command } from "../commands/interface.ts";
2
+ export { print } from "./trace.ts";
3
+ export type LogObjectID = string;
4
+ export type LogStatus = "error" | "warn" | "notify" | "info";
5
+ export type LogKind = "event" | "ticket";
6
+ export interface ILogDispatcher {
7
+ notifyError(error: Error, subject?: any): any;
8
+ notifyObject(object: LogObject): any;
9
+ }
10
+ export interface ILogSubject {
11
+ getSubject(): string;
12
+ }
13
+ export interface LogAction extends Command {
14
+ optional?: boolean;
15
+ doc_uri?: string;
16
+ callback?: Command;
17
+ }
18
+ export interface LogObject {
19
+ id: LogObjectID;
20
+ kind: LogKind;
21
+ status: LogStatus;
22
+ message: string;
23
+ component_id: string;
24
+ doc_uri?: string;
25
+ icon?: string;
26
+ title?: string;
27
+ attributes?: Record<string, string | number>;
28
+ actions?: LogAction[];
29
+ }
30
+ export declare function registerLogCollector(collector: ILogDispatcher): void;
31
+ export declare function unregisterLogCollector(collector: ILogDispatcher): void;
32
+ export declare function queryLogCount(): number;
33
+ export type QueryLogResult = {
34
+ objects: LogObject[];
35
+ hasMore: boolean;
36
+ };
37
+ export declare function queryLogObjects(count: number, component_id?: string): QueryLogResult;
38
+ export type LogInfos = {
39
+ action_expected_count: number;
40
+ error_count: number;
41
+ warn_count: number;
42
+ notify_count: number;
43
+ info_count: number;
44
+ };
45
+ export declare function queryLogInfos(component_id?: string): LogInfos;
46
+ export declare const Log: {
47
+ send(object: LogObject): void;
48
+ error(error: Error, target?: any): void;
49
+ event(target: any, options?: Partial<LogObject>): void;
50
+ openTicket(target: any, name: string, options?: Partial<LogObject>): void;
51
+ closeTicket(target: any, name: string): void;
52
+ };
53
+ export declare function createLogFromError(error: Error, target?: any): LogObject;