silgi 0.24.14 → 0.24.15

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.d.mts CHANGED
@@ -1,8 +1,21 @@
1
- import { SilgiConfig, Silgi, SilgiEvents, SilgiFunction, SilgiOperation, MergedSilgiSchema, ServiceType, SilgiSchema, RequiredServiceType, SilgiRuntimeSharedsExtend, SilgiRuntimeContext, DefaultNamespaces, BaseSchemaType, SilgiRuntimeShareds, StorageConfig, SilgiCLI, SilgiStorageBase } from 'silgi/types';
1
+ import { SilgiCLI, SilgiCLIConfig, LoadConfigOptions, SilgiConfig, Silgi, SilgiEvents, SilgiFunction, SilgiOperation, MergedSilgiSchema, ServiceType, SilgiSchema, RequiredServiceType, SilgiRuntimeSharedsExtend, SilgiRuntimeContext, DefaultNamespaces, BaseSchemaType, SilgiRuntimeShareds, StorageConfig, SilgiStorageBase } from 'silgi/types';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
3
  import { Storage, StorageValue } from 'unstorage';
4
4
  import * as unctx from 'unctx';
5
5
 
6
+ /**
7
+ * Prepares route rules for the build
8
+ */
9
+ declare function prepareBuild(silgi: SilgiCLI): Promise<void>;
10
+
11
+ declare function prepare(_silgi: SilgiCLI): Promise<void>;
12
+
13
+ declare function createSilgiCLI(config?: SilgiCLIConfig, opts?: LoadConfigOptions): Promise<SilgiCLI>;
14
+
15
+ declare function writeCoreFile(silgi: SilgiCLI): Promise<void>;
16
+
17
+ declare function writeTypesAndFiles(silgi: SilgiCLI): Promise<void>;
18
+
6
19
  declare function createSilgi(config: SilgiConfig): Promise<Silgi>;
7
20
 
8
21
  declare function silgi(event?: SilgiEvents | Record<string, any>): SilgiFunction;
@@ -267,5 +280,5 @@ declare function storageMount<T extends Storage = Storage>(silgi?: Silgi): (base
267
280
 
268
281
  declare const autoImportTypes: string[];
269
282
 
270
- export { ErrorCategory, ErrorFactory, ErrorSeverity, HttpStatus, SilgiError, autoImportTypes, createSchema, createService, createShared, createSilgi, createStorage, getEvent, getEventContext, isBaseError, mergeSchemas, mergeServices, mergeShared, parseURI, replaceRuntimeValues, silgi, silgiCLICtx, silgiCtx, storageMount, tryUseSilgi, tryUseSilgiCLI, useSilgi, useSilgiCLI, useSilgiStorage };
283
+ export { ErrorCategory, ErrorFactory, ErrorSeverity, HttpStatus, SilgiError, autoImportTypes, createSchema, createService, createShared, createSilgi, createSilgiCLI, createStorage, getEvent, getEventContext, isBaseError, mergeSchemas, mergeServices, mergeShared, parseURI, prepare, prepareBuild, replaceRuntimeValues, silgi, silgiCLICtx, silgiCtx, storageMount, tryUseSilgi, tryUseSilgiCLI, useSilgi, useSilgiCLI, useSilgiStorage, writeCoreFile, writeTypesAndFiles };
271
284
  export type { BaseError, ErrorMetadata };
package/dist/index.mjs CHANGED
@@ -1,14 +1,44 @@
1
+ import { e as createRouteRules } from './_chunks/silgiApp.mjs';
2
+ export { c as createSilgiCLI, a as prepare, d as prepareBuild, f as silgiCLICtx, t as tryUseSilgiCLI, u as useSilgiCLI, b as writeCoreFile, w as writeTypesAndFiles } from './_chunks/silgiApp.mjs';
1
3
  import { createConsola } from 'consola';
2
4
  import defu, { defu as defu$1 } from 'defu';
3
5
  import { createHooks } from 'hookable';
4
- import { c as createRouteRules } from './_chunks/silgiApp.mjs';
5
- export { a as silgiCLICtx, t as tryUseSilgiCLI, u as useSilgiCLI } from './_chunks/silgiApp.mjs';
6
6
  import { getContext } from 'unctx';
7
7
  import { Buffer } from 'node:buffer';
8
8
  import { klona } from 'klona';
9
9
  import { useSilgiRuntimeConfig } from 'silgi/runtime';
10
10
  import { createStorage as createStorage$1, builtinDrivers, prefixStorage } from 'unstorage';
11
+ import 'knitwork';
12
+ import 'pathe';
13
+ import 'silgi/kit';
14
+ import 'node:fs';
15
+ import 'node:fs/promises';
16
+ import 'silgi';
17
+ import 'silgi/runtime/meta';
18
+ import 'unimport';
11
19
  import 'ufo';
20
+ import '@clack/prompts';
21
+ import 'dotenv';
22
+ import 'mlly';
23
+ import 'dev-jiti';
24
+ import './cli/compatibility.mjs';
25
+ import 'semver/functions/satisfies.js';
26
+ import 'silgi/meta';
27
+ import 'node:url';
28
+ import 'exsolve';
29
+ import 'untyped';
30
+ import 'globby';
31
+ import 'ignore';
32
+ import '@oxc-parser/wasm';
33
+ import './cli/types.mjs';
34
+ import 'c12';
35
+ import 'compatx';
36
+ import 'klona/full';
37
+ import 'std-env';
38
+ import 'consola/utils';
39
+ import 'escape-string-regexp';
40
+ import 'pkg-types';
41
+ import 'pathe/utils';
12
42
 
13
43
  const silgiCtx = getContext("silgi");
14
44
  function useSilgi() {
@@ -1,34 +1,17 @@
1
+ import { ConsolaOptions, ConsolaInstance } from 'consola';
1
2
  import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, ServiceParseModule, SilgiPreset, SilgiPresetMeta, SilgiTemplate, ResolvedSilgiTemplate, SilgiEvents } from 'silgi/types';
2
3
  import { Buffer } from 'node:buffer';
3
- import * as consola from 'consola';
4
- import { ConsolaOptions } from 'consola';
5
4
  import { IncomingMessage, ServerResponse } from 'node:http';
6
5
 
7
- declare function hasError(type: SilgiCLI['errors'][0]['type'], silgi?: SilgiCLI): boolean;
6
+ declare function useLogger(tag?: string, options?: Partial<ConsolaOptions>): ConsolaInstance;
8
7
 
9
- declare function directoryToURL(dir: string): URL;
10
- /**
11
- * Resolve a module from a given root path using an algorithm patterned on
12
- * the upcoming `import.meta.resolve`. It returns a file URL
13
- *
14
- * @internal
15
- */
16
- declare function tryResolveModule(id: string, url?: string | string[]): Promise<string | undefined>;
8
+ declare function hasError(type: SilgiCLI['errors'][0]['type'], silgi?: SilgiCLI): boolean;
17
9
 
18
10
  declare function writeFile(file: string, contents: Buffer | string, log?: boolean): Promise<void>;
19
11
  declare function isDirectory(path: string): Promise<boolean>;
20
12
 
21
- declare function genEnsureSafeVar(name: string | any): string;
22
- declare function getAllEntries(obj: object): [string, any][];
23
-
24
13
  declare function hash(data: any): string;
25
14
 
26
- declare function isNuxt(): boolean;
27
- declare function isNitro(): boolean;
28
- declare function isH3(): boolean;
29
-
30
- declare function useLogger(tag?: string, options?: Partial<ConsolaOptions>): consola.ConsolaInstance;
31
-
32
15
  /**
33
16
  * Define a Silgi module, automatically merging defaults with user provided options, installing
34
17
  * any hooks that are provided, and calling an optional setup function for full control.
@@ -127,6 +110,22 @@ declare function getIpAddress(event: SilgiEvents): string | false;
127
110
  */
128
111
  declare function ipAddress(req: IncomingMessage): string;
129
112
 
113
+ declare function directoryToURL(dir: string): URL;
114
+ /**
115
+ * Resolve a module from a given root path using an algorithm patterned on
116
+ * the upcoming `import.meta.resolve`. It returns a file URL
117
+ *
118
+ * @internal
119
+ */
120
+ declare function tryResolveModule(id: string, url?: string | string[]): Promise<string | undefined>;
121
+
122
+ declare function genEnsureSafeVar(name: string | any): string;
123
+ declare function getAllEntries(obj: object): [string, any][];
124
+
125
+ declare function isNuxt(): boolean;
126
+ declare function isNitro(): boolean;
127
+ declare function isH3(): boolean;
128
+
130
129
  declare function relativeWithDot(from: string, to: string): string;
131
130
  /** @since 3.9.0 */
132
131
  declare function toArray<T>(value: T | T[]): T[];
@@ -1,23 +1,27 @@
1
+ import consola$1, { consola } from 'consola';
1
2
  import { tryUseSilgiCLI, useSilgiCLI, useSilgi } from 'silgi';
2
- import { pathToFileURL, fileURLToPath } from 'node:url';
3
- import { resolvePath as resolvePath$1 } from 'mlly';
4
3
  import fsp from 'node:fs/promises';
5
- import consola, { consola as consola$1 } from 'consola';
6
4
  import { relative, resolve, dirname, normalize, isAbsolute, join, parse, basename } from 'pathe';
7
5
  import { colors } from 'consola/utils';
8
6
  import { getProperty } from 'dot-prop';
9
- import { genString, genObjectFromRaw, genObjectFromValues, genObjectFromRawEntries } from 'knitwork';
10
7
  import { hash as hash$1 } from 'ohash';
11
8
  import { camelCase } from 'scule';
12
9
  import { defu } from 'defu';
13
10
  import { c as checkSilgiCompatibility } from '../cli/compatibility.mjs';
14
11
  import { withLeadingSlash } from 'ufo';
15
12
  import { existsSync, promises } from 'node:fs';
13
+ import { fileURLToPath, pathToFileURL } from 'node:url';
14
+ import { resolvePath as resolvePath$1 } from 'mlly';
16
15
  import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
17
16
  import { hash as hash$2 } from 'silgi/kit';
17
+ import { genString, genObjectFromRaw, genObjectFromValues, genObjectFromRawEntries } from 'knitwork';
18
18
  import 'semver/functions/satisfies.js';
19
19
  import 'silgi/meta';
20
20
 
21
+ function useLogger(tag, options = {}) {
22
+ return tag ? consola.create(options).withTag(tag) : consola;
23
+ }
24
+
21
25
  function hasError(type, silgi) {
22
26
  silgi = silgi ?? tryUseSilgiCLI() ?? void 0;
23
27
  if (silgi && silgi.errors.some((error) => error.type === type)) {
@@ -26,16 +30,6 @@ function hasError(type, silgi) {
26
30
  return false;
27
31
  }
28
32
 
29
- function directoryToURL(dir) {
30
- return pathToFileURL(`${dir}/`);
31
- }
32
- async function tryResolveModule(id, url = import.meta.url) {
33
- try {
34
- return await resolvePath$1(id, { url });
35
- } catch {
36
- }
37
- }
38
-
39
33
  function prettyPath(p, highlight = true) {
40
34
  p = relative(process.cwd(), p);
41
35
  return highlight ? colors.cyan(p) : p;
@@ -56,7 +50,7 @@ function _compilePathTemplate(contents) {
56
50
  return (params) => contents.replace(/\{\{ ?([\w.]+) ?\}\}/g, (_, match) => {
57
51
  const val = getProperty(params, match);
58
52
  if (!val) {
59
- consola.warn(
53
+ consola$1.warn(
60
54
  `cannot resolve template param '${match}' in ${contents.slice(0, 20)}`
61
55
  );
62
56
  }
@@ -76,7 +70,7 @@ async function writeFile(file, contents, log = false) {
76
70
  typeof contents === "string" ? "utf8" : void 0
77
71
  );
78
72
  if (log) {
79
- consola$1.info("Generated", prettyPath(file));
73
+ consola.info("Generated", prettyPath(file));
80
74
  }
81
75
  }
82
76
  async function isDirectory$1(path) {
@@ -87,78 +81,10 @@ async function isDirectory$1(path) {
87
81
  }
88
82
  }
89
83
 
90
- const reservedCode = /* @__PURE__ */ new Set([
91
- "process",
92
- "global",
93
- "runtime",
94
- "runtimeConfig"
95
- ]);
96
- function genEnsureSafeVar(name) {
97
- if (typeof name !== "string") {
98
- return genString(name);
99
- }
100
- for (const reserved of reservedCode) {
101
- if (name === reserved || name.startsWith(`${reserved}.`)) {
102
- return name;
103
- }
104
- }
105
- return genString(name);
106
- }
107
- function getAllEntries(obj) {
108
- return Object.entries(obj).map(([
109
- key,
110
- value
111
- ]) => {
112
- if (typeof value === "function") {
113
- return [key, genObjectFromRaw(value)];
114
- }
115
- if (typeof value === "string") {
116
- return [key, genEnsureSafeVar(value)];
117
- }
118
- if (typeof value === "object" && value !== null) {
119
- if (Array.isArray(value)) {
120
- return [key, genObjectFromValues(value.map(
121
- (item) => typeof item === "object" && item !== null ? genObjectFromRawEntries(getAllEntries(item)) : item
122
- ))];
123
- } else {
124
- return [key, genObjectFromRawEntries(getAllEntries(value))];
125
- }
126
- }
127
- return [key, value];
128
- });
129
- }
130
-
131
84
  function hash(data) {
132
85
  return camelCase(hash$1(data));
133
86
  }
134
87
 
135
- function isNuxt() {
136
- const silgi = useSilgi();
137
- if (silgi.options.present === "nitro" || silgi.options.present === "h3" || silgi.options.present === "nuxt") {
138
- return true;
139
- }
140
- return false;
141
- }
142
- function isNitro() {
143
- const silgi = useSilgi();
144
- if (silgi.options.present === "nitro" || silgi.options.present === "h3") {
145
- return true;
146
- }
147
- return false;
148
- }
149
- function isH3() {
150
- const silgi = useSilgi();
151
- if (silgi.options.present === "h3") {
152
- return true;
153
- }
154
- return false;
155
- }
156
-
157
- const logger = consola$1;
158
- function useLogger(tag, options = {}) {
159
- return tag ? logger.create(options).withTag(tag) : logger;
160
- }
161
-
162
88
  function defineSilgiModule(definition) {
163
89
  if (definition) {
164
90
  return _defineSilgiModule(definition);
@@ -526,4 +452,77 @@ function isValidIp(ip) {
526
452
  return false;
527
453
  }
528
454
 
455
+ function directoryToURL(dir) {
456
+ return pathToFileURL(`${dir}/`);
457
+ }
458
+ async function tryResolveModule(id, url = import.meta.url) {
459
+ try {
460
+ return await resolvePath$1(id, { url });
461
+ } catch {
462
+ }
463
+ }
464
+
465
+ const reservedCode = /* @__PURE__ */ new Set([
466
+ "process",
467
+ "global",
468
+ "runtime",
469
+ "runtimeConfig"
470
+ ]);
471
+ function genEnsureSafeVar(name) {
472
+ if (typeof name !== "string") {
473
+ return genString(name);
474
+ }
475
+ for (const reserved of reservedCode) {
476
+ if (name === reserved || name.startsWith(`${reserved}.`)) {
477
+ return name;
478
+ }
479
+ }
480
+ return genString(name);
481
+ }
482
+ function getAllEntries(obj) {
483
+ return Object.entries(obj).map(([
484
+ key,
485
+ value
486
+ ]) => {
487
+ if (typeof value === "function") {
488
+ return [key, genObjectFromRaw(value)];
489
+ }
490
+ if (typeof value === "string") {
491
+ return [key, genEnsureSafeVar(value)];
492
+ }
493
+ if (typeof value === "object" && value !== null) {
494
+ if (Array.isArray(value)) {
495
+ return [key, genObjectFromValues(value.map(
496
+ (item) => typeof item === "object" && item !== null ? genObjectFromRawEntries(getAllEntries(item)) : item
497
+ ))];
498
+ } else {
499
+ return [key, genObjectFromRawEntries(getAllEntries(value))];
500
+ }
501
+ }
502
+ return [key, value];
503
+ });
504
+ }
505
+
506
+ function isNuxt() {
507
+ const silgi = useSilgi();
508
+ if (silgi.options.present === "nitro" || silgi.options.present === "h3" || silgi.options.present === "nuxt") {
509
+ return true;
510
+ }
511
+ return false;
512
+ }
513
+ function isNitro() {
514
+ const silgi = useSilgi();
515
+ if (silgi.options.present === "nitro" || silgi.options.present === "h3") {
516
+ return true;
517
+ }
518
+ return false;
519
+ }
520
+ function isH3() {
521
+ const silgi = useSilgi();
522
+ if (silgi.options.present === "h3") {
523
+ return true;
524
+ }
525
+ return false;
526
+ }
527
+
529
528
  export { MODE_RE, addTemplate, baseHeaderBannerComment, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.24.14",
4
+ "version": "0.24.15",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {