@fuzdev/fuz_app 0.136.0 → 0.137.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/actions/action_spec.d.ts +0 -48
- package/dist/actions/action_spec.d.ts.map +1 -1
- package/dist/auth/account_action_specs.d.ts +1 -1
- package/dist/auth/account_action_specs.d.ts.map +1 -1
- package/dist/auth/account_action_specs.js +3 -4
- package/dist/auth/account_schema.d.ts +1 -6
- package/dist/auth/account_schema.d.ts.map +1 -1
- package/dist/auth/account_schema.js +1 -0
- package/dist/auth/actor_search_action_specs.d.ts +1 -1
- package/dist/auth/actor_search_action_specs.d.ts.map +1 -1
- package/dist/auth/actor_search_action_specs.js +3 -6
- package/dist/auth/cell_action_specs.d.ts +3 -3
- package/dist/auth/cell_action_specs.d.ts.map +1 -1
- package/dist/auth/cell_action_specs.js +7 -8
- package/dist/auth/cell_item_action_specs.d.ts.map +1 -1
- package/dist/auth/cell_item_action_specs.js +2 -4
- package/dist/auth/password.d.ts +2 -2
- package/dist/auth/password.d.ts.map +1 -1
- package/dist/auth/password.js +10 -12
- package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_action_specs.js +5 -10
- package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_notifications.js +2 -1
- package/dist/auth/role_grant_offer_schema.d.ts +1 -1
- package/dist/auth/role_grant_offer_schema.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_schema.js +4 -7
- package/dist/auth/role_schema.d.ts.map +1 -1
- package/dist/auth/role_schema.js +5 -4
- package/dist/auth/scope_kind_schema.d.ts +1 -1
- package/dist/auth/scope_kind_schema.d.ts.map +1 -1
- package/dist/auth/scope_kind_schema.js +6 -5
- package/dist/cli/args.d.ts +21 -15
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +40 -16
- package/dist/cli/daemon.d.ts +0 -5
- package/dist/cli/daemon.d.ts.map +1 -1
- package/dist/cli/help.d.ts +45 -6
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +81 -4
- package/dist/http/auth_shape.d.ts +0 -27
- package/dist/http/auth_shape.d.ts.map +1 -1
- package/dist/primitive_schemas.d.ts +38 -4
- package/dist/primitive_schemas.d.ts.map +1 -1
- package/dist/primitive_schemas.js +77 -13
- package/dist/server/x_accel.d.ts +0 -1
- package/dist/server/x_accel.d.ts.map +1 -1
- package/dist/testing/cross_backend/action_manifest.d.ts +0 -14
- package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +0 -9
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/package.json +7 -5
|
@@ -39,7 +39,7 @@ import { z } from 'zod';
|
|
|
39
39
|
export declare const SCOPE_KIND_NAME_REGEX: RegExp;
|
|
40
40
|
/**
|
|
41
41
|
* Maximum length of a `scope_kind`, in UTF-16 code units (what
|
|
42
|
-
* `String.length`
|
|
42
|
+
* `String.length` measures; enforced by `bounded_string`). Bounds the tag where it enters
|
|
43
43
|
* — the grant inputs (`role_grant_offer_create`, `role_grant_assign`) copy it
|
|
44
44
|
* into the row and its audit metadata — and a registered name, so no
|
|
45
45
|
* registry declares a kind the grant inputs would refuse. Same value as
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope_kind_schema.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/scope_kind_schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"scope_kind_schema.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/scope_kind_schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,QAAgC,CAAC;AAEnE;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC,oDAAoD;AACpD,eAAO,MAAM,aAAa,aAMzB,CAAC;AACF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAE1D;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,gFAAgF;AAChF,MAAM,WAAW,qBAAqB;IACrC;;;;;OAKG;IACH,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7B;;;OAGG;IACH,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAChD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,wBAAwB,GACpC,gBAAgB,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,KAC3C,qBAwBF,CAAC"}
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
* @module
|
|
31
31
|
*/
|
|
32
32
|
import { z } from 'zod';
|
|
33
|
+
import { bounded_string } from '../primitive_schemas.js';
|
|
33
34
|
/**
|
|
34
35
|
* Letter (lowercase a-z) start and end (or single letter), with letters
|
|
35
36
|
* and underscores in between. Mirrors `RoleName`. Rejects empty strings,
|
|
@@ -39,7 +40,7 @@ import { z } from 'zod';
|
|
|
39
40
|
export const SCOPE_KIND_NAME_REGEX = /^[a-z][a-z_]*[a-z]$|^[a-z]$/;
|
|
40
41
|
/**
|
|
41
42
|
* Maximum length of a `scope_kind`, in UTF-16 code units (what
|
|
42
|
-
* `String.length`
|
|
43
|
+
* `String.length` measures; enforced by `bounded_string`). Bounds the tag where it enters
|
|
43
44
|
* — the grant inputs (`role_grant_offer_create`, `role_grant_assign`) copy it
|
|
44
45
|
* into the row and its audit metadata — and a registered name, so no
|
|
45
46
|
* registry declares a kind the grant inputs would refuse. Same value as
|
|
@@ -48,10 +49,10 @@ export const SCOPE_KIND_NAME_REGEX = /^[a-z][a-z_]*[a-z]$|^[a-z]$/;
|
|
|
48
49
|
*/
|
|
49
50
|
export const SCOPE_KIND_LENGTH_MAX = 64;
|
|
50
51
|
/** Zod schema for valid scope-kind name strings. */
|
|
51
|
-
export const ScopeKindName =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
export const ScopeKindName = bounded_string({
|
|
53
|
+
max: SCOPE_KIND_LENGTH_MAX,
|
|
54
|
+
max_message: `Scope-kind names must be at most ${SCOPE_KIND_LENGTH_MAX} characters`
|
|
55
|
+
}).regex(SCOPE_KIND_NAME_REGEX, 'Scope-kind names must be lowercase letters and underscores (a-z_), no leading/trailing underscore');
|
|
55
56
|
/**
|
|
56
57
|
* Create a scope-kind schema from a consumer-declared registry.
|
|
57
58
|
*
|
package/dist/cli/args.d.ts
CHANGED
|
@@ -3,45 +3,51 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Provides `parse_command_args` for schema-validated command parsing and
|
|
5
5
|
* `create_extract_global_flags` as a factory for project-specific global flag extraction.
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
|
+
* Both take `@fuzdev/fuz_schema` object schemas, the schemas `args_parse` from
|
|
8
|
+
* `@fuzdev/fuz_util/args.ts` reads, with aliases given by `meta(entry, {aliases})`.
|
|
7
9
|
*
|
|
8
10
|
* @module
|
|
9
11
|
*/
|
|
10
12
|
import { type ParsedArgs } from '@fuzdev/fuz_util/args.ts';
|
|
11
|
-
import {
|
|
13
|
+
import { type Schema } from '@fuzdev/fuz_schema/schema.ts';
|
|
12
14
|
/**
|
|
13
15
|
* Discriminated union result for CLI argument parsing.
|
|
14
16
|
*/
|
|
15
|
-
export type
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
export type ParseCommandArgsResult<T> = {
|
|
18
|
+
ok: true;
|
|
19
|
+
value: T;
|
|
18
20
|
} | {
|
|
19
|
-
|
|
21
|
+
ok: false;
|
|
20
22
|
error: string;
|
|
21
23
|
};
|
|
22
24
|
/**
|
|
23
|
-
* Parse command-specific args against a
|
|
25
|
+
* Parse command-specific args against a fuz_schema object schema.
|
|
24
26
|
*
|
|
25
27
|
* Validates `remaining` args (after global flag extraction) with alias expansion
|
|
26
|
-
* and returns a typed result or
|
|
28
|
+
* and returns a typed result or an error string, each issue formatted by
|
|
29
|
+
* `format_issue` on a line of its own.
|
|
27
30
|
*
|
|
28
31
|
* @param remaining - remaining args after global flag extraction
|
|
29
|
-
* @param schema -
|
|
30
|
-
* @returns parse result with typed
|
|
32
|
+
* @param schema - fuz_schema object schema for the command
|
|
33
|
+
* @returns parse result with the typed value or an error message
|
|
31
34
|
*/
|
|
32
|
-
export declare const parse_command_args: <T extends Record<string, unknown>>(remaining: ParsedArgs, schema:
|
|
35
|
+
export declare const parse_command_args: <T extends Record<string, unknown>>(remaining: ParsedArgs, schema: Schema<T, any>) => ParseCommandArgsResult<T>;
|
|
33
36
|
/**
|
|
34
37
|
* Create a project-specific global flag extractor.
|
|
35
38
|
*
|
|
36
39
|
* Returns a function that separates global flags from command-specific args.
|
|
37
|
-
* The schema defines which flags are global (with aliases via
|
|
38
|
-
* and the fallback provides defaults
|
|
40
|
+
* The schema defines which flags are global (with aliases via `meta(entry, {aliases})`,
|
|
41
|
+
* read on any wrapper layer of the entry), and the fallback provides defaults
|
|
42
|
+
* when parsing fails. Every entry is global, both of a `no-` pair like `color`
|
|
43
|
+
* and `no-color` included, so `--no-color`, which `argv_parse` reads as
|
|
44
|
+
* `color: false`, never lands in `remaining`.
|
|
39
45
|
*
|
|
40
|
-
* @param schema -
|
|
46
|
+
* @param schema - fuz_schema object schema for global flags
|
|
41
47
|
* @param fallback - default values when parsing fails
|
|
42
48
|
* @returns extractor function `(unparsed) => {flags, remaining}`
|
|
43
49
|
*/
|
|
44
|
-
export declare const create_extract_global_flags: <T extends Record<string, unknown>>(schema:
|
|
50
|
+
export declare const create_extract_global_flags: <T extends Record<string, unknown>>(schema: Schema<T, any>, fallback: T) => ((unparsed: ParsedArgs) => {
|
|
45
51
|
flags: T;
|
|
46
52
|
remaining: ParsedArgs;
|
|
47
53
|
});
|
package/dist/cli/args.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"args.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/cli/args.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/cli/args.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAyB,KAAK,UAAU,EAAiB,MAAM,0BAA0B,CAAC;AACjG,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAGzE;;GAEG;AACH,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9F;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnE,WAAW,UAAU,EACrB,QAAQ,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,KACpB,sBAAsB,CAAC,CAAC,CAM1B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,2BAA2B,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5E,QAAQ,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,EACtB,UAAU,CAAC,KACT,CAAC,CAAC,QAAQ,EAAE,UAAU,KAAK;IAAE,KAAK,EAAE,CAAC,CAAC;IAAC,SAAS,EAAE,UAAU,CAAA;CAAE,CA4ChE,CAAC"}
|
package/dist/cli/args.js
CHANGED
|
@@ -3,46 +3,59 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Provides `parse_command_args` for schema-validated command parsing and
|
|
5
5
|
* `create_extract_global_flags` as a factory for project-specific global flag extraction.
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
|
+
* Both take `@fuzdev/fuz_schema` object schemas, the schemas `args_parse` from
|
|
8
|
+
* `@fuzdev/fuz_util/args.ts` reads, with aliases given by `meta(entry, {aliases})`.
|
|
7
9
|
*
|
|
8
10
|
* @module
|
|
9
11
|
*/
|
|
10
12
|
import { args_parse } from '@fuzdev/fuz_util/args.ts';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
+
import { format_issue } from '@fuzdev/fuz_schema/schema.ts';
|
|
14
|
+
import { get_schema_entries, get_schema_meta } from '@fuzdev/fuz_schema/introspect.ts';
|
|
13
15
|
/**
|
|
14
|
-
* Parse command-specific args against a
|
|
16
|
+
* Parse command-specific args against a fuz_schema object schema.
|
|
15
17
|
*
|
|
16
18
|
* Validates `remaining` args (after global flag extraction) with alias expansion
|
|
17
|
-
* and returns a typed result or
|
|
19
|
+
* and returns a typed result or an error string, each issue formatted by
|
|
20
|
+
* `format_issue` on a line of its own.
|
|
18
21
|
*
|
|
19
22
|
* @param remaining - remaining args after global flag extraction
|
|
20
|
-
* @param schema -
|
|
21
|
-
* @returns parse result with typed
|
|
23
|
+
* @param schema - fuz_schema object schema for the command
|
|
24
|
+
* @returns parse result with the typed value or an error message
|
|
22
25
|
*/
|
|
23
26
|
export const parse_command_args = (remaining, schema) => {
|
|
24
27
|
const parsed = args_parse(remaining, schema);
|
|
25
|
-
if (!parsed.
|
|
26
|
-
return {
|
|
28
|
+
if (!parsed.ok) {
|
|
29
|
+
return { ok: false, error: parsed.issues.map(format_issue).join('\n') };
|
|
27
30
|
}
|
|
28
|
-
return {
|
|
31
|
+
return { ok: true, value: parsed.value };
|
|
29
32
|
};
|
|
30
33
|
/**
|
|
31
34
|
* Create a project-specific global flag extractor.
|
|
32
35
|
*
|
|
33
36
|
* Returns a function that separates global flags from command-specific args.
|
|
34
|
-
* The schema defines which flags are global (with aliases via
|
|
35
|
-
* and the fallback provides defaults
|
|
37
|
+
* The schema defines which flags are global (with aliases via `meta(entry, {aliases})`,
|
|
38
|
+
* read on any wrapper layer of the entry), and the fallback provides defaults
|
|
39
|
+
* when parsing fails. Every entry is global, both of a `no-` pair like `color`
|
|
40
|
+
* and `no-color` included, so `--no-color`, which `argv_parse` reads as
|
|
41
|
+
* `color: false`, never lands in `remaining`.
|
|
36
42
|
*
|
|
37
|
-
* @param schema -
|
|
43
|
+
* @param schema - fuz_schema object schema for global flags
|
|
38
44
|
* @param fallback - default values when parsing fails
|
|
39
45
|
* @returns extractor function `(unparsed) => {flags, remaining}`
|
|
40
46
|
*/
|
|
41
47
|
export const create_extract_global_flags = (schema, fallback) => {
|
|
42
48
|
return (unparsed) => {
|
|
43
49
|
// get all global flag names and aliases from schema
|
|
44
|
-
const
|
|
45
|
-
const
|
|
50
|
+
const global_props = to_global_props(schema);
|
|
51
|
+
const global_names = new Set();
|
|
52
|
+
for (const prop of global_props) {
|
|
53
|
+
if (prop.name === '_')
|
|
54
|
+
continue;
|
|
55
|
+
global_names.add(prop.name);
|
|
56
|
+
for (const alias of prop.aliases)
|
|
57
|
+
global_names.add(alias);
|
|
58
|
+
}
|
|
46
59
|
// extract global flag values, handling aliases
|
|
47
60
|
const flags_input = {};
|
|
48
61
|
for (const prop of global_props) {
|
|
@@ -61,7 +74,7 @@ export const create_extract_global_flags = (schema, fallback) => {
|
|
|
61
74
|
}
|
|
62
75
|
// parse global flags
|
|
63
76
|
const global_parsed = args_parse(flags_input, schema);
|
|
64
|
-
const flags = global_parsed.
|
|
77
|
+
const flags = global_parsed.ok ? global_parsed.value : fallback;
|
|
65
78
|
// build remaining args without global flags
|
|
66
79
|
const remaining = { _: [...unparsed._] };
|
|
67
80
|
for (const [key, value] of Object.entries(unparsed)) {
|
|
@@ -74,3 +87,14 @@ export const create_extract_global_flags = (schema, fallback) => {
|
|
|
74
87
|
return { flags, remaining };
|
|
75
88
|
};
|
|
76
89
|
};
|
|
90
|
+
// each entry of an object schema with its aliases, a `no-` pair as two entries
|
|
91
|
+
const to_global_props = (schema) => {
|
|
92
|
+
const entries = get_schema_entries(schema);
|
|
93
|
+
if (!entries)
|
|
94
|
+
return [];
|
|
95
|
+
const props = [];
|
|
96
|
+
for (const name in entries) {
|
|
97
|
+
props.push({ name, aliases: get_schema_meta(entries[name], 'aliases') ?? [] });
|
|
98
|
+
}
|
|
99
|
+
return props;
|
|
100
|
+
};
|
package/dist/cli/daemon.d.ts
CHANGED
|
@@ -13,15 +13,10 @@ import { type CommandDeps, type EnvDeps, type FetchDeps, type FsReadDeps, type F
|
|
|
13
13
|
* Daemon info schema for `~/.{name}/run/daemon.json`.
|
|
14
14
|
*/
|
|
15
15
|
export declare const DaemonInfo: z.ZodObject<{
|
|
16
|
-
/** Schema version. */
|
|
17
16
|
version: z.ZodNumber;
|
|
18
|
-
/** Server process ID. */
|
|
19
17
|
pid: z.ZodNumber;
|
|
20
|
-
/** Port the server is listening on. */
|
|
21
18
|
port: z.ZodNumber;
|
|
22
|
-
/** ISO timestamp when server started. */
|
|
23
19
|
started: z.ZodString;
|
|
24
|
-
/** Package version of the application. */
|
|
25
20
|
app_version: z.ZodString;
|
|
26
21
|
}, z.core.$strict>;
|
|
27
22
|
export type DaemonInfo = z.infer<typeof DaemonInfo>;
|
package/dist/cli/daemon.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"daemon.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/cli/daemon.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACN,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,YAAY,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AK,MAAM,KAAG,OAAO,CAAC,OAAO,CAG1F,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,GAC/B,MAAM,SAAS,EACf,MAAM,MAAM,EACZ,aAAkB,EAClB,mBAAiB,KACf,OAAO,CAAC,OAAO,CAYjB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,oCAAoC;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,yCAAyC;IACzC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,GACvB,SAAS,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,GAChC,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,gBAAgB,CAAC,GAC3C,YAAY,GACZ,WAAW,GACX,OAAO,EACR,MAAM,MAAM,KACV,OAAO,CAAC,gBAAgB,CA2C1B,CAAC"}
|
package/dist/cli/help.d.ts
CHANGED
|
@@ -5,15 +5,20 @@
|
|
|
5
5
|
* once with `create_help` and get back `generate_main_help`,
|
|
6
6
|
* `generate_command_help`, and `get_help_text`.
|
|
7
7
|
*
|
|
8
|
+
* Schemas are `@fuzdev/fuz_schema` object schemas, the ones `parse_command_args`
|
|
9
|
+
* and `create_extract_global_flags` take, read with fuz_schema's `introspect.ts`:
|
|
10
|
+
* each entry's `description` and `aliases` metadata, its default, and its type
|
|
11
|
+
* as `format_schema_type` renders it.
|
|
12
|
+
*
|
|
8
13
|
* @module
|
|
9
14
|
*/
|
|
10
|
-
import type {
|
|
11
|
-
import { type ZodSchemaProperty } from '@fuzdev/fuz_util/zod.ts';
|
|
15
|
+
import type { AnySchema } from '@fuzdev/fuz_schema/schema.ts';
|
|
12
16
|
/**
|
|
13
17
|
* Command metadata for help generation.
|
|
14
18
|
*/
|
|
15
19
|
export interface CommandMeta<TCategory extends string = string> {
|
|
16
|
-
schema
|
|
20
|
+
/** fuz_schema object schema for the command's args. */
|
|
21
|
+
schema?: AnySchema;
|
|
17
22
|
summary: string;
|
|
18
23
|
usage: string;
|
|
19
24
|
category: TCategory;
|
|
@@ -41,8 +46,8 @@ export interface HelpOptions<TCategory extends string = string> {
|
|
|
41
46
|
categories: Array<HelpCategory<TCategory>>;
|
|
42
47
|
/** Example commands for main help. */
|
|
43
48
|
examples: Array<string>;
|
|
44
|
-
/**
|
|
45
|
-
global_args_schema:
|
|
49
|
+
/** fuz_schema object schema for global arguments (shown in all help output). */
|
|
50
|
+
global_args_schema: AnySchema;
|
|
46
51
|
/** Whether to use ANSI colors in output. Defaults to `true`. */
|
|
47
52
|
use_colors?: boolean;
|
|
48
53
|
}
|
|
@@ -57,6 +62,40 @@ export interface HelpGenerator {
|
|
|
57
62
|
/** Get help text for a command or main help. */
|
|
58
63
|
get_help_text: (command?: string, subcommand?: string) => string;
|
|
59
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* One arg as help output shows it, read from an entry of an object schema.
|
|
67
|
+
*/
|
|
68
|
+
export interface HelpArgProperty {
|
|
69
|
+
/** The entry's key, `_` for positionals. */
|
|
70
|
+
name: string;
|
|
71
|
+
/** The type the entry accepts, as `format_schema_type` renders it. */
|
|
72
|
+
type: string;
|
|
73
|
+
/** The `description` metadata, or `''`. */
|
|
74
|
+
description: string;
|
|
75
|
+
/** The default, made by calling a `with_default_fn`'s function, or `undefined`. */
|
|
76
|
+
default: unknown;
|
|
77
|
+
/** The `aliases` metadata, or `[]`. */
|
|
78
|
+
aliases: Array<string>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Read the args of an object schema for help output, in order.
|
|
82
|
+
*
|
|
83
|
+
* An entry whose `no-` negation is also an entry is left out, so a pair like
|
|
84
|
+
* `color` and `no-color` is shown once, as `--no-color`.
|
|
85
|
+
*
|
|
86
|
+
* @param schema - fuz_schema object schema
|
|
87
|
+
* @returns the args, none when `schema` is not an object schema
|
|
88
|
+
*/
|
|
89
|
+
export declare const to_help_arg_properties: (schema: AnySchema) => Array<HelpArgProperty>;
|
|
90
|
+
/**
|
|
91
|
+
* Format a default value for display, `''` for none.
|
|
92
|
+
*
|
|
93
|
+
* Strings and arrays are written as JSON, as the type column writes a string literal.
|
|
94
|
+
*
|
|
95
|
+
* @param value - the default
|
|
96
|
+
* @returns display text
|
|
97
|
+
*/
|
|
98
|
+
export declare const format_arg_default: (value: unknown) => string;
|
|
60
99
|
/**
|
|
61
100
|
* Get maximum length from array.
|
|
62
101
|
*
|
|
@@ -74,7 +113,7 @@ export declare const to_max_length: <T>(items: Array<T>, to_string: (item: T) =>
|
|
|
74
113
|
* @param prop - schema property
|
|
75
114
|
* @returns formatted name string
|
|
76
115
|
*/
|
|
77
|
-
export declare const format_arg_name: (prop:
|
|
116
|
+
export declare const format_arg_name: (prop: HelpArgProperty) => string;
|
|
78
117
|
/**
|
|
79
118
|
* Create a help generator configured for an application.
|
|
80
119
|
*
|
package/dist/cli/help.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"help.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/cli/help.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"help.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/cli/help.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,8BAA8B,CAAC;AAY1E;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,SAAS,SAAS,MAAM,GAAG,MAAM;IAC7D,uDAAuD;IACvD,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,SAAS,SAAS,MAAM,GAAG,MAAM;IAC9D,GAAG,EAAE,SAAS,C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Q,SAAS,KAAG,KAAK,CAAC,eAAe,CAe/E,CAAC;AA6BF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,OAAO,KAAG,MAMnD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,KAAG,MACb,CAAC;AAEvE;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,eAAe,KAAG,MAWvD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,SAAS,SAAS,MAAM,EACnD,SAAS,WAAW,CAAC,SAAS,CAAC,KAC7B,aAoHF,CAAC"}
|
package/dist/cli/help.js
CHANGED
|
@@ -5,10 +5,87 @@
|
|
|
5
5
|
* once with `create_help` and get back `generate_main_help`,
|
|
6
6
|
* `generate_command_help`, and `get_help_text`.
|
|
7
7
|
*
|
|
8
|
+
* Schemas are `@fuzdev/fuz_schema` object schemas, the ones `parse_command_args`
|
|
9
|
+
* and `create_extract_global_flags` take, read with fuz_schema's `introspect.ts`:
|
|
10
|
+
* each entry's `description` and `aliases` metadata, its default, and its type
|
|
11
|
+
* as `format_schema_type` renders it.
|
|
12
|
+
*
|
|
8
13
|
* @module
|
|
9
14
|
*/
|
|
10
|
-
import {
|
|
15
|
+
import { format_schema_type, get_schema_fields, get_schema_meta } from '@fuzdev/fuz_schema/introspect.ts';
|
|
11
16
|
import { colors } from './util.js';
|
|
17
|
+
/**
|
|
18
|
+
* Read the args of an object schema for help output, in order.
|
|
19
|
+
*
|
|
20
|
+
* An entry whose `no-` negation is also an entry is left out, so a pair like
|
|
21
|
+
* `color` and `no-color` is shown once, as `--no-color`.
|
|
22
|
+
*
|
|
23
|
+
* @param schema - fuz_schema object schema
|
|
24
|
+
* @returns the args, none when `schema` is not an object schema
|
|
25
|
+
*/
|
|
26
|
+
export const to_help_arg_properties = (schema) => {
|
|
27
|
+
const fields = get_schema_fields(schema);
|
|
28
|
+
const names = new Set(fields.map((f) => f.name));
|
|
29
|
+
const properties = [];
|
|
30
|
+
for (const field of fields) {
|
|
31
|
+
if (names.has('no-' + field.name))
|
|
32
|
+
continue;
|
|
33
|
+
properties.push({
|
|
34
|
+
name: field.name,
|
|
35
|
+
type: format_schema_type(field.schema),
|
|
36
|
+
description: field.description ?? '',
|
|
37
|
+
default: to_field_default(field),
|
|
38
|
+
aliases: get_schema_meta(field.schema, 'aliases') ?? []
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return properties;
|
|
42
|
+
};
|
|
43
|
+
// the default a field's help shows: a `with_default_fn`'s is made by calling its `make`,
|
|
44
|
+
// as each parse that fills the key in does, found by walking the layers `get_schema_fields`
|
|
45
|
+
// reads, whose first `optional` or default it is when `default_computed`
|
|
46
|
+
const to_field_default = (field) => {
|
|
47
|
+
if (!field.default_computed)
|
|
48
|
+
return field.default;
|
|
49
|
+
let layer = field.schema;
|
|
50
|
+
for (;;) {
|
|
51
|
+
switch (layer.kind) {
|
|
52
|
+
case 'with_default_fn':
|
|
53
|
+
return layer.def.make();
|
|
54
|
+
case 'optional':
|
|
55
|
+
case 'nullable':
|
|
56
|
+
case 'with_default':
|
|
57
|
+
layer = layer.def.schema;
|
|
58
|
+
break;
|
|
59
|
+
case 'pipe':
|
|
60
|
+
layer = layer.def[0];
|
|
61
|
+
break;
|
|
62
|
+
case 'lazy':
|
|
63
|
+
layer = layer.def();
|
|
64
|
+
break;
|
|
65
|
+
default:
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Format a default value for display, `''` for none.
|
|
72
|
+
*
|
|
73
|
+
* Strings and arrays are written as JSON, as the type column writes a string literal.
|
|
74
|
+
*
|
|
75
|
+
* @param value - the default
|
|
76
|
+
* @returns display text
|
|
77
|
+
*/
|
|
78
|
+
export const format_arg_default = (value) => {
|
|
79
|
+
if (value === undefined)
|
|
80
|
+
return '';
|
|
81
|
+
if (value === null)
|
|
82
|
+
return 'null';
|
|
83
|
+
if (typeof value === 'string' || typeof value === 'object')
|
|
84
|
+
return JSON.stringify(value);
|
|
85
|
+
if (typeof value === 'boolean' || typeof value === 'number')
|
|
86
|
+
return String(value);
|
|
87
|
+
return '';
|
|
88
|
+
};
|
|
12
89
|
/**
|
|
13
90
|
* Get maximum length from array.
|
|
14
91
|
*
|
|
@@ -50,7 +127,7 @@ export const create_help = (options) => {
|
|
|
50
127
|
? colors
|
|
51
128
|
: { green: '', yellow: '', blue: '', red: '', cyan: '', dim: '', bold: '', reset: '' };
|
|
52
129
|
const generate_global_options = () => {
|
|
53
|
-
const properties =
|
|
130
|
+
const properties = to_help_arg_properties(options.global_args_schema);
|
|
54
131
|
const max_width = to_max_length(properties, (p) => ` ${format_arg_name(p)}`);
|
|
55
132
|
return properties.map((prop) => {
|
|
56
133
|
const name = format_arg_name(prop);
|
|
@@ -65,7 +142,7 @@ export const create_help = (options) => {
|
|
|
65
142
|
lines.push(`${c.yellow}Usage${c.reset}: ${meta.usage}`);
|
|
66
143
|
lines.push('');
|
|
67
144
|
if (meta.schema) {
|
|
68
|
-
const properties =
|
|
145
|
+
const properties = to_help_arg_properties(meta.schema);
|
|
69
146
|
const flag_props = properties.filter((p) => p.name !== '_');
|
|
70
147
|
const positional_prop = properties.find((p) => p.name === '_');
|
|
71
148
|
if (positional_prop?.description) {
|
|
@@ -79,7 +156,7 @@ export const create_help = (options) => {
|
|
|
79
156
|
for (const prop of flag_props) {
|
|
80
157
|
const name = format_arg_name(prop).padEnd(longest_name);
|
|
81
158
|
const type = prop.type.padEnd(longest_type);
|
|
82
|
-
const def =
|
|
159
|
+
const def = format_arg_default(prop.default);
|
|
83
160
|
const desc = prop.description || '';
|
|
84
161
|
const default_str = def ? ` (default: ${def})` : '';
|
|
85
162
|
lines.push(` ${name} ${type} ${desc}${default_str}`);
|
|
@@ -134,33 +134,6 @@ export declare const RouteAuth: z.ZodObject<{
|
|
|
134
134
|
}>;
|
|
135
135
|
roles: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
136
136
|
credential_types: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
137
|
-
/**
|
|
138
|
-
* The capability a **narrowed** api token's scope must admit to reach this
|
|
139
|
-
* route, in the `<section>:<id>` vocabulary a denial reports back as
|
|
140
|
-
* `required_scope`:
|
|
141
|
-
*
|
|
142
|
-
* - `surface:<name>` — a non-RPC surface, refused to every narrowed token
|
|
143
|
-
* whatever its method list says (token scoping's rule that a narrowed
|
|
144
|
-
* token is RPC-only). `surface:audit_stream`, `surface:fact_bare`, and
|
|
145
|
-
* `surface:app_surface` are the spine's route-spec ones; a consumer names
|
|
146
|
-
* its own without registering it.
|
|
147
|
-
* - `rpc:<method>` — one action method, refused unless the token lists it.
|
|
148
|
-
* What a route bridged from an `ActionSpec` declares: it carries the
|
|
149
|
-
* method's identity but never reaches the dispatcher's per-method gate.
|
|
150
|
-
*
|
|
151
|
-
* Declaring it makes the guard resolver mount the refusal ahead of the role
|
|
152
|
-
* gate, instead of the route hand-rolling the check in its handler (which
|
|
153
|
-
* the auth phase has already role-gated by then, so a narrowed token whose
|
|
154
|
-
* account lacks the role would be told about the role rather than about the
|
|
155
|
-
* scope).
|
|
156
|
-
*
|
|
157
|
-
* Opt-in rather than blanket: the account REST routes cross no boundary, and
|
|
158
|
-
* the RPC endpoint runs its own per-method check inside the dispatcher — and
|
|
159
|
-
* both are route specs too.
|
|
160
|
-
*
|
|
161
|
-
* Typed as a plain string here to keep `http/` from importing `auth/`; the
|
|
162
|
-
* resolver parses it at registration and throws on a malformed one.
|
|
163
|
-
*/
|
|
164
137
|
required_scope: z.ZodOptional<z.ZodString>;
|
|
165
138
|
}, z.core.$strict>;
|
|
166
139
|
export type RouteAuth = z.infer<typeof RouteAuth>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth_shape.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/auth_shape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,WAAW,6DAGtB,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG,MAAM,GAAG,SAGtD,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa;;;;EAA2C,CAAC;AACtE,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,SAAS
|
|
1
|
+
{"version":3,"file":"auth_shape.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/auth_shape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,WAAW,6DAGtB,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG,MAAM,GAAG,SAGtD,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa;;;;EAA2C,CAAC;AACtE,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,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level (not inside `auth/` or `http/`) because
|
|
2
|
+
* Reusable validator-schema primitives — `bounded_string`, `Username`,
|
|
3
|
+
* `UsernameProvided`, `Email`. Lives at the top level (not inside `auth/` or `http/`) because
|
|
4
4
|
* these shapes don't depend on or imply any domain — accounts hold a
|
|
5
5
|
* username and email, but invites, password resets, future cell-sharing,
|
|
6
6
|
* and other surfaces all reach for the same primitives without going
|
|
@@ -15,11 +15,45 @@
|
|
|
15
15
|
* @module
|
|
16
16
|
*/
|
|
17
17
|
import { z } from 'zod';
|
|
18
|
+
/** Length bounds for `bounded_string`, in UTF-16 code units. */
|
|
19
|
+
export interface BoundedStringOptions {
|
|
20
|
+
/** Shortest string admitted. Omit for no lower bound. */
|
|
21
|
+
min?: number;
|
|
22
|
+
/** Longest string admitted. */
|
|
23
|
+
max: number;
|
|
24
|
+
/** Message for the over-`max` issue, in place of Zod's default. */
|
|
25
|
+
max_message?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A string schema whose length is bounded in UTF-16 code units — what
|
|
29
|
+
* `String.length` measures, and what the Rust spine counts
|
|
30
|
+
* (`encode_utf16().count()`), so an astral-plane character costs two on both.
|
|
31
|
+
* Every `.min()` / `.max()` length bound on a wire string in the package is
|
|
32
|
+
* built here, bar a bare `.min(1)`, which reads the same in either count.
|
|
33
|
+
*
|
|
34
|
+
* Zod's `.min()` / `.max()` alone don't pin the unit: depending on the
|
|
35
|
+
* installed Zod they count code units or Unicode code points, and the peer
|
|
36
|
+
* range admits both. The schema still carries them — they are what puts
|
|
37
|
+
* `minLength` / `maxLength` in the generated JSON Schema — and a check beside
|
|
38
|
+
* them settles the verdict on `String.length`: it adds the over-`max` or
|
|
39
|
+
* under-`min` issue when Zod raised none, and withdraws one Zod raised for a
|
|
40
|
+
* string that is within the bound in units. The issue it adds has the fields
|
|
41
|
+
* of Zod's own and, like Zod's, lets the checks chained after it run, so a
|
|
42
|
+
* refusal reads the same whichever count Zod used.
|
|
43
|
+
*
|
|
44
|
+
* Returns a plain `ZodString`, so format checks, `.brand()`, `.nullish()` and
|
|
45
|
+
* `.meta()` chain as usual. Don't chain a further `.min()` / `.max()` — pass
|
|
46
|
+
* the bound here.
|
|
47
|
+
*
|
|
48
|
+
* @param options - the bounds, in UTF-16 code units
|
|
49
|
+
* @returns the bounded string schema
|
|
50
|
+
*/
|
|
51
|
+
export declare const bounded_string: ({ min, max, max_message }: BoundedStringOptions) => z.ZodString;
|
|
18
52
|
/** Minimum username length (must have start + middle + end characters). */
|
|
19
53
|
export declare const USERNAME_LENGTH_MIN = 3;
|
|
20
|
-
/** Maximum username length (matches GitHub's limit). */
|
|
54
|
+
/** Maximum username length (matches GitHub's limit). The grammar is ASCII, so units and characters agree. */
|
|
21
55
|
export declare const USERNAME_LENGTH_MAX = 39;
|
|
22
|
-
/** Maximum length for username input on login/lookup — more permissive than `USERNAME_LENGTH_MAX` for forward-compatibility if the creation limit is raised. */
|
|
56
|
+
/** Maximum length for username input on login/lookup, in UTF-16 code units, measured before trimming — more permissive than `USERNAME_LENGTH_MAX` for forward-compatibility if the creation limit is raised. */
|
|
23
57
|
export declare const USERNAME_PROVIDED_LENGTH_MAX = 255;
|
|
24
58
|
/**
|
|
25
59
|
* Username for account creation — starts with letter, alphanumeric/dash/underscore middle, ends with alphanumeric. No @ or . allowed.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitive_schemas.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/primitive_schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,
|
|
1
|
+
{"version":3,"file":"primitive_schemas.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/primitive_schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,CAAC,EAAE,MA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