@modular-circuit/middleware 0.0.25

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 (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/build/bom/bom_match.d.ts +11 -0
  4. package/build/bom/bom_match.d.ts.map +1 -0
  5. package/build/bom/bom_match.js +0 -0
  6. package/build/bom/index.d.ts +2 -0
  7. package/build/bom/index.d.ts.map +1 -0
  8. package/build/bom/index.js +1 -0
  9. package/build/index.d.ts +3 -0
  10. package/build/index.d.ts.map +1 -0
  11. package/build/index.js +2 -0
  12. package/build/mock/index.d.ts +3 -0
  13. package/build/mock/index.d.ts.map +1 -0
  14. package/build/mock/index.js +2 -0
  15. package/build/mock/module_circuits/index.d.ts +5 -0
  16. package/build/mock/module_circuits/index.d.ts.map +1 -0
  17. package/build/mock/module_circuits/index.js +3 -0
  18. package/build/mock/module_circuits/test_module_a.json +71 -0
  19. package/build/mock/module_circuits/test_module_b.json +71 -0
  20. package/build/mock/module_circuits_categories/categories.json +1 -0
  21. package/build/mock/module_circuits_categories/index.d.ts +87 -0
  22. package/build/mock/module_circuits_categories/index.d.ts.map +1 -0
  23. package/build/mock/module_circuits_categories/index.js +2 -0
  24. package/build/registry/default_registry_mgr.d.ts +12 -0
  25. package/build/registry/default_registry_mgr.d.ts.map +1 -0
  26. package/build/registry/default_registry_mgr.js +118 -0
  27. package/build/registry/http_registry.d.ts +21 -0
  28. package/build/registry/http_registry.d.ts.map +1 -0
  29. package/build/registry/http_registry.js +85 -0
  30. package/build/registry/index.d.ts +4 -0
  31. package/build/registry/index.d.ts.map +1 -0
  32. package/build/registry/index.js +3 -0
  33. package/build/registry/registry_mgr.d.ts +8 -0
  34. package/build/registry/registry_mgr.d.ts.map +1 -0
  35. package/build/registry/registry_mgr.js +0 -0
  36. package/build/tsconfig.build.tsbuildinfo +1 -0
  37. package/build/utils/index.d.ts +3 -0
  38. package/build/utils/index.d.ts.map +1 -0
  39. package/build/utils/index.js +27 -0
  40. package/package.json +38 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022-current Alberto Schiabel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Modular Circuit Runtime
2
+
3
+ Runtime for Modular Circuit
@@ -0,0 +1,11 @@
1
+ import type { Component, SCH_SYMBOL_PROPERTIES } from '@modular-circuit/ir';
2
+ /**
3
+ * BOM 匹配
4
+ */
5
+ export interface BomMatch {
6
+ /**
7
+ * 匹配 KiCad的原理图符号
8
+ */
9
+ match_sch_symbol(sch_symbol: SCH_SYMBOL_PROPERTIES & Record<string, string>): Component[];
10
+ }
11
+ //# sourceMappingURL=bom_match.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bom_match.d.ts","sourceRoot":"","sources":["../../src/bom/bom_match.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAE3E;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,gBAAgB,CAAC,UAAU,EAAE,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAAE,CAAA;CAC1F"}
File without changes
@@ -0,0 +1,2 @@
1
+ export * from './bom_match';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bom/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
@@ -0,0 +1 @@
1
+ export * from './bom_match';
@@ -0,0 +1,3 @@
1
+ export * from './registry';
2
+ export * from './bom';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,OAAO,CAAA"}
package/build/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './registry';
2
+ export * from './bom';
@@ -0,0 +1,3 @@
1
+ export * from './module_circuits';
2
+ export * from './module_circuits_categories';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mock/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,8BAA8B,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './module_circuits';
2
+ export * from './module_circuits_categories';
@@ -0,0 +1,5 @@
1
+ import type { ModuleCircuit } from '@modular-circuit/ir';
2
+ declare const Test_Module_A: Promise<ModuleCircuit>;
3
+ declare const Test_Module_B: Promise<ModuleCircuit>;
4
+ export { Test_Module_A, Test_Module_B };
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mock/module_circuits/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAExD,QAAA,MAAM,aAAa,EAAgD,OAAO,CAAC,aAAa,CAAC,CAAA;AACzF,QAAA,MAAM,aAAa,EAAgD,OAAO,CAAC,aAAa,CAAC,CAAA;AAEzF,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,CAAA"}
@@ -0,0 +1,3 @@
1
+ var Test_Module_A = import('./test_module_a.json');
2
+ var Test_Module_B = import('./test_module_b.json');
3
+ export { Test_Module_A, Test_Module_B };
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "TestModuleNamA",
3
+ "main": "example_module.modular_circuit",
4
+ "author": "Jane Doe",
5
+ "short_description": "This is a short description of the module.",
6
+ "detailed_description": "This is a detailed description of the module, including its features and usage.",
7
+ "create_date_time": "2024-04-01T12:00:00Z",
8
+ "dependencies": {
9
+ "dependency1": "1.0.0",
10
+ "dependency2": "2.0.0"
11
+ },
12
+ "bom_is_completed": true,
13
+ "version": "1.0.0",
14
+ "specifications": [
15
+ {
16
+ "name": "Voltage",
17
+ "value": "5V",
18
+ "functionality": ""
19
+ },
20
+ {
21
+ "name": "Current",
22
+ "value": "2A",
23
+ "functionality": ""
24
+ }
25
+ ],
26
+ "categories": ["category1", "category2"],
27
+ "tags": [
28
+ {
29
+ "name": "Electronics",
30
+ "description": "Electronic components"
31
+ },
32
+ {
33
+ "name": "Power",
34
+ "description": "Power supply modules"
35
+ }
36
+ ],
37
+ "bom": [
38
+ {
39
+ "item": "Resistor",
40
+ "value": "100 Ohms",
41
+ "quantity": 10
42
+ },
43
+ {
44
+ "item": "Capacitor",
45
+ "value": "10uF",
46
+ "quantity": 5
47
+ }
48
+ ],
49
+ "ports": {
50
+ "power:GND": {
51
+ "type": "GND",
52
+ "description": "Input port"
53
+ },
54
+ "power:+3V3": {
55
+ "type": "power",
56
+ "description": "Output port"
57
+ },
58
+ "PortA": {
59
+ "type": "analog",
60
+ "shape": "input",
61
+ "description": "Output port"
62
+ },
63
+ "PortB": {
64
+ "type": "analog",
65
+ "shape": "output",
66
+ "description": "Output port"
67
+ }
68
+ },
69
+ "number_of_uses": 150,
70
+ "number_of_collections": 50
71
+ }
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "TestModuleNamB",
3
+ "main": "example_module.modular_circuit",
4
+ "author": "Jane Doe",
5
+ "short_description": "This is a short description of the module.",
6
+ "detailed_description": "This is a detailed description of the module, including its features and usage.",
7
+ "create_date_time": "2024-04-01T12:00:00Z",
8
+ "dependencies": {
9
+ "dependency1": "1.0.0",
10
+ "dependency2": "2.0.0"
11
+ },
12
+ "bom_is_completed": true,
13
+ "version": "1.0.0",
14
+ "specifications": [
15
+ {
16
+ "name": "Voltage",
17
+ "value": "5V",
18
+ "functionality": ""
19
+ },
20
+ {
21
+ "name": "Current",
22
+ "value": "2A",
23
+ "functionality": ""
24
+ }
25
+ ],
26
+ "categories": ["category1", "category2"],
27
+ "tags": [
28
+ {
29
+ "name": "Electronics",
30
+ "description": "Electronic components"
31
+ },
32
+ {
33
+ "name": "Power",
34
+ "description": "Power supply modules"
35
+ }
36
+ ],
37
+ "bom": [
38
+ {
39
+ "item": "Resistor",
40
+ "value": "100 Ohms",
41
+ "quantity": 10
42
+ },
43
+ {
44
+ "item": "Capacitor",
45
+ "value": "10uF",
46
+ "quantity": 5
47
+ }
48
+ ],
49
+ "ports": {
50
+ "power:GND": {
51
+ "type": "GND",
52
+ "description": "Input port"
53
+ },
54
+ "power:+3V3": {
55
+ "type": "power",
56
+ "description": "Output port"
57
+ },
58
+ "PortA": {
59
+ "type": "analog",
60
+ "shape": "input",
61
+ "description": "Output port"
62
+ },
63
+ "PortB": {
64
+ "type": "analog",
65
+ "shape": "output",
66
+ "description": "Output port"
67
+ }
68
+ },
69
+ "number_of_uses": 150,
70
+ "number_of_collections": 50
71
+ }
@@ -0,0 +1 @@
1
+ ["AUDIO INPUT", "AC DC VOLTAGE CONVERTER", "BLUETOOTH", "EEPROM", "FLASH", "MCU", "USB BRIDGE"]
@@ -0,0 +1,87 @@
1
+ declare const Categories: Promise<{
2
+ default: string[];
3
+ length: number;
4
+ toString(): string;
5
+ toLocaleString(): string;
6
+ toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string;
7
+ pop(): string | undefined;
8
+ push(...items: string[]): number;
9
+ concat(...items: ConcatArray<string>[]): string[];
10
+ concat(...items: (string | ConcatArray<string>)[]): string[];
11
+ join(separator?: string): string;
12
+ reverse(): string[];
13
+ shift(): string | undefined;
14
+ slice(start?: number, end?: number): string[];
15
+ sort(compareFn?: ((a: string, b: string) => number) | undefined): string[];
16
+ splice(start: number, deleteCount?: number): string[];
17
+ splice(start: number, deleteCount: number, ...items: string[]): string[];
18
+ unshift(...items: string[]): number;
19
+ indexOf(searchElement: string, fromIndex?: number): number;
20
+ lastIndexOf(searchElement: string, fromIndex?: number): number;
21
+ every<S extends string>(predicate: (value: string, index: number, array: string[]) => value is S, thisArg?: any): this is S[];
22
+ every(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): boolean;
23
+ some(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): boolean;
24
+ forEach(callbackfn: (value: string, index: number, array: string[]) => void, thisArg?: any): void;
25
+ map<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): U[];
26
+ filter<S extends string>(predicate: (value: string, index: number, array: string[]) => value is S, thisArg?: any): S[];
27
+ filter(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): string[];
28
+ reduce(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string;
29
+ reduce(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string;
30
+ reduce<U>(callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U;
31
+ reduceRight(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string;
32
+ reduceRight(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string;
33
+ reduceRight<U>(callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U;
34
+ find<S extends string>(predicate: (value: string, index: number, obj: string[]) => value is S, thisArg?: any): S | undefined;
35
+ find(predicate: (value: string, index: number, obj: string[]) => unknown, thisArg?: any): string | undefined;
36
+ findIndex(predicate: (value: string, index: number, obj: string[]) => unknown, thisArg?: any): number;
37
+ fill(value: string, start?: number, end?: number): string[];
38
+ copyWithin(target: number, start: number, end?: number): string[];
39
+ entries(): ArrayIterator<[number, string]>;
40
+ keys(): ArrayIterator<number>;
41
+ values(): ArrayIterator<string>;
42
+ includes(searchElement: string, fromIndex?: number): boolean;
43
+ flatMap<U, This = undefined>(callback: (this: This, value: string, index: number, array: string[]) => U | readonly U[], thisArg?: This | undefined): U[];
44
+ flat<A, D extends number = 1>(this: A, depth?: D | undefined): FlatArray<A, D>[];
45
+ [Symbol.iterator](): ArrayIterator<string>;
46
+ [Symbol.unscopables]: {
47
+ [x: number]: boolean | undefined;
48
+ length?: boolean | undefined;
49
+ toString?: boolean | undefined;
50
+ toLocaleString?: boolean | undefined;
51
+ pop?: boolean | undefined;
52
+ push?: boolean | undefined;
53
+ concat?: boolean | undefined;
54
+ join?: boolean | undefined;
55
+ reverse?: boolean | undefined;
56
+ shift?: boolean | undefined;
57
+ slice?: boolean | undefined;
58
+ sort?: boolean | undefined;
59
+ splice?: boolean | undefined;
60
+ unshift?: boolean | undefined;
61
+ indexOf?: boolean | undefined;
62
+ lastIndexOf?: boolean | undefined;
63
+ every?: boolean | undefined;
64
+ some?: boolean | undefined;
65
+ forEach?: boolean | undefined;
66
+ map?: boolean | undefined;
67
+ filter?: boolean | undefined;
68
+ reduce?: boolean | undefined;
69
+ reduceRight?: boolean | undefined;
70
+ find?: boolean | undefined;
71
+ findIndex?: boolean | undefined;
72
+ fill?: boolean | undefined;
73
+ copyWithin?: boolean | undefined;
74
+ entries?: boolean | undefined;
75
+ keys?: boolean | undefined;
76
+ values?: boolean | undefined;
77
+ includes?: boolean | undefined;
78
+ flatMap?: boolean | undefined;
79
+ flat?: boolean | undefined;
80
+ [Symbol.iterator]?: boolean | undefined;
81
+ readonly [Symbol.unscopables]?: boolean | undefined;
82
+ at?: boolean | undefined;
83
+ };
84
+ at(index: number): string | undefined;
85
+ }>;
86
+ export { Categories };
87
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mock/module_circuits_categories/index.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAA8B,CAAA;AAE9C,OAAO,EAAE,UAAU,EAAE,CAAA"}
@@ -0,0 +1,2 @@
1
+ var Categories = import('./categories.json');
2
+ export { Categories };
@@ -0,0 +1,12 @@
1
+ import type { ModuleCircuit, ModuleResolver } from '@modular-circuit/ir';
2
+ import type { ModuleIndex } from '@modular-circuit/ir';
3
+ import { type HttpConfig } from './http_registry';
4
+ import type { RegistryMgr } from './registry_mgr';
5
+ export declare class DefaultRegistryMgr implements RegistryMgr {
6
+ private registries;
7
+ constructor(http_registries: HttpConfig[]);
8
+ get_available_registries(): Promise<ModuleResolver[]>;
9
+ get_module_achieve(idx: ModuleIndex): Promise<URL | undefined>;
10
+ get_module_circuit(idx: ModuleIndex): Promise<ModuleCircuit | undefined>;
11
+ }
12
+ //# sourceMappingURL=default_registry_mgr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default_registry_mgr.d.ts","sourceRoot":"","sources":["../../src/registry/default_registry_mgr.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,KAAK,UAAU,EAAgB,MAAM,iBAAiB,CAAA;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAEjD,qBAAa,kBAAmB,YAAW,WAAW;IACpD,OAAO,CAAC,UAAU,CAAuB;gBACtB,eAAe,EAAE,UAAU,EAAE;IAK1C,wBAAwB,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAG3D,kBAAkB,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC;IAS9D,kBAAkB,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CASzE"}
@@ -0,0 +1,118 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ var __values = (this && this.__values) || function(o) {
38
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
39
+ if (m) return m.call(o);
40
+ if (o && typeof o.length === "number") return {
41
+ next: function () {
42
+ if (o && i >= o.length) o = void 0;
43
+ return { value: o && o[i++], done: !o };
44
+ }
45
+ };
46
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
47
+ };
48
+ import { HttpRegistry } from './http_registry';
49
+ var DefaultRegistryMgr = /** @class */ (function () {
50
+ function DefaultRegistryMgr(http_registries) {
51
+ var e_1, _a;
52
+ this.registries = [];
53
+ try {
54
+ for (var http_registries_1 = __values(http_registries), http_registries_1_1 = http_registries_1.next(); !http_registries_1_1.done; http_registries_1_1 = http_registries_1.next()) {
55
+ var cnf = http_registries_1_1.value;
56
+ this.registries.push(new HttpRegistry(cnf));
57
+ }
58
+ }
59
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
60
+ finally {
61
+ try {
62
+ if (http_registries_1_1 && !http_registries_1_1.done && (_a = http_registries_1.return)) _a.call(http_registries_1);
63
+ }
64
+ finally { if (e_1) throw e_1.error; }
65
+ }
66
+ }
67
+ DefaultRegistryMgr.prototype.get_available_registries = function () {
68
+ return __awaiter(this, void 0, void 0, function () {
69
+ return __generator(this, function (_a) {
70
+ return [2 /*return*/, this.registries];
71
+ });
72
+ });
73
+ };
74
+ DefaultRegistryMgr.prototype.get_module_achieve = function (idx) {
75
+ var _this = this;
76
+ return this.registries.reduce(function (prev, registry) { return __awaiter(_this, void 0, void 0, function () {
77
+ var res, _a;
78
+ return __generator(this, function (_b) {
79
+ switch (_b.label) {
80
+ case 0: return [4 /*yield*/, registry.get_module_achieve(idx)];
81
+ case 1:
82
+ res = _b.sent();
83
+ if (!res) return [3 /*break*/, 2];
84
+ _a = res;
85
+ return [3 /*break*/, 4];
86
+ case 2: return [4 /*yield*/, prev];
87
+ case 3:
88
+ _a = _b.sent();
89
+ _b.label = 4;
90
+ case 4: return [2 /*return*/, _a];
91
+ }
92
+ });
93
+ }); }, Promise.resolve(undefined));
94
+ };
95
+ DefaultRegistryMgr.prototype.get_module_circuit = function (idx) {
96
+ var _this = this;
97
+ return this.registries.reduce(function (prev, registry) { return __awaiter(_this, void 0, void 0, function () {
98
+ var res, _a;
99
+ return __generator(this, function (_b) {
100
+ switch (_b.label) {
101
+ case 0: return [4 /*yield*/, registry.get_module_circuit(idx)];
102
+ case 1:
103
+ res = _b.sent();
104
+ if (!res) return [3 /*break*/, 2];
105
+ _a = res;
106
+ return [3 /*break*/, 4];
107
+ case 2: return [4 /*yield*/, prev];
108
+ case 3:
109
+ _a = _b.sent();
110
+ _b.label = 4;
111
+ case 4: return [2 /*return*/, _a];
112
+ }
113
+ });
114
+ }); }, Promise.resolve(undefined));
115
+ };
116
+ return DefaultRegistryMgr;
117
+ }());
118
+ export { DefaultRegistryMgr };
@@ -0,0 +1,21 @@
1
+ import type { ModuleCircuit, ModuleResolver } from '@modular-circuit/ir';
2
+ import type { ModuleIndex } from '@modular-circuit/ir';
3
+ export interface HttpResponse {
4
+ code: number;
5
+ message: string;
6
+ result: unknown;
7
+ }
8
+ export interface HttpConfig {
9
+ module_achieve_url: URL;
10
+ module_circuit_url: URL;
11
+ zip_origin?: string;
12
+ }
13
+ export declare class HttpRegistry implements ModuleResolver {
14
+ private cnf;
15
+ private zip_origin;
16
+ private module_caches;
17
+ constructor(cnf: HttpConfig);
18
+ get_module_achieve(idx: ModuleIndex): Promise<URL | undefined>;
19
+ get_module_circuit(idx: ModuleIndex): Promise<ModuleCircuit | undefined>;
20
+ }
21
+ //# sourceMappingURL=http_registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http_registry.d.ts","sourceRoot":"","sources":["../../src/registry/http_registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAItD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,OAAO,CAAA;CAChB;AAED,MAAM,WAAW,UAAU;IACzB,kBAAkB,EAAE,GAAG,CAAA;IACvB,kBAAkB,EAAE,GAAG,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AACD,qBAAa,YAAa,YAAW,cAAc;IAG9B,OAAO,CAAC,GAAG;IAF9B,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,aAAa,CAAoC;gBAC9B,GAAG,EAAE,UAAU;IAGpC,kBAAkB,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC;IAO9D,kBAAkB,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAQ/E"}
@@ -0,0 +1,85 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { stringify_dependency } from '@modular-circuit/utils';
38
+ import { do_fetch } from '../utils';
39
+ var HttpRegistry = /** @class */ (function () {
40
+ function HttpRegistry(cnf) {
41
+ var _a;
42
+ this.cnf = cnf;
43
+ this.module_caches = {};
44
+ this.zip_origin = (_a = cnf.zip_origin) !== null && _a !== void 0 ? _a : cnf.module_achieve_url.origin;
45
+ }
46
+ HttpRegistry.prototype.get_module_achieve = function (idx) {
47
+ return __awaiter(this, void 0, void 0, function () {
48
+ var it, pp, full;
49
+ return __generator(this, function (_a) {
50
+ switch (_a.label) {
51
+ case 0: return [4 /*yield*/, do_fetch(this.cnf.module_achieve_url, idx)];
52
+ case 1:
53
+ it = _a.sent();
54
+ return [4 /*yield*/, it.json()];
55
+ case 2:
56
+ pp = (_a.sent()).result;
57
+ if (!pp)
58
+ return [2 /*return*/];
59
+ full = "".concat(this.zip_origin).concat(pp);
60
+ return [2 /*return*/, new URL(full)];
61
+ }
62
+ });
63
+ });
64
+ };
65
+ HttpRegistry.prototype.get_module_circuit = function (idx) {
66
+ return __awaiter(this, void 0, void 0, function () {
67
+ var module_idx, it;
68
+ return __generator(this, function (_a) {
69
+ switch (_a.label) {
70
+ case 0:
71
+ module_idx = stringify_dependency(idx);
72
+ if (module_idx in this.module_caches)
73
+ return [2 /*return*/, this.module_caches[module_idx]];
74
+ return [4 /*yield*/, do_fetch(this.cnf.module_circuit_url, idx)];
75
+ case 1:
76
+ it = _a.sent();
77
+ return [4 /*yield*/, it.json()];
78
+ case 2: return [2 /*return*/, (_a.sent()).result];
79
+ }
80
+ });
81
+ });
82
+ };
83
+ return HttpRegistry;
84
+ }());
85
+ export { HttpRegistry };
@@ -0,0 +1,4 @@
1
+ export * from './default_registry_mgr';
2
+ export * from './http_registry';
3
+ export * from './registry_mgr';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/registry/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './default_registry_mgr';
2
+ export * from './http_registry';
3
+ export * from './registry_mgr';
@@ -0,0 +1,8 @@
1
+ import type { ModuleResolver } from '@modular-circuit/ir';
2
+ export interface RegistryMgr extends ModuleResolver {
3
+ /**
4
+ * 获取所有可用的Registry
5
+ */
6
+ get_available_registries(): Promise<ModuleResolver[]>;
7
+ }
8
+ //# sourceMappingURL=registry_mgr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry_mgr.d.ts","sourceRoot":"","sources":["../../src/registry/registry_mgr.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEzD,MAAM,WAAW,WAAY,SAAQ,cAAc;IACjD;;OAEG;IACH,wBAAwB,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAAA;CACtD"}
File without changes
@@ -0,0 +1 @@
1
+ {"root":["../src/index.ts","../src/bom/bom_match.ts","../src/bom/index.ts","../src/mock/index.ts","../src/mock/module_circuits/index.ts","../src/mock/module_circuits_categories/index.ts","../src/registry/default_registry_mgr.ts","../src/registry/http_registry.ts","../src/registry/index.ts","../src/registry/registry_mgr.ts","../src/utils/index.ts"],"version":"5.8.3"}
@@ -0,0 +1,3 @@
1
+ export declare const fmt_parameter_to_url: (params: unknown) => string;
2
+ export declare function do_fetch(url: URL, params: unknown): Promise<Response>;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,GAAI,QAAQ,OAAO,WAInD,CAAA;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,qBAEjD"}
@@ -0,0 +1,27 @@
1
+ var __read = (this && this.__read) || function (o, n) {
2
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
3
+ if (!m) return o;
4
+ var i = m.call(o), r, ar = [], e;
5
+ try {
6
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
+ }
8
+ catch (error) { e = { error: error }; }
9
+ finally {
10
+ try {
11
+ if (r && !r.done && (m = i["return"])) m.call(i);
12
+ }
13
+ finally { if (e) throw e.error; }
14
+ }
15
+ return ar;
16
+ };
17
+ export var fmt_parameter_to_url = function (params) {
18
+ return Object.entries(params)
19
+ .map(function (_a) {
20
+ var _b = __read(_a, 2), k = _b[0], v = _b[1];
21
+ return "".concat(k, "=").concat(v);
22
+ })
23
+ .join('&');
24
+ };
25
+ export function do_fetch(url, params) {
26
+ return fetch("".concat(url, "?").concat(fmt_parameter_to_url(params)));
27
+ }
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@modular-circuit/middleware",
3
+ "version": "0.0.25",
4
+ "description": "Intermediate representation of the modular circuit",
5
+ "main": "./build/index.js",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./build/index.js",
9
+ "require": "./build/index.js",
10
+ "types": "./build/index.d.ts"
11
+ }
12
+ },
13
+ "files": [
14
+ "build"
15
+ ],
16
+ "keywords": [],
17
+ "author": "",
18
+ "license": "ISC",
19
+ "devDependencies": {
20
+ "@biomejs/biome": "^1.8.3",
21
+ "@types/convert-units": "^2.3.9",
22
+ "esbuild": "^0.20.2",
23
+ "tsup": "^8.3.0",
24
+ "typescript": "^5.4.5"
25
+ },
26
+ "dependencies": {
27
+ "@modular-circuit/ir": "0.0.51",
28
+ "@modular-circuit/utils": "0.0.29"
29
+ },
30
+ "scripts": {
31
+ "clean": "rimraf build",
32
+ "prebuild": "pnpm clean",
33
+ "build": "tsc --build tsconfig.build.json",
34
+ "lint:ci": "biome ci",
35
+ "lint": "biome check --fix --unsafe",
36
+ "test:integration": "vitest --workspace ../../vitest.workspace.ts --project integration run"
37
+ }
38
+ }