new sdk for front with vendor entity

This commit is contained in:
José Salazar
2025-11-24 12:16:40 -05:00
parent 93f17ce517
commit 0e0d5c647e
18 changed files with 1482 additions and 204 deletions

View File

@@ -10,11 +10,13 @@ This README will guide you through the process of using the generated JavaScript
- [**Accessing the connector**](#accessing-the-connector)
- [*Connecting to the local Emulator*](#connecting-to-the-local-emulator)
- [**Queries**](#queries)
- [*listStaff*](#liststaff)
- [*listVendor*](#listvendor)
- [*listEvents*](#listevents)
- [*listStaff*](#liststaff)
- [**Mutations**](#mutations)
- [*CreateEvent*](#createevent)
- [*CreateStaff*](#createstaff)
- [*CreateVendor*](#createvendor)
# Accessing the connector
A connector is a collection of Queries and Mutations. One SDK is generated for each connector - this SDK is generated for the connector `krow-connector`. You can find more information about connectors in the [Data Connect documentation](https://firebase.google.com/docs/data-connect#how-does).
@@ -61,105 +63,103 @@ The following is true for both the action shortcut function and the `QueryRef` f
Below are examples of how to use the `krow-connector` connector's generated functions to execute each query. You can also follow the examples from the [Data Connect documentation](https://firebase.google.com/docs/data-connect/web-sdk#using-queries).
## listStaff
You can execute the `listStaff` query using the following action shortcut function, or by calling `executeQuery()` after calling the following `QueryRef` function, both of which are defined in [dataconnect-generated/index.d.ts](./index.d.ts):
## listVendor
You can execute the `listVendor` query using the following action shortcut function, or by calling `executeQuery()` after calling the following `QueryRef` function, both of which are defined in [dataconnect-generated/index.d.ts](./index.d.ts):
```typescript
listStaff(): QueryPromise<ListStaffData, undefined>;
listVendor(): QueryPromise<ListVendorData, undefined>;
interface ListStaffRef {
interface ListVendorRef {
...
/* Allow users to create refs without passing in DataConnect */
(): QueryRef<ListStaffData, undefined>;
(): QueryRef<ListVendorData, undefined>;
}
export const listStaffRef: ListStaffRef;
export const listVendorRef: ListVendorRef;
```
You can also pass in a `DataConnect` instance to the action shortcut function or `QueryRef` function.
```typescript
listStaff(dc: DataConnect): QueryPromise<ListStaffData, undefined>;
listVendor(dc: DataConnect): QueryPromise<ListVendorData, undefined>;
interface ListStaffRef {
interface ListVendorRef {
...
(dc: DataConnect): QueryRef<ListStaffData, undefined>;
(dc: DataConnect): QueryRef<ListVendorData, undefined>;
}
export const listStaffRef: ListStaffRef;
export const listVendorRef: ListVendorRef;
```
If you need the name of the operation without creating a ref, you can retrieve the operation name by calling the `operationName` property on the listStaffRef:
If you need the name of the operation without creating a ref, you can retrieve the operation name by calling the `operationName` property on the listVendorRef:
```typescript
const name = listStaffRef.operationName;
const name = listVendorRef.operationName;
console.log(name);
```
### Variables
The `listStaff` query has no variables.
The `listVendor` query has no variables.
### Return Type
Recall that executing the `listStaff` query returns a `QueryPromise` that resolves to an object with a `data` property.
Recall that executing the `listVendor` query returns a `QueryPromise` that resolves to an object with a `data` property.
The `data` property is an object of type `ListStaffData`, which is defined in [dataconnect-generated/index.d.ts](./index.d.ts). It has the following fields:
The `data` property is an object of type `ListVendorData`, which is defined in [dataconnect-generated/index.d.ts](./index.d.ts). It has the following fields:
```typescript
export interface ListStaffData {
staffs: ({
export interface ListVendorData {
vendors: ({
id: UUIDString;
employeeName: string;
vendorId?: UUIDString | null;
email?: string | null;
position?: string | null;
employmentType: EmploymentType;
rating?: number | null;
reliabilityScore?: number | null;
backgroundCheckStatus: BackgroundCheckStatus;
certifications?: string | null;
} & Staff_Key)[];
vendorNumber: string;
legalName: string;
region: VendorRegion;
platformType: VendorPlatformType;
primaryContactEmail: string;
approvalStatus: VendorApprovalStatus;
isActive?: boolean | null;
} & Vendor_Key)[];
}
```
### Using `listStaff`'s action shortcut function
### Using `listVendor`'s action shortcut function
```typescript
import { getDataConnect } from 'firebase/data-connect';
import { connectorConfig, listStaff } from '@dataconnect/generated';
import { connectorConfig, listVendor } from '@dataconnect/generated';
// Call the `listStaff()` function to execute the query.
// Call the `listVendor()` function to execute the query.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await listStaff();
const { data } = await listVendor();
// You can also pass in a `DataConnect` instance to the action shortcut function.
const dataConnect = getDataConnect(connectorConfig);
const { data } = await listStaff(dataConnect);
const { data } = await listVendor(dataConnect);
console.log(data.staffs);
console.log(data.vendors);
// Or, you can use the `Promise` API.
listStaff().then((response) => {
listVendor().then((response) => {
const data = response.data;
console.log(data.staffs);
console.log(data.vendors);
});
```
### Using `listStaff`'s `QueryRef` function
### Using `listVendor`'s `QueryRef` function
```typescript
import { getDataConnect, executeQuery } from 'firebase/data-connect';
import { connectorConfig, listStaffRef } from '@dataconnect/generated';
import { connectorConfig, listVendorRef } from '@dataconnect/generated';
// Call the `listStaffRef()` function to get a reference to the query.
const ref = listStaffRef();
// Call the `listVendorRef()` function to get a reference to the query.
const ref = listVendorRef();
// You can also pass in a `DataConnect` instance to the `QueryRef` function.
const dataConnect = getDataConnect(connectorConfig);
const ref = listStaffRef(dataConnect);
const ref = listVendorRef(dataConnect);
// Call `executeQuery()` on the reference to execute the query.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await executeQuery(ref);
console.log(data.staffs);
console.log(data.vendors);
// Or, you can use the `Promise` API.
executeQuery(ref).then((response) => {
const data = response.data;
console.log(data.staffs);
console.log(data.vendors);
});
```
@@ -265,6 +265,108 @@ executeQuery(ref).then((response) => {
});
```
## listStaff
You can execute the `listStaff` query using the following action shortcut function, or by calling `executeQuery()` after calling the following `QueryRef` function, both of which are defined in [dataconnect-generated/index.d.ts](./index.d.ts):
```typescript
listStaff(): QueryPromise<ListStaffData, undefined>;
interface ListStaffRef {
...
/* Allow users to create refs without passing in DataConnect */
(): QueryRef<ListStaffData, undefined>;
}
export const listStaffRef: ListStaffRef;
```
You can also pass in a `DataConnect` instance to the action shortcut function or `QueryRef` function.
```typescript
listStaff(dc: DataConnect): QueryPromise<ListStaffData, undefined>;
interface ListStaffRef {
...
(dc: DataConnect): QueryRef<ListStaffData, undefined>;
}
export const listStaffRef: ListStaffRef;
```
If you need the name of the operation without creating a ref, you can retrieve the operation name by calling the `operationName` property on the listStaffRef:
```typescript
const name = listStaffRef.operationName;
console.log(name);
```
### Variables
The `listStaff` query has no variables.
### Return Type
Recall that executing the `listStaff` query returns a `QueryPromise` that resolves to an object with a `data` property.
The `data` property is an object of type `ListStaffData`, which is defined in [dataconnect-generated/index.d.ts](./index.d.ts). It has the following fields:
```typescript
export interface ListStaffData {
staffs: ({
id: UUIDString;
employeeName: string;
vendorId?: UUIDString | null;
email?: string | null;
position?: string | null;
employmentType: EmploymentType;
rating?: number | null;
reliabilityScore?: number | null;
backgroundCheckStatus: BackgroundCheckStatus;
certifications?: string | null;
} & Staff_Key)[];
}
```
### Using `listStaff`'s action shortcut function
```typescript
import { getDataConnect } from 'firebase/data-connect';
import { connectorConfig, listStaff } from '@dataconnect/generated';
// Call the `listStaff()` function to execute the query.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await listStaff();
// You can also pass in a `DataConnect` instance to the action shortcut function.
const dataConnect = getDataConnect(connectorConfig);
const { data } = await listStaff(dataConnect);
console.log(data.staffs);
// Or, you can use the `Promise` API.
listStaff().then((response) => {
const data = response.data;
console.log(data.staffs);
});
```
### Using `listStaff`'s `QueryRef` function
```typescript
import { getDataConnect, executeQuery } from 'firebase/data-connect';
import { connectorConfig, listStaffRef } from '@dataconnect/generated';
// Call the `listStaffRef()` function to get a reference to the query.
const ref = listStaffRef();
// You can also pass in a `DataConnect` instance to the `QueryRef` function.
const dataConnect = getDataConnect(connectorConfig);
const ref = listStaffRef(dataConnect);
// Call `executeQuery()` on the reference to execute the query.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await executeQuery(ref);
console.log(data.staffs);
// Or, you can use the `Promise` API.
executeQuery(ref).then((response) => {
const data = response.data;
console.log(data.staffs);
});
```
# Mutations
There are two ways to execute a Data Connect Mutation using the generated Web SDK:
@@ -552,3 +654,130 @@ executeMutation(ref).then((response) => {
});
```
## CreateVendor
You can execute the `CreateVendor` mutation using the following action shortcut function, or by calling `executeMutation()` after calling the following `MutationRef` function, both of which are defined in [dataconnect-generated/index.d.ts](./index.d.ts):
```typescript
createVendor(vars: CreateVendorVariables): MutationPromise<CreateVendorData, CreateVendorVariables>;
interface CreateVendorRef {
...
/* Allow users to create refs without passing in DataConnect */
(vars: CreateVendorVariables): MutationRef<CreateVendorData, CreateVendorVariables>;
}
export const createVendorRef: CreateVendorRef;
```
You can also pass in a `DataConnect` instance to the action shortcut function or `MutationRef` function.
```typescript
createVendor(dc: DataConnect, vars: CreateVendorVariables): MutationPromise<CreateVendorData, CreateVendorVariables>;
interface CreateVendorRef {
...
(dc: DataConnect, vars: CreateVendorVariables): MutationRef<CreateVendorData, CreateVendorVariables>;
}
export const createVendorRef: CreateVendorRef;
```
If you need the name of the operation without creating a ref, you can retrieve the operation name by calling the `operationName` property on the createVendorRef:
```typescript
const name = createVendorRef.operationName;
console.log(name);
```
### Variables
The `CreateVendor` mutation requires an argument of type `CreateVendorVariables`, which is defined in [dataconnect-generated/index.d.ts](./index.d.ts). It has the following fields:
```typescript
export interface CreateVendorVariables {
vendorNumber: string;
legalName: string;
region: VendorRegion;
platformType: VendorPlatformType;
primaryContactEmail: string;
approvalStatus: VendorApprovalStatus;
isActive?: boolean | null;
}
```
### Return Type
Recall that executing the `CreateVendor` mutation returns a `MutationPromise` that resolves to an object with a `data` property.
The `data` property is an object of type `CreateVendorData`, which is defined in [dataconnect-generated/index.d.ts](./index.d.ts). It has the following fields:
```typescript
export interface CreateVendorData {
vendor_insert: Vendor_Key;
}
```
### Using `CreateVendor`'s action shortcut function
```typescript
import { getDataConnect } from 'firebase/data-connect';
import { connectorConfig, createVendor, CreateVendorVariables } from '@dataconnect/generated';
// The `CreateVendor` mutation requires an argument of type `CreateVendorVariables`:
const createVendorVars: CreateVendorVariables = {
vendorNumber: ...,
legalName: ...,
region: ...,
platformType: ...,
primaryContactEmail: ...,
approvalStatus: ...,
isActive: ..., // optional
};
// Call the `createVendor()` function to execute the mutation.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await createVendor(createVendorVars);
// Variables can be defined inline as well.
const { data } = await createVendor({ vendorNumber: ..., legalName: ..., region: ..., platformType: ..., primaryContactEmail: ..., approvalStatus: ..., isActive: ..., });
// You can also pass in a `DataConnect` instance to the action shortcut function.
const dataConnect = getDataConnect(connectorConfig);
const { data } = await createVendor(dataConnect, createVendorVars);
console.log(data.vendor_insert);
// Or, you can use the `Promise` API.
createVendor(createVendorVars).then((response) => {
const data = response.data;
console.log(data.vendor_insert);
});
```
### Using `CreateVendor`'s `MutationRef` function
```typescript
import { getDataConnect, executeMutation } from 'firebase/data-connect';
import { connectorConfig, createVendorRef, CreateVendorVariables } from '@dataconnect/generated';
// The `CreateVendor` mutation requires an argument of type `CreateVendorVariables`:
const createVendorVars: CreateVendorVariables = {
vendorNumber: ...,
legalName: ...,
region: ...,
platformType: ...,
primaryContactEmail: ...,
approvalStatus: ...,
isActive: ..., // optional
};
// Call the `createVendorRef()` function to get a reference to the mutation.
const ref = createVendorRef(createVendorVars);
// Variables can be defined inline as well.
const ref = createVendorRef({ vendorNumber: ..., legalName: ..., region: ..., platformType: ..., primaryContactEmail: ..., approvalStatus: ..., isActive: ..., });
// You can also pass in a `DataConnect` instance to the `MutationRef` function.
const dataConnect = getDataConnect(connectorConfig);
const ref = createVendorRef(dataConnect, createVendorVars);
// Call `executeMutation()` on the reference to execute the mutation.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await executeMutation(ref);
console.log(data.vendor_insert);
// Or, you can use the `Promise` API.
executeMutation(ref).then((response) => {
const data = response.data;
console.log(data.vendor_insert);
});
```