@servora/proto-utils 0.1.2 → 0.1.4
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/client/request.d.ts +1 -1
- package/dist/client/request.d.ts.map +1 -1
- package/dist/client/request.js +1 -0
- package/dist/client/request.js.map +1 -1
- package/dist/crud/index.d.ts +66 -0
- package/dist/crud/index.d.ts.map +1 -0
- package/dist/crud/index.js +190 -0
- package/dist/crud/index.js.map +1 -0
- package/dist/gen/servora/audit/v1/index.d.ts +20 -2
- package/dist/gen/servora/audit/v1/index.d.ts.map +1 -1
- package/dist/gen/servora/audit/v1/index.js +10 -2
- package/dist/gen/servora/audit/v1/index.js.map +1 -1
- package/dist/gen/servora/authn/audit/v1/index.d.ts +27 -9
- package/dist/gen/servora/authn/audit/v1/index.d.ts.map +1 -1
- package/dist/gen/servora/authn/audit/v1/index.js +10 -2
- package/dist/gen/servora/authn/audit/v1/index.js.map +1 -1
- package/dist/gen/servora/authn/v1/index.d.ts +21 -3
- package/dist/gen/servora/authn/v1/index.d.ts.map +1 -1
- package/dist/gen/servora/authn/v1/index.js +10 -2
- package/dist/gen/servora/authn/v1/index.js.map +1 -1
- package/dist/gen/servora/authz/audit/v1/index.d.ts +27 -9
- package/dist/gen/servora/authz/audit/v1/index.d.ts.map +1 -1
- package/dist/gen/servora/authz/audit/v1/index.js +10 -2
- package/dist/gen/servora/authz/audit/v1/index.js.map +1 -1
- package/dist/gen/servora/authz/openfga/audit/v1/index.d.ts +26 -8
- package/dist/gen/servora/authz/openfga/audit/v1/index.d.ts.map +1 -1
- package/dist/gen/servora/authz/openfga/audit/v1/index.js +10 -2
- package/dist/gen/servora/authz/openfga/audit/v1/index.js.map +1 -1
- package/dist/gen/servora/authz/v1/index.d.ts +23 -5
- package/dist/gen/servora/authz/v1/index.d.ts.map +1 -1
- package/dist/gen/servora/authz/v1/index.js +10 -2
- package/dist/gen/servora/authz/v1/index.js.map +1 -1
- package/dist/gen/servora/cloudevents/v1/index.d.ts +28 -11
- package/dist/gen/servora/cloudevents/v1/index.d.ts.map +1 -1
- package/dist/gen/servora/cloudevents/v1/index.js +10 -2
- package/dist/gen/servora/cloudevents/v1/index.js.map +1 -1
- package/dist/gen/servora/conf/v1/index.d.ts +22 -4
- package/dist/gen/servora/conf/v1/index.d.ts.map +1 -1
- package/dist/gen/servora/conf/v1/index.js +10 -2
- package/dist/gen/servora/conf/v1/index.js.map +1 -1
- package/dist/gen/servora/contrib/db/clickhouse/v1/index.d.ts +32 -15
- package/dist/gen/servora/contrib/db/clickhouse/v1/index.d.ts.map +1 -1
- package/dist/gen/servora/contrib/db/clickhouse/v1/index.js +10 -2
- package/dist/gen/servora/contrib/db/clickhouse/v1/index.js.map +1 -1
- package/dist/gen/servora/contrib/db/redis/v1/index.d.ts +25 -8
- package/dist/gen/servora/contrib/db/redis/v1/index.d.ts.map +1 -1
- package/dist/gen/servora/contrib/db/redis/v1/index.js +10 -2
- package/dist/gen/servora/contrib/db/redis/v1/index.js.map +1 -1
- package/dist/gen/servora/contrib/kafka/v1/index.d.ts +36 -19
- package/dist/gen/servora/contrib/kafka/v1/index.d.ts.map +1 -1
- package/dist/gen/servora/contrib/kafka/v1/index.js +10 -2
- package/dist/gen/servora/contrib/kafka/v1/index.js.map +1 -1
- package/dist/gen/servora/contrib/mail/v1/index.d.ts +28 -11
- package/dist/gen/servora/contrib/mail/v1/index.d.ts.map +1 -1
- package/dist/gen/servora/contrib/mail/v1/index.js +10 -2
- package/dist/gen/servora/contrib/mail/v1/index.js.map +1 -1
- package/dist/gen/servora/core/v1/index.d.ts +106 -89
- package/dist/gen/servora/core/v1/index.d.ts.map +1 -1
- package/dist/gen/servora/core/v1/index.js +10 -2
- package/dist/gen/servora/core/v1/index.js.map +1 -1
- package/dist/gen/servora/crud/v1/index.d.ts +40 -0
- package/dist/gen/servora/crud/v1/index.d.ts.map +1 -0
- package/dist/gen/servora/crud/v1/index.js +14 -0
- package/dist/gen/servora/crud/v1/index.js.map +1 -0
- package/dist/gen/servora/errors/v1/index.d.ts +19 -0
- package/dist/gen/servora/errors/v1/index.d.ts.map +1 -0
- package/dist/gen/servora/errors/v1/index.js +14 -0
- package/dist/gen/servora/errors/v1/index.js.map +1 -0
- package/dist/gen/servora/example/v1/example.crud.d.ts +29 -0
- package/dist/gen/servora/example/v1/example.crud.d.ts.map +1 -0
- package/dist/gen/servora/example/v1/example.crud.js +54 -0
- package/dist/gen/servora/example/v1/example.crud.js.map +1 -0
- package/dist/gen/servora/example/v1/index.d.ts +86 -0
- package/dist/gen/servora/example/v1/index.d.ts.map +1 -0
- package/dist/gen/servora/example/v1/index.js +158 -0
- package/dist/gen/servora/example/v1/index.js.map +1 -0
- package/dist/gen/servora/obs/audit/v1/index.d.ts +22 -4
- package/dist/gen/servora/obs/audit/v1/index.d.ts.map +1 -1
- package/dist/gen/servora/obs/audit/v1/index.js +10 -2
- package/dist/gen/servora/obs/audit/v1/index.js.map +1 -1
- package/dist/gen/servora/security/authn/oidc/v1/index.d.ts +22 -4
- package/dist/gen/servora/security/authn/oidc/v1/index.d.ts.map +1 -1
- package/dist/gen/servora/security/authn/oidc/v1/index.js +10 -2
- package/dist/gen/servora/security/authn/oidc/v1/index.js.map +1 -1
- package/dist/gen/servora/security/authz/openfga/v1/index.d.ts +22 -4
- package/dist/gen/servora/security/authz/openfga/v1/index.d.ts.map +1 -1
- package/dist/gen/servora/security/authz/openfga/v1/index.js +10 -2
- package/dist/gen/servora/security/authz/openfga/v1/index.js.map +1 -1
- package/dist/gen/servora/security/jwt/v1/index.d.ts +24 -6
- package/dist/gen/servora/security/jwt/v1/index.d.ts.map +1 -1
- package/dist/gen/servora/security/jwt/v1/index.js +10 -2
- package/dist/gen/servora/security/jwt/v1/index.js.map +1 -1
- package/dist/gen/servora/security/tls/v1/index.d.ts +22 -4
- package/dist/gen/servora/security/tls/v1/index.d.ts.map +1 -1
- package/dist/gen/servora/security/tls/v1/index.js +10 -2
- package/dist/gen/servora/security/tls/v1/index.js.map +1 -1
- package/dist/gen/servora/transport/http/cors/v1/index.d.ts +24 -7
- package/dist/gen/servora/transport/http/cors/v1/index.d.ts.map +1 -1
- package/dist/gen/servora/transport/http/cors/v1/index.js +10 -2
- package/dist/gen/servora/transport/http/cors/v1/index.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/client/request.ts +8 -7
- package/src/crud/AGENTS.md +24 -0
- package/src/crud/index.ts +307 -0
- package/src/gen/servora/audit/v1/index.ts +44 -8
- package/src/gen/servora/authn/audit/v1/index.ts +53 -17
- package/src/gen/servora/authn/v1/index.ts +44 -8
- package/src/gen/servora/authz/audit/v1/index.ts +53 -17
- package/src/gen/servora/authz/openfga/audit/v1/index.ts +48 -12
- package/src/gen/servora/authz/v1/index.ts +49 -13
- package/src/gen/servora/cloudevents/v1/index.ts +49 -13
- package/src/gen/servora/conf/v1/index.ts +42 -6
- package/src/gen/servora/contrib/db/clickhouse/v1/index.ts +53 -17
- package/src/gen/servora/contrib/db/redis/v1/index.ts +46 -10
- package/src/gen/servora/contrib/kafka/v1/index.ts +57 -21
- package/src/gen/servora/contrib/mail/v1/index.ts +49 -13
- package/src/gen/servora/core/v1/index.ts +134 -98
- package/src/gen/servora/crud/v1/index.ts +104 -0
- package/src/gen/servora/errors/v1/index.ts +42 -0
- package/src/gen/servora/example/v1/example.crud.ts +63 -0
- package/src/gen/servora/example/v1/index.ts +441 -0
- package/src/gen/servora/obs/audit/v1/index.ts +42 -6
- package/src/gen/servora/security/authn/oidc/v1/index.ts +42 -6
- package/src/gen/servora/security/authz/openfga/v1/index.ts +42 -6
- package/src/gen/servora/security/jwt/v1/index.ts +44 -8
- package/src/gen/servora/security/tls/v1/index.ts +42 -6
- package/src/gen/servora/transport/http/cors/v1/index.ts +45 -9
- package/src/index.ts +0 -1
- package/dist/gen/servora/mapper/v1/index.d.ts +0 -7
- package/dist/gen/servora/mapper/v1/index.d.ts.map +0 -1
- package/dist/gen/servora/mapper/v1/index.js +0 -6
- package/dist/gen/servora/mapper/v1/index.js.map +0 -1
- package/dist/gen/servora/pagination/v1/index.d.ts +0 -26
- package/dist/gen/servora/pagination/v1/index.d.ts.map +0 -1
- package/dist/gen/servora/pagination/v1/index.js +0 -6
- package/dist/gen/servora/pagination/v1/index.js.map +0 -1
- package/dist/query.d.ts +0 -57
- package/dist/query.d.ts.map +0 -1
- package/dist/query.js +0 -77
- package/dist/query.js.map +0 -1
- package/src/gen/servora/mapper/v1/index.ts +0 -18
- package/src/gen/servora/pagination/v1/index.ts +0 -37
- package/src/query.ts +0 -83
package/src/client/request.ts
CHANGED
|
@@ -24,10 +24,10 @@ export type RequestMeta = {
|
|
|
24
24
|
method: string;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
export type RequestHandler = (
|
|
27
|
+
export type RequestHandler = <T = unknown>(
|
|
28
28
|
request: RequestType,
|
|
29
29
|
meta: RequestMeta,
|
|
30
|
-
) => Promise<
|
|
30
|
+
) => Promise<T>;
|
|
31
31
|
|
|
32
32
|
export interface TokenStore {
|
|
33
33
|
getAccessToken: () => string | null;
|
|
@@ -125,11 +125,11 @@ export function createRequestHandler(
|
|
|
125
125
|
return refreshPromise;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
async function doRequest(
|
|
128
|
+
async function doRequest<T = unknown>(
|
|
129
129
|
request: RequestType,
|
|
130
130
|
meta: RequestMeta,
|
|
131
131
|
isRetry = false,
|
|
132
|
-
): Promise<
|
|
132
|
+
): Promise<T> {
|
|
133
133
|
const headers: Record<string, string> = {
|
|
134
134
|
Accept: "application/json",
|
|
135
135
|
};
|
|
@@ -149,10 +149,11 @@ export function createRequestHandler(
|
|
|
149
149
|
Object.assign(headers, contextHeaders(meta));
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
const fetchOptions: FetchOptions = {
|
|
152
|
+
const fetchOptions: FetchOptions<"json", T> = {
|
|
153
153
|
baseURL: baseUrl,
|
|
154
154
|
method: request.method as FetchOptions["method"],
|
|
155
155
|
headers,
|
|
156
|
+
responseType: "json",
|
|
156
157
|
timeout: timeoutMs,
|
|
157
158
|
};
|
|
158
159
|
|
|
@@ -163,7 +164,7 @@ export function createRequestHandler(
|
|
|
163
164
|
const normalizedPath = ensureLeadingSlash(request.path);
|
|
164
165
|
|
|
165
166
|
try {
|
|
166
|
-
return await ofetch(normalizedPath, fetchOptions);
|
|
167
|
+
return await ofetch<T>(normalizedPath, fetchOptions);
|
|
167
168
|
} catch (err: unknown) {
|
|
168
169
|
const fetchError =
|
|
169
170
|
err != null && typeof err === "object"
|
|
@@ -195,7 +196,7 @@ export function createRequestHandler(
|
|
|
195
196
|
) {
|
|
196
197
|
const refreshed = await tryRefreshToken();
|
|
197
198
|
if (refreshed) {
|
|
198
|
-
return doRequest(request, meta, true);
|
|
199
|
+
return doRequest<T>(request, meta, true);
|
|
199
200
|
}
|
|
200
201
|
}
|
|
201
202
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# AGENTS.md - web/packages/proto-utils/src/crud/
|
|
2
|
+
|
|
3
|
+
<!-- Parent: ../../AGENTS.md -->
|
|
4
|
+
<!-- Updated: 2026-07-21 -->
|
|
5
|
+
|
|
6
|
+
## 模块目的
|
|
7
|
+
|
|
8
|
+
`crud` 是 `@servora/proto-utils/crud` 的框架无关 TypeScript 运行时,供 `protoc-gen-servora-crud target=ts` 生成物消费。
|
|
9
|
+
|
|
10
|
+
## 核心边界
|
|
11
|
+
|
|
12
|
+
- 只提供资源名错误、FieldMask、AIP filter/order 文本和无状态 pager helper。
|
|
13
|
+
- 不生成或持有 Proto message、HTTP client、UI hooks、业务状态、授权或持久化逻辑。
|
|
14
|
+
- 所有 helper 不修改调用方传入对象;字段参数必须来自生成的 `XxxFields` / `XxxUpdateFields`。
|
|
15
|
+
- Resource name 只处理未 URL 编码 canonical name;百分号编码属于 transport。
|
|
16
|
+
|
|
17
|
+
## 验证
|
|
18
|
+
|
|
19
|
+
在 `servora/` 执行:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
just web-typecheck
|
|
23
|
+
just web-build
|
|
24
|
+
```
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
export class ResourceNameError extends Error {
|
|
2
|
+
override readonly name = "ResourceNameError";
|
|
3
|
+
|
|
4
|
+
constructor(message: string) {
|
|
5
|
+
super(message);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type FieldCollection =
|
|
10
|
+
| readonly string[]
|
|
11
|
+
| Readonly<Record<string, string>>;
|
|
12
|
+
|
|
13
|
+
export type FieldOf<Fields extends FieldCollection> =
|
|
14
|
+
Fields extends readonly (infer Field extends string)[]
|
|
15
|
+
? Field
|
|
16
|
+
: Fields extends Readonly<Record<string, infer Field extends string>>
|
|
17
|
+
? Field
|
|
18
|
+
: never;
|
|
19
|
+
|
|
20
|
+
export type FieldKeyOf<Fields extends FieldCollection> =
|
|
21
|
+
Fields extends readonly (infer Field extends string)[]
|
|
22
|
+
? Field
|
|
23
|
+
: Fields extends Readonly<Record<infer Key extends string, string>>
|
|
24
|
+
? Key
|
|
25
|
+
: never;
|
|
26
|
+
|
|
27
|
+
function fieldEntries(
|
|
28
|
+
fields: FieldCollection,
|
|
29
|
+
): ReadonlyArray<readonly [string, string]> {
|
|
30
|
+
return Array.isArray(fields)
|
|
31
|
+
? fields.map((field) => [field, field] as const)
|
|
32
|
+
: Object.entries(fields as Readonly<Record<string, string>>);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function fieldValues(fields: FieldCollection): readonly string[] {
|
|
36
|
+
return fieldEntries(fields).map(([, path]) => path);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function allowedFields(fields: FieldCollection): ReadonlySet<string> {
|
|
40
|
+
return new Set(fieldValues(fields));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Builds a comma-separated Proto FieldMask from fields present on values.
|
|
45
|
+
* Presence is based on own keys, so an explicit `undefined` still selects a
|
|
46
|
+
* field and can represent a Clear intent at the caller boundary.
|
|
47
|
+
*/
|
|
48
|
+
export function makeUpdateMask<
|
|
49
|
+
const Fields extends FieldCollection,
|
|
50
|
+
Values extends Partial<Record<FieldKeyOf<Fields>, unknown>>,
|
|
51
|
+
>(fields: Fields, values: Values): string {
|
|
52
|
+
const entries = fieldEntries(fields);
|
|
53
|
+
const allowedKeys = new Set(entries.map(([key]) => key));
|
|
54
|
+
const selected = new Set(Object.keys(values));
|
|
55
|
+
const unknown = [...selected].filter((field) => !allowedKeys.has(field));
|
|
56
|
+
if (unknown.length > 0) {
|
|
57
|
+
throw new RangeError(`unknown update field: ${unknown.join(", ")}`);
|
|
58
|
+
}
|
|
59
|
+
return entries
|
|
60
|
+
.filter(([key]) => selected.has(key))
|
|
61
|
+
.map(([, path]) => path)
|
|
62
|
+
.join(",");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type FilterOperator = "=" | "!=" | "<" | "<=" | ">" | ">=" | ":";
|
|
66
|
+
|
|
67
|
+
const filterOperators: Record<FilterOperator, true> = {
|
|
68
|
+
"=": true,
|
|
69
|
+
"!=": true,
|
|
70
|
+
"<": true,
|
|
71
|
+
"<=": true,
|
|
72
|
+
">": true,
|
|
73
|
+
">=": true,
|
|
74
|
+
":": true,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const rawFilterValueSymbol: unique symbol = Symbol("RawFilterValue");
|
|
78
|
+
|
|
79
|
+
export type RawFilterValue = Readonly<{
|
|
80
|
+
[rawFilterValueSymbol]: true;
|
|
81
|
+
text: string;
|
|
82
|
+
}>;
|
|
83
|
+
|
|
84
|
+
/** Use for validated enum symbols or AIP functions such as duration("5s"). */
|
|
85
|
+
export function rawFilterValue(text: string): RawFilterValue {
|
|
86
|
+
if (text.length === 0) {
|
|
87
|
+
throw new RangeError("raw filter value must not be empty");
|
|
88
|
+
}
|
|
89
|
+
return Object.freeze({ [rawFilterValueSymbol]: true as const, text });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const stringMatchValueSymbol: unique symbol = Symbol("StringMatchValue");
|
|
93
|
+
|
|
94
|
+
export type StringMatchValueKind = "prefix" | "suffix" | "contains";
|
|
95
|
+
|
|
96
|
+
export type StringMatchValue = Readonly<{
|
|
97
|
+
[stringMatchValueSymbol]: true;
|
|
98
|
+
kind: StringMatchValueKind;
|
|
99
|
+
value: string;
|
|
100
|
+
}>;
|
|
101
|
+
|
|
102
|
+
function stringMatchValue(
|
|
103
|
+
kind: StringMatchValueKind,
|
|
104
|
+
value: string,
|
|
105
|
+
): StringMatchValue {
|
|
106
|
+
return Object.freeze({
|
|
107
|
+
[stringMatchValueSymbol]: true as const,
|
|
108
|
+
kind,
|
|
109
|
+
value,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Builds a typed string prefix filter value. */
|
|
114
|
+
export function filterPrefix(value: string): StringMatchValue {
|
|
115
|
+
return stringMatchValue("prefix", value);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Builds a typed string suffix filter value. */
|
|
119
|
+
export function filterSuffix(value: string): StringMatchValue {
|
|
120
|
+
return stringMatchValue("suffix", value);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Builds a typed string contains filter value. */
|
|
124
|
+
export function filterContains(value: string): StringMatchValue {
|
|
125
|
+
return stringMatchValue("contains", value);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export type FilterValue =
|
|
129
|
+
| string
|
|
130
|
+
| number
|
|
131
|
+
| bigint
|
|
132
|
+
| boolean
|
|
133
|
+
| Date
|
|
134
|
+
| null
|
|
135
|
+
| RawFilterValue
|
|
136
|
+
| StringMatchValue;
|
|
137
|
+
|
|
138
|
+
export type FilterExpression<Field extends string> =
|
|
139
|
+
| Readonly<{
|
|
140
|
+
field: Field;
|
|
141
|
+
operator: FilterOperator;
|
|
142
|
+
value: FilterValue;
|
|
143
|
+
}>
|
|
144
|
+
| Readonly<{ and: readonly FilterExpression<Field>[] }>
|
|
145
|
+
| Readonly<{ or: readonly FilterExpression<Field>[] }>;
|
|
146
|
+
|
|
147
|
+
/** Serializes a typed expression into the AIP-160 filter text accepted by CRUD. */
|
|
148
|
+
export function buildFilter<const Fields extends FieldCollection>(
|
|
149
|
+
fields: Fields,
|
|
150
|
+
expression?: FilterExpression<FieldOf<Fields>> | null,
|
|
151
|
+
): string | undefined {
|
|
152
|
+
if (expression == null) return undefined;
|
|
153
|
+
return renderFilter(expression, allowedFields(fields));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function renderFilter(
|
|
157
|
+
expression: FilterExpression<string>,
|
|
158
|
+
fields: ReadonlySet<string>,
|
|
159
|
+
): string {
|
|
160
|
+
if ("field" in expression) {
|
|
161
|
+
if (!fields.has(expression.field)) {
|
|
162
|
+
throw new RangeError(`unknown filter field: ${expression.field}`);
|
|
163
|
+
}
|
|
164
|
+
if (
|
|
165
|
+
!Object.prototype.hasOwnProperty.call(
|
|
166
|
+
filterOperators,
|
|
167
|
+
expression.operator,
|
|
168
|
+
)
|
|
169
|
+
) {
|
|
170
|
+
throw new RangeError(
|
|
171
|
+
`unsupported filter operator: ${String(expression.operator)}`,
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
if (
|
|
175
|
+
expression.value === null &&
|
|
176
|
+
!["=", "!="].includes(expression.operator)
|
|
177
|
+
) {
|
|
178
|
+
throw new RangeError("null filter values only support = and !=");
|
|
179
|
+
}
|
|
180
|
+
if (
|
|
181
|
+
isStringMatchValue(expression.value) &&
|
|
182
|
+
expression.operator !== "=" &&
|
|
183
|
+
expression.operator !== "!="
|
|
184
|
+
) {
|
|
185
|
+
throw new RangeError(
|
|
186
|
+
"typed wildcard filter values only support = and !=",
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
return `${expression.field} ${expression.operator} ${renderFilterValue(expression.value)}`;
|
|
190
|
+
}
|
|
191
|
+
const [operator, children] =
|
|
192
|
+
"and" in expression
|
|
193
|
+
? (["AND", expression.and] as const)
|
|
194
|
+
: (["OR", expression.or] as const);
|
|
195
|
+
if (children.length === 0) {
|
|
196
|
+
throw new RangeError(`${operator} filter group must not be empty`);
|
|
197
|
+
}
|
|
198
|
+
return `(${children.map((child) => renderFilter(child, fields)).join(` ${operator} `)})`;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function renderFilterValue(value: FilterValue): string {
|
|
202
|
+
if (value === null) return "null";
|
|
203
|
+
if (typeof value === "string") {
|
|
204
|
+
return JSON.stringify(escapeWildcardLiteral(value));
|
|
205
|
+
}
|
|
206
|
+
if (typeof value === "boolean" || typeof value === "bigint") {
|
|
207
|
+
return value.toString();
|
|
208
|
+
}
|
|
209
|
+
if (typeof value === "number") {
|
|
210
|
+
if (!Number.isFinite(value)) {
|
|
211
|
+
throw new RangeError("filter numbers must be finite");
|
|
212
|
+
}
|
|
213
|
+
return value.toString();
|
|
214
|
+
}
|
|
215
|
+
if (value instanceof Date) {
|
|
216
|
+
if (Number.isNaN(value.getTime())) {
|
|
217
|
+
throw new RangeError("filter date must be valid");
|
|
218
|
+
}
|
|
219
|
+
return `timestamp(${JSON.stringify(value.toISOString())})`;
|
|
220
|
+
}
|
|
221
|
+
if (isStringMatchValue(value)) {
|
|
222
|
+
return renderStringMatchValue(value);
|
|
223
|
+
}
|
|
224
|
+
return value.text;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function isStringMatchValue(value: FilterValue): value is StringMatchValue {
|
|
228
|
+
return (
|
|
229
|
+
typeof value === "object" &&
|
|
230
|
+
value !== null &&
|
|
231
|
+
stringMatchValueSymbol in value
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function escapeWildcardLiteral(value: string): string {
|
|
236
|
+
return value.replaceAll("\\", "\\\\").replaceAll("*", "\\*");
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function renderStringMatchValue(value: StringMatchValue): string {
|
|
240
|
+
if (value.value.length === 0) return JSON.stringify("*");
|
|
241
|
+
const literal = escapeWildcardLiteral(value.value);
|
|
242
|
+
switch (value.kind) {
|
|
243
|
+
case "prefix":
|
|
244
|
+
return JSON.stringify(`${literal}*`);
|
|
245
|
+
case "suffix":
|
|
246
|
+
return JSON.stringify(`*${literal}`);
|
|
247
|
+
case "contains":
|
|
248
|
+
return JSON.stringify(`*${literal}*`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export type OrderDirection = "asc" | "desc";
|
|
253
|
+
|
|
254
|
+
export type OrderTerm<Field extends string> = Readonly<{
|
|
255
|
+
field: Field;
|
|
256
|
+
direction?: OrderDirection;
|
|
257
|
+
}>;
|
|
258
|
+
|
|
259
|
+
/** Serializes typed terms into canonical AIP-132 order_by text. */
|
|
260
|
+
export function buildOrderBy<const Fields extends FieldCollection>(
|
|
261
|
+
fields: Fields,
|
|
262
|
+
terms?: readonly OrderTerm<FieldOf<Fields>>[] | null,
|
|
263
|
+
): string | undefined {
|
|
264
|
+
if (terms == null || terms.length === 0) return undefined;
|
|
265
|
+
const allowed = allowedFields(fields);
|
|
266
|
+
const seen = new Set<string>();
|
|
267
|
+
return terms
|
|
268
|
+
.map(({ field, direction = "asc" }) => {
|
|
269
|
+
if (!allowed.has(field)) {
|
|
270
|
+
throw new RangeError(`unknown order field: ${field}`);
|
|
271
|
+
}
|
|
272
|
+
if (seen.has(field)) {
|
|
273
|
+
throw new RangeError(`duplicate order field: ${field}`);
|
|
274
|
+
}
|
|
275
|
+
seen.add(field);
|
|
276
|
+
return direction === "desc" ? `${field} desc` : field;
|
|
277
|
+
})
|
|
278
|
+
.join(",");
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export type Pager = Readonly<{
|
|
282
|
+
pageToken?: string;
|
|
283
|
+
exhausted: boolean;
|
|
284
|
+
}>;
|
|
285
|
+
|
|
286
|
+
export const firstPage: Pager = Object.freeze({ exhausted: false });
|
|
287
|
+
|
|
288
|
+
/** Returns the state for the response's next page without mutating prior state. */
|
|
289
|
+
export function advancePager(nextPageToken?: string | null): Pager {
|
|
290
|
+
return nextPageToken
|
|
291
|
+
? Object.freeze({ pageToken: nextPageToken, exhausted: false })
|
|
292
|
+
: Object.freeze({ exhausted: true });
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** Applies the current token to a cloned request object. */
|
|
296
|
+
export function applyPager<Request extends Readonly<Record<string, unknown>>>(
|
|
297
|
+
pager: Pager,
|
|
298
|
+
request: Request,
|
|
299
|
+
): Request & { pageToken?: string } {
|
|
300
|
+
const next = { ...request } as Request & { pageToken?: string };
|
|
301
|
+
if (pager.pageToken === undefined) {
|
|
302
|
+
delete next.pageToken;
|
|
303
|
+
} else {
|
|
304
|
+
next.pageToken = pager.pageToken;
|
|
305
|
+
}
|
|
306
|
+
return next;
|
|
307
|
+
}
|
|
@@ -1,23 +1,59 @@
|
|
|
1
1
|
// Code generated by protoc-gen-typescript-http. DO NOT EDIT.
|
|
2
|
-
/* eslint-disable
|
|
3
|
-
|
|
2
|
+
/* eslint-disable no-use-before-define, @typescript-eslint/no-unused-vars, prettier/prettier */
|
|
3
|
+
|
|
4
|
+
interface TransportMeta {
|
|
5
|
+
service: string;
|
|
6
|
+
method: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface ClientTransport {
|
|
10
|
+
unary<T>(
|
|
11
|
+
path: string,
|
|
12
|
+
method: string,
|
|
13
|
+
body: null | string,
|
|
14
|
+
meta: TransportMeta,
|
|
15
|
+
): Promise<T>;
|
|
16
|
+
serverStream<T>(path: string, meta: TransportMeta): ServerStream<T>;
|
|
17
|
+
duplexStream<TIn, TOut>(path: string, meta: TransportMeta): DuplexStream<TIn, TOut>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ServerStream<T> {
|
|
21
|
+
onEvent(listener: (data: T) => void): () => void;
|
|
22
|
+
onError(handler: (error: Error) => void): void;
|
|
23
|
+
close(): void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface DuplexStream<TIn, TOut> extends ServerStream<TOut> {
|
|
27
|
+
send(data: TIn): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function encodePathSegment(value: unknown): string {
|
|
31
|
+
return encodeURIComponent(String(value)).replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function encodeMultiSegmentPath(value: unknown): string {
|
|
35
|
+
return String(value)
|
|
36
|
+
.split('/')
|
|
37
|
+
.map(encodePathSegment)
|
|
38
|
+
.join('/');
|
|
39
|
+
}
|
|
4
40
|
|
|
5
41
|
// AuditMode controls whether an RPC operation produces a runtime audit event.
|
|
6
42
|
export type AuditMode =
|
|
7
|
-
// UNSPECIFIED inherits the service-level default; treated as DISABLED if no
|
|
8
|
-
// service default is declared.
|
|
9
|
-
| "AUDIT_MODE_UNSPECIFIED"
|
|
10
43
|
// DISABLED suppresses audit events for this operation.
|
|
11
|
-
|
|
|
44
|
+
| 'AUDIT_MODE_DISABLED'
|
|
12
45
|
// ENABLED emits a servora.audit.rpc.v1 CloudEvents event for every call.
|
|
13
|
-
|
|
|
46
|
+
| 'AUDIT_MODE_ENABLED'
|
|
47
|
+
// UNSPECIFIED inherits the service-level default; treated as DISABLED if no
|
|
48
|
+
// service default is declared.
|
|
49
|
+
| 'AUDIT_MODE_UNSPECIFIED';
|
|
14
50
|
// AuditRule is the RPC audit on/off switch. It intentionally carries only
|
|
15
51
|
// mode: event type, severity, field extraction and CloudEvents extensions are
|
|
16
52
|
// the responsibility of the event producer (authn, authz, CRUD generator, or
|
|
17
53
|
// business code). Keeping this annotation minimal prevents it from becoming a
|
|
18
54
|
// mixed DSL.
|
|
19
55
|
export type AuditRule = {
|
|
20
|
-
mode
|
|
56
|
+
mode?: AuditMode;
|
|
21
57
|
};
|
|
22
58
|
|
|
23
59
|
|
|
@@ -1,41 +1,77 @@
|
|
|
1
1
|
// Code generated by protoc-gen-typescript-http. DO NOT EDIT.
|
|
2
|
-
/* eslint-disable
|
|
3
|
-
|
|
2
|
+
/* eslint-disable no-use-before-define, @typescript-eslint/no-unused-vars, prettier/prettier */
|
|
3
|
+
|
|
4
|
+
interface TransportMeta {
|
|
5
|
+
service: string;
|
|
6
|
+
method: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface ClientTransport {
|
|
10
|
+
unary<T>(
|
|
11
|
+
path: string,
|
|
12
|
+
method: string,
|
|
13
|
+
body: null | string,
|
|
14
|
+
meta: TransportMeta,
|
|
15
|
+
): Promise<T>;
|
|
16
|
+
serverStream<T>(path: string, meta: TransportMeta): ServerStream<T>;
|
|
17
|
+
duplexStream<TIn, TOut>(path: string, meta: TransportMeta): DuplexStream<TIn, TOut>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ServerStream<T> {
|
|
21
|
+
onEvent(listener: (data: T) => void): () => void;
|
|
22
|
+
onError(handler: (error: Error) => void): void;
|
|
23
|
+
close(): void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface DuplexStream<TIn, TOut> extends ServerStream<TOut> {
|
|
27
|
+
send(data: TIn): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function encodePathSegment(value: unknown): string {
|
|
31
|
+
return encodeURIComponent(String(value)).replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function encodeMultiSegmentPath(value: unknown): string {
|
|
35
|
+
return String(value)
|
|
36
|
+
.split('/')
|
|
37
|
+
.map(encodePathSegment)
|
|
38
|
+
.join('/');
|
|
39
|
+
}
|
|
4
40
|
|
|
5
41
|
// AuthnFailure is the CloudEvents data payload for servora.authn.failure.v1
|
|
6
42
|
// events. All string fields MUST be sanitised — no raw tokens, API keys, or
|
|
7
43
|
// full JWT claims may appear here.
|
|
8
44
|
export type AuthnFailure = {
|
|
9
|
-
// reason is the high-level failure reason (e.g. "AUTHN_FAILED").
|
|
10
|
-
reason: string | undefined;
|
|
11
|
-
// code is the HTTP/gRPC status code (e.g. 401).
|
|
12
|
-
code: number | undefined;
|
|
13
|
-
// message is a sanitised, human-readable failure description.
|
|
14
|
-
message: string | undefined;
|
|
15
45
|
// attempts lists the per-scheme authentication results when Multi dispatch
|
|
16
46
|
// was used.
|
|
17
|
-
attempts
|
|
47
|
+
attempts?: SchemeAttempt[];
|
|
48
|
+
// code is the HTTP/gRPC status code (e.g. 401).
|
|
49
|
+
code?: number;
|
|
50
|
+
// message is a sanitised, human-readable failure description.
|
|
51
|
+
message?: string;
|
|
52
|
+
// reason is the high-level failure reason (e.g. "AUTHN_FAILED").
|
|
53
|
+
reason?: string;
|
|
18
54
|
};
|
|
19
55
|
|
|
20
56
|
// SchemeAttempt records the outcome of a single authentication scheme within a
|
|
21
57
|
// Multi-dispatcher round.
|
|
22
58
|
export type SchemeAttempt = {
|
|
23
|
-
// scheme is the authenticator name (e.g. "jwt", "apikey", "casdoor").
|
|
24
|
-
scheme: string | undefined;
|
|
25
|
-
// reason is the sanitised failure reason returned by this scheme's backend.
|
|
26
|
-
reason: string | undefined;
|
|
27
59
|
// message is a sanitised description from this scheme's backend.
|
|
28
|
-
message
|
|
60
|
+
message?: string;
|
|
61
|
+
// reason is the sanitised failure reason returned by this scheme's backend.
|
|
62
|
+
reason?: string;
|
|
63
|
+
// scheme is the authenticator name (e.g. "jwt", "apikey", "casdoor").
|
|
64
|
+
scheme?: string;
|
|
29
65
|
};
|
|
30
66
|
|
|
31
67
|
// AuthnSuccess is the CloudEvents data payload for servora.authn.success.v1
|
|
32
68
|
// events. Identity fields are intentionally omitted — the authenticated
|
|
33
69
|
// subject is carried in CloudEvents extensions or set by the business layer.
|
|
34
70
|
export type AuthnSuccess = {
|
|
35
|
-
// scheme is the authentication scheme that succeeded (e.g. "jwt", "apikey").
|
|
36
|
-
scheme: string | undefined;
|
|
37
71
|
// message is an optional human-readable note.
|
|
38
|
-
message
|
|
72
|
+
message?: string;
|
|
73
|
+
// scheme is the authentication scheme that succeeded (e.g. "jwt", "apikey").
|
|
74
|
+
scheme?: string;
|
|
39
75
|
};
|
|
40
76
|
|
|
41
77
|
|
|
@@ -1,25 +1,61 @@
|
|
|
1
1
|
// Code generated by protoc-gen-typescript-http. DO NOT EDIT.
|
|
2
|
-
/* eslint-disable
|
|
3
|
-
|
|
2
|
+
/* eslint-disable no-use-before-define, @typescript-eslint/no-unused-vars, prettier/prettier */
|
|
3
|
+
|
|
4
|
+
interface TransportMeta {
|
|
5
|
+
service: string;
|
|
6
|
+
method: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface ClientTransport {
|
|
10
|
+
unary<T>(
|
|
11
|
+
path: string,
|
|
12
|
+
method: string,
|
|
13
|
+
body: null | string,
|
|
14
|
+
meta: TransportMeta,
|
|
15
|
+
): Promise<T>;
|
|
16
|
+
serverStream<T>(path: string, meta: TransportMeta): ServerStream<T>;
|
|
17
|
+
duplexStream<TIn, TOut>(path: string, meta: TransportMeta): DuplexStream<TIn, TOut>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ServerStream<T> {
|
|
21
|
+
onEvent(listener: (data: T) => void): () => void;
|
|
22
|
+
onError(handler: (error: Error) => void): void;
|
|
23
|
+
close(): void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface DuplexStream<TIn, TOut> extends ServerStream<TOut> {
|
|
27
|
+
send(data: TIn): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function encodePathSegment(value: unknown): string {
|
|
31
|
+
return encodeURIComponent(String(value)).replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function encodeMultiSegmentPath(value: unknown): string {
|
|
35
|
+
return String(value)
|
|
36
|
+
.split('/')
|
|
37
|
+
.map(encodePathSegment)
|
|
38
|
+
.join('/');
|
|
39
|
+
}
|
|
4
40
|
|
|
5
41
|
// AuthnRule 声明 RPC 方法的认证策略。
|
|
6
42
|
export type AuthnRule = {
|
|
7
43
|
// 认证模式。
|
|
8
|
-
mode
|
|
44
|
+
mode?: AuthnRule_Mode;
|
|
9
45
|
// 接受的认证机制;空列表表示沿用框架默认引擎。
|
|
10
46
|
// 取值是各 wrapper 子包持有的私有 method 字符串常量(如 `jwt`、`mtls`、`api_key`、`aksk`);
|
|
11
47
|
// framework 不枚举这些值,业务自定义引擎也可填任意字符串。
|
|
12
48
|
// 多个值表示"任一通过即可"。
|
|
13
|
-
schemes
|
|
49
|
+
schemes?: string[];
|
|
14
50
|
};
|
|
15
51
|
|
|
16
52
|
// Mode 表达认证模式三态。
|
|
17
53
|
export type AuthnRule_Mode =
|
|
18
|
-
// 未指定,等价"未写注解":私有 + 框架默认引擎(fail-closed 默认)。
|
|
19
|
-
| "MODE_UNSPECIFIED"
|
|
20
54
|
// 显式公开。schemes 必须为空。
|
|
21
|
-
|
|
|
55
|
+
| 'MODE_PUBLIC'
|
|
22
56
|
// 必须用 schemes 指定的认证机制。schemes 必须非空。
|
|
23
|
-
|
|
|
57
|
+
| 'MODE_REQUIRED'
|
|
58
|
+
// 未指定,等价"未写注解":私有 + 框架默认引擎(fail-closed 默认)。
|
|
59
|
+
| 'MODE_UNSPECIFIED';
|
|
24
60
|
|
|
25
61
|
// @@protoc_insertion_point(typescript-http-eof)
|