@aromix/core 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +11 -491
- package/dist/index.d.cts +21 -177
- package/dist/index.d.ts +21 -177
- package/dist/index.js +10 -490
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true})
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
// src/build.ts
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/build.ts
|
|
9
2
|
function build(options) {
|
|
10
3
|
return options;
|
|
11
4
|
}
|
|
@@ -15,6 +8,10 @@ function config(config2) {
|
|
|
15
8
|
return typeof config2 === "function" ? config2() : config2;
|
|
16
9
|
}
|
|
17
10
|
|
|
11
|
+
// src/entity/builder.ts
|
|
12
|
+
var Builder = class {
|
|
13
|
+
};
|
|
14
|
+
|
|
18
15
|
// src/entity/entity.ts
|
|
19
16
|
function entity(options) {
|
|
20
17
|
}
|
|
@@ -49,498 +46,21 @@ var Codec = {
|
|
|
49
46
|
function toFetchHandler() {
|
|
50
47
|
}
|
|
51
48
|
|
|
52
|
-
// src/
|
|
53
|
-
function
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// src/load.ts
|
|
58
|
-
function detectRuntime() {
|
|
59
|
-
if (typeof globalThis.Deno !== "undefined") return "deno";
|
|
60
|
-
if (typeof globalThis.Bun !== "undefined") return "bun";
|
|
61
|
-
if (typeof process !== "undefined" && _optionalChain([process, 'access', _ => _.versions, 'optionalAccess', _2 => _2.node])) return "node";
|
|
62
|
-
return "worker";
|
|
63
|
-
}
|
|
64
|
-
var RUNTIME = detectRuntime();
|
|
65
|
-
function makeNodeAdapter() {
|
|
66
|
-
const fs = __require("fs");
|
|
67
|
-
const path = __require("path");
|
|
68
|
-
const statCache = /* @__PURE__ */ new Map();
|
|
69
|
-
return {
|
|
70
|
-
cwd: () => process.cwd(),
|
|
71
|
-
readdir: (dir) => fs.readdirSync(dir),
|
|
72
|
-
lstat: (p) => {
|
|
73
|
-
if (statCache.has(p)) return statCache.get(p);
|
|
74
|
-
const s = fs.lstatSync(p);
|
|
75
|
-
const result = { isFile: s.isFile(), isDirectory: s.isDirectory() };
|
|
76
|
-
statCache.set(p, result);
|
|
77
|
-
return result;
|
|
78
|
-
},
|
|
79
|
-
exists: (p) => {
|
|
80
|
-
try {
|
|
81
|
-
fs.accessSync(p);
|
|
82
|
-
return true;
|
|
83
|
-
} catch (e2) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
readText: (p) => fs.readFileSync(p, "utf8"),
|
|
88
|
-
resolve: (...parts) => path.resolve(...parts),
|
|
89
|
-
join: (...parts) => path.join(...parts),
|
|
90
|
-
relative: (from, to) => path.relative(from, to),
|
|
91
|
-
sep: path.sep
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
function makeDenoAdapter() {
|
|
95
|
-
const deno = globalThis.Deno;
|
|
96
|
-
const statCache = /* @__PURE__ */ new Map();
|
|
97
|
-
const join = (...parts) => parts.reduce((a, b) => a.replace(/\/+$/, "") + "/" + b.replace(/^\/+/, ""));
|
|
98
|
-
const resolve = (...parts) => {
|
|
99
|
-
let base = parts[0].startsWith("/") ? parts[0] : join(deno.cwd(), parts[0]);
|
|
100
|
-
for (let i = 1; i < parts.length; i++) {
|
|
101
|
-
const p = parts[i];
|
|
102
|
-
base = p.startsWith("/") ? p : join(base, p);
|
|
103
|
-
}
|
|
104
|
-
const segments = base.split("/");
|
|
105
|
-
const out = [];
|
|
106
|
-
for (const s of segments) {
|
|
107
|
-
if (s === "..") out.pop();
|
|
108
|
-
else if (s !== ".") out.push(s);
|
|
109
|
-
}
|
|
110
|
-
return out.join("/") || "/";
|
|
111
|
-
};
|
|
112
|
-
return {
|
|
113
|
-
cwd: () => deno.cwd(),
|
|
114
|
-
readdir: (dir) => [...deno.readDirSync(dir)].map((e) => e.name),
|
|
115
|
-
lstat: (p) => {
|
|
116
|
-
if (statCache.has(p)) return statCache.get(p);
|
|
117
|
-
const s = deno.lstatSync(p);
|
|
118
|
-
const result = { isFile: s.isFile, isDirectory: s.isDirectory };
|
|
119
|
-
statCache.set(p, result);
|
|
120
|
-
return result;
|
|
121
|
-
},
|
|
122
|
-
exists: (p) => {
|
|
123
|
-
try {
|
|
124
|
-
deno.lstatSync(p);
|
|
125
|
-
return true;
|
|
126
|
-
} catch (e3) {
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
readText: (p) => deno.readTextFileSync(p),
|
|
131
|
-
resolve,
|
|
132
|
-
join,
|
|
133
|
-
relative: (from, to) => {
|
|
134
|
-
const f = from.split("/").filter(Boolean);
|
|
135
|
-
const t = to.split("/").filter(Boolean);
|
|
136
|
-
let i = 0;
|
|
137
|
-
while (i < f.length && f[i] === t[i]) i++;
|
|
138
|
-
return [...f.slice(i).map(() => ".."), ...t.slice(i)].join("/") || ".";
|
|
139
|
-
},
|
|
140
|
-
sep: "/"
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
function makeWorkerAdapter() {
|
|
144
|
-
const noFS = (method) => () => {
|
|
145
|
-
throw new Error(
|
|
146
|
-
`load(): filesystem access unavailable in Cloudflare Workers (called: ${method}). Only pre-resolved paths or alias-only patterns are supported.`
|
|
147
|
-
);
|
|
148
|
-
};
|
|
149
|
-
return {
|
|
150
|
-
cwd: noFS("cwd"),
|
|
151
|
-
readdir: noFS("readdir"),
|
|
152
|
-
lstat: noFS("lstat"),
|
|
153
|
-
exists: () => false,
|
|
154
|
-
readText: noFS("readText"),
|
|
155
|
-
resolve: (...parts) => parts.join("/").replace(/\/+/g, "/"),
|
|
156
|
-
join: (...parts) => parts.join("/").replace(/\/+/g, "/"),
|
|
157
|
-
relative: noFS("relative"),
|
|
158
|
-
sep: "/"
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
function makeAdapter() {
|
|
162
|
-
if (RUNTIME === "deno") return makeDenoAdapter();
|
|
163
|
-
if (RUNTIME === "worker") return makeWorkerAdapter();
|
|
164
|
-
return makeNodeAdapter();
|
|
165
|
-
}
|
|
166
|
-
function expandBraces(pattern) {
|
|
167
|
-
const open = pattern.indexOf("{");
|
|
168
|
-
if (open === -1) return [pattern];
|
|
169
|
-
let depth = 0;
|
|
170
|
-
let close = -1;
|
|
171
|
-
for (let i = open; i < pattern.length; i++) {
|
|
172
|
-
if (pattern[i] === "{") depth++;
|
|
173
|
-
else if (pattern[i] === "}") {
|
|
174
|
-
depth--;
|
|
175
|
-
if (depth === 0) {
|
|
176
|
-
close = i;
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
if (close === -1) return [pattern];
|
|
182
|
-
const prefix = pattern.slice(0, open);
|
|
183
|
-
const suffix = pattern.slice(close + 1);
|
|
184
|
-
const inner = pattern.slice(open + 1, close);
|
|
185
|
-
const parts = [];
|
|
186
|
-
let buf = "";
|
|
187
|
-
let d = 0;
|
|
188
|
-
for (const ch of inner) {
|
|
189
|
-
if (ch === "{") {
|
|
190
|
-
d++;
|
|
191
|
-
buf += ch;
|
|
192
|
-
} else if (ch === "}") {
|
|
193
|
-
d--;
|
|
194
|
-
buf += ch;
|
|
195
|
-
} else if (ch === "," && d === 0) {
|
|
196
|
-
parts.push(buf);
|
|
197
|
-
buf = "";
|
|
198
|
-
} else buf += ch;
|
|
199
|
-
}
|
|
200
|
-
parts.push(buf);
|
|
201
|
-
const results = [];
|
|
202
|
-
for (const part of parts) {
|
|
203
|
-
for (const expanded of expandBraces(prefix + part + suffix)) {
|
|
204
|
-
results.push(expanded);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
return results;
|
|
208
|
-
}
|
|
209
|
-
function globToRegex(glob, opts = {}) {
|
|
210
|
-
let src = "^";
|
|
211
|
-
let i = 0;
|
|
212
|
-
const len = glob.length;
|
|
213
|
-
while (i < len) {
|
|
214
|
-
const ch = glob[i];
|
|
215
|
-
if (ch === "*") {
|
|
216
|
-
if (glob[i + 1] === "*") {
|
|
217
|
-
src += opts.globstar !== false ? ".*" : "[^/]*";
|
|
218
|
-
i += 2;
|
|
219
|
-
if (glob[i] === "/") i++;
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
src += "[^/]*";
|
|
223
|
-
} else if (ch === "?") {
|
|
224
|
-
src += "[^/]";
|
|
225
|
-
} else if (".+^${}|[]()\\".includes(ch)) {
|
|
226
|
-
src += "\\" + ch;
|
|
227
|
-
} else {
|
|
228
|
-
src += ch;
|
|
229
|
-
}
|
|
230
|
-
i++;
|
|
231
|
-
}
|
|
232
|
-
src += "$";
|
|
233
|
-
return new RegExp(src);
|
|
234
|
-
}
|
|
235
|
-
var HIDDEN = /(^|[/\\])\.[^/\\.]/;
|
|
236
|
-
function walkSync(fs, baseDir, globParts, currentDir, opts) {
|
|
237
|
-
if (globParts.length === 0) return [];
|
|
238
|
-
const results = [];
|
|
239
|
-
const [head, ...rest] = globParts;
|
|
240
|
-
const isLast = rest.length === 0;
|
|
241
|
-
let entries;
|
|
242
|
-
try {
|
|
243
|
-
entries = fs.readdir(currentDir);
|
|
244
|
-
} catch (e4) {
|
|
245
|
-
return results;
|
|
246
|
-
}
|
|
247
|
-
if (head === "**") {
|
|
248
|
-
for (const name of entries) {
|
|
249
|
-
const full = fs.join(currentDir, name);
|
|
250
|
-
if (!opts.dot && HIDDEN.test(name)) continue;
|
|
251
|
-
let stat;
|
|
252
|
-
try {
|
|
253
|
-
stat = fs.lstat(full);
|
|
254
|
-
} catch (e5) {
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
if (stat.isDirectory) {
|
|
258
|
-
results.push(...walkSync(fs, baseDir, globParts, full, opts));
|
|
259
|
-
if (rest.length > 0) {
|
|
260
|
-
results.push(...walkSync(fs, baseDir, rest, full, opts));
|
|
261
|
-
}
|
|
262
|
-
} else if (stat.isFile) {
|
|
263
|
-
if (rest.length === 0) results.push(full);
|
|
264
|
-
else {
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
return results;
|
|
269
|
-
}
|
|
270
|
-
const regex = globToRegex(head, { globstar: false });
|
|
271
|
-
for (const name of entries) {
|
|
272
|
-
if (!opts.dot && HIDDEN.test(name)) continue;
|
|
273
|
-
if (!regex.test(name)) continue;
|
|
274
|
-
const full = fs.join(currentDir, name);
|
|
275
|
-
let stat;
|
|
276
|
-
try {
|
|
277
|
-
stat = fs.lstat(full);
|
|
278
|
-
} catch (e6) {
|
|
279
|
-
continue;
|
|
280
|
-
}
|
|
281
|
-
if (isLast) {
|
|
282
|
-
if (stat.isFile) results.push(full);
|
|
283
|
-
else if (stat.isDirectory && !opts.filesOnly) results.push(full);
|
|
284
|
-
} else {
|
|
285
|
-
if (stat.isDirectory) {
|
|
286
|
-
results.push(...walkSync(fs, baseDir, rest, full, opts));
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
return results;
|
|
291
|
-
}
|
|
292
|
-
function resolveGlob(fsAdapter, pattern, opts) {
|
|
293
|
-
const sep = /[/\\]/;
|
|
294
|
-
const parts = pattern.split(sep);
|
|
295
|
-
let staticParts = [];
|
|
296
|
-
let globParts = [];
|
|
297
|
-
let inGlob = false;
|
|
298
|
-
for (const p of parts) {
|
|
299
|
-
if (!inGlob && !p.includes("*") && !p.includes("?")) {
|
|
300
|
-
staticParts.push(p);
|
|
301
|
-
} else {
|
|
302
|
-
inGlob = true;
|
|
303
|
-
globParts.push(p);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
const baseDir = fsAdapter.resolve(opts.cwd, staticParts.join("/"));
|
|
307
|
-
if (globParts.length === 0) {
|
|
308
|
-
try {
|
|
309
|
-
const stat = fsAdapter.lstat(baseDir);
|
|
310
|
-
if (opts.filesOnly && !stat.isFile) return [];
|
|
311
|
-
return [baseDir];
|
|
312
|
-
} catch (e7) {
|
|
313
|
-
return [];
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
return walkSync(fsAdapter, baseDir, globParts, baseDir, opts);
|
|
317
|
-
}
|
|
318
|
-
var aliasCache = /* @__PURE__ */ new Map();
|
|
319
|
-
function findTsconfig(fsAdapter, startDir) {
|
|
320
|
-
let dir = startDir;
|
|
321
|
-
while (true) {
|
|
322
|
-
const candidate = fsAdapter.join(dir, "tsconfig.json");
|
|
323
|
-
if (fsAdapter.exists(candidate)) return candidate;
|
|
324
|
-
const parent = fsAdapter.resolve(dir, "..");
|
|
325
|
-
if (parent === dir) return null;
|
|
326
|
-
dir = parent;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
function loadTsconfig(fsAdapter, tsconfigPath) {
|
|
330
|
-
if (aliasCache.has(tsconfigPath)) return aliasCache.get(tsconfigPath);
|
|
331
|
-
try {
|
|
332
|
-
const raw = fsAdapter.readText(tsconfigPath);
|
|
333
|
-
const cleaned = raw.replace(/\/\/[^\n]*/g, "");
|
|
334
|
-
const json = JSON.parse(cleaned);
|
|
335
|
-
const co = _nullishCoalesce(_optionalChain([json, 'optionalAccess', _3 => _3.compilerOptions]), () => ( {}));
|
|
336
|
-
const baseUrl = co.baseUrl ? fsAdapter.resolve(fsAdapter.join(tsconfigPath, ".."), co.baseUrl) : fsAdapter.join(tsconfigPath, "..");
|
|
337
|
-
const paths = _nullishCoalesce(co.paths, () => ( {}));
|
|
338
|
-
const result = { paths, baseUrl };
|
|
339
|
-
aliasCache.set(tsconfigPath, result);
|
|
340
|
-
return result;
|
|
341
|
-
} catch (e8) {
|
|
342
|
-
aliasCache.set(tsconfigPath, null);
|
|
343
|
-
return null;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
function resolveAliases(pattern, aliasMap) {
|
|
347
|
-
const { paths, baseUrl } = aliasMap;
|
|
348
|
-
for (const [key, targets] of Object.entries(paths)) {
|
|
349
|
-
const aliasRegex = new RegExp("^" + key.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "(.*)") + "$");
|
|
350
|
-
const match = pattern.match(aliasRegex);
|
|
351
|
-
if (!match) continue;
|
|
352
|
-
const capture = _nullishCoalesce(match[1], () => ( ""));
|
|
353
|
-
return targets.map((target) => {
|
|
354
|
-
const concrete = target.includes("*") ? target.replace("*", capture) : target;
|
|
355
|
-
return concrete.startsWith("/") ? concrete : `${baseUrl}/${concrete}`.replace(/\/+/g, "/");
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
return [pattern];
|
|
359
|
-
}
|
|
360
|
-
function load(pattern, options = {}) {
|
|
361
|
-
const fsAdapter = makeAdapter();
|
|
362
|
-
const cwd = _nullishCoalesce(options.cwd, () => ( (RUNTIME !== "worker" ? fsAdapter.cwd() : "/")));
|
|
363
|
-
const dot = _nullishCoalesce(options.dot, () => ( false));
|
|
364
|
-
const filesOnly = _nullishCoalesce(options.filesOnly, () => ( true));
|
|
365
|
-
let aliasMap = null;
|
|
366
|
-
if (RUNTIME !== "worker") {
|
|
367
|
-
const tsconfigPath = options.tsconfig ? fsAdapter.resolve(cwd, options.tsconfig) : findTsconfig(fsAdapter, cwd);
|
|
368
|
-
if (tsconfigPath) {
|
|
369
|
-
aliasMap = loadTsconfig(fsAdapter, tsconfigPath);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
const patterns = Array.isArray(pattern) ? pattern : [pattern];
|
|
373
|
-
const seen = /* @__PURE__ */ new Set();
|
|
374
|
-
const results = [];
|
|
375
|
-
for (const rawPattern of patterns) {
|
|
376
|
-
const aliasExpanded = aliasMap ? resolveAliases(rawPattern, aliasMap) : [rawPattern];
|
|
377
|
-
for (const aliasPattern of aliasExpanded) {
|
|
378
|
-
const braceExpanded = expandBraces(aliasPattern);
|
|
379
|
-
for (const globPattern of braceExpanded) {
|
|
380
|
-
if (RUNTIME === "worker") {
|
|
381
|
-
if (!seen.has(globPattern)) {
|
|
382
|
-
seen.add(globPattern);
|
|
383
|
-
results.push(globPattern);
|
|
384
|
-
}
|
|
385
|
-
continue;
|
|
386
|
-
}
|
|
387
|
-
const matches = resolveGlob(fsAdapter, globPattern, { cwd, dot, filesOnly });
|
|
388
|
-
for (const m of matches) {
|
|
389
|
-
if (!seen.has(m)) {
|
|
390
|
-
seen.add(m);
|
|
391
|
-
results.push(m);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
return results;
|
|
398
|
-
}
|
|
399
|
-
function clearCache() {
|
|
400
|
-
aliasCache.clear();
|
|
49
|
+
// src/macro.ts
|
|
50
|
+
function load(pattern) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
"load() is a build-time macro and must not be called at runtime. Ensure your project is compiled with the Aromix build pipeline."
|
|
53
|
+
);
|
|
401
54
|
}
|
|
402
55
|
|
|
403
56
|
// src/make/impl.ts
|
|
404
57
|
function make() {
|
|
405
58
|
}
|
|
406
59
|
|
|
407
|
-
// src/make/util.ts
|
|
408
|
-
function filter(hooks, on) {
|
|
409
|
-
return hooks.filter((h) => h.on === on).map((h) => h.run);
|
|
410
|
-
}
|
|
411
|
-
|
|
412
60
|
// src/plugin.ts
|
|
413
61
|
function plugin() {
|
|
414
62
|
}
|
|
415
63
|
|
|
416
|
-
// src/program/types.ts
|
|
417
|
-
var programMeta = /* @__PURE__ */ Symbol("aromix.program.meta");
|
|
418
|
-
|
|
419
|
-
// src/program/impl.ts
|
|
420
|
-
function program(config2) {
|
|
421
|
-
const meta = {
|
|
422
|
-
name: config2.name,
|
|
423
|
-
deps: _nullishCoalesce(config2.deps, () => ( {})),
|
|
424
|
-
hooks: _nullishCoalesce(config2.hooks, () => ( [])),
|
|
425
|
-
routes: []
|
|
426
|
-
};
|
|
427
|
-
return {
|
|
428
|
-
[programMeta]: meta,
|
|
429
|
-
command(options) {
|
|
430
|
-
meta.routes.push({
|
|
431
|
-
type: "command",
|
|
432
|
-
options
|
|
433
|
-
});
|
|
434
|
-
},
|
|
435
|
-
stream(options) {
|
|
436
|
-
meta.routes.push({
|
|
437
|
-
type: "stream",
|
|
438
|
-
options
|
|
439
|
-
});
|
|
440
|
-
},
|
|
441
|
-
socket(options) {
|
|
442
|
-
meta.routes.push({
|
|
443
|
-
type: "socket",
|
|
444
|
-
options
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// src/service/facade.ts
|
|
451
|
-
function hasKey(obj, key) {
|
|
452
|
-
if (typeof key === "symbol") {
|
|
453
|
-
return Object.getOwnPropertySymbols(obj).includes(key);
|
|
454
|
-
}
|
|
455
|
-
return Object.hasOwn(obj, key);
|
|
456
|
-
}
|
|
457
|
-
var NativeKeys = /* @__PURE__ */ new Set([
|
|
458
|
-
...Object.getOwnPropertyNames(Object.prototype),
|
|
459
|
-
...Object.getOwnPropertySymbols(Object.prototype),
|
|
460
|
-
...Object.getOwnPropertyNames(Function.prototype),
|
|
461
|
-
...Object.getOwnPropertySymbols(Function.prototype)
|
|
462
|
-
]);
|
|
463
|
-
function addInstanceProperties(serviceInstance, targetObj) {
|
|
464
|
-
const ownKeys = [...Object.getOwnPropertyNames(serviceInstance), ...Object.getOwnPropertySymbols(serviceInstance)];
|
|
465
|
-
for (const key of ownKeys) {
|
|
466
|
-
if (hasKey(targetObj, key)) continue;
|
|
467
|
-
const descriptor = Object.getOwnPropertyDescriptor(serviceInstance, key);
|
|
468
|
-
if (typeof descriptor.value === "function") continue;
|
|
469
|
-
if (descriptor.get || descriptor.set) continue;
|
|
470
|
-
Object.defineProperty(targetObj, key, {
|
|
471
|
-
get: () => serviceInstance[key],
|
|
472
|
-
set: (v) => serviceInstance[key] = v,
|
|
473
|
-
enumerable: true,
|
|
474
|
-
configurable: true
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
function addPrototypeProperties(serviceInstance, targetObj) {
|
|
479
|
-
let currentProto = Object.getPrototypeOf(serviceInstance);
|
|
480
|
-
while (currentProto && currentProto !== Object.prototype) {
|
|
481
|
-
const protoKeys = [...Object.getOwnPropertyNames(currentProto), ...Object.getOwnPropertySymbols(currentProto)];
|
|
482
|
-
for (const key of protoKeys) {
|
|
483
|
-
if (hasKey(targetObj, key)) continue;
|
|
484
|
-
if (NativeKeys.has(key)) continue;
|
|
485
|
-
const descriptor = Object.getOwnPropertyDescriptor(currentProto, key);
|
|
486
|
-
if (descriptor.get || descriptor.set) {
|
|
487
|
-
Object.defineProperty(targetObj, key, {
|
|
488
|
-
get: descriptor.get ? () => descriptor.get.call(serviceInstance) : void 0,
|
|
489
|
-
set: descriptor.set ? (v) => descriptor.set.call(serviceInstance, v) : void 0,
|
|
490
|
-
enumerable: true,
|
|
491
|
-
configurable: true
|
|
492
|
-
});
|
|
493
|
-
} else if (typeof descriptor.value === "function") {
|
|
494
|
-
targetObj[key] = descriptor.value.bind(serviceInstance);
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
currentProto = Object.getPrototypeOf(currentProto);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
function createFacadeObj(serviceInstance) {
|
|
501
|
-
const targetObj = {};
|
|
502
|
-
addInstanceProperties(serviceInstance, targetObj);
|
|
503
|
-
addPrototypeProperties(serviceInstance, targetObj);
|
|
504
|
-
Object.defineProperty(targetObj, "constructor", {
|
|
505
|
-
get: () => serviceInstance.constructor,
|
|
506
|
-
enumerable: false,
|
|
507
|
-
configurable: true
|
|
508
|
-
});
|
|
509
|
-
return targetObj;
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
// src/service/service.ts
|
|
513
|
-
var ServiceToken = /* @__PURE__ */ Symbol.for("aromix.service.token");
|
|
514
|
-
var ServiceRegistry = /* @__PURE__ */ new Map();
|
|
515
|
-
function provide() {
|
|
516
|
-
return (target) => {
|
|
517
|
-
const token = crypto.randomUUID();
|
|
518
|
-
target[ServiceToken] = token;
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
function inject(Service) {
|
|
522
|
-
const token = Service[ServiceToken];
|
|
523
|
-
if (!token) {
|
|
524
|
-
throw new Error(`Class ${Service.name} is not marked as injectable. Use @provide().`);
|
|
525
|
-
}
|
|
526
|
-
if (!ServiceRegistry.has(token)) {
|
|
527
|
-
ServiceRegistry.set(Service, new Service());
|
|
528
|
-
}
|
|
529
|
-
let instance = ServiceRegistry.get(Service);
|
|
530
|
-
return instance;
|
|
531
|
-
}
|
|
532
|
-
inject.facade = (Service) => {
|
|
533
|
-
const instance = inject(Service);
|
|
534
|
-
return createFacadeObj(instance);
|
|
535
|
-
};
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
64
|
|
|
545
65
|
|
|
546
66
|
|
|
@@ -550,4 +70,4 @@ inject.facade = (Service) => {
|
|
|
550
70
|
|
|
551
71
|
|
|
552
72
|
|
|
553
|
-
exports.
|
|
73
|
+
exports.Builder = Builder; exports.Codec = Codec; exports.build = build; exports.config = config; exports.entity = entity; exports.load = load; exports.make = make; exports.plugin = plugin; exports.toFetchHandler = toFetchHandler;
|