Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a middleware for admin api using ServiceWorker #111

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions apps/web-ui/app/entry.client.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { RemixBrowser } from '@remix-run/react';
import { startTransition, StrictMode } from 'react';
import { hydrateRoot } from 'react-dom/client';
import { register } from '@restate/data-access/middleware-service-worker';

startTransition(() => {
hydrateRoot(
document,
<StrictMode>
<RemixBrowser />
</StrictMode>
);
register().then(() => {
startTransition(() => {
hydrateRoot(
document,
<StrictMode>
<RemixBrowser />
</StrictMode>
);
});
});
7 changes: 4 additions & 3 deletions apps/web-ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default defineConfig(({ mode }) => {
const ADMIN_BASE_URL = env['ADMIN_BASE_URL'] || '';
const SERVER_HEADERS = {
'Set-Cookie': `adminBaseUrl=${ADMIN_BASE_URL}; SameSite=Strict; Path=/`,
'Service-Worker-Allowed': '/',
};

return {
Expand Down Expand Up @@ -51,9 +52,9 @@ export default defineConfig(({ mode }) => {
],

// Uncomment this if you are using workers.
// worker: {
// plugins: [ nxViteTsPaths() ],
// },
worker: {
plugins: () => [nxViteTsPaths()],
},
build: {
commonjsOptions: {
transformMixedEsModules: true,
Expand Down
9 changes: 6 additions & 3 deletions libs/data-access/admin-api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
"executor": "nx:run-commands",
"options": {
"commands": [
"redocly lint ./libs/data-access/admin-api/src/lib/api/spec.json || true",
"openapi-typescript ./libs/data-access/admin-api/src/lib/api/spec.json -o ./libs/data-access/admin-api/src/lib/api/index.d.ts"
]
"./libs/data-access/admin-api/src/merge.mjs",
"redocly lint ./libs/data-access/admin-api/src/lib/api/output.json || true",
"openapi-typescript ./libs/data-access/admin-api/src/lib/api/output.json -o ./libs/data-access/admin-api/src/lib/api/index.d.ts",
"nx format"
],
"parallel": false
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions libs/data-access/admin-api/src/lib/api/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,14 @@ export function useServiceOpenApi(

return { ...results, queryKey: queryOptions.queryKey };
}

export function useListInvocations(
options?: HookQueryOptions<'/query/invocations', 'get'>
) {
const baseUrl = useAdminBaseUrl();

return useQuery({
...adminApi('query', '/query/invocations', 'get', { baseUrl }),
...options,
});
}
228 changes: 208 additions & 20 deletions libs/data-access/admin-api/src/lib/api/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,46 @@ export interface paths {
patch?: never;
trace?: never;
};
'/query': {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get?: never;
put?: never;
/**
* Query journal
* @description Query journal
*/
post: operations['query'];
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
'/query/invocations': {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/**
* List invocations
* @description List invocations
*/
get: operations['list_invocations'];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
}
export type webhooks = Record<string, never>;
export interface components {
Expand Down Expand Up @@ -503,15 +543,14 @@ export interface components {
ListDeploymentsResponse: {
deployments: components['schemas']['DeploymentResponse'][];
};
DeploymentResponse: {
id: components['schemas']['String'];
/**
* Services
* @description List of services exposed by this deployment.
*/
services: components['schemas']['ServiceNameRevPair'][];
} & (
DeploymentResponse:
| {
id: components['schemas']['String'];
/**
* Services
* @description List of services exposed by this deployment.
*/
services: components['schemas']['ServiceNameRevPair'][];
uri: string;
protocol_type: components['schemas']['ProtocolType'];
http_version: string;
Expand All @@ -525,6 +564,12 @@ export interface components {
max_protocol_version: number;
}
| {
id: components['schemas']['String'];
/**
* Services
* @description List of services exposed by this deployment.
*/
services: components['schemas']['ServiceNameRevPair'][];
arn: components['schemas']['LambdaARN'];
assume_role_arn?: string | null;
additional_headers?: {
Expand All @@ -535,8 +580,7 @@ export interface components {
min_protocol_version: number;
/** Format: int32 */
max_protocol_version: number;
}
);
};
ServiceNameRevPair: {
name: string;
/** Format: uint32 */
Expand Down Expand Up @@ -648,14 +692,7 @@ export interface components {
id: components['schemas']['String'];
services: components['schemas']['ServiceMetadata'][];
};
DetailedDeploymentResponse: {
id: components['schemas']['String'];
/**
* Services
* @description List of services exposed by this deployment.
*/
services: components['schemas']['ServiceMetadata'][];
} & (
DetailedDeploymentResponse:
| {
uri: string;
protocol_type: components['schemas']['ProtocolType'];
Expand All @@ -668,6 +705,12 @@ export interface components {
min_protocol_version: number;
/** Format: int32 */
max_protocol_version: number;
id: components['schemas']['String'];
/**
* Services
* @description List of services exposed by this deployment.
*/
services: components['schemas']['ServiceMetadata'][];
}
| {
arn: components['schemas']['LambdaARN'];
Expand All @@ -680,8 +723,13 @@ export interface components {
min_protocol_version: number;
/** Format: int32 */
max_protocol_version: number;
}
);
id?: components['schemas']['String'];
/**
* Services
* @description List of services exposed by this deployment.
*/
services: components['schemas']['ServiceMetadata'][];
};
};
responses: never;
parameters: never;
Expand Down Expand Up @@ -1793,4 +1841,144 @@ export interface operations {
};
};
};
query: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody: {
content: {
'application/json': {
query: string;
};
};
};
responses: {
200: {
headers: {
[name: string]: unknown;
};
content: {
'application/json': Record<string, never>;
};
};
400: {
headers: {
[name: string]: unknown;
};
content: {
'application/json': components['schemas']['ErrorDescriptionResponse'];
};
};
403: {
headers: {
[name: string]: unknown;
};
content: {
'application/json': components['schemas']['ErrorDescriptionResponse'];
};
};
404: {
headers: {
[name: string]: unknown;
};
content: {
'application/json': components['schemas']['ErrorDescriptionResponse'];
};
};
409: {
headers: {
[name: string]: unknown;
};
content: {
'application/json': components['schemas']['ErrorDescriptionResponse'];
};
};
500: {
headers: {
[name: string]: unknown;
};
content: {
'application/json': components['schemas']['ErrorDescriptionResponse'];
};
};
503: {
headers: {
[name: string]: unknown;
};
content: {
'application/json': components['schemas']['ErrorDescriptionResponse'];
};
};
};
};
list_invocations: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
200: {
headers: {
[name: string]: unknown;
};
content: {
'application/json': Record<string, never>;
};
};
400: {
headers: {
[name: string]: unknown;
};
content: {
'application/json': components['schemas']['ErrorDescriptionResponse'];
};
};
403: {
headers: {
[name: string]: unknown;
};
content: {
'application/json': components['schemas']['ErrorDescriptionResponse'];
};
};
404: {
headers: {
[name: string]: unknown;
};
content: {
'application/json': components['schemas']['ErrorDescriptionResponse'];
};
};
409: {
headers: {
[name: string]: unknown;
};
content: {
'application/json': components['schemas']['ErrorDescriptionResponse'];
};
};
500: {
headers: {
[name: string]: unknown;
};
content: {
'application/json': components['schemas']['ErrorDescriptionResponse'];
};
};
503: {
headers: {
[name: string]: unknown;
};
content: {
'application/json': components['schemas']['ErrorDescriptionResponse'];
};
};
};
};
}
Loading
Loading